diff --git a/src/main/java/org/alliancegenome/curation_api/model/entities/HTPExpressionDatasetAnnotation.java b/src/main/java/org/alliancegenome/curation_api/model/entities/HTPExpressionDatasetAnnotation.java index 77d69d8e6..0ebb8ddef 100644 --- a/src/main/java/org/alliancegenome/curation_api/model/entities/HTPExpressionDatasetAnnotation.java +++ b/src/main/java/org/alliancegenome/curation_api/model/entities/HTPExpressionDatasetAnnotation.java @@ -9,6 +9,8 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import org.hibernate.search.engine.backend.types.Aggregable; import org.hibernate.search.engine.backend.types.Projectable; import org.hibernate.search.engine.backend.types.Searchable; @@ -87,6 +89,7 @@ public class HTPExpressionDatasetAnnotation extends AuditedObject { @IndexedEmbedded(includePaths = {"name", "name_keyword"}) @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW) @ManyToMany + @OnDelete(action = OnDeleteAction.CASCADE) @JsonView({ View.FieldsAndLists.class }) @JoinTable(name = "htpexpressiondatasetannotation_categorytags", indexes = { @Index(name = "htpdatasetannotation_htpdatasetid_index", columnList = "htpexpressiondatasetannotation_id"), @Index(name = "htpdatasetannotation_categorytags_index", columnList = "categorytags_id")}) List categoryTags; diff --git a/src/main/java/org/alliancegenome/curation_api/model/entities/ResourceDescriptor.java b/src/main/java/org/alliancegenome/curation_api/model/entities/ResourceDescriptor.java index f1a5e0b6c..434faa2c1 100644 --- a/src/main/java/org/alliancegenome/curation_api/model/entities/ResourceDescriptor.java +++ b/src/main/java/org/alliancegenome/curation_api/model/entities/ResourceDescriptor.java @@ -7,6 +7,8 @@ import org.alliancegenome.curation_api.model.entities.base.AuditedObject; import org.alliancegenome.curation_api.view.View; import org.eclipse.microprofile.openapi.annotations.media.Schema; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; import org.hibernate.search.engine.backend.types.Aggregable; import org.hibernate.search.engine.backend.types.Searchable; import org.hibernate.search.engine.backend.types.Sortable; @@ -61,6 +63,7 @@ public class ResourceDescriptor extends AuditedObject { @KeywordField(name = "synoynyms_keyword", aggregable = Aggregable.YES, sortable = Sortable.YES, searchable = Searchable.YES) @ElementCollection @JoinTable(indexes = @Index(columnList = "resourcedescriptor_id")) + @Fetch(FetchMode.JOIN) @JsonView({ View.ResourceDescriptorView.class, View.FieldsAndLists.class }) private List synonyms; diff --git a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/fms/HTPExpressionDatasetAnnotationFmsDTOValidator.java b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/fms/HTPExpressionDatasetAnnotationFmsDTOValidator.java index 2a5bf54ea..60733d14c 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/fms/HTPExpressionDatasetAnnotationFmsDTOValidator.java +++ b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/fms/HTPExpressionDatasetAnnotationFmsDTOValidator.java @@ -15,6 +15,7 @@ import org.alliancegenome.curation_api.model.entities.HTPExpressionDatasetAnnotation; import org.alliancegenome.curation_api.model.entities.Note; import org.alliancegenome.curation_api.model.entities.Reference; +import org.alliancegenome.curation_api.model.input.Pagination; import org.alliancegenome.curation_api.model.entities.VocabularyTerm; import org.alliancegenome.curation_api.model.ingest.dto.fms.HTPExpressionDatasetAnnotationFmsDTO; import org.alliancegenome.curation_api.model.ingest.dto.fms.PublicationFmsDTO; @@ -117,18 +118,33 @@ public HTPExpressionDatasetAnnotation validateHTPExpressionDatasetAnnotationFmsD } if (CollectionUtils.isNotEmpty(dto.getCategoryTags())) { - List categoryTags = new ArrayList<>(); + Map categoryTags = new HashMap<>(); for (String categoryTag : dto.getCategoryTags()) { if (StringUtils.isNotEmpty(categoryTag)) { - VocabularyTerm tag = vocabularyTermService.getTermInVocabulary(VocabularyConstants.HTP_DATASET_CATEGORY_TAGS, categoryTag).getEntity(); - if (tag == null) { + Map params = new HashMap<>(); + params.put("name", categoryTag); + params.put("query_operator", "or"); + params.put("synonyms", categoryTag); + SearchResponse searchResponse = vocabularyTermService.findByParams(new Pagination(), params); + boolean added = false; + if (searchResponse.getTotalResults() > 0) { + for (VocabularyTerm tag : searchResponse.getResults()) { + if (tag.getVocabulary().getName().equals("Data Set Category Tags") && (tag.getName().equals(categoryTag) || tag.getSynonyms().contains(categoryTag))) { + if (categoryTags.containsKey(categoryTag)) { + htpAnnotationResponse.addErrorMessage("categoryTags", ValidationConstants.INVALID_MESSAGE + " Multiple Tags found in the Vocabulary " + " (" + categoryTag + ")"); + } else { + categoryTags.put(categoryTag, tag); + added = true; + } + } + } + } + if (!added) { htpAnnotationResponse.addErrorMessage("categoryTags", ValidationConstants.INVALID_MESSAGE + " (" + categoryTag + ")"); - } else { - categoryTags.add(tag); } } } - htpannotation.setCategoryTags(categoryTags); + htpannotation.setCategoryTags(new ArrayList<>(categoryTags.values())); } else { htpAnnotationResponse.addErrorMessage("categoryTags", ValidationConstants.REQUIRED_MESSAGE); } diff --git a/src/main/resources/db/migration/v0.37.0.58__htp_tags_fix.sql b/src/main/resources/db/migration/v0.37.0.58__htp_tags_fix.sql new file mode 100644 index 000000000..2d48e8687 --- /dev/null +++ b/src/main/resources/db/migration/v0.37.0.58__htp_tags_fix.sql @@ -0,0 +1,13 @@ +DELETE FROM htpexpressiondatasetannotation_categorytags WHERE categorytags_id IN (SELECT id FROM vocabularyterm WHERE name = 'strain study'); +DELETE FROM vocabularyterm_synonyms WHERE vocabularyterm_id IN (SELECT id FROM vocabularyterm WHERE name = 'strain study'); + +DELETE FROM vocabularyterm WHERE name = 'strain study'; + +DELETE FROM vocabularyterm_synonyms WHERE vocabularyterm_id IN (SELECT id FROM vocabularyterm WHERE name = 'anatomical structure'); +DELETE FROM vocabularyterm_synonyms WHERE vocabularyterm_id IN (SELECT id FROM vocabularyterm WHERE name = 'chemical stimulus'); + +INSERT INTO vocabularyterm_synonyms (vocabularyterm_id, synonyms) SELECT id, 'tissue type study' FROM vocabularyterm WHERE name = 'anatomical structure'; +INSERT INTO vocabularyterm_synonyms (vocabularyterm_id, synonyms) SELECT id, 'tissue specific' FROM vocabularyterm WHERE name = 'anatomical structure'; + +INSERT INTO vocabularyterm_synonyms (vocabularyterm_id, synonyms) SELECT id, 'chemical stimulus study' FROM vocabularyterm WHERE name = 'chemical stimulus'; +INSERT INTO vocabularyterm_synonyms (vocabularyterm_id, synonyms) SELECT id, 'response to chemical' FROM vocabularyterm WHERE name = 'chemical stimulus'; \ No newline at end of file