From 5427be55871e68f7e4f5754c3b4b64de391992b8 Mon Sep 17 00:00:00 2001 From: pfurio Date: Wed, 17 Jan 2024 11:21:03 +0100 Subject: [PATCH 1/2] catalog: remove deprecated fields from VSets, #TASK-1294 --- .../CatalogVariantMetadataFactory.java | 2 +- .../converters/AnnotationConverter.java | 6 +- .../catalog/utils/AnnotationUtils.java | 6 +- .../utils/CatalogSampleAnnotationsLoader.java | 3 +- .../CatalogAnnotationsValidatorTest.java | 2 +- .../CatalogSampleAnnotationsLoaderTest.java | 3 +- .../core/models/common/AnnotationSet.java | 72 +------------------ .../opencga/core/models/study/Variable.java | 18 +---- 8 files changed, 10 insertions(+), 102 deletions(-) diff --git a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogVariantMetadataFactory.java b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogVariantMetadataFactory.java index cbffe4e9e21..1dde494f3d0 100644 --- a/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogVariantMetadataFactory.java +++ b/opencga-analysis/src/main/java/org/opencb/opencga/analysis/variant/metadata/CatalogVariantMetadataFactory.java @@ -164,7 +164,7 @@ private void fillSamples(String studyId, List(sample.getAnnotations())); for (AnnotationSet annotationSet : annotationSets) { - String prefix = annotationSets.size() > 1 ? annotationSet.getName() + '.' : ""; + String prefix = annotationSets.size() > 1 ? annotationSet.getId() + '.' : ""; Map annotations = annotationSet.getAnnotations(); for (Map.Entry annotationEntry : annotations.entrySet()) { Object value = annotationEntry.getValue(); diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/converters/AnnotationConverter.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/converters/AnnotationConverter.java index abf9dc3be11..310c86df19c 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/converters/AnnotationConverter.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/db/mongodb/converters/AnnotationConverter.java @@ -177,8 +177,7 @@ public List fromDBToAnnotation(List annotationList, Doc String variableSetId = variableSetUidIdMap.getString(String.valueOf(variableSetUid)); if (!annotationSetMap.containsKey(compoundKey)) { - annotationSetMap.put(compoundKey, new AnnotationSet(annSetName, variableSetId, new HashMap<>(), - Collections.emptyMap())); + annotationSetMap.put(compoundKey, new AnnotationSet(annSetName, variableSetId, new HashMap<>())); } annotationSetMap.get(compoundKey).getAnnotations().put(annotationDocument.getString(ID), annotationDocument.get(VALUE)); @@ -203,8 +202,7 @@ public List fromDBToAnnotation(List annotationList, Doc String variableSetId = variableSetUidIdMap.getString(String.valueOf(variableSetUid)); if (!annotationSetMap.containsKey(compoundKey)) { - annotationSetMap.put(compoundKey, new AnnotationSet(annSetName, variableSetId, new HashMap<>(), - Collections.emptyMap())); + annotationSetMap.put(compoundKey, new AnnotationSet(annSetName, variableSetId, new HashMap<>())); } // We provide the map from the annotation set in order to be automatically filled in diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/AnnotationUtils.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/AnnotationUtils.java index 30494174dfa..f0d39c5cf01 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/AnnotationUtils.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/AnnotationUtils.java @@ -79,10 +79,6 @@ public static void checkVariable(Variable variable) throws CatalogException { throw new CatalogException("Only variables with type \"OBJECT\" can define an internal variableSet"); } - if (variable.getType() == Variable.VariableType.TEXT) { - variable.setType(Variable.VariableType.STRING); - } - //Check default values switch (variable.getType()) { case BOOLEAN: @@ -431,7 +427,7 @@ private static void checkAllowedValue(Variable variable, Object value, String me Map objectMap = (Map) object; checkAnnotationSet(new VariableSet(variable.getId(), variable.getId(), false, false, false, variable.getDescription(), variable.getVariables(), null, 1, null), - new AnnotationSet("", variable.getId(), objectMap, null, 1, null), null, true); + new AnnotationSet("", variable.getId(), objectMap), null, true); } } break; diff --git a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoader.java b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoader.java index 25e618a4e68..59eae91d2b7 100644 --- a/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoader.java +++ b/opencga-catalog/src/main/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoader.java @@ -86,8 +86,7 @@ public DataResult loadSampleAnnotations(File pedFile, String variableSet for (Individual individual : ped.getIndividuals().values()) { Map annotation = getAnnotation(individual, sampleMap, variableSet, ped.getFields()); try { - AnnotationUtils.checkAnnotationSet(variableSet, new AnnotationSet("", variableSet.getId(), annotation, "", 1, - null), null, true); + AnnotationUtils.checkAnnotationSet(variableSet, new AnnotationSet("", variableSet.getId(), annotation), null, true); } catch (CatalogException e) { String message = "Validation with the variableSet {id: " + variableSetId + "} over ped File = {path: " + pedFile.getPath() + ", name: \"" + pedFile.getName() + "\"} failed"; diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogAnnotationsValidatorTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogAnnotationsValidatorTest.java index e085c2a08a3..ae67ac884fb 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogAnnotationsValidatorTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogAnnotationsValidatorTest.java @@ -201,7 +201,7 @@ public void mergeAnnotationsTest() { annotations.put("K", "V"); annotations.put("K2", "V2"); annotations.put("K4", false); - AnnotationSet annotationSet = new AnnotationSet("", "", annotations, "", 1, Collections.emptyMap()); + AnnotationSet annotationSet = new AnnotationSet("", "", annotations); Map newAnnotations = new ObjectMap() .append("K", "newValue") //Modify .append("K2", null) //Delete diff --git a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoaderTest.java b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoaderTest.java index 336d60295c5..f0c8713a1c3 100644 --- a/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoaderTest.java +++ b/opencga-catalog/src/test/java/org/opencb/opencga/catalog/utils/CatalogSampleAnnotationsLoaderTest.java @@ -151,8 +151,7 @@ public void testLoadPedigreeCatalog() throws Exception { private void validate(Pedigree pedigree, VariableSet variableSet) throws CatalogException { for (Map.Entry entry : pedigree.getIndividuals().entrySet()) { Map annotation = loader.getAnnotation(entry.getValue(), null, variableSet, pedigree.getFields()); - AnnotationUtils.checkAnnotationSet(variableSet, new AnnotationSet("", variableSet.getId(), annotation, "", 1, - null), null, true); + AnnotationUtils.checkAnnotationSet(variableSet, new AnnotationSet("", variableSet.getId(), annotation), null, true); } } } \ No newline at end of file diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/models/common/AnnotationSet.java b/opencga-core/src/main/java/org/opencb/opencga/core/models/common/AnnotationSet.java index 490527ef6f5..79a2128be8d 100644 --- a/opencga-core/src/main/java/org/opencb/opencga/core/models/common/AnnotationSet.java +++ b/opencga-core/src/main/java/org/opencb/opencga/core/models/common/AnnotationSet.java @@ -16,13 +16,10 @@ package org.opencb.opencga.core.models.common; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.opencb.opencga.core.common.JacksonUtils; -import org.opencb.opencga.core.common.TimeUtils; -import java.util.Collections; import java.util.Map; /** @@ -31,38 +28,16 @@ public class AnnotationSet { private String id; - @Deprecated - private String name; private String variableSetId; private Map annotations; - @Deprecated - private String creationDate; - @Deprecated - private int release; - @Deprecated - private Map attributes; - public AnnotationSet() { } public AnnotationSet(String id, String variableSetId, Map annotations) { - this(id, variableSetId, annotations, TimeUtils.getTime(), 1, Collections.emptyMap()); - } - - public AnnotationSet(String id, String variableSetId, Map annotations, Map attributes) { - this(id, variableSetId, annotations, TimeUtils.getTime(), 1, attributes); - } - - public AnnotationSet(String id, String variableSetId, Map annotations, String creationDate, int release, - Map attributes) { this.id = id; - this.name = id; this.variableSetId = variableSetId; this.annotations = annotations; - this.creationDate = creationDate; - this.release = release; - this.attributes = attributes; } @Override @@ -71,9 +46,6 @@ public String toString() { sb.append("id='").append(id).append('\''); sb.append(", variableSetId=").append(variableSetId); sb.append(", annotations=").append(annotations); - sb.append(", creationDate='").append(creationDate).append('\''); - sb.append(", release=").append(release); - sb.append(", attributes=").append(attributes); sb.append('}'); return sb.toString(); } @@ -89,15 +61,13 @@ public boolean equals(Object o) { } AnnotationSet that = (AnnotationSet) o; - return new EqualsBuilder().append(variableSetId, that.variableSetId).append(release, that.release).append(id, that.id) - .append(annotations, that.annotations).append(creationDate, that.creationDate).append(attributes, that.attributes) + return new EqualsBuilder().append(variableSetId, that.variableSetId).append(id, that.id).append(annotations, that.annotations) .isEquals(); } @Override public int hashCode() { - return new HashCodeBuilder(17, 37).append(id).append(variableSetId).append(annotations).append(creationDate).append(release) - .append(attributes).toHashCode(); + return new HashCodeBuilder(17, 37).append(id).append(variableSetId).append(annotations).toHashCode(); } public String getId() { @@ -106,17 +76,6 @@ public String getId() { public AnnotationSet setId(String id) { this.id = id; - this.name = StringUtils.isEmpty(this.name) ? this.id : this.name; - return this; - } - - public String getName() { - return name; - } - - public AnnotationSet setName(String name) { - this.name = name; - this.id = StringUtils.isEmpty(this.id) ? this.name : this.id; return this; } @@ -138,33 +97,6 @@ public AnnotationSet setAnnotations(Map annotations) { return this; } - public String getCreationDate() { - return creationDate; - } - - public AnnotationSet setCreationDate(String creationDate) { - this.creationDate = creationDate; - return this; - } - - public int getRelease() { - return release; - } - - public AnnotationSet setRelease(int release) { - this.release = release; - return this; - } - - public Map getAttributes() { - return attributes; - } - - public AnnotationSet setAttributes(Map attributes) { - this.attributes = attributes; - return this; - } - public T to(Class tClass) { return JacksonUtils.getDefaultObjectMapper().convertValue(this.getAnnotations(), tClass); } diff --git a/opencga-core/src/main/java/org/opencb/opencga/core/models/study/Variable.java b/opencga-core/src/main/java/org/opencb/opencga/core/models/study/Variable.java index b6cf603f78f..772b168ccfc 100644 --- a/opencga-core/src/main/java/org/opencb/opencga/core/models/study/Variable.java +++ b/opencga-core/src/main/java/org/opencb/opencga/core/models/study/Variable.java @@ -47,11 +47,7 @@ public class Variable { private long rank; private String dependsOn; private String description; - /** - * Variables for validate internal fields. Only valid if type is OBJECT. - **/ - @Deprecated - private Set variableSet; + private Set variables; private Map attributes; @@ -90,8 +86,6 @@ public enum VariableType { CATEGORICAL, INTEGER, DOUBLE, - @Deprecated - TEXT, STRING, OBJECT, MAP_BOOLEAN, @@ -229,16 +223,6 @@ public Variable setDescription(String description) { return this; } - @Deprecated - public Set getVariableSet() { - return getVariables(); - } - - @Deprecated - public Variable setVariableSet(Set variableSet) { - return setVariables(variableSet); - } - public Set getVariables() { return variables; } From f77353bc596a4c8a865ddaef8b7f0f9717b63bff Mon Sep 17 00:00:00 2001 From: pfurio Date: Fri, 19 Jan 2024 13:12:02 +0100 Subject: [PATCH 2/2] pom: workaround for CI/CD --- pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pom.xml b/pom.xml index 0de0a7fdc99..370c8dd4688 100644 --- a/pom.xml +++ b/pom.xml @@ -147,6 +147,13 @@ 2.5-20081211 2.23.0 + + + true