Skip to content

Commit

Permalink
feat(#341): Création de Services compas
Browse files Browse the repository at this point in the history
- DataSetService
- DoService
- DoTypeService
- ExtRefReaderService
- IedService
- LdeviceService
- LnService
- LnodeTypeService
- renommage de LdeviceStatus en ActiveStatus

Signed-off-by: gleizesDor <115622893+gleizesDor@users.noreply.github.com>
  • Loading branch information
gleizesDor committed Nov 27, 2023
1 parent 7a7f543 commit 2297563
Show file tree
Hide file tree
Showing 79 changed files with 2,670 additions and 793 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgs>--enable-preview</compilerArgs>
</configuration>
</plugin>
<plugin>
Expand All @@ -145,6 +146,11 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<!--keep the existing values using @{argLine} syntax-->
<!-- https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#argLine -->
<argLine>@{argLine} --enable-preview</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.LDeviceAdapter;
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
import org.lfenergy.compas.sct.commons.testhelpers.SclTestMarshaller;

import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
package org.lfenergy.compas.sct.commons;

import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.sct.commons.api.ControlBlockEditor;
import org.lfenergy.compas.sct.commons.dto.*;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.NetworkRanges;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.RangesPerCbType;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.Settings;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.SettingsOrError;
import org.lfenergy.compas.sct.commons.dto.FcdaForDataSetsCreation;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.*;
import org.lfenergy.compas.sct.commons.util.*;
import org.lfenergy.compas.sct.commons.scl.ied.ControlBlockAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
import org.lfenergy.compas.sct.commons.scl.ln.LNAdapter;
import org.lfenergy.compas.sct.commons.util.ControlBlockEnum;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.*;
import java.util.stream.Stream;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: 2022 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.lfenergy.compas.scl2007b4.model.LN0;
import org.lfenergy.compas.scl2007b4.model.TAnyLN;
import org.lfenergy.compas.scl2007b4.model.TDataSet;
import org.lfenergy.compas.scl2007b4.model.TLN;

import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class DataSetService {

public Stream<TDataSet> getDataSets(TAnyLN tAnyLN) {
return switch (tAnyLN) {
case LN0 ln0 -> ln0.isSetDataSet() ? ln0.getDataSet().stream() : Stream.empty();
case TLN tln -> tln.isSetDataSet() ? tln.getDataSet().stream() : Stream.empty();
default -> throw new IllegalStateException("Unexpected value: " + tAnyLN);
};
}

public Stream<TDataSet> getFilteredDataSets(TAnyLN tAnyLN, Predicate<TDataSet> dataSetPredicate) {
return getDataSets(tAnyLN).filter(dataSetPredicate);
}

public Optional<TDataSet> findDataSet(TAnyLN tAnyLN, Predicate<TDataSet> dataSetPredicate) {
return getFilteredDataSets(tAnyLN, dataSetPredicate).findFirst();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.lfenergy.compas.scl2007b4.model.TDO;
import org.lfenergy.compas.scl2007b4.model.TLNodeType;

import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class DoService {

public Stream<TDO> getDos(TLNodeType tlNodeType) {
return tlNodeType.getDO().stream();
}

public Stream<TDO> getFilteredDos(TLNodeType tlNodeType, Predicate<TDO> tdoPredicate) {
return getDos(tlNodeType).filter(tdoPredicate);
}

public Optional<TDO> findDo(TLNodeType tlNodeType, Predicate<TDO> tdoPredicate) {
return getFilteredDos(tlNodeType, tdoPredicate).findFirst();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.lfenergy.compas.scl2007b4.model.TDataTypeTemplates;
import org.lfenergy.compas.scl2007b4.model.TDOType;

import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class DoTypeService {

public Stream<TDOType> getDoTypes(TDataTypeTemplates tDataTypeTemplates) {
return tDataTypeTemplates.getDOType().stream();
}

public Stream<TDOType> getFilteredDoTypes(TDataTypeTemplates tDataTypeTemplates, Predicate<TDOType> tdoTypePredicate) {
return getDoTypes(tDataTypeTemplates).filter(tdoTypePredicate);
}

public Optional<TDOType> findDoType(TDataTypeTemplates tDataTypeTemplates, Predicate<TDOType> tdoTypePredicate) {
return getFilteredDoTypes(tDataTypeTemplates, tdoTypePredicate).findFirst();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: 2022 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.lfenergy.compas.scl2007b4.model.LN0;
import org.lfenergy.compas.scl2007b4.model.TAnyLN;
import org.lfenergy.compas.scl2007b4.model.TExtRef;
import org.lfenergy.compas.scl2007b4.model.TLN;
import org.lfenergy.compas.sct.commons.api.ExtRefReader;

import java.util.stream.Stream;

public class ExtRefReaderService implements ExtRefReader {

public Stream<TExtRef> getExtRefs(TAnyLN tAnyLN) {
return switch (tAnyLN) {
case LN0 ln0 -> ln0.isSetInputs() ? ln0.getInputs().getExtRef().stream() : Stream.empty();
case TLN tln -> tln.isSetInputs() ? tln.getInputs().getExtRef().stream() : Stream.empty();
default -> throw new IllegalStateException("Unexpected value: " + tAnyLN);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@
import org.lfenergy.compas.sct.commons.api.ExtRefEditor;
import org.lfenergy.compas.sct.commons.dto.*;
import org.lfenergy.compas.sct.commons.exception.ScdException;
import org.lfenergy.compas.sct.commons.model.epf.*;
import org.lfenergy.compas.sct.commons.model.epf.EPF;
import org.lfenergy.compas.sct.commons.model.epf.TCBscopeType;
import org.lfenergy.compas.sct.commons.model.epf.TChannel;
import org.lfenergy.compas.sct.commons.model.epf.TChannelType;
import org.lfenergy.compas.sct.commons.scl.SclRootAdapter;
import org.lfenergy.compas.sct.commons.scl.ied.*;
import org.lfenergy.compas.sct.commons.util.*;
import org.lfenergy.compas.sct.commons.scl.ied.IEDAdapter;
import org.lfenergy.compas.sct.commons.scl.ldevice.LDeviceAdapter;
import org.lfenergy.compas.sct.commons.scl.ln.AbstractLNAdapter;
import org.lfenergy.compas.sct.commons.scl.ln.LN0Adapter;
import org.lfenergy.compas.sct.commons.util.ActiveStatus;
import org.lfenergy.compas.sct.commons.util.PrivateEnum;
import org.lfenergy.compas.sct.commons.util.PrivateUtils;
import org.lfenergy.compas.sct.commons.util.Utils;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.apache.commons.lang3.StringUtils.*;
import static org.lfenergy.compas.sct.commons.util.CommonConstants.*;
import static org.lfenergy.compas.sct.commons.util.Utils.*;
import static org.lfenergy.compas.sct.commons.util.Utils.isExtRefFeedBySameControlBlock;

public class ExtRefService implements ExtRefEditor {
private static final String INVALID_OR_MISSING_ATTRIBUTES_IN_EXT_REF_BINDING_INFO = "Invalid or missing attributes in ExtRef binding info";
Expand Down Expand Up @@ -217,7 +226,9 @@ private static List<TIED> getIedSources(SclRootAdapter sclRootAdapter, TCompasBa
.map(lnAdapter -> isValidDataTypeTemplate(lnAdapter, channel))
.orElse(false))
.orElse(false))
.map(IEDAdapter::getCurrentElem).limit(2).toList();
.map(IEDAdapter::getCurrentElem)
.limit(2)
.toList();
}

/**
Expand Down Expand Up @@ -259,10 +270,10 @@ private static boolean doesIcdHeaderMatchLDEPFChannel(IEDAdapter iedAdapter, TCh
* @return LDeviceAdapter object that matches the EPF channel
*/
private static Optional<LDeviceAdapter> getActiveSourceLDeviceByLDEPFChannel(IEDAdapter iedAdapter, TChannel channel) {
return iedAdapter.findLDeviceAdapterByLdInst(channel.getLDInst())
.filter(lDeviceAdapter -> new Ldevice(lDeviceAdapter.getCurrentElem()).getLdeviceStatus()
.map(status -> status.equals(LdeviceStatus.ON))
.orElse(false));
LdeviceService ldeviceService = new LdeviceService();
return ldeviceService.findLdevice(iedAdapter.getCurrentElem(), tlDevice -> tlDevice.getInst().equals(channel.getLDInst()))
.filter(tlDevice -> ldeviceService.getLdeviceStatus(tlDevice).map(ActiveStatus.ON::equals).orElse(false))
.map(tlDevice -> new LDeviceAdapter(iedAdapter, tlDevice));
}

/**
Expand All @@ -272,13 +283,14 @@ private static Optional<LDeviceAdapter> getActiveSourceLDeviceByLDEPFChannel(IED
* @return AbstractLNAdapter object that matches the EPF channel
*/
private static Optional<AbstractLNAdapter<?>> getActiveLNSourceByLDEPFChannel(LDeviceAdapter lDeviceAdapter, TChannel channel) {
return lDeviceAdapter.getLNAdaptersIncludingLN0().stream()
return lDeviceAdapter.getLNAdaptersIncludingLN0()
.stream()
.filter(lnAdapter -> lnAdapter.getLNClass().equals(channel.getLNClass())
&& lnAdapter.getLNInst().equals(channel.getLNInst())
&& trimToEmpty(channel.getLNPrefix()).equals(trimToEmpty(lnAdapter.getPrefix())))
.findFirst()
.filter(lnAdapter -> lnAdapter.getDaiModStValValue()
.map(status -> status.equals(LdeviceStatus.ON.getValue()))
.map(status -> status.equals(ActiveStatus.ON.getValue()))
.orElse(true));
}

Expand Down Expand Up @@ -308,7 +320,7 @@ private static boolean isValidDataTypeTemplate(AbstractLNAdapter<?> lnAdapter, T
return lnAdapter.getDataTypeTemplateAdapter().getLNodeTypeAdapterById(lnAdapter.getLnType())
.filter(lNodeTypeAdapter -> {
try {
lNodeTypeAdapter.check(doTypeName, daTypeName);
lNodeTypeAdapter.checkDoAndDaTypeName(doTypeName, daTypeName);
} catch (ScdException ex) {
return false;
}
Expand Down Expand Up @@ -358,7 +370,7 @@ private Optional<SclReportItem> updateVal(AbstractLNAdapter<?> lnAdapter, String
case DU_DA_NAME -> setting.getChannelShortLabel();
case SETVAL_DA_NAME ->
LN_PREFIX_B.equals(lnAdapter.getPrefix()) || LN_PREFIX_A.equals(lnAdapter.getPrefix()) ? setting.getChannelLevModQ().value() : setting.getChannelLevMod().value();
case STVAL_DA_NAME -> LdeviceStatus.ON.getValue();
case STVAL_DA_NAME -> ActiveStatus.ON.getValue();
case SETSRCREF_DA_NAME -> computeDaiValue(lnAdapter, extRef, setting.getDAName());
default -> null;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TIED;

import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class IedService {

public Stream<TIED> getFilteredIeds(SCL scd, Predicate<TIED> iedPredicate) {
return scd.getIED().stream().filter(iedPredicate);
}

public Optional<TIED> findIed(SCL scd, Predicate<TIED> iedPredicate) {
return getFilteredIeds(scd, iedPredicate).findFirst();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons;

import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.util.ActiveStatus;

import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class LdeviceService {

public Stream<TLDevice> getLdevices(TIED tied) {
if (!tied.isSetAccessPoint()) {
return Stream.empty();
}
return tied.getAccessPoint()
.stream()
.map(TAccessPoint::getServer)
.filter(Objects::nonNull)
.filter(TServer::isSetLDevice)
.flatMap(tServer -> tServer.getLDevice().stream());
}

public Stream<TLDevice> getActiveLdevices(TIED tied) {
return getLdevices(tied)
.filter(ldevice -> getLdeviceStatus(ldevice).map(ActiveStatus.ON::equals).orElse(false));
}

public Stream<TLDevice> getFilteredLdevices(TIED tied, Predicate<TLDevice> ldevicePredicate) {
return getLdevices(tied).filter(ldevicePredicate);
}

public Optional<TLDevice> findLdevice(TIED tied, Predicate<TLDevice> ldevicePredicate) {
return getFilteredLdevices(tied, ldevicePredicate).findFirst();
}

public Optional<ActiveStatus> getLdeviceStatus(TLDevice tlDevice) {
LnService lnService = new LnService();
return lnService.getDaiModStval(tlDevice.getLN0());
}
}
Loading

0 comments on commit 2297563

Please sign in to comment.