8
8
import de .bund .digitalservice .ris .norms .application .port .output .LoadRegelungstextPort ;
9
9
import de .bund .digitalservice .ris .norms .application .port .output .UpdateNormPort ;
10
10
import de .bund .digitalservice .ris .norms .domain .entity .*;
11
- import de .bund .digitalservice .ris .norms .domain .entity .eli .DokumentExpressionEli ;
12
11
import de .bund .digitalservice .ris .norms .domain .entity .eli .NormExpressionEli ;
13
12
import de .bund .digitalservice .ris .norms .utils .EidConsistencyGuardian ;
14
13
import de .bund .digitalservice .ris .norms .utils .XmlMapper ;
15
14
import java .util .*;
16
- import java .util .stream .Collectors ;
17
- import java .util .stream .Stream ;
18
15
import org .springframework .stereotype .Service ;
19
16
20
17
/**
@@ -32,18 +29,15 @@ public class NormService
32
29
33
30
private final LoadNormPort loadNormPort ;
34
31
private final UpdateNormPort updateNormPort ;
35
- private final UpdateNormService updateNormService ;
36
32
private final LoadRegelungstextPort loadRegelungstextPort ;
37
33
38
34
public NormService (
39
35
LoadNormPort loadNormPort ,
40
36
UpdateNormPort updateNormPort ,
41
- UpdateNormService updateNormService ,
42
37
LoadRegelungstextPort loadRegelungstextPort
43
38
) {
44
39
this .loadNormPort = loadNormPort ;
45
40
this .updateNormPort = updateNormPort ;
46
- this .updateNormService = updateNormService ;
47
41
this .loadRegelungstextPort = loadRegelungstextPort ;
48
42
}
49
43
@@ -103,66 +97,25 @@ public String updateRegelungstextXml(UpdateRegelungstextXmlUseCase.Query query)
103
97
}
104
98
105
99
/**
106
- * It not only saves a {@link Norm} but makes sure that all Eids are consistent and if it is an amending norm makes sure
107
- * that all target norms have a passive modification for every active modification in the amending norm.
100
+ * It not only saves a {@link Norm} but makes sure that all Eids are consistent.
108
101
*
109
102
* @param normToBeUpdated the norm which shall be saved
110
103
* @return An {@link Map} containing the updated and saved {@link Norm}
111
104
* @throws NormNotFoundException if the norm cannot be found
112
105
*/
113
106
public Map <NormExpressionEli , Norm > updateNorm (Norm normToBeUpdated ) {
114
- // Collect all target norms' ELI without duplications
115
- Set <NormExpressionEli > allTargetLawsEli = normToBeUpdated
116
- .getRegelungstext1 ()
117
- .getMeta ()
118
- .getAnalysis ()
119
- .map (analysis -> analysis .getActiveModifications ().stream ())
120
- .orElse (Stream .empty ())
121
- .map (TextualMod ::getDestinationHref )
122
- .flatMap (Optional ::stream )
123
- .map (Href ::getExpressionEli )
124
- .flatMap (Optional ::stream )
125
- .map (DokumentExpressionEli ::asNormEli )
126
- .collect (Collectors .toSet ());
127
-
128
- // Load all target norms
129
- Map <NormExpressionEli , Norm > zf0s = allTargetLawsEli
130
- .stream ()
131
- .map (expressionEli -> {
132
- Norm zf0 = loadNorm (new LoadNormUseCase .Query (expressionEli ));
133
- return new AbstractMap .SimpleImmutableEntry <>(expressionEli , zf0 );
134
- })
135
- .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
136
-
137
- // Update passive modifications for each target norm
138
- zf0s .forEach ((eli , zf0 ) ->
139
- updateNormService .updateOnePassiveModification (
140
- new UpdatePassiveModificationsUseCase .Query (zf0 , normToBeUpdated , eli )
141
- )
142
- );
143
-
144
- // Add the norm to be updated to the map of updated norms
145
- Map <NormExpressionEli , Norm > updatedNorms = new HashMap <>(zf0s );
146
- updatedNorms .put (normToBeUpdated .getExpressionEli (), normToBeUpdated );
147
-
148
- return updatedNorms
149
- .entrySet ()
150
- .stream ()
151
- .map (entry -> {
152
- Norm norm = entry .getValue ();
153
- norm
154
- .getRegelungstexte ()
155
- .forEach (regelungstext -> {
156
- EidConsistencyGuardian .eliminateDeadReferences (regelungstext .getDocument ());
157
- EidConsistencyGuardian .correctEids (regelungstext .getDocument ());
158
- });
159
-
160
- Norm savedNorm = updateNormPort
161
- .updateNorm (new UpdateNormPort .Command (norm ))
162
- .orElseThrow (() -> new NormNotFoundException (norm .getManifestationEli ().toString ()));
163
-
164
- return new AbstractMap .SimpleImmutableEntry <>(entry .getKey (), savedNorm );
165
- })
166
- .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
107
+ normToBeUpdated
108
+ .getDokumente ()
109
+ .forEach (dokument -> {
110
+ EidConsistencyGuardian .eliminateDeadReferences (dokument .getDocument ());
111
+ EidConsistencyGuardian .correctEids (dokument .getDocument ());
112
+ });
113
+
114
+ Norm savedNorm = updateNormPort
115
+ .updateNorm (new UpdateNormPort .Command (normToBeUpdated ))
116
+ .orElseThrow (() -> new NormNotFoundException (normToBeUpdated .getManifestationEli ().toString ())
117
+ );
118
+
119
+ return Map .of (normToBeUpdated .getExpressionEli (), savedNorm );
167
120
}
168
121
}
0 commit comments