File tree 3 files changed +30
-2
lines changed
song-server/src/main/java/bio/overture/song/server
3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 22
22
import java .util .Optional ;
23
23
import org .springframework .data .jpa .repository .JpaRepository ;
24
24
import org .springframework .data .jpa .repository .JpaSpecificationExecutor ;
25
+ import org .springframework .data .jpa .repository .Query ;
25
26
26
27
public interface AnalysisSchemaRepository
27
28
extends JpaRepository <AnalysisSchema , Integer >, JpaSpecificationExecutor <AnalysisSchema > {
@@ -32,5 +33,5 @@ public interface AnalysisSchemaRepository
32
33
33
34
Optional <AnalysisSchema > findByNameAndVersion (String name , Integer version );
34
35
35
- List <AnalysisSchema > findByName (String name );
36
+ List <AnalysisSchema > findAllByName (String name );
36
37
}
Original file line number Diff line number Diff line change @@ -99,6 +99,10 @@ public Schema getAnalysisTypeRegistrationSchema() {
99
99
return analysisTypeRegistrationSchema ;
100
100
}
101
101
102
+ public List <AnalysisSchema > getAllAnalysisSchemas (String name ) {
103
+ return analysisSchemaRepository .findAllByName (name );
104
+ }
105
+
102
106
public AnalysisType getAnalysisType (
103
107
@ NonNull String name , @ Nullable Integer version , boolean unrenderedOnly ) {
104
108
val resolvedVersion = isNull (version ) ? getLatestVersionNumber (name ) : version ;
@@ -265,6 +269,24 @@ private AnalysisType commitAnalysisType(
265
269
if (options != null && CollectionUtils .isNotEmpty (options .getFileTypes ())) {
266
270
fileTypes = options .getFileTypes ();
267
271
}
272
+
273
+ // checking if file types is empty
274
+ // if the version is new version of the schema , we are checking the previous version allowed file types
275
+ // if it is new then it is empty
276
+ if (fileTypes .isEmpty ()){
277
+ List <AnalysisSchema > analysisSchemaList = analysisSchemaRepository .findAllByName (analysisTypeName );
278
+
279
+ if (!analysisSchemaList .isEmpty ()){
280
+ Optional <AnalysisSchema > latestSchemaOptional = analysisSchemaList .stream ()
281
+ .filter (schema -> schema .getVersion () != null )
282
+ .max (Comparator .comparingInt (AnalysisSchema ::getVersion ));
283
+
284
+ if (latestSchemaOptional .isPresent ()){
285
+ fileTypes = latestSchemaOptional .get ().getFileTypes ();
286
+ }
287
+ }
288
+ }
289
+
268
290
val analysisSchema =
269
291
AnalysisSchema .builder ()
270
292
.name (analysisTypeName )
Original file line number Diff line number Diff line change 30
30
31
31
import bio .overture .song .core .model .AnalysisTypeId ;
32
32
import bio .overture .song .core .model .FileData ;
33
+ import bio .overture .song .server .model .entity .AnalysisSchema ;
33
34
import bio .overture .song .server .model .enums .UploadStates ;
34
35
import bio .overture .song .server .repository .UploadRepository ;
35
36
import bio .overture .song .server .validation .SchemaValidator ;
36
37
import bio .overture .song .server .validation .ValidationResponse ;
37
38
import com .fasterxml .jackson .databind .JsonNode ;
38
39
import java .util .ArrayList ;
39
40
import java .util .List ;
41
+ import java .util .Objects ;
40
42
import java .util .Optional ;
41
43
import java .util .function .Supplier ;
44
+ import java .util .stream .Collectors ;
42
45
import lombok .NonNull ;
43
46
import lombok .SneakyThrows ;
44
47
import lombok .extern .slf4j .Slf4j ;
@@ -96,7 +99,9 @@ public Optional<String> validate(@NonNull JsonNode payload) {
96
99
fileTypes = analysisType .getOptions ().getFileTypes ();
97
100
}
98
101
99
- validateFileType (fileTypes , payload );
102
+ if (!fileTypes .isEmpty ()) {
103
+ validateFileType (fileTypes , payload );
104
+ }
100
105
101
106
val schema = buildSchema (analysisType .getSchema ());
102
107
validateWithSchema (schema , payload );
You can’t perform that action at this time.
0 commit comments