2020import org .lfenergy .compas .sct .commons .scl .ied .*;
2121import org .lfenergy .compas .sct .commons .scl .ldevice .LDeviceAdapter ;
2222import org .lfenergy .compas .sct .commons .util .ControlBlockEnum ;
23+ import org .lfenergy .compas .sct .commons .util .Utils ;
2324
2425import java .util .*;
2526import java .util .stream .Collectors ;
5354 * <li>{@link AbstractLNAdapter#getDAI <em>Returns the value of the <b>DataAttributeRef </b> containment reference By filter</em>}</li>
5455 * <li>{@link AbstractLNAdapter#getDAIValues(DataAttributeRef) <em>Returns <b>DAI (sGroup, value) </b> containment reference list By <b>DataAttributeRef </b> filter</em>}</li>
5556 *
56- * <li>{@link AbstractLNAdapter#getDataSetByName(String) <em>Returns the value of the <b>TDataSet </b>object reference By the value of the <b>name </b>attribute </em>}</li>
57- *
58- * <li>{@link AbstractLNAdapter#getControlBlocks(List, TServiceType) <em>Returns the value of the <b>ControlBlock </b>containment reference list that match <b>datSet </b> value of given <b>TDataSet</b> </em>}</li>
5957 * <li>{@link AbstractLNAdapter#addPrivate <em>Add <b>TPrivate </b>under this object</em>}</li>
6058 * <li>{@link AbstractLNAdapter#removeAllControlBlocksAndDatasets() <em>Remove all <b>ControlBlock</b></em>}</li>
6159 * </ul>
@@ -81,7 +79,7 @@ public abstract class AbstractLNAdapter<T extends TAnyLN> extends SclElementAdap
8179
8280 public static final DoTypeName MOD_DO_TYPE_NAME = new DoTypeName (MOD_DO_NAME );
8381 public static final DaTypeName STVAL_DA_TYPE_NAME = new DaTypeName (STVAL_DA_NAME );
84- private static final String DAI_MOD_STVAL_VALUE_ON = "on" ;
82+ private static final int CONTROLBLOCK_ID_MAX_LENGTH = 14 ;
8583
8684 /**
8785 * Constructor
@@ -264,7 +262,7 @@ public void updateExtRefBinders(ExtRefInfo extRefInfo) throws ScdException {
264262 log .warn ("More the one desc for ExtRef [pDO({}),intAddr({})] in {}{}/{}" ,
265263 signalInfo .getPDO (), signalInfo .getIntAddr (), iedName , ldInst , getLNClass ());
266264 }
267- TExtRef extRef = tExtRefs .get ( 0 );
265+ TExtRef extRef = tExtRefs .getFirst ( );
268266 // update ExtRef with binding info
269267 updateExtRefBindingInfo (extRef , extRefInfo );
270268 }
@@ -555,7 +553,7 @@ public TExtRef extractExtRefFromExtRefInfo(@NonNull ExtRefInfo extRefInfo) {
555553 log .error (msg );
556554 throw new ScdException (msg );
557555 }
558- TExtRef extRef = extRefs .get ( 0 );// to be refined : what's the criteria for ExtRef's uniqueness
556+ TExtRef extRef = extRefs .getFirst ( );// to be refined : what's the criteria for ExtRef's uniqueness
559557 ExtRefBindingInfo bindingInfo = extRefInfo .getBindingInfo ();
560558 if (!bindingInfo .isWrappedIn (extRef )) {
561559 String msg = "No relation between binding info and the matched TExtRef" ;
@@ -952,46 +950,29 @@ public Stream<ControlBlockAdapter> streamControlBlocks(ControlBlockEnum controlB
952950
953951 /**
954952 * Create ControlBlock if there is no ControlBlock of the same type (controlBlockEnum) and with the same cbName in this LN/LN0.
955- * When the controlBlock already exists, the id and datSet attributes are NOT updated with the given values.
953+ * When the controlBlock already exists, the idSeed and datSet attributes are NOT updated with the given values.
956954 *
957955 * @param cbName cbName of the controlBlock to look for. When not found, the cbName of the controlBlock to create.
958- * @param id When controlBlock not found, the id of the controlBlock to create
956+ * @param idSeed When controlBlock not found, the text that will be used to compute the controlBlock Id (appId, smvId, rptId)
959957 * @param datSet the datSet of the controlBlock to create
960958 * @param controlBlockEnum the type of ControlBlock to create
961959 * @return existing controlBlock if a controlBlock of the same type and with same cbName was found in this LN/LN0, otherwise the created ControlBlock.
962960 * The returned ControlBlock is always a child of this LN/LN0.
963961 */
964- public ControlBlockAdapter createControlBlockIfNotExists (String cbName , String id , String datSet , ControlBlockEnum controlBlockEnum ) {
962+ public ControlBlockAdapter createControlBlockIfNotExists (String cbName , String idSeed , String datSet , ControlBlockEnum controlBlockEnum ) {
963+ String computedId = Utils .sha256 (idSeed ).substring (0 , CONTROLBLOCK_ID_MAX_LENGTH );
965964 return findControlBlock (cbName , controlBlockEnum )
966965 .orElseGet (() -> addControlBlock (
967966 switch (controlBlockEnum ) {
968- case GSE -> new GooseControlBlock (cbName , id , datSet );
969- case SAMPLED_VALUE -> new SMVControlBlock (cbName , id , datSet );
970- case REPORT -> new ReportControlBlock (cbName , id , datSet );
967+ case GSE -> new GooseControlBlock (cbName , computedId , datSet );
968+ case SAMPLED_VALUE -> new SMVControlBlock (cbName , computedId , datSet );
969+ case REPORT -> new ReportControlBlock (cbName , computedId , datSet );
971970 default -> throw new IllegalArgumentException ("Unsupported ControlBlock Type " + controlBlockEnum );
972971 }
973972 )
974973 );
975974 }
976975
977- /**
978- * Generate a ControlBlock Id based on the current LN and the given ldName (ldName can be different from the parent LD.name)
979- *
980- * @param ldName LD name to use for generating the id
981- * @param cbName name of the ControlBlock
982- * @return "ldName/LnPrefixLnClassLnInst.cbName". Blank values are omitted (e.g "IEDNAME1LD1/LLN0.CBNAME1")
983- */
984- public String generateControlBlockId (String ldName , String cbName ) {
985- String s = getLNInst ();
986- String s1 = getPrefix ();
987- return StringUtils .trimToEmpty (ldName )
988- + "/"
989- + StringUtils .trimToEmpty (s1 )
990- + StringUtils .defaultString (getLNClass (), "" )
991- + StringUtils .trimToEmpty (s )
992- + "."
993- + StringUtils .trimToEmpty (cbName );
994- }
995976
996977 /**
997978 * Finds all FCDAs in DataSet of Control Block feeding ExtRef
0 commit comments