55package org .lfenergy .compas .sct .commons .util ;
66
77import com .opencsv .bean .CsvBindByPosition ;
8- import lombok .EqualsAndHashCode ;
9- import lombok .Getter ;
10- import lombok .NoArgsConstructor ;
11- import lombok .Setter ;
8+ import lombok .ToString ;
129import org .apache .commons .lang3 .StringUtils ;
13- import org .lfenergy .compas .scl2007b4 .model .TCompasICDHeader ;
14- import org .lfenergy .compas .scl2007b4 .model .TCompasIEDRedundancy ;
15- import org .lfenergy .compas .scl2007b4 .model .TCompasIEDType ;
16- import org .lfenergy .compas .scl2007b4 .model .TDurationInMilliSec ;
10+ import org .lfenergy .compas .scl2007b4 .model .*;
1711import org .lfenergy .compas .sct .commons .dto .ControlBlockNetworkSettings ;
1812import org .lfenergy .compas .sct .commons .scl .ied .ControlBlockAdapter ;
1913import org .lfenergy .compas .sct .commons .scl .ied .IEDAdapter ;
2014
2115import java .io .Reader ;
16+ import java .math .BigInteger ;
2217import java .util .Map ;
2318import java .util .Objects ;
19+ import java .util .Optional ;
2420import java .util .stream .Collectors ;
2521
2622/**
@@ -38,7 +34,7 @@ public class ControlBlockNetworkSettingsCsvHelper implements ControlBlockNetwork
3834 private static final int MAX_VLAN_PRIORITY = 7 ;
3935 private static final String NONE = "none" ;
4036
41- private final Map <Criteria , Settings > settings ;
37+ private final Map <Criteria , Settings > allSettings ;
4238
4339 /**
4440 * Constructor
@@ -48,7 +44,7 @@ public class ControlBlockNetworkSettingsCsvHelper implements ControlBlockNetwork
4844 * @param csvSource a reader that provides the data as CSV. For example :
4945 */
5046 public ControlBlockNetworkSettingsCsvHelper (Reader csvSource ) {
51- settings = readCsvFile (csvSource );
47+ allSettings = readCsvFile (csvSource );
5248 }
5349
5450 private Map <Criteria , Settings > readCsvFile (Reader csvSource ) {
@@ -61,48 +57,62 @@ private Map<Criteria, Settings> readCsvFile(Reader csvSource) {
6157 }
6258
6359 @ Override
64- public Settings getNetworkSettings (ControlBlockAdapter controlBlockAdapter ) {
60+ public SettingsOrError getNetworkSettings (ControlBlockAdapter controlBlockAdapter ) {
6561 ControlBlockEnum controlBlockEnum = controlBlockAdapter .getControlBlockEnum ();
6662 IEDAdapter iedAdapter = controlBlockAdapter .getParentIedAdapter ();
67- String systemVersion = iedAdapter .getCompasSystemVersion ()
68- .map (version -> version .getMainSystemVersion () + "." + version .getMinorSystemVersion ())
69- .orElse (null );
70- String systemVersionWithoutV = removeVFromSystemVersion (systemVersion );
71- TCompasIEDType iedType = iedAdapter .getCompasICDHeader ().map (TCompasICDHeader ::getIEDType ).orElse (null );
72- TCompasIEDRedundancy iedRedundancy = iedAdapter .getCompasICDHeader ().map (TCompasICDHeader ::getIEDredundancy ).orElse (null );
63+ Optional <TCompasSystemVersion > compasSystemVersion = iedAdapter .getCompasSystemVersion ();
64+ if (compasSystemVersion .isEmpty ()) {
65+ return new SettingsOrError (null , "No private COMPAS-SystemVersion found in this IED" );
66+ }
67+ String systemVersionWithoutV = removeVFromSystemVersion (compasSystemVersion .get ());
68+ Optional <TCompasICDHeader > compasICDHeader = iedAdapter .getCompasICDHeader ();
69+ if (compasICDHeader .isEmpty ()) {
70+ return new SettingsOrError (null , "No private COMPAS-ICDHeader found in this IED" );
71+ }
72+ TCompasIEDType iedType = compasICDHeader .get ().getIEDType ();
73+ TCompasIEDRedundancy iedRedundancy = compasICDHeader .get ().getIEDredundancy ();
74+ BigInteger iedSystemVersionInstance = compasICDHeader .get ().getIEDSystemVersioninstance ();
7375 boolean isBayInternal = controlBlockAdapter .getName ().endsWith ("I" );
74- return findSettings (new Criteria (controlBlockEnum , systemVersionWithoutV , iedType , iedRedundancy , isBayInternal ));
76+
77+ Criteria criteria = new Criteria (controlBlockEnum , systemVersionWithoutV , iedType , iedRedundancy , iedSystemVersionInstance , isBayInternal );
78+ Settings settings = findSettings (criteria );
79+ return settings != null ?
80+ new SettingsOrError (settings , null ) :
81+ new SettingsOrError (null , "No row found with these criteria " + criteria );
7582 }
7683
7784 private Settings findSettings (Criteria criteria ) {
7885 Objects .requireNonNull (criteria );
7986 if (criteria .systemVersionWithoutV () == null
8087 || criteria .iedType () == null
81- || criteria .iedRedundancy () == null ) {
88+ || criteria .iedRedundancy () == null
89+ || criteria .iedSystemVersionInstance == null ) {
8290 return null ;
8391 }
84- return settings .get (criteria );
92+ return allSettings .get (criteria );
8593 }
8694
87- private static String removeVFromSystemVersion (String systemVersion ) {
88- if (systemVersion == null ) {
95+ private static String removeVFromSystemVersion (TCompasSystemVersion compasSystemVersion ) {
96+ if (StringUtils .isBlank (compasSystemVersion .getMainSystemVersion ())
97+ || (StringUtils .isBlank (compasSystemVersion .getMinorSystemVersion ()))) {
8998 return null ;
9099 }
91- String [] systemVersionParts = systemVersion .split ("\\ ." );
92- if (systemVersionParts .length < 4 ) {
93- return systemVersion ;
94- }
95- return systemVersionParts [0 ] + "." + systemVersionParts [1 ] + "." + systemVersionParts [2 ] + "." + systemVersionParts [3 ];
100+ String [] minorVersionParts = compasSystemVersion .getMinorSystemVersion ().split ("\\ ." );
101+ return (minorVersionParts .length == 3 ) ?
102+ compasSystemVersion .getMainSystemVersion () + "." + minorVersionParts [0 ] + "." + minorVersionParts [1 ]
103+ : null ;
96104 }
97105
98106 private static Criteria rowToCriteria (Row row ) {
99107 if (StringUtils .isBlank (row .cbType )
100108 || StringUtils .isBlank (row .xy )
101109 || StringUtils .isBlank (row .zw )
102110 || StringUtils .isBlank (row .iedType )
111+ || StringUtils .isBlank (row .iedRedundancy )
112+ || StringUtils .isBlank (row .iedSystemVersionInstance )
103113 || StringUtils .isBlank (row .bindingType )
104114 ) {
105- throw new IllegalArgumentException ("At least one criteria (cbType, xy, zw, iedType, bindingType) is blank" );
115+ throw new IllegalArgumentException ("At least one criteria is null in row " + row );
106116 }
107117 ControlBlockEnum controlBlockEnum = switch (row .cbType ) {
108118 case "GOOSE" -> ControlBlockEnum .GSE ;
@@ -114,6 +124,7 @@ private static Criteria rowToCriteria(Row row) {
114124 row .xy + "." + row .zw ,
115125 TCompasIEDType .fromValue (row .iedType ),
116126 TCompasIEDRedundancy .fromValue (row .iedRedundancy ),
127+ new BigInteger (row .iedSystemVersionInstance ),
117128 row .bindingType .equals ("BAY_INTERNAL" )
118129 );
119130 }
@@ -160,13 +171,11 @@ private record Criteria(
160171 String systemVersionWithoutV ,
161172 TCompasIEDType iedType ,
162173 TCompasIEDRedundancy iedRedundancy ,
174+ BigInteger iedSystemVersionInstance ,
163175 boolean isBayInternal ) {
164176 }
165177
166- @ NoArgsConstructor
167- @ Getter
168- @ Setter
169- @ EqualsAndHashCode
178+ @ ToString
170179 public static class Row {
171180 @ CsvBindByPosition (position = 0 )
172181 private String cbType ;
@@ -179,14 +188,16 @@ public static class Row {
179188 @ CsvBindByPosition (position = 4 )
180189 private String iedRedundancy ;
181190 @ CsvBindByPosition (position = 5 )
182- private String bindingType ;
191+ private String iedSystemVersionInstance ;
183192 @ CsvBindByPosition (position = 6 )
184- private String vlanId ;
193+ private String bindingType ;
185194 @ CsvBindByPosition (position = 7 )
186- private String vlanPriority ;
195+ private String vlanId ;
187196 @ CsvBindByPosition (position = 8 )
188- private String minTime ;
197+ private String vlanPriority ;
189198 @ CsvBindByPosition (position = 9 )
199+ private String minTime ;
200+ @ CsvBindByPosition (position = 10 )
190201 private String maxTime ;
191202 }
192203
0 commit comments