42
42
import bio .overture .song .core .exceptions .ServerErrors ;
43
43
import bio .overture .song .core .model .AnalysisType ;
44
44
import bio .overture .song .core .model .AnalysisTypeId ;
45
+ import bio .overture .song .core .model .AnalysisTypeOptions ;
45
46
import bio .overture .song .core .model .PageDTO ;
46
47
import bio .overture .song .server .controller .analysisType .AnalysisTypeController ;
47
48
import bio .overture .song .server .model .entity .AnalysisSchema ;
50
51
import com .fasterxml .jackson .databind .node .ArrayNode ;
51
52
import com .fasterxml .jackson .databind .node .ObjectNode ;
52
53
import java .io .IOException ;
53
- import java .util .Collection ;
54
+ import java .util .* ;
54
55
import java .util .function .Supplier ;
55
56
import java .util .regex .Pattern ;
56
57
import javax .transaction .Transactional ;
57
58
import lombok .NonNull ;
58
59
import lombok .SneakyThrows ;
59
60
import lombok .extern .slf4j .Slf4j ;
60
61
import lombok .val ;
62
+ import org .apache .commons .collections .CollectionUtils ;
61
63
import org .everit .json .schema .Schema ;
62
64
import org .everit .json .schema .SchemaException ;
63
65
import org .everit .json .schema .ValidationException ;
@@ -149,21 +151,29 @@ public AnalysisSchema getAnalysisSchema(String name, Integer version) {
149
151
public AnalysisType getAnalysisType (
150
152
@ NonNull AnalysisTypeId analysisTypeId , boolean unrenderedOnly ) {
151
153
val analysisSchema = getAnalysisSchema (analysisTypeId );
154
+
152
155
val resolvedSchemaJson =
153
156
resolveSchemaJsonView (analysisSchema .getSchema (), unrenderedOnly , false );
157
+
158
+ List <String > fileTypes =
159
+ (analysisSchema .getFileTypes () != null && !analysisSchema .getFileTypes ().isEmpty ())
160
+ ? analysisSchema .getFileTypes ()
161
+ : new ArrayList <>();
154
162
return AnalysisType .builder ()
155
163
.name (analysisTypeId .getName ())
156
164
.version (analysisTypeId .getVersion ())
157
165
.createdAt (analysisSchema .getCreatedAt ())
158
166
.schema (resolvedSchemaJson )
167
+ .options (AnalysisTypeOptions .builder ().fileTypes (fileTypes ).build ())
159
168
.build ();
160
169
}
161
170
162
171
@ Transactional
163
- public AnalysisType register (@ NonNull String analysisTypeName , JsonNode analysisTypeSchema ) {
172
+ public AnalysisType register (
173
+ @ NonNull String analysisTypeName , AnalysisTypeOptions options , JsonNode analysisTypeSchema ) {
164
174
validateAnalysisTypeName (analysisTypeName );
165
175
validateAnalysisTypeSchema (analysisTypeSchema );
166
- return commitAnalysisType (analysisTypeName , analysisTypeSchema );
176
+ return commitAnalysisType (analysisTypeName , analysisTypeSchema , options );
167
177
}
168
178
169
179
public PageDTO <AnalysisType > listAnalysisTypes (
@@ -246,9 +256,23 @@ private void validateAnalysisTypeSchema(JsonNode analysisTypeSchema) {
246
256
247
257
@ SneakyThrows
248
258
private AnalysisType commitAnalysisType (
249
- @ NonNull String analysisTypeName , @ NonNull JsonNode analysisTypeSchema ) {
259
+ @ NonNull String analysisTypeName ,
260
+ @ NonNull JsonNode analysisTypeSchema ,
261
+ AnalysisTypeOptions options ) {
262
+
263
+ List <String > fileTypes = new ArrayList <>();
264
+
265
+ if (options != null && CollectionUtils .isNotEmpty (options .getFileTypes ())) {
266
+ fileTypes = options .getFileTypes ();
267
+ }
250
268
val analysisSchema =
251
- AnalysisSchema .builder ().name (analysisTypeName ).schema (analysisTypeSchema ).build ();
269
+ AnalysisSchema .builder ()
270
+ .name (analysisTypeName )
271
+ .schema (analysisTypeSchema )
272
+ .fileTypes (fileTypes )
273
+ .build ();
274
+
275
+ log .debug ("Creating analysisSchema with file types: {} " + fileTypes );
252
276
analysisSchemaRepository .save (analysisSchema );
253
277
val version =
254
278
analysisSchemaRepository .countAllByNameAndIdLessThanEqual (
@@ -275,6 +299,7 @@ private AnalysisType commitAnalysisType(
275
299
.version (version )
276
300
.createdAt (createdAt )
277
301
.schema (resolvedSchemaJson )
302
+ .options (options )
278
303
.build ();
279
304
}
280
305
0 commit comments