Skip to content

Commit c9f2d9b

Browse files
Rob TjalmaRob Tjalma
authored andcommitted
Added method for adding filename/filetype
Signed-off-by: Rob Tjalma <[email protected]>
1 parent 08684d4 commit c9f2d9b

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

service/src/main/java/org/lfenergy/compas/scl/data/service/CompasSclDataService.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
package org.lfenergy.compas.scl.data.service;
66

77
import org.lfenergy.compas.scl.SCL;
8+
import org.lfenergy.compas.scl.TPrivate;
9+
import org.lfenergy.compas.scl.compas.ObjectFactory;
10+
import org.lfenergy.compas.scl.compas.TSclFileType;
811
import org.lfenergy.compas.scl.data.model.ChangeSetType;
912
import org.lfenergy.compas.scl.data.model.Item;
1013
import org.lfenergy.compas.scl.data.model.SclType;
@@ -13,7 +16,10 @@
1316

1417
import javax.enterprise.context.ApplicationScoped;
1518
import javax.inject.Inject;
19+
import javax.xml.bind.JAXBElement;
20+
1621
import java.util.List;
22+
import java.util.Optional;
1723
import java.util.UUID;
1824

1925
@ApplicationScoped
@@ -47,7 +53,8 @@ public UUID create(SclType type, String name, SCL scl) {
4753
// When the SCL is create the version will be set to 1.0.0
4854
var version = new Version(1, 0, 0);
4955
scl.getHeader().setVersion(version.toString());
50-
// TODO: Add name and type to SCL before storing the SCL.
56+
57+
setSclCompasPrivateElement(scl, name, type);
5158

5259
repository.create(type, id, scl, version);
5360
return id;
@@ -69,8 +76,33 @@ public void update(SclType type, UUID id, ChangeSetType changeSetType, SCL scl)
6976
public void delete(SclType type, UUID id) {
7077
repository.delete(type, id);
7178
}
72-
79+
7380
public void delete(SclType type, UUID id, Version version) {
7481
repository.delete(type, id, version);
7582
}
83+
84+
/**
85+
* Set the full CoMPAS private element for the given SCL file.
86+
* @param scl the SCL file to edit.
87+
* @param filename the filename to add
88+
* @param fileType the file type to add.
89+
*/
90+
private void setSclCompasPrivateElement(SCL scl, String filename, SclType fileType) {
91+
// Creating a private
92+
var compasPrivate = new TPrivate();
93+
var compasPrivateElementFactory = new ObjectFactory();
94+
95+
// Setting the type (required for a SCL private element)
96+
compasPrivate.setType("compas_scl");
97+
98+
// Adding the filename element and the file type element
99+
compasPrivate.getContent().add(compasPrivateElementFactory.createSclFilename(filename));
100+
101+
// TODO: Make this work!
102+
// TSclFileType sclFileType = TSclFileType.valueOf(fileType.toString());
103+
// compasPrivate.getContent().add(compasPrivateElementFactory.createSclFileType(sclFileType));
104+
105+
// Adding it to the SCL file.
106+
scl.getPrivate().add(compasPrivate);
107+
}
76108
}

0 commit comments

Comments
 (0)