Skip to content

Commit

Permalink
Review 2
Browse files Browse the repository at this point in the history
Signed-off-by: Slimane AMAR <amarsli@gm0winl104.bureau.si.interne>
  • Loading branch information
Slimane AMAR committed Feb 7, 2025
1 parent c30f85f commit 0bc6af8
Showing 1 changed file with 14 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,29 +268,30 @@ private void flushEquipmentInfos() {
equipmentInfosService.addAllEquipmentInfos(modifiedEquipments);
}

private List<? extends AbstractBaseImpact> reduceDeletionImpacts() {
List<SimpleElementImpact> deletionImpacts = getDeletionSimpleImpacts();
return (getImpactedSubstationIds(deletionImpacts).size() >= collectionThreshold) ? getFullNetworkImpact() : deletionImpacts;
}

private List<AbstractBaseImpact> reduceNoDeletionImpacts() {
private List<AbstractBaseImpact> reduceNetworkImpacts() {
List<AbstractBaseImpact> reducedImpacts = new ArrayList<>();
Set<String> impactedSubstationsIds = new HashSet<>();
List<SimpleElementImpact> deletionImpacts = getDeletionSimpleImpacts();

// All network is impacted by deletions
if (getImpactedSubstationIds(deletionImpacts).size() >= collectionThreshold) {
return getFullNetworkImpact();
}

// Group simple impacts over same element type into collection impact
// And compute impactedSubstationsIds on the way
for (IdentifiableType elementType : IdentifiableType.values()) {
List<SimpleElementImpact> noDeletionImpactsByType = getNoDeletionSimpleImpacts(elementType);
if (noDeletionImpactsByType.size() >= collectionThreshold) {
List<SimpleElementImpact> impactsByType = getCreationModificationSimpleImpacts(elementType);
if (impactsByType.size() >= collectionThreshold) {
reducedImpacts.add(CollectionElementImpact.builder()
.elementType(elementType)
.build());
} else {
impactedSubstationsIds.addAll(getImpactedSubstationIds(noDeletionImpactsByType));
impactedSubstationsIds.addAll(getImpactedSubstationIds(impactsByType));
}
}

// All network is impacted ? then return only one substation collection impact
// All network is impacted by modifications and/or creations
if (impactedSubstationsIds.size() >= collectionThreshold) {
return getFullNetworkImpact();
}
Expand All @@ -307,23 +308,8 @@ private List<AbstractBaseImpact> reduceNoDeletionImpacts() {
).toList()
);

return reducedImpacts;
}

private List<AbstractBaseImpact> reduceNetworkImpacts() {

List<? extends AbstractBaseImpact> reducedDeletionImpacts = reduceDeletionImpacts();
if (isAllNetworkImpacted(reducedDeletionImpacts)) {
return getFullNetworkImpact();
}

List<AbstractBaseImpact> reducedModificationImpacts = reduceNoDeletionImpacts();
if (isAllNetworkImpacted(reducedModificationImpacts)) {
return getFullNetworkImpact();
}

// fuse both reduced impacts
return Stream.concat(reducedModificationImpacts.stream(), reducedDeletionImpacts.stream()).toList();
// Fuse both reduced impacts
return Stream.concat(reducedImpacts.stream(), deletionImpacts.stream()).toList();
}

private List<AbstractBaseImpact> getFullNetworkImpact() {
Expand All @@ -332,13 +318,6 @@ private List<AbstractBaseImpact> getFullNetworkImpact() {
.build());
}

private boolean isAllNetworkImpacted(List<? extends AbstractBaseImpact> impacts) {
return impacts.stream()
.filter(AbstractBaseImpact::isCollection)
.filter(c -> c.getElementType() == IdentifiableType.SUBSTATION)
.count() > 0;
}

private Set<String> getImpactedSubstationIds(List<SimpleElementImpact> impacts) {
Set<String> impactedSubstationsIds = new HashSet<>();
impactedSubstationsIds.addAll(impacts.stream().flatMap(i -> i.getSubstationIds().stream()).toList());
Expand All @@ -352,7 +331,7 @@ private List<SimpleElementImpact> getDeletionSimpleImpacts() {
.toList();
}

private List<SimpleElementImpact> getNoDeletionSimpleImpacts(IdentifiableType elementType) {
private List<SimpleElementImpact> getCreationModificationSimpleImpacts(IdentifiableType elementType) {
return simpleImpacts.stream()
.filter(i -> !i.isDeletion() && i.getElementType() == elementType)
.distinct()
Expand Down

0 comments on commit 0bc6af8

Please sign in to comment.