5
5
package org .lfenergy .compas .scl .data .service ;
6
6
7
7
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 ;
8
11
import org .lfenergy .compas .scl .data .model .ChangeSetType ;
9
12
import org .lfenergy .compas .scl .data .model .Item ;
10
13
import org .lfenergy .compas .scl .data .model .SclType ;
13
16
14
17
import javax .enterprise .context .ApplicationScoped ;
15
18
import javax .inject .Inject ;
19
+ import javax .xml .bind .JAXBElement ;
20
+
16
21
import java .util .List ;
22
+ import java .util .Optional ;
17
23
import java .util .UUID ;
18
24
19
25
@ ApplicationScoped
@@ -47,7 +53,8 @@ public UUID create(SclType type, String name, SCL scl) {
47
53
// When the SCL is create the version will be set to 1.0.0
48
54
var version = new Version (1 , 0 , 0 );
49
55
scl .getHeader ().setVersion (version .toString ());
50
- // TODO: Add name and type to SCL before storing the SCL.
56
+
57
+ setSclCompasPrivateElement (scl , name , type );
51
58
52
59
repository .create (type , id , scl , version );
53
60
return id ;
@@ -69,8 +76,33 @@ public void update(SclType type, UUID id, ChangeSetType changeSetType, SCL scl)
69
76
public void delete (SclType type , UUID id ) {
70
77
repository .delete (type , id );
71
78
}
72
-
79
+
73
80
public void delete (SclType type , UUID id , Version version ) {
74
81
repository .delete (type , id , version );
75
82
}
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
+ }
76
108
}
0 commit comments