Skip to content

Commit

Permalink
refactor(#110): give PrivateService the new name PrivateUtils and cha…
Browse files Browse the repository at this point in the history
…nge the package from scl to util.

Changing the name of PrivateService to PrivateUtils and move it from scl to util package , closes #110

BREAKING CHANGE: 💥 in sct-commons:
    The services which provide static methods are moved from scl to service package.
    Now  those services implements interfaces, no static methods.
    ℹ️ Expect for PrivateService which is an UtilityClass is renamed to PrivateUtils and moved from scl to util package.

Signed-off-by: Samir Romdhani <[email protected]>
  • Loading branch information
samirromdhani committed Aug 23, 2023
1 parent be9ba23 commit 7ae1629
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.ObjectReference;
import org.lfenergy.compas.sct.commons.scl.PrivateService;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.util.MonitoringLnClassEnum;
Expand Down Expand Up @@ -322,7 +322,7 @@ public Optional<TPrivate> getPrivateHeader(String privateType) {
* @return value of private compas:Bay if present, empty Optional otherwise
*/
public Optional<TCompasBay> getPrivateCompasBay() {
return PrivateService.extractCompasPrivate(currentElem, TCompasBay.class);
return PrivateUtils.extractCompasPrivate(currentElem, TCompasBay.class);
}

/**
Expand Down Expand Up @@ -374,7 +374,7 @@ private Stream<AccessPointAdapter> streamAccessPointAdapters() {
* @return COMPAS-ICDHeader private value if present, else empty Optional
*/
public Optional<TCompasICDHeader> getCompasICDHeader() {
return PrivateService.extractCompasPrivate(currentElem, TCompasICDHeader.class);
return PrivateUtils.extractCompasPrivate(currentElem, TCompasICDHeader.class);
}

/**
Expand All @@ -383,7 +383,7 @@ public Optional<TCompasICDHeader> getCompasICDHeader() {
* @return COMPAS-SystemVersion private value if present, else empty Optional
*/
public Optional<TCompasSystemVersion> getCompasSystemVersion() {
return PrivateService.extractCompasPrivate(currentElem, TCompasSystemVersion.class);
return PrivateUtils.extractCompasPrivate(currentElem, TCompasSystemVersion.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.lfenergy.compas.sct.commons.dto.DataAttributeRef;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.PrivateService;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.service.impl.ExtRefService;
Expand Down Expand Up @@ -136,7 +136,7 @@ private Optional<SclReportItem> updateExtRefIedName(TExtRef extRef, IEDAdapter s
clearBinding(extRef);
return sourceValidationError;
}
String sourceIedName = PrivateService.extractCompasPrivate(sourceIed.getCurrentElem(), TCompasICDHeader.class)
String sourceIedName = PrivateUtils.extractCompasPrivate(sourceIed.getCurrentElem(), TCompasICDHeader.class)
.map(TCompasICDHeader::getIEDName).orElse("");
extRef.setIedName(sourceIedName);
compasFlow.setExtRefiedName(sourceIedName);
Expand Down Expand Up @@ -226,7 +226,7 @@ private String extRefXPath(String extRefDesc) {
* @return list of matching CompasFlows
*/
private List<TCompasFlow> getMatchingCompasFlows(TExtRef extRef) {
return PrivateService.extractCompasPrivates(currentElem, TCompasFlow.class)
return PrivateUtils.extractCompasPrivates(currentElem, TCompasFlow.class)
.filter(compasFlow -> isMatchingExtRef(compasFlow, extRef))
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.lfenergy.compas.sct.commons.dto.*;
import org.lfenergy.compas.sct.commons.scl.LDeviceActivation;
import org.lfenergy.compas.sct.commons.scl.ObjectReference;
import org.lfenergy.compas.sct.commons.scl.PrivateService;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -187,7 +187,7 @@ public Optional<SclReportItem> updateLDeviceStatus(List<Pair<String, String>> ie
return Optional.of(buildFatalReportItem("The LDevice doesn't have a DO @name='Beh' OR its associated DA@fc='ST' AND DA@name='stVal'"));
}
Set<String> enumValues = getEnumValues(daiBehList.get(0).getDaName().getType());
Optional<TCompasLDevice> optionalTCompasLDevice = PrivateService.extractCompasPrivate(getParentAdapter().getCurrentElem(), TCompasLDevice.class);
Optional<TCompasLDevice> optionalTCompasLDevice = PrivateUtils.extractCompasPrivate(getParentAdapter().getCurrentElem(), TCompasLDevice.class);
if (optionalTCompasLDevice.isEmpty()) {
return Optional.of(buildFatalReportItem("The LDevice doesn't have a Private compas:LDevice."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import lombok.NonNull;
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.PrivateService;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
import org.lfenergy.compas.sct.commons.service.impl.SubstationService;
import org.lfenergy.compas.sct.commons.scl.sstation.SubstationAdapter;
import org.lfenergy.compas.sct.commons.scl.sstation.VoltageLevelAdapter;
Expand All @@ -26,7 +26,7 @@
* @see org.lfenergy.compas.sct.commons.scl.sstation.BayAdapter
* @see org.lfenergy.compas.sct.commons.scl.sstation.FunctionAdapter
* @see org.lfenergy.compas.sct.commons.scl.sstation.LNodeAdapter
* @see PrivateService
* @see PrivateUtils
*/
public interface ISubstationService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.lfenergy.compas.sct.commons.dto.LDEPFSettingData;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.PrivateService;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.*;
import org.lfenergy.compas.sct.commons.service.IExtRefService;
Expand Down Expand Up @@ -153,7 +153,7 @@ private List<SclReportItem> checkIedCompasIcdHeaderAttributes(SclRootAdapter scl

private List<SclReportItem> checkIedUnityOfIcdSystemVersionUuid(SclRootAdapter sclRootAdapter) {
Map<String, List<TIED>> systemVersionToIedList = sclRootAdapter.getCurrentElem().getIED().stream()
.collect(Collectors.groupingBy(ied -> PrivateService.extractCompasPrivate(ied, TCompasICDHeader.class)
.collect(Collectors.groupingBy(ied -> PrivateUtils.extractCompasPrivate(ied, TCompasICDHeader.class)
.map(TCompasICDHeader::getICDSystemVersionUUID)
.orElse("")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct. commons.dto.*;
import org.lfenergy.compas.sct. commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.PrivateService;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct. commons.scl.com.CommunicationAdapter;
import org.lfenergy.compas.sct. commons.scl.com.ConnectedAPAdapter;
Expand All @@ -37,7 +37,7 @@ public class SclService implements ISclService {
@Override
public SCL initScl(final UUID hId, final String hVersion, final String hRevision) throws ScdException {
SclRootAdapter scdAdapter = new SclRootAdapter(hId.toString(), hVersion, hRevision);
scdAdapter.addPrivate(org.lfenergy.compas.sct.commons.scl.PrivateService.createPrivate(TCompasSclFileType.SCD));
scdAdapter.addPrivate(PrivateUtils.createPrivate(TCompasSclFileType.SCD));
return scdAdapter.getCurrentElem();
}

Expand Down Expand Up @@ -282,13 +282,13 @@ public Set<EnumValDTO> getEnumTypeValues(SCL scd, String idEnum) throws ScdExcep
public void importSTDElementsInSCD(SCL scd, List<SCL> stds, List<SubNetworkTypeDTO> subNetworkTypes) throws ScdException {

//Check SCD and STD compatibilities
Map<String, org.lfenergy.compas.sct.commons.scl.PrivateService.PrivateLinkedToSTDs> mapICDSystemVersionUuidAndSTDFile = org.lfenergy.compas.sct.commons.scl.PrivateService.createMapICDSystemVersionUuidAndSTDFile(stds);
org.lfenergy.compas.sct.commons.scl.PrivateService.checkSTDCorrespondanceWithLNodeCompasICDHeader(mapICDSystemVersionUuidAndSTDFile);
Map<String, PrivateUtils.PrivateLinkedToSTDs> mapICDSystemVersionUuidAndSTDFile = PrivateUtils.createMapICDSystemVersionUuidAndSTDFile(stds);
PrivateUtils.checkSTDCorrespondanceWithLNodeCompasICDHeader(mapICDSystemVersionUuidAndSTDFile);
// List all Private and remove duplicated one with same iedName
// For each Private.ICDSystemVersionUUID and Private.iedName find STD File
List<String> iedNamesUsed = new ArrayList<>();
SclRootAdapter scdRootAdapter = new SclRootAdapter(scd);
org.lfenergy.compas.sct.commons.scl.PrivateService.streamIcdHeaders(scd)
PrivateUtils.streamIcdHeaders(scd)
.forEach(icdHeader -> {
if (!iedNamesUsed.contains(icdHeader.getIedName())) {
String iedName = icdHeader.getIedName();
Expand All @@ -301,8 +301,8 @@ public void importSTDElementsInSCD(SCL scd, List<SCL> stds, List<SubNetworkTypeD
SclRootAdapter stdRootAdapter = new SclRootAdapter(std);
IEDAdapter stdIedAdapter = new IEDAdapter(stdRootAdapter, std.getIED().get(0));
Optional<TPrivate> optionalTPrivate = stdIedAdapter.getPrivateHeader(COMPAS_ICDHEADER.getPrivateType());
if (optionalTPrivate.isPresent() && optionalTPrivate.flatMap(org.lfenergy.compas.sct.commons.scl.PrivateService::extractCompasICDHeader).map(IcdHeader::new).get().equals(icdHeader)) {
PrivateService.copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate(optionalTPrivate.get(), icdHeader.toTCompasICDHeader());
if (optionalTPrivate.isPresent() && optionalTPrivate.flatMap(PrivateUtils::extractCompasICDHeader).map(IcdHeader::new).get().equals(icdHeader)) {
PrivateUtils.copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate(optionalTPrivate.get(), icdHeader.toTCompasICDHeader());
} else throw new ScdException("COMPAS-ICDHeader is not the same in Substation and in IED");
scdRootAdapter.addIED(std, iedName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons.scl;
package org.lfenergy.compas.sct.commons.util;

import lombok.NonNull;
import lombok.experimental.UtilityClass;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.icd.IcdHeader;
import org.lfenergy.compas.sct.commons.util.PrivateEnum;

import javax.xml.bind.JAXBElement;
import java.util.*;
Expand All @@ -20,18 +19,18 @@
import static org.lfenergy.compas.sct.commons.util.PrivateEnum.COMPAS_ICDHEADER;

/**
* A representation of the <em><b>{@link PrivateService PrivateService}</b></em>.
* A representation of the <em><b>{@link PrivateUtils PrivateService}</b></em>.
* <p>
* The following features are supported:
* </p>
* <ol>
* <li>{@link PrivateService#extractCompasPrivates(TBaseElement, Class)
* <li>{@link PrivateUtils#extractCompasPrivates(TBaseElement, Class)
* <em>Returns the value of the <b>TPrivate </b> containment reference list from given <b>TBaseElement </b> By class type</em>}</li>
* </ol>
* @see org.lfenergy.compas.scl2007b4.model.TPrivate
*/
@UtilityClass
public final class PrivateService {
public final class PrivateUtils {

private static final ObjectFactory objectFactory = new ObjectFactory();

Expand Down Expand Up @@ -194,7 +193,7 @@ public static Map<String, PrivateLinkedToSTDs> createMapICDSystemVersionUuidAndS
stds.forEach(std -> std.getIED()
.forEach(ied -> ied.getPrivate()
.forEach(tp ->
PrivateService.extractCompasICDHeader(tp)
PrivateUtils.extractCompasICDHeader(tp)
.map(TCompasICDHeader::getICDSystemVersionUUID)
.ifPresent(icdSysVer -> {
PrivateLinkedToSTDs privateLinkedToSTDs = icdSysVerToPrivateStdsMap.get(icdSysVer);
Expand Down Expand Up @@ -236,7 +235,7 @@ public static void checkSTDCorrespondanceWithLNodeCompasICDHeader(Map<String, Pr
* @throws ScdException throws when parameter not present in Private
*/
public static String stdCheckFormatExceptionMessage(TPrivate key) throws ScdException {
Optional<TCompasICDHeader> optionalCompasICDHeader = PrivateService.extractCompasICDHeader(key);
Optional<TCompasICDHeader> optionalCompasICDHeader = PrivateUtils.extractCompasICDHeader(key);
return HEADER_ID + " = " + optionalCompasICDHeader.map(TCompasICDHeader::getHeaderId).orElse(null) + " " +
HEADER_VERSION + " = " + optionalCompasICDHeader.map(TCompasICDHeader::getHeaderVersion).orElse(null) + " " +
HEADER_REVISION + " = " + optionalCompasICDHeader.map(TCompasICDHeader::getHeaderRevision).orElse(null) +
Expand All @@ -259,7 +258,7 @@ public static Stream<IcdHeader> streamIcdHeaders(SCL scd) {
.map(TBay::getFunction).flatMap(Collection::stream)
.map(TFunction::getLNode).flatMap(Collection::stream)
.map(TLNode::getPrivate).flatMap(Collection::stream)
.map(PrivateService::extractCompasICDHeader)
.map(PrivateUtils::extractCompasICDHeader)
.filter(Optional::isPresent)
.map(Optional::get)
.map(IcdHeader::new);
Expand All @@ -274,9 +273,9 @@ public static Stream<IcdHeader> streamIcdHeaders(SCL scd) {
* @throws ScdException throws when Private is not COMPAS_ICDHEADER one
*/
public static boolean comparePrivateCompasICDHeaders(TPrivate iedPrivate, TPrivate scdPrivate) throws ScdException {
TCompasICDHeader iedCompasICDHeader = PrivateService.extractCompasICDHeader(iedPrivate)
TCompasICDHeader iedCompasICDHeader = PrivateUtils.extractCompasICDHeader(iedPrivate)
.orElseThrow(() -> new ScdException(COMPAS_ICDHEADER + "not found in IED Private "));
TCompasICDHeader scdCompasICDHeader = PrivateService.extractCompasICDHeader(scdPrivate)
TCompasICDHeader scdCompasICDHeader = PrivateUtils.extractCompasICDHeader(scdPrivate)
.orElseThrow(() -> new ScdException(COMPAS_ICDHEADER + "not found in LNode Private "));
return Objects.equals(iedCompasICDHeader.getIEDType(), scdCompasICDHeader.getIEDType())
&& Objects.equals(iedCompasICDHeader.getICDSystemVersionUUID(), scdCompasICDHeader.getICDSystemVersionUUID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package org.lfenergy.compas.scl2007b4.model;

import org.junit.jupiter.api.Test;
import org.lfenergy.compas.sct.commons.scl.PrivateService;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
import org.lfenergy.compas.sct.commons.testhelpers.MarshallerWrapper;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -16,7 +16,7 @@ class NamespaceConfigurationTest {
void marshalling_SCL_and_Compas_Privates_should_set_correct_prefix() {
// Given
SCL scl = createValidScl();
TPrivate aCompasPrivate = PrivateService.createPrivate(TCompasSclFileType.SCD);
TPrivate aCompasPrivate = PrivateUtils.createPrivate(TCompasSclFileType.SCD);
scl.getPrivate().add(aCompasPrivate);
// When
String result = MarshallerWrapper.marshall(scl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TDurationInMilliSec;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.SettingsOrError;
import org.lfenergy.compas.sct.commons.scl.PrivateService;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.ControlBlockAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
Expand Down Expand Up @@ -193,7 +193,7 @@ void getNetworkSettings_should_return_null_when_missing_ied_private(PrivateEnum
//Given
SCL scd = SclTestMarshaller.getSCLFromFile("/scd-extref-create-dataset-and-controlblocks/scd_create_controlblock_network_configuration.xml");
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
PrivateService.removePrivates(findIed(sclRootAdapter.getCurrentElem(), "IED_NAME2").getCurrentElem(), missingPrivate);
PrivateUtils.removePrivates(findIed(sclRootAdapter.getCurrentElem(), "IED_NAME2").getCurrentElem(), missingPrivate);
ControlBlockAdapter controlBlockAdapter = findControlBlock(sclRootAdapter.getCurrentElem(), "IED_NAME2", "LD_INST21", "CB_LD_INST21_GSI", ControlBlockEnum.GSE);

//When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.ObjectReference;
import org.lfenergy.compas.sct.commons.scl.PrivateService;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;
import org.lfenergy.compas.sct.commons.util.MonitoringLnClassEnum;
Expand Down Expand Up @@ -291,7 +291,7 @@ void getCompasICDHeader_should_return_compas_icd_header(){
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName("IED_NAME");
TCompasICDHeader tCompasICDHeader = new TCompasICDHeader();
tCompasICDHeader.setHeaderId("HEADER_ID");
iedAdapter.getCurrentElem().getPrivate().add(PrivateService.createPrivate(tCompasICDHeader));
iedAdapter.getCurrentElem().getPrivate().add(PrivateUtils.createPrivate(tCompasICDHeader));

// When
Optional<TCompasICDHeader> compasICDHeader = iedAdapter.getCompasICDHeader();
Expand All @@ -307,7 +307,7 @@ void getCompasSystemVersion_should_return_compas_icd_header(){
IEDAdapter iedAdapter = sclRootAdapter.getIEDAdapterByName("IED_NAME");
TCompasSystemVersion tCompasSystemVersion = new TCompasSystemVersion();
tCompasSystemVersion.setMainSystemVersion("01.00");
iedAdapter.getCurrentElem().getPrivate().add(PrivateService.createPrivate(tCompasSystemVersion));
iedAdapter.getCurrentElem().getPrivate().add(PrivateUtils.createPrivate(tCompasSystemVersion));

// When
Optional<TCompasSystemVersion> compasSystemVersion = iedAdapter.getCompasSystemVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.junit.platform.commons.support.HierarchyTraversalMode;
import org.junit.platform.commons.support.ReflectionSupport;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.scl.PrivateService;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;

import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
Expand Down Expand Up @@ -60,7 +60,7 @@ void addPrivate_should_succeed() {
// Given
TLNode tlNode = new TLNode();
LNodeAdapter lNodeAdapter = new LNodeAdapter(null, tlNode);
TPrivate tPrivate = PrivateService.createPrivate(TCompasSclFileType.SCD);
TPrivate tPrivate = PrivateUtils.createPrivate(TCompasSclFileType.SCD);
// When
lNodeAdapter.addPrivate(tPrivate);
// Then
Expand All @@ -87,7 +87,7 @@ void deepCopy_should_succeed() {
tText.getContent().add("Text1");
tText.getOtherAttributes().put(QName.valueOf("Text1_attribute1"), "Text1_value1");
tlNode.setText(tText);
tlNode.getPrivate().add(PrivateService.createPrivate(TCompasSclFileType.SCD));
tlNode.getPrivate().add(PrivateUtils.createPrivate(TCompasSclFileType.SCD));
tlNode.getOtherAttributes().put(QName.valueOf("tlNode_attribute1"), "tlNode_value1");
LNodeAdapter lNodeAdapter = new LNodeAdapter(null, tlNode);
// When
Expand Down
Loading

0 comments on commit 7ae1629

Please sign in to comment.