Skip to content

Enable Version-Based File Type Validation for Analysis Submission #866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

public interface AnalysisSchemaRepository
extends JpaRepository<AnalysisSchema, Integer>, JpaSpecificationExecutor<AnalysisSchema> {
Expand All @@ -32,5 +33,5 @@ public interface AnalysisSchemaRepository

Optional<AnalysisSchema> findByNameAndVersion(String name, Integer version);

List<AnalysisSchema> findByName(String name);
List<AnalysisSchema> findAllByName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public Schema getAnalysisTypeRegistrationSchema() {
return analysisTypeRegistrationSchema;
}

public List<AnalysisSchema> getAllAnalysisSchemas(String name) {
return analysisSchemaRepository.findAllByName(name);
}

public AnalysisType getAnalysisType(
@NonNull String name, @Nullable Integer version, boolean unrenderedOnly) {
val resolvedVersion = isNull(version) ? getLatestVersionNumber(name) : version;
Expand Down Expand Up @@ -265,6 +269,24 @@ private AnalysisType commitAnalysisType(
if (options != null && CollectionUtils.isNotEmpty(options.getFileTypes())) {
fileTypes = options.getFileTypes();
}

// checking if file types is empty
// if the version is new version of the schema , we are checking the previous version allowed file types
// if it is new then it is empty
if(fileTypes.isEmpty()){
List<AnalysisSchema> analysisSchemaList = analysisSchemaRepository.findAllByName(analysisTypeName);

if(!analysisSchemaList.isEmpty()){
Optional<AnalysisSchema> latestSchemaOptional = analysisSchemaList.stream()
.filter(schema -> schema.getVersion() != null)
.max(Comparator.comparingInt(AnalysisSchema::getVersion));

if(latestSchemaOptional.isPresent()){
fileTypes = latestSchemaOptional.get().getFileTypes();
}
}
}

val analysisSchema =
AnalysisSchema.builder()
.name(analysisTypeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@

import bio.overture.song.core.model.AnalysisTypeId;
import bio.overture.song.core.model.FileData;
import bio.overture.song.server.model.entity.AnalysisSchema;
import bio.overture.song.server.model.enums.UploadStates;
import bio.overture.song.server.repository.UploadRepository;
import bio.overture.song.server.validation.SchemaValidator;
import bio.overture.song.server.validation.ValidationResponse;
import com.fasterxml.jackson.databind.JsonNode;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import lombok.NonNull;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -96,7 +99,9 @@ public Optional<String> validate(@NonNull JsonNode payload) {
fileTypes = analysisType.getOptions().getFileTypes();
}

validateFileType(fileTypes, payload);
if (!fileTypes.isEmpty()) {
validateFileType(fileTypes, payload);
}

val schema = buildSchema(analysisType.getSchema());
validateWithSchema(schema, payload);
Expand Down