Skip to content

Commit

Permalink
Merge pull request #268 from com-pas/develop
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
AliouDIAITE authored Apr 4, 2023
2 parents adebd26 + 2e44581 commit 7a7f680
Show file tree
Hide file tree
Showing 30 changed files with 1,671 additions and 271 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: Release Project

on:
release:
types: [ released ]
types: [ published ]

jobs:
publish:
Expand Down Expand Up @@ -42,4 +42,4 @@ jobs:
- name: Deploy with Maven to GitHub Packages
run: mvn --batch-mode -s custom_maven_settings.xml clean deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-FileCopyrightText: 2023 RTE FRANCE
//
// SPDX-License-Identifier: Apache-2.0

package org.lfenergy.compas.sct.commons.dto;

import java.util.List;

/**
* Represents a list of LDEPF settings
* This is a functional interface whose functional method is getLDEPFSettings
* the type of the input to the operation
*
* @param <T> the type of the result of the LDEPFSettings
*
* @see org.lfenergy.compas.sct.commons.util.SettingLDEPFCsvHelper
*/
@FunctionalInterface
public interface LDEPFSettings<T> {

/**
* This method provides list of LDEPF settings
*/
List<T> getSettings();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.*;
import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.scl.ied.AbstractLNAdapter;
import org.lfenergy.compas.sct.commons.util.SclConstructorHelper;

import java.util.ArrayList;
Expand Down Expand Up @@ -50,12 +51,25 @@ public class ResumedDataTemplate {
@NonNull
private DaTypeName daName = new DaTypeName("");

/**
* Constructor
*/
public ResumedDataTemplate(AbstractLNAdapter<?> lnAdapter, String doName, String daName) {
this.lnClass = lnAdapter.getLNClass();
this.lnInst = lnAdapter.getLNInst();
this.prefix = lnAdapter.getPrefix();
this.lnType = lnAdapter.getLnType();
this.doName = new DoTypeName(doName);
this.daName = new DaTypeName(daName);
}

/**
* Copies summarized DataTypeTemplate information to another one
*
* @param dtt input
* @return Updated ResumedDataTemplate object
*/
public static ResumedDataTemplate copyFrom(ResumedDataTemplate dtt){
public static ResumedDataTemplate copyFrom(ResumedDataTemplate dtt) {
ResumedDataTemplate resumedDataTemplate = new ResumedDataTemplate();
resumedDataTemplate.prefix = dtt.prefix;
resumedDataTemplate.lnClass = dtt.lnClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.apache.commons.lang3.StringUtils;
import org.lfenergy.compas.scl2007b4.model.SCL;
import org.lfenergy.compas.scl2007b4.model.TCompasICDHeader;
import org.lfenergy.compas.scl2007b4.model.TExtRef;
import org.lfenergy.compas.scl2007b4.model.TIED;
import org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings;
import org.lfenergy.compas.sct.commons.dto.SclReport;
Expand All @@ -27,6 +28,7 @@
import java.util.stream.Stream;

import static org.lfenergy.compas.sct.commons.dto.ControlBlockNetworkSettings.*;
import static org.lfenergy.compas.sct.commons.util.Utils.isExtRefFeedBySameControlBlock;

@UtilityClass
public class ExtRefService {
Expand Down Expand Up @@ -226,4 +228,19 @@ private static Optional<SclReportItem> configureControlBlockNetwork(ControlBlock
return controlBlockAdapter.configureNetwork(appIdIterator.nextLong(), macAddressIterator.next(), settings.vlanId(), settings.vlanPriority(),
settings.minTime(), settings.maxTime());
}


/**
* Remove ExtRef which are fed by same Control Block
*
* @return list ExtRefs without duplication
*/
public static List<TExtRef> filterDuplicatedExtRefs(List<TExtRef> tExtRefs) {
List<TExtRef> filteredList = new ArrayList<>();
tExtRefs.forEach(tExtRef -> {
if (filteredList.stream().noneMatch(t -> isExtRefFeedBySameControlBlock(tExtRef, t)))
filteredList.add(tExtRef);
});
return filteredList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public class SclService {

private static final String UNKNOWN_LDEVICE_S_IN_IED_S = "Unknown LDevice (%s) in IED (%s)";
private static final String INVALID_OR_MISSING_ATTRIBUTES_IN_EXT_REF_BINDING_INFO = "Invalid or missing attributes in ExtRef binding info";
private static final String IED_TEST_NAME = "IEDTEST";

private SclService() {
throw new IllegalStateException("SclService class");
Expand Down Expand Up @@ -609,4 +610,20 @@ public static SclReport updateDoInRef(SCL scd) {
.toList();
return new SclReport(sclRootAdapter, sclReportItems);
}

/**
* Update and/or create Monitoring LNs (LSVS and LGOS) for bound GOOSE and SMV Control Blocks
*
* @param scd SCL file for which LNs (LSVS and LGOS) should be updated and/or created in each LDevice LDSUIED with matching ExtRef information
* @return SclReport Object that contain SCL file and set of errors
*/
public static SclReport manageMonitoringLns(SCL scd) {
SclRootAdapter sclRootAdapter = new SclRootAdapter(scd);
List<SclReportItem> sclReportItems = sclRootAdapter.streamIEDAdapters()
.filter(iedAdapter -> !iedAdapter.getName().contains(IED_TEST_NAME))
.map(IEDAdapter::manageMonitoringLns)
.flatMap(List::stream)
.toList();
return new SclReport(sclRootAdapter, sclReportItems);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.lfenergy.compas.sct.commons.scl.ExtRefService.filterDuplicatedExtRefs;

/**
* A representation of the model object
* <em><b>{@link org.lfenergy.compas.scl2007b4.model.TAccessPoint AccessPoint}</b></em>.
Expand All @@ -35,7 +37,6 @@
public class AccessPointAdapter extends SclElementAdapter<IEDAdapter, TAccessPoint> {

public static final long MAX_OCCURRENCE_NO_LIMIT_VALUE = -1L;
private static final String CLIENT_IED_NAME = "The Client IED ";

/**
* Constructor
Expand Down Expand Up @@ -219,7 +220,7 @@ public Optional<SclReportItem> checkLimitationForBoundIedFcdas(List<TExtRef> tEx
* @param sclReportItems
* @param tExtRefs
*/
record ExtRefAnalyzeRecord(List<SclReportItem> sclReportItems, List<TExtRef> tExtRefs) {
public record ExtRefAnalyzeRecord(List<SclReportItem> sclReportItems, List<TExtRef> tExtRefs) {
}

/**
Expand All @@ -229,21 +230,20 @@ record ExtRefAnalyzeRecord(List<SclReportItem> sclReportItems, List<TExtRef> tEx
*/
public ExtRefAnalyzeRecord getAllCoherentExtRefForAnalyze() {
List<SclReportItem> sclReportItems = new ArrayList<>();
List<TExtRef> tExtRefList = new ArrayList<>();
streamLDeviceAdapters().map(lDeviceAdapter -> {
List<TExtRef> extRefs = lDeviceAdapter.getLN0Adapter().getExtRefs().stream().filter(TExtRef::isSetSrcCBName).collect(Collectors.toCollection(ArrayList::new));
sclReportItems.addAll(checkExtRefWithoutServiceType(extRefs, lDeviceAdapter.getLN0Adapter().getXPath()));
extRefs.removeIf(tExtRef -> !tExtRef.isSetServiceType());
return extRefs;
}).flatMap(Collection::stream).forEach(tExtRef -> {
if (tExtRefList.isEmpty())
tExtRefList.add(tExtRef);
else {
if (tExtRefList.stream().noneMatch(t -> isExtRefFeedBySameControlBlock(tExtRef, t)))
tExtRefList.add(tExtRef);
}
});
return new ExtRefAnalyzeRecord(sclReportItems, tExtRefList);
List<TExtRef> tExtRefList = streamLDeviceAdapters()
.map(LDeviceAdapter::getLN0Adapter)
.map(ln0Adapter -> {
List<TExtRef> extRefs = new ArrayList<>();
if (ln0Adapter.hasInputs()) {
extRefs.addAll(ln0Adapter.getInputsAdapter().filterDuplicatedExtRefs()
.stream().filter(TExtRef::isSetSrcCBName).collect(Collectors.toCollection(ArrayList::new)));
sclReportItems.addAll(checkExtRefWithoutServiceType(extRefs, ln0Adapter.getXPath()));
extRefs.removeIf(tExtRef -> !tExtRef.isSetServiceType());
}
return extRefs;
}).flatMap(Collection::stream)
.toList();
return new ExtRefAnalyzeRecord(sclReportItems, filterDuplicatedExtRefs(tExtRefList));
}

/**
Expand All @@ -262,25 +262,6 @@ private List<SclReportItem> checkExtRefWithoutServiceType(List<TExtRef> tExtRefs
.toList();
}

/**
* Checks if two ExtRefs fed by same Control Block for SCL limits analyze
* Nota : this equality is only for checking limitation check
*
* @param t1 extref to compare
* @param t2 extref to compare
* @return true if the two ExtRef are fed by same Control Block, otherwise false
*/
private static boolean isExtRefFeedBySameControlBlock(TExtRef t1, TExtRef t2) {
String srcLNClass1 = (t1.isSetSrcLNClass()) ? t1.getSrcLNClass().get(0) : TLLN0Enum.LLN_0.value();
String srcLNClass2 = (t2.isSetSrcLNClass()) ? t2.getSrcLNClass().get(0) : TLLN0Enum.LLN_0.value();
return Utils.equalsOrBothBlank(t1.getIedName(), t2.getIedName())
&& Utils.equalsOrBothBlank(t1.getSrcLDInst(), t2.getSrcLDInst())
&& srcLNClass1.equals(srcLNClass2)
&& Utils.equalsOrBothBlank(t1.getSrcLNInst(), t2.getSrcLNInst())
&& Utils.equalsOrBothBlank(t1.getSrcPrefix(), t2.getSrcPrefix())
&& t1.getServiceType().equals(t2.getServiceType());
}

/**
* Checks Control Blocks (Report, Goose, SMV) number limitation for bound IED
*
Expand All @@ -300,7 +281,6 @@ public List<SclReportItem> checkLimitationForBoundIEDControls(List<TExtRef> tExt
* Checks Control Block number limitation for bound IED
*
* @param tExtRefs list of ExtRefs referenced same ied
* @param msg message to display hen error occured
* @param servicesConfigEnum type of Control Block for which check is done
* @return Optional of encountered error or empty
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.lfenergy.compas.scl2007b4.model.*;
import org.lfenergy.compas.sct.commons.dto.ExtrefTarget;
import org.lfenergy.compas.sct.commons.dto.ResumedDataTemplate;
import org.lfenergy.compas.sct.commons.dto.SclReportItem;
import org.lfenergy.compas.sct.commons.scl.ObjectReference;
import org.lfenergy.compas.sct.commons.scl.SclElementAdapter;
Expand Down Expand Up @@ -109,36 +110,45 @@ public AbstractDAIAdapter<?> toAdapter(TDAI childTDAI) {
* @return a filled SclReportItem if an error occurs, empty SclReportItem otherwise
*/
public Optional<SclReportItem> updateDaiFromExtRef(List<TExtRef> tExtRefs) {
Optional<SclReportItem> optionalSclReportItem;
Optional<TExtRef> tExtRefMinOptional = tExtRefs.stream().min(EXTREF_DESC_SUFFIX_COMPARATOR);

if (tExtRefMinOptional.isPresent() && extractDescSuffix(tExtRefMinOptional.get().getDesc()) == 1) {
TExtRef tExtRefMin = tExtRefMinOptional.get();
findDataAdapterByName(DA_NAME_SET_SRC_REF)
.orElse(addDAI(DA_NAME_SET_SRC_REF, true))
.setVal(createInRefValNominalString(tExtRefMin));
String valueSrcRef = createInRefValNominalString(tExtRefMin);
optionalSclReportItem = updateDAI(DA_NAME_SET_SRC_REF, valueSrcRef);
if (tExtRefMin.isSetSrcCBName()) {
findDataAdapterByName(DA_NAME_SET_SRC_CB)
.orElse(addDAI(DA_NAME_SET_SRC_CB, true))
.setVal(createInRefValTestString(tExtRefMin));
String valueSrcCb = createInRefValTestString(tExtRefMin);
optionalSclReportItem = updateDAI(DA_NAME_SET_SRC_CB, valueSrcCb);
}

Optional<TExtRef> tExtRefMaxOptional = tExtRefs.stream().max(EXTREF_DESC_SUFFIX_COMPARATOR);
if (tExtRefMaxOptional.isPresent() && extractDescSuffix(tExtRefMaxOptional.get().getDesc()) > 1) {
TExtRef tExtRefMax = tExtRefMaxOptional.get();
findDataAdapterByName(DA_NAME_SET_TST_REF)
.orElse(addDAI(DA_NAME_SET_TST_REF, true))
.setVal(createInRefValNominalString(tExtRefMax));
String valueTstRef = createInRefValNominalString(tExtRefMax);
optionalSclReportItem = updateDAI(DA_NAME_SET_TST_REF, valueTstRef);
if (tExtRefMax.isSetSrcCBName()) {
findDataAdapterByName(DA_NAME_SET_TST_CB)
.orElse(addDAI(DA_NAME_SET_TST_CB, true))
.setVal(createInRefValTestString(tExtRefMax));
String valueTstCb = createInRefValTestString(tExtRefMax);
optionalSclReportItem = updateDAI(DA_NAME_SET_TST_CB, valueTstCb);
}
}
} else {
return Optional.of(SclReportItem.warning(getXPath(), "The DOI %s can't be bound with an ExtRef".formatted(getXPath())));
optionalSclReportItem = Optional.of(SclReportItem.warning(getXPath(), "The DOI %s can't be bound with an ExtRef".formatted(getXPath())));
}

return optionalSclReportItem;
}

private Optional<SclReportItem> updateDAI(String daName, String value) {
ResumedDataTemplate daiFilterSrcRef = new ResumedDataTemplate(getParentAdapter(), getName(), daName);
Optional<ResumedDataTemplate> foundDais = getParentAdapter().getDAI(daiFilterSrcRef, true).stream().findFirst();
if (foundDais.isEmpty()) {
return Optional.of(SclReportItem.warning(getXPath() + "/DAI@name=\"" + daName + "\"/Val", "The DAI cannot be updated"));
}
ResumedDataTemplate filterForUpdate = foundDais.get();
filterForUpdate.setVal(value);
getParentAdapter().updateDAI(filterForUpdate);
return Optional.empty();

}

private static int extractDescSuffix(String desc) throws NumberFormatException {
Expand Down
Loading

0 comments on commit 7a7f680

Please sign in to comment.