|
10 | 10 | import org.lfenergy.compas.sct.commons.util.PrivateEnum; |
11 | 11 |
|
12 | 12 | import javax.xml.bind.JAXBElement; |
13 | | -import java.util.ArrayList; |
14 | | -import java.util.Collections; |
15 | | -import java.util.List; |
16 | | -import java.util.Optional; |
| 13 | +import java.util.*; |
17 | 14 | import java.util.function.Predicate; |
18 | | -import java.util.stream.Collectors; |
| 15 | +import java.util.stream.Stream; |
| 16 | + |
| 17 | +import static java.util.stream.Collectors.toList; |
| 18 | +import static org.lfenergy.compas.sct.commons.util.CommonConstants.*; |
| 19 | +import static org.lfenergy.compas.sct.commons.util.PrivateEnum.COMPAS_ICDHEADER; |
19 | 20 |
|
20 | 21 | /** |
21 | 22 | * A representation of the <em><b>{@link PrivateService PrivateService}</b></em>. |
@@ -57,7 +58,7 @@ public static <T> List<T> extractCompasPrivates(List<TPrivate> tPrivates, Class< |
57 | 58 | .map(TAnyContentFromOtherNamespace::getContent).flatMap(List::stream) |
58 | 59 | .filter(JAXBElement.class::isInstance).map(JAXBElement.class::cast) |
59 | 60 | .filter(Predicate.not(JAXBElement::isNil)) |
60 | | - .map(JAXBElement::getValue).collect(Collectors.toList()); |
| 61 | + .map(JAXBElement::getValue).collect(toList()); |
61 | 62 |
|
62 | 63 | List<T> result = new ArrayList<>(); |
63 | 64 | for (Object compasElement : compasElements) { |
@@ -239,13 +240,121 @@ private static TPrivate createPrivate(JAXBElement<?> jaxbElement) { |
239 | 240 | } |
240 | 241 |
|
241 | 242 |
|
| 243 | + /** |
| 244 | + * Sorts in map of ICD_SYSTEM_VERSION_UUID and related Private coupled with all corresponding STD for all given STD |
| 245 | + * |
| 246 | + * @param stds list of STD to short |
| 247 | + * @return map of ICD_SYSTEM_VERSION_UUID attribute in IED/Private:COMPAS-ICDHeader and related Private coupled with |
| 248 | + * all corresponding STD |
| 249 | + */ |
| 250 | + public static Map<String, PrivateLinkedToSTDs> createMapICDSystemVersionUuidAndSTDFile(Set<SCL> stds) { |
| 251 | + Map<String, PrivateLinkedToSTDs> stringSCLMap = new HashMap<>(); |
| 252 | + stds.forEach(std -> std.getIED().forEach(ied -> ied.getPrivate().forEach(tp -> |
| 253 | + PrivateService.extractCompasICDHeader(tp).map(TCompasICDHeader::getICDSystemVersionUUID).ifPresent(icdSysVer -> { |
| 254 | + PrivateLinkedToSTDs privateLinkedToSTDs = stringSCLMap.get(icdSysVer); |
| 255 | + List<SCL> list = privateLinkedToSTDs != null ? privateLinkedToSTDs.stdList() : new ArrayList<>(); |
| 256 | + list.add(std); |
| 257 | + stringSCLMap.put(icdSysVer, new PrivateLinkedToSTDs(tp, list)); |
| 258 | + }) |
| 259 | + ))); |
| 260 | + return stringSCLMap; |
| 261 | + } |
242 | 262 |
|
243 | 263 |
|
| 264 | + public record PrivateLinkedToSTDs (TPrivate tPrivate, List<SCL> stdList) { |
| 265 | + } |
244 | 266 |
|
245 | 267 |
|
| 268 | + /** |
| 269 | + * Checks SCD and STD compatibilities by checking if there is at least one ICD_SYSTEM_VERSION_UUID in |
| 270 | + * Substation/../LNode/Private COMPAS-ICDHeader of SCL not present in IED/Private COMPAS-ICDHeader of STD |
| 271 | + * |
| 272 | + * @param mapICDSystemVersionUuidAndSTDFile map of ICD_SYSTEM_VERSION_UUID and list of corresponding STD |
| 273 | + * @throws ScdException throws when there are several STD files corresponding to <em>ICD_SYSTEM_VERSION_UUID</em> |
| 274 | + * from Substation/../LNode/Private COMPAS-ICDHeader of SCL |
| 275 | + */ |
| 276 | + public static void checkSTDCorrespondanceWithLNodeCompasICDHeader(Map<String, PrivateLinkedToSTDs> mapICDSystemVersionUuidAndSTDFile) throws ScdException { |
| 277 | + mapICDSystemVersionUuidAndSTDFile.values().stream() |
| 278 | + .filter(privateLinkedToSTDs -> privateLinkedToSTDs.stdList().size() != 1) |
| 279 | + .findFirst() |
| 280 | + .ifPresent(pToStd -> { |
| 281 | + throw new ScdException("There are several STD files corresponding to " + stdCheckFormatExceptionMessage(pToStd.tPrivate())); |
| 282 | + }); |
| 283 | + } |
246 | 284 |
|
| 285 | + /** |
| 286 | + * Creates formatted message including data's of Private for Exception |
| 287 | + * |
| 288 | + * @param key Private causing exception |
| 289 | + * @return formatted message |
| 290 | + * @throws ScdException throws when parameter not present in Private |
| 291 | + */ |
| 292 | + public static String stdCheckFormatExceptionMessage(TPrivate key) throws ScdException { |
| 293 | + Optional<TCompasICDHeader> optionalCompasICDHeader = PrivateService.extractCompasICDHeader(key); |
| 294 | + return HEADER_ID + " = " + optionalCompasICDHeader.map(TCompasICDHeader::getHeaderId).orElse(null) + " " + |
| 295 | + HEADER_VERSION + " = " + optionalCompasICDHeader.map(TCompasICDHeader::getHeaderVersion).orElse(null) + " " + |
| 296 | + HEADER_REVISION + " = " + optionalCompasICDHeader.map(TCompasICDHeader::getHeaderRevision).orElse(null) + |
| 297 | + " and " + ICD_SYSTEM_VERSION_UUID + " = " + optionalCompasICDHeader.map(TCompasICDHeader::getICDSystemVersionUUID).orElse(null); |
| 298 | + } |
247 | 299 |
|
248 | 300 |
|
| 301 | + /** |
| 302 | + * Creates map of IEDName and related Private for all Privates COMPAS-ICDHeader in /Substation of SCL |
| 303 | + * |
| 304 | + * @param scdRootAdapter SCL file in which Private should be found |
| 305 | + * @return map of Private and its IEDName parameter |
| 306 | + */ |
| 307 | + public static Stream<TPrivate> createMapIEDNameAndPrivate(SclRootAdapter scdRootAdapter) { |
| 308 | + return scdRootAdapter.getCurrentElem().getSubstation().get(0).getVoltageLevel().stream() |
| 309 | + .map(TVoltageLevel::getBay).flatMap(Collection::stream) |
| 310 | + .map(TBay::getFunction).flatMap(Collection::stream) |
| 311 | + .map(TFunction::getLNode).flatMap(Collection::stream) |
| 312 | + .map(TLNode::getPrivate).flatMap(Collection::stream) |
| 313 | + .filter(tPrivate -> |
| 314 | + tPrivate.getType().equals(COMPAS_ICDHEADER.getPrivateType()) |
| 315 | + && PrivateService.extractCompasICDHeader(tPrivate).isPresent() |
| 316 | + && PrivateService.extractCompasICDHeader(tPrivate).get().getIEDName() != null); |
| 317 | + } |
| 318 | + |
| 319 | + |
| 320 | + /** |
| 321 | + * Compares if two Private:COMPAS-ICDHeader have all attributes equal except IEDNane, BayLabel and IEDinstance |
| 322 | + * |
| 323 | + * @param iedPrivate Private of IED from STD to compare |
| 324 | + * @param scdPrivate Private of LNode fro SCD to compare |
| 325 | + * @return <em>Boolean</em> value of check result |
| 326 | + * @throws ScdException throws when Private is not COMPAS_ICDHEADER one |
| 327 | + */ |
| 328 | + public static boolean comparePrivateCompasICDHeaders(TPrivate iedPrivate, TPrivate scdPrivate) throws ScdException { |
| 329 | + TCompasICDHeader iedCompasICDHeader = PrivateService.extractCompasICDHeader(iedPrivate) |
| 330 | + .orElseThrow(() -> new ScdException(COMPAS_ICDHEADER + "not found in IED Private ")); |
| 331 | + TCompasICDHeader scdCompasICDHeader = PrivateService.extractCompasICDHeader(scdPrivate) |
| 332 | + .orElseThrow(() -> new ScdException(COMPAS_ICDHEADER + "not found in LNode Private ")); |
| 333 | + return Objects.equals(iedCompasICDHeader.getIEDType(), scdCompasICDHeader.getIEDType()) |
| 334 | + && Objects.equals(iedCompasICDHeader.getICDSystemVersionUUID(), scdCompasICDHeader.getICDSystemVersionUUID()) |
| 335 | + && Objects.equals(iedCompasICDHeader.getVendorName(), scdCompasICDHeader.getVendorName()) |
| 336 | + && Objects.equals(iedCompasICDHeader.getIEDredundancy(), scdCompasICDHeader.getIEDredundancy()) |
| 337 | + && Objects.equals(iedCompasICDHeader.getIEDmodel(), scdCompasICDHeader.getIEDmodel()) |
| 338 | + && Objects.equals(iedCompasICDHeader.getHwRev(), scdCompasICDHeader.getHwRev()) |
| 339 | + && Objects.equals(iedCompasICDHeader.getSwRev(), scdCompasICDHeader.getSwRev()) |
| 340 | + && Objects.equals(iedCompasICDHeader.getHeaderId(), scdCompasICDHeader.getHeaderId()) |
| 341 | + && Objects.equals(iedCompasICDHeader.getHeaderRevision(), scdCompasICDHeader.getHeaderRevision()) |
| 342 | + && Objects.equals(iedCompasICDHeader.getHeaderVersion(), scdCompasICDHeader.getHeaderVersion()); |
| 343 | + } |
| 344 | + |
| 345 | + /** |
| 346 | + * Copy Private COMPAS_ICDHEADER from LNode of SCD into Private COMPAS_ICDHEADER from IED of STD |
| 347 | + * |
| 348 | + * @param stdPrivate Private of IED from STD in which to copy new data |
| 349 | + * @param lNodePrivate Private of IED from STD from which new data are taken |
| 350 | + * @throws ScdException throws when Private is not COMPAS_ICDHEADER one |
| 351 | + */ |
| 352 | + public static void copyCompasICDHeaderFromLNodePrivateIntoSTDPrivate(TPrivate stdPrivate, TPrivate lNodePrivate) throws ScdException { |
| 353 | + TCompasICDHeader lNodeCompasICDHeader = extractCompasICDHeader(lNodePrivate) |
| 354 | + .orElseThrow(() -> new ScdException(COMPAS_ICDHEADER + " not found in LNode Private ")); |
| 355 | + stdPrivate.getContent().clear(); |
| 356 | + stdPrivate.getContent().add(objectFactory.createICDHeader(lNodeCompasICDHeader)); |
| 357 | + } |
249 | 358 |
|
250 | 359 |
|
251 | 360 | } |
0 commit comments