Skip to content
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

RGD load and category tag validation change #1685

Merged
merged 1 commit into from
Oct 9, 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 @@ -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;
Expand Down Expand Up @@ -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<VocabularyTerm> categoryTags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> synonyms;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,18 +118,33 @@ public HTPExpressionDatasetAnnotation validateHTPExpressionDatasetAnnotationFmsD
}

if (CollectionUtils.isNotEmpty(dto.getCategoryTags())) {
List<VocabularyTerm> categoryTags = new ArrayList<>();
Map<String, VocabularyTerm> 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<String, Object> params = new HashMap<>();
params.put("name", categoryTag);
params.put("query_operator", "or");
params.put("synonyms", categoryTag);
SearchResponse<VocabularyTerm> 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);
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/db/migration/v0.37.0.58__htp_tags_fix.sql
Original file line number Diff line number Diff line change
@@ -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';
Loading