Skip to content

Commit

Permalink
Merge pull request #990 from digitalservicebund/remove-update-of-targ…
Browse files Browse the repository at this point in the history
…et-norms

Stop updating target norms when updating a norm
  • Loading branch information
malte-laukoetter authored Feb 13, 2025
2 parents 8da55d0 + a549c78 commit dd67ebf
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 1,546 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,41 @@ public class AnnouncementService
private final LoadAnnouncementByNormEliPort loadAnnouncementByNormEliPort;
private final LoadNormPort loadNormPort;
private final LoadNormByGuidPort loadNormByGuidPort;
private final CreateZf0Service createZf0Service;
private final UpdateOrSaveAnnouncementPort updateOrSaveAnnouncementPort;
private final BillToActService billToActService;
private final LdmlDeValidator ldmlDeValidator;
private final DeleteAnnouncementByNormEliPort deleteAnnouncementByNormEliPort;
private final DeleteNormPort deleteNormPort;
private final ReferenceService referenceService;
private final UpdateOrSaveNormPort updateOrSaveNormPort;
private final CreateNewVersionOfNormService createNewVersionOfNormService;

public AnnouncementService(
LoadAllAnnouncementsPort loadAllAnnouncementsPort,
LoadAnnouncementByNormEliPort loadAnnouncementByNormEliPort,
LoadNormPort loadNormPort,
LoadNormByGuidPort loadNormByGuidPort,
CreateZf0Service createZf0Service,
UpdateOrSaveAnnouncementPort updateOrSaveAnnouncementPort,
BillToActService billToActService,
LdmlDeValidator ldmlDeValidator,
DeleteAnnouncementByNormEliPort deleteAnnouncementByNormEliPort,
DeleteNormPort deleteNormPort,
ReferenceService referenceService,
UpdateOrSaveNormPort updateOrSaveNormPort
UpdateOrSaveNormPort updateOrSaveNormPort,
CreateNewVersionOfNormService createNewVersionOfNormService
) {
this.loadAllAnnouncementsPort = loadAllAnnouncementsPort;
this.loadAnnouncementByNormEliPort = loadAnnouncementByNormEliPort;
this.loadNormPort = loadNormPort;
this.loadNormByGuidPort = loadNormByGuidPort;
this.createZf0Service = createZf0Service;
this.updateOrSaveAnnouncementPort = updateOrSaveAnnouncementPort;
this.billToActService = billToActService;
this.ldmlDeValidator = ldmlDeValidator;
this.deleteAnnouncementByNormEliPort = deleteAnnouncementByNormEliPort;
this.deleteNormPort = deleteNormPort;
this.referenceService = referenceService;
this.updateOrSaveNormPort = updateOrSaveNormPort;
this.createNewVersionOfNormService = createNewVersionOfNormService;
}

@Override
Expand Down Expand Up @@ -246,9 +246,10 @@ private void runPreProcessing(
activeModDestinationElis.forEach(eli ->
loadNormPort
.loadNorm(new LoadNormPort.Command(eli.asNormEli()))
.ifPresent(targetNorm ->
createZf0Service.createZf0(new CreateZf0UseCase.Query(norm, targetNorm, true))
)
.ifPresent(targetNorm -> {
var newManifestation = createNewVersionOfNormService.createNewManifestation(targetNorm);
updateOrSaveNormPort.updateOrSave(new UpdateOrSaveNormPort.Command(newManifestation));
})
);
// 3. Reference recognition
referenceService.findAndCreateReferences(norm);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
import de.bund.digitalservice.ris.norms.application.port.output.LoadRegelungstextPort;
import de.bund.digitalservice.ris.norms.application.port.output.UpdateNormPort;
import de.bund.digitalservice.ris.norms.domain.entity.*;
import de.bund.digitalservice.ris.norms.domain.entity.eli.DokumentExpressionEli;
import de.bund.digitalservice.ris.norms.domain.entity.eli.NormExpressionEli;
import de.bund.digitalservice.ris.norms.utils.EidConsistencyGuardian;
import de.bund.digitalservice.ris.norms.utils.XmlMapper;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.stereotype.Service;

/**
Expand All @@ -32,18 +29,15 @@ public class NormService

private final LoadNormPort loadNormPort;
private final UpdateNormPort updateNormPort;
private final UpdateNormService updateNormService;
private final LoadRegelungstextPort loadRegelungstextPort;

public NormService(
LoadNormPort loadNormPort,
UpdateNormPort updateNormPort,
UpdateNormService updateNormService,
LoadRegelungstextPort loadRegelungstextPort
) {
this.loadNormPort = loadNormPort;
this.updateNormPort = updateNormPort;
this.updateNormService = updateNormService;
this.loadRegelungstextPort = loadRegelungstextPort;
}

Expand Down Expand Up @@ -103,66 +97,25 @@ public String updateRegelungstextXml(UpdateRegelungstextXmlUseCase.Query query)
}

/**
* It not only saves a {@link Norm} but makes sure that all Eids are consistent and if it is an amending norm makes sure
* that all target norms have a passive modification for every active modification in the amending norm.
* It not only saves a {@link Norm} but makes sure that all Eids are consistent.
*
* @param normToBeUpdated the norm which shall be saved
* @return An {@link Map} containing the updated and saved {@link Norm}
* @throws NormNotFoundException if the norm cannot be found
*/
public Map<NormExpressionEli, Norm> updateNorm(Norm normToBeUpdated) {
// Collect all target norms' ELI without duplications
Set<NormExpressionEli> allTargetLawsEli = normToBeUpdated
.getRegelungstext1()
.getMeta()
.getAnalysis()
.map(analysis -> analysis.getActiveModifications().stream())
.orElse(Stream.empty())
.map(TextualMod::getDestinationHref)
.flatMap(Optional::stream)
.map(Href::getExpressionEli)
.flatMap(Optional::stream)
.map(DokumentExpressionEli::asNormEli)
.collect(Collectors.toSet());

// Load all target norms
Map<NormExpressionEli, Norm> zf0s = allTargetLawsEli
.stream()
.map(expressionEli -> {
Norm zf0 = loadNorm(new LoadNormUseCase.Query(expressionEli));
return new AbstractMap.SimpleImmutableEntry<>(expressionEli, zf0);
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

// Update passive modifications for each target norm
zf0s.forEach((eli, zf0) ->
updateNormService.updateOnePassiveModification(
new UpdatePassiveModificationsUseCase.Query(zf0, normToBeUpdated, eli)
)
);

// Add the norm to be updated to the map of updated norms
Map<NormExpressionEli, Norm> updatedNorms = new HashMap<>(zf0s);
updatedNorms.put(normToBeUpdated.getExpressionEli(), normToBeUpdated);

return updatedNorms
.entrySet()
.stream()
.map(entry -> {
Norm norm = entry.getValue();
norm
.getRegelungstexte()
.forEach(regelungstext -> {
EidConsistencyGuardian.eliminateDeadReferences(regelungstext.getDocument());
EidConsistencyGuardian.correctEids(regelungstext.getDocument());
});

Norm savedNorm = updateNormPort
.updateNorm(new UpdateNormPort.Command(norm))
.orElseThrow(() -> new NormNotFoundException(norm.getManifestationEli().toString()));

return new AbstractMap.SimpleImmutableEntry<>(entry.getKey(), savedNorm);
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
normToBeUpdated
.getDokumente()
.forEach(dokument -> {
EidConsistencyGuardian.eliminateDeadReferences(dokument.getDocument());
EidConsistencyGuardian.correctEids(dokument.getDocument());
});

Norm savedNorm = updateNormPort
.updateNorm(new UpdateNormPort.Command(normToBeUpdated))
.orElseThrow(() -> new NormNotFoundException(normToBeUpdated.getManifestationEli().toString())
);

return Map.of(normToBeUpdated.getExpressionEli(), savedNorm);
}
}
Loading

0 comments on commit dd67ebf

Please sign in to comment.