@@ -130,7 +130,7 @@ public String create(SclFileType type, String name, String who, String comment,
130
130
createHistoryItem (header , "SCL created" , who , comment , version );
131
131
132
132
// Update or add the Compas Private Element to the SCL File.
133
- setSclCompasPrivateElement (scl , Optional . of ( name ) , type );
133
+ setSclCompasPrivateElement (scl , name , type );
134
134
135
135
var newSclData = converter .convertToString (scl );
136
136
repository .create (type , id , name , newSclData , version , who );
@@ -167,10 +167,11 @@ public String update(SclFileType type, UUID id, ChangeSetType changeSetType, Str
167
167
createHistoryItem (header , "SCL updated" , who , comment , version );
168
168
169
169
// Update or add the Compas Private Element to the SCL File.
170
- setSclCompasPrivateElement (scl , Optional .ofNullable (currentSclMetaInfo .getName ()), type );
170
+ var newSclName = getFilenameFromXML (scl ).orElse (currentSclMetaInfo .getName ());
171
+ setSclCompasPrivateElement (scl , newSclName , type );
171
172
172
173
var newSclData = converter .convertToString (scl );
173
- repository .create (type , id , currentSclMetaInfo . getName () , newSclData , version , who );
174
+ repository .create (type , id , newSclName , newSclData , version , who );
174
175
return newSclData ;
175
176
}
176
177
@@ -216,24 +217,37 @@ private Element createOrUpdateHeader(Element scl, UUID id, Version version) {
216
217
return header ;
217
218
}
218
219
220
+ /**
221
+ * Retrieve the CoMPAS SCL Filename from the private element of CoMPAS.
222
+ *
223
+ * @param scl The SCL file to edit.
224
+ * @return If there was a private SclName the value of this tag.
225
+ */
226
+ private Optional <String > getFilenameFromXML (Element scl ) {
227
+ return sclElementProcessor .getCompasPrivate (scl )
228
+ .stream ()
229
+ .map (compasPrivate -> sclElementProcessor .getChildNodeByName (compasPrivate , COMPAS_SCL_NAME_EXTENSION ))
230
+ .flatMap (Optional ::stream )
231
+ .map (Element ::getTextContent )
232
+ .findFirst ();
233
+ }
234
+
219
235
/**
220
236
* Create/update the CoMPAS private element on the SCL Element for the given file.
221
237
*
222
238
* @param scl The SCL file to edit.
223
239
* @param name The name to add.
224
240
* @param fileType The file type to add.
225
241
*/
226
- private void setSclCompasPrivateElement (Element scl , Optional < String > name , SclFileType fileType ) {
242
+ private void setSclCompasPrivateElement (Element scl , String name , SclFileType fileType ) {
227
243
var compasPrivate = sclElementProcessor .getCompasPrivate (scl )
228
244
.orElseGet (() -> sclElementProcessor .addCompasPrivate (scl ));
229
245
230
246
sclElementProcessor .getChildNodeByName (compasPrivate , COMPAS_SCL_NAME_EXTENSION )
231
247
.ifPresentOrElse (
232
248
// Override the value of the element with the name passed.
233
- element -> name .ifPresent (element ::setTextContent ),
234
- () -> name .ifPresent (
235
- // Add the Compas Element and give it a value with the name passed.
236
- value -> sclElementProcessor .addCompasElement (compasPrivate , COMPAS_SCL_NAME_EXTENSION , value ))
249
+ element -> element .setTextContent (name ),
250
+ () -> sclElementProcessor .addCompasElement (compasPrivate , COMPAS_SCL_NAME_EXTENSION , name )
237
251
);
238
252
239
253
// Always set the file type as private element.
0 commit comments