Skip to content

Commit

Permalink
change tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamal-khey committed Jun 20, 2024
1 parent b688c68 commit 13cdd3d
Showing 1 changed file with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,23 @@ ContingencyListMetadata fromContingencyListEntity(AbstractContingencyEntity enti

List<ContingencyListMetadata> getContingencyListsMetadata() {
return Stream.of(
scriptContingencyListRepository.findAll().stream().map(scriptContingencyListEntity ->
fromContingencyListEntity(scriptContingencyListEntity, ContingencyListType.SCRIPT)),
formContingencyListRepository.findAll().stream().map(formContingencyListEntity ->
fromContingencyListEntity(formContingencyListEntity, ContingencyListType.FORM)),
idBasedContingencyListRepository.findAll().stream().map(idBasedContingencyListEntity ->
fromContingencyListEntity(idBasedContingencyListEntity, ContingencyListType.IDENTIFIERS))
scriptContingencyListRepository.findAll().stream().map(scriptContingencyListEntity ->
fromContingencyListEntity(scriptContingencyListEntity, ContingencyListType.SCRIPT)),
formContingencyListRepository.findAll().stream().map(formContingencyListEntity ->
fromContingencyListEntity(formContingencyListEntity, ContingencyListType.FORM)),
idBasedContingencyListRepository.findAll().stream().map(idBasedContingencyListEntity ->
fromContingencyListEntity(idBasedContingencyListEntity, ContingencyListType.IDENTIFIERS))
).flatMap(Function.identity()).collect(Collectors.toList());
}

List<ContingencyListMetadata> getContingencyListsMetadata(List<UUID> ids) {
return Stream.of(
scriptContingencyListRepository.findAllById(ids).stream().map(scriptContingencyListEntity ->
fromContingencyListEntity(scriptContingencyListEntity, ContingencyListType.SCRIPT)),
formContingencyListRepository.findAllById(ids).stream().map(formContingencyListEntity ->
fromContingencyListEntity(formContingencyListEntity, ContingencyListType.FORM)),
idBasedContingencyListRepository.findAllById(ids).stream().map(idBasedContingencyListEntity ->
fromContingencyListEntity(idBasedContingencyListEntity, ContingencyListType.IDENTIFIERS))
scriptContingencyListRepository.findAllById(ids).stream().map(scriptContingencyListEntity ->
fromContingencyListEntity(scriptContingencyListEntity, ContingencyListType.SCRIPT)),
formContingencyListRepository.findAllById(ids).stream().map(formContingencyListEntity ->
fromContingencyListEntity(formContingencyListEntity, ContingencyListType.FORM)),
idBasedContingencyListRepository.findAllById(ids).stream().map(idBasedContingencyListEntity ->
fromContingencyListEntity(idBasedContingencyListEntity, ContingencyListType.IDENTIFIERS))
).flatMap(Function.identity()).collect(Collectors.toList());
}

Expand Down Expand Up @@ -148,11 +148,11 @@ private List<Contingency> getPowsyblContingencies(PersistentContingencyList cont
public Integer getContingencyCount(List<UUID> ids, UUID networkUuid, String variantId) {
Network network = getNetworkFromUuid(networkUuid, variantId);
return ids.stream()
.map(uuid -> {
Optional<PersistentContingencyList> contingencyList = getAnyContingencyList(uuid, network);
return contingencyList.map(l -> getContingencies(l, network).size()).orElse(0);
})
.reduce(0, Integer::sum);
.map(uuid -> {
Optional<PersistentContingencyList> contingencyList = getAnyContingencyList(uuid, network);
return contingencyList.map(l -> getContingencies(l, network).size()).orElse(0);
})
.reduce(0, Integer::sum);
}

@Transactional(readOnly = true)
Expand Down Expand Up @@ -192,23 +192,23 @@ private List<ContingencyInfos> evaluateContingencyList(PersistentContingencyList
Map<String, Set<String>> notFoundElements = persistentContingencyList.getNotFoundElements(network);


Map<String, Set<String>> notConnected = contingencies.stream()
.map( contingency -> {
List<ContingencyInfos> contingencyInfos = new ArrayList<>();
notFoundElements.entrySet().stream()
.filter(stringSetEntry -> contingencies.stream().noneMatch(c -> c.getId().equals(stringSetEntry.getKey())))
.map(stringSetEntry -> new ContingencyInfos(stringSetEntry.getKey(), null, stringSetEntry.getValue(), null))
.forEach(contingencyInfos::add);

contingencies.stream()
.map(contingency -> {
Set<String> disconnects = contingency.getElements().stream()
.filter(contingencyElement -> {
var connectable = network.getConnectable(contingencyElement.getId());
return connectable != null && isDisconnected(connectable);
})
.map(ContingencyElement::getId)
.collect(Collectors.toSet());
return new AbstractMap.SimpleEntry<>(contingency.getId(),disconnects);
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

List<ContingencyInfos> contingencyInfos = contingencies.stream()
.map( contingency -> new ContingencyInfos(contingency, notFoundElements.getOrDefault(contingency.getId(), null),
notConnected.getOrDefault(contingency.getId(), null))).toList();

return new ContingencyInfos(contingency.getId(),contingency,null, disconnects);
}).forEach(contingencyInfos::add);

return contingencyInfos;
}
Expand Down

0 comments on commit 13cdd3d

Please sign in to comment.