diff --git a/src/main/java/org/alliancegenome/curation_api/dao/ReferenceDAO.java b/src/main/java/org/alliancegenome/curation_api/dao/ReferenceDAO.java index 3edde99bb..1c716ae73 100644 --- a/src/main/java/org/alliancegenome/curation_api/dao/ReferenceDAO.java +++ b/src/main/java/org/alliancegenome/curation_api/dao/ReferenceDAO.java @@ -1,11 +1,13 @@ package org.alliancegenome.curation_api.dao; -import org.alliancegenome.curation_api.dao.base.BaseSQLDAO; -import org.alliancegenome.curation_api.model.entities.Reference; - import jakarta.enterprise.context.ApplicationScoped; import jakarta.persistence.Query; import jakarta.transaction.Transactional; +import org.alliancegenome.curation_api.dao.base.BaseSQLDAO; +import org.alliancegenome.curation_api.model.entities.Reference; + +import java.util.*; +import java.util.stream.Collectors; @ApplicationScoped public class ReferenceDAO extends BaseSQLDAO { @@ -35,4 +37,53 @@ protected void deleteReferenceForeignKey(String table, String column, String ori jpqlQuery.executeUpdate(); } + public HashMap getReferenceMap() { + HashMap referenceIdMap = new HashMap<>(); + Query q = entityManager.createNativeQuery(""" + SELECT ref.id, cr.referencedcurie + FROM Reference as ref, reference_crossreference as assoc, Crossreference as cr + where assoc.reference_id = ref.id + and assoc.crossreferences_id = cr.id + """); + List ids = q.getResultList(); + Set refIDs = ids.stream().map(object -> (Long) object[0]).collect(Collectors.toSet()); + Map> idMap = ids.stream().collect(Collectors.groupingBy(o -> (Long) o[0])); + List refs = new ArrayList<>(); + refIDs.forEach(id -> { + Reference reference = entityManager.getReference(Reference.class, id); + refs.add(reference); + referenceIdMap.put(String.valueOf(id), reference); + if (idMap.get(id) != null) { + idMap.get(id).forEach(objects -> { + referenceIdMap.put((String) objects[1], reference); + }); + } + }); + return referenceIdMap; + } + + public HashMap getShallowReferenceMap() { + HashMap referenceIdMap = new HashMap<>(); + Query q = entityManager.createNativeQuery(""" + SELECT ref.id, cr.referencedcurie + FROM Reference as ref, reference_crossreference as assoc, Crossreference as cr + where assoc.reference_id = ref.id + and assoc.crossreferences_id = cr.id + """); + List ids = q.getResultList(); + Set refIDs = ids.stream().map(object -> (Long) object[0]).collect(Collectors.toSet()); + Map> idMap = ids.stream().collect(Collectors.groupingBy(o -> (Long) o[0])); + List refs = new ArrayList<>(); + refIDs.forEach(id -> { + Reference reference = getShallowEntity(Reference.class, id); + refs.add(reference); + referenceIdMap.put(String.valueOf(id), reference); + if (idMap.get(id) != null) { + idMap.get(id).forEach(objects -> { + referenceIdMap.put((String) objects[1], reference); + }); + } + }); + return referenceIdMap; + } } diff --git a/src/main/java/org/alliancegenome/curation_api/model/entities/AffectedGenomicModel.java b/src/main/java/org/alliancegenome/curation_api/model/entities/AffectedGenomicModel.java index bf2b61b71..c9611c9a3 100644 --- a/src/main/java/org/alliancegenome/curation_api/model/entities/AffectedGenomicModel.java +++ b/src/main/java/org/alliancegenome/curation_api/model/entities/AffectedGenomicModel.java @@ -4,6 +4,7 @@ import org.alliancegenome.curation_api.constants.LinkMLSchemaConstants; import org.alliancegenome.curation_api.interfaces.AGRCurationSchemaVersion; +import org.alliancegenome.curation_api.model.entities.associations.constructAssociations.ConstructGenomicEntityAssociation; import org.alliancegenome.curation_api.view.View; import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.hibernate.search.mapper.pojo.automaticindexing.ReindexOnUpdate; @@ -26,7 +27,7 @@ @Entity @Data @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true) -@ToString(exclude = { "agmDiseaseAnnotations" }, callSuper = true) +@ToString(exclude = { "agmDiseaseAnnotations", "constructGenomicEntityAssociations" }, callSuper = true) @Schema(name = "AffectedGenomicModel", description = "POJO that represents the AGM") @AGRCurationSchemaVersion(min = "1.5.0", max = LinkMLSchemaConstants.LATEST_RELEASE, dependencies = { GenomicEntity.class }, partial = true) public class AffectedGenomicModel extends GenomicEntity { @@ -43,4 +44,15 @@ public class AffectedGenomicModel extends GenomicEntity { @ManyToOne @JsonView({ View.FieldsOnly.class, View.ForPublic.class }) private VocabularyTerm subtype; + + @IndexedEmbedded(includePaths = { + "constructAssociationSubject.curie", "constructAssociationSubject.constructSymbol.displayText", "constructAssociationSubject.constructSymbol.formatText", + "constructAssociationSubject.constructFullName.displayText", "constructAssociationSubject.constructFullName.formatText", "constructAssociationSubject.modEntityId", + "constructAssociationSubject.curie_keyword", "constructAssociationSubject.constructSymbol.displayText_keyword", "constructAssociationSubject.constructSymbol.formatText_keyword", + "constructAssociationSubject.constructFullName.displayText_keyword", "constructAssociationSubject.constructFullName.formatText_keyword", "constructAssociationSubject.modEntityId_keyword" + }) + @OneToMany(mappedBy = "constructGenomicEntityAssociationObject", cascade = CascadeType.ALL, orphanRemoval = true) + @JsonView({ View.FieldsAndLists.class, View.GeneDetailView.class }) + private List constructGenomicEntityAssociations; + } diff --git a/src/main/java/org/alliancegenome/curation_api/model/entities/Allele.java b/src/main/java/org/alliancegenome/curation_api/model/entities/Allele.java index d5d9a1bbc..18bd7a5e1 100644 --- a/src/main/java/org/alliancegenome/curation_api/model/entities/Allele.java +++ b/src/main/java/org/alliancegenome/curation_api/model/entities/Allele.java @@ -2,11 +2,13 @@ import java.util.List; +import jakarta.persistence.*; import org.alliancegenome.curation_api.constants.LinkMLSchemaConstants; import org.alliancegenome.curation_api.interfaces.AGRCurationSchemaVersion; import org.alliancegenome.curation_api.model.bridges.BooleanAndNullValueBridge; import org.alliancegenome.curation_api.model.entities.associations.alleleAssociations.AlleleGeneAssociation; import org.alliancegenome.curation_api.model.entities.associations.alleleAssociations.AlleleVariantAssociation; +import org.alliancegenome.curation_api.model.entities.associations.constructAssociations.ConstructGenomicEntityAssociation; import org.alliancegenome.curation_api.model.entities.slotAnnotations.alleleSlotAnnotations.AlleleDatabaseStatusSlotAnnotation; import org.alliancegenome.curation_api.model.entities.slotAnnotations.alleleSlotAnnotations.AlleleFullNameSlotAnnotation; import org.alliancegenome.curation_api.model.entities.slotAnnotations.alleleSlotAnnotations.AlleleFunctionalImpactSlotAnnotation; @@ -34,15 +36,6 @@ import com.fasterxml.jackson.annotation.JsonManagedReference; import com.fasterxml.jackson.annotation.JsonView; -import jakarta.persistence.CascadeType; -import jakarta.persistence.Entity; -import jakarta.persistence.Index; -import jakarta.persistence.JoinTable; -import jakarta.persistence.ManyToMany; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; -import jakarta.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -55,7 +48,7 @@ exclude = { "alleleGeneAssociations", "alleleVariantAssociations", "alleleDiseaseAnnotations", "alleleMutationTypes", "alleleSymbol", "alleleFullName", "alleleSynonyms", "alleleSecondaryIds", "alleleInheritanceModes", "alleleFunctionalImpacts", "alleleGermlineTransmissionStatus", "alleleDatabaseStatus", - "alleleNomenclatureEvents" + "alleleNomenclatureEvents", "constructGenomicEntityAssociations" }, callSuper = true ) @@ -212,4 +205,15 @@ public class Allele extends GenomicEntity { @Index(name = "allele_note_relatednotes_index", columnList = "relatedNotes_id")}) private List relatedNotes; + + @IndexedEmbedded(includePaths = { + "constructAssociationSubject.curie", "constructAssociationSubject.constructSymbol.displayText", "constructAssociationSubject.constructSymbol.formatText", + "constructAssociationSubject.constructFullName.displayText", "constructAssociationSubject.constructFullName.formatText", "constructAssociationSubject.modEntityId", + "constructAssociationSubject.curie_keyword", "constructAssociationSubject.constructSymbol.displayText_keyword", "constructAssociationSubject.constructSymbol.formatText_keyword", + "constructAssociationSubject.constructFullName.displayText_keyword", "constructAssociationSubject.constructFullName.formatText_keyword", "constructAssociationSubject.modEntityId_keyword" + }) + @OneToMany(mappedBy = "constructGenomicEntityAssociationObject", cascade = CascadeType.ALL, orphanRemoval = true) + @JsonView({ View.FieldsAndLists.class, View.GeneDetailView.class }) + private List constructGenomicEntityAssociations; + } diff --git a/src/main/java/org/alliancegenome/curation_api/model/entities/Gene.java b/src/main/java/org/alliancegenome/curation_api/model/entities/Gene.java index cdeaa6496..c84a39d07 100644 --- a/src/main/java/org/alliancegenome/curation_api/model/entities/Gene.java +++ b/src/main/java/org/alliancegenome/curation_api/model/entities/Gene.java @@ -5,6 +5,7 @@ import org.alliancegenome.curation_api.constants.LinkMLSchemaConstants; import org.alliancegenome.curation_api.interfaces.AGRCurationSchemaVersion; import org.alliancegenome.curation_api.model.entities.associations.alleleAssociations.AlleleGeneAssociation; +import org.alliancegenome.curation_api.model.entities.associations.constructAssociations.ConstructGenomicEntityAssociation; import org.alliancegenome.curation_api.model.entities.associations.geneAssociations.GeneGenomicLocationAssociation; import org.alliancegenome.curation_api.model.entities.associations.sequenceTargetingReagentAssociations.SequenceTargetingReagentGeneAssociation; import org.alliancegenome.curation_api.model.entities.associations.transcriptAssociations.TranscriptGeneAssociation; @@ -40,7 +41,7 @@ @Data @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true) @ToString(exclude = { "geneDiseaseAnnotations", "geneGeneAssociations", "geneSymbol", "geneFullName", "geneSystematicName", "geneSynonyms", "geneSecondaryIds", - "geneGenomicLocationAssociations", "alleleGeneAssociations", "sequenceTargetingReagentGeneAssociations", "transcriptGeneAssociations" }, callSuper = true) + "geneGenomicLocationAssociations", "alleleGeneAssociations", "sequenceTargetingReagentGeneAssociations", "transcriptGeneAssociations", "constructGenomicEntityAssociations" }, callSuper = true) @Schema(name = "Gene", description = "POJO that represents the Gene") @AGRCurationSchemaVersion(min = "1.5.0", max = LinkMLSchemaConstants.LATEST_RELEASE, dependencies = { GenomicEntity.class }, partial = true) @Table(indexes = { @Index(name = "gene_genetype_index", columnList = "geneType_id") }) @@ -119,4 +120,16 @@ public class Gene extends GenomicEntity { @OneToMany(mappedBy = "geneAssociationSubject", cascade = CascadeType.ALL, orphanRemoval = true) @JsonView({ View.FieldsAndLists.class, View.GeneDetailView.class }) private List geneGenomicLocationAssociations; + + + @IndexedEmbedded(includePaths = { + "constructAssociationSubject.curie", "constructAssociationSubject.constructSymbol.displayText", "constructAssociationSubject.constructSymbol.formatText", + "constructAssociationSubject.constructFullName.displayText", "constructAssociationSubject.constructFullName.formatText", "constructAssociationSubject.modEntityId", + "constructAssociationSubject.curie_keyword", "constructAssociationSubject.constructSymbol.displayText_keyword", "constructAssociationSubject.constructSymbol.formatText_keyword", + "constructAssociationSubject.constructFullName.displayText_keyword", "constructAssociationSubject.constructFullName.formatText_keyword", "constructAssociationSubject.modEntityId_keyword" + }) + @OneToMany(mappedBy = "constructGenomicEntityAssociationObject", cascade = CascadeType.ALL, orphanRemoval = true) + @JsonView({ View.FieldsAndLists.class, View.GeneDetailView.class }) + private List constructGenomicEntityAssociations; + } diff --git a/src/main/java/org/alliancegenome/curation_api/model/entities/GenomicEntity.java b/src/main/java/org/alliancegenome/curation_api/model/entities/GenomicEntity.java index 3bc9a17c8..1ff242104 100644 --- a/src/main/java/org/alliancegenome/curation_api/model/entities/GenomicEntity.java +++ b/src/main/java/org/alliancegenome/curation_api/model/entities/GenomicEntity.java @@ -1,31 +1,24 @@ package org.alliancegenome.curation_api.model.entities; -import java.util.List; - +import com.fasterxml.jackson.annotation.JsonView; +import jakarta.persistence.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import org.alliancegenome.curation_api.constants.LinkMLSchemaConstants; import org.alliancegenome.curation_api.interfaces.AGRCurationSchemaVersion; -import org.alliancegenome.curation_api.model.entities.associations.constructAssociations.ConstructGenomicEntityAssociation; import org.alliancegenome.curation_api.view.View; import org.hibernate.search.mapper.pojo.automaticindexing.ReindexOnUpdate; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexingDependency; -import com.fasterxml.jackson.annotation.JsonView; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.Entity; -import jakarta.persistence.Index; -import jakarta.persistence.JoinTable; -import jakarta.persistence.OneToMany; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; +import java.util.List; @Entity @Data @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true) -@ToString(exclude = { "constructGenomicEntityAssociations" }, callSuper = true) -@AGRCurationSchemaVersion(min = "1.5.0", max = LinkMLSchemaConstants.LATEST_RELEASE, dependencies = { BiologicalEntity.class }) +@ToString(callSuper = true) +@AGRCurationSchemaVersion(min = "1.5.0", max = LinkMLSchemaConstants.LATEST_RELEASE, dependencies = {BiologicalEntity.class}) public class GenomicEntity extends BiologicalEntity { @IndexedEmbedded(includePaths = {"referencedCurie", "displayName", "resourceDescriptorPage.name", "referencedCurie_keyword", "displayName_keyword", "resourceDescriptorPage.name_keyword"}) @@ -37,18 +30,8 @@ public class GenomicEntity extends BiologicalEntity { @Index(columnList = "crossreferences_id", name = "genomicentity_crossreference_crossreferences_index") }) @EqualsAndHashCode.Include - @JsonView({ View.FieldsAndLists.class, View.AlleleView.class, View.GeneView.class, View.AffectedGenomicModelView.class, View.VariantView.class }) + @JsonView({View.FieldsAndLists.class, View.AlleleView.class, View.GeneView.class, View.AffectedGenomicModelView.class, View.VariantView.class}) private List crossReferences; - - @IndexedEmbedded(includePaths = { - "constructAssociationSubject.curie", "constructAssociationSubject.constructSymbol.displayText", "constructAssociationSubject.constructSymbol.formatText", - "constructAssociationSubject.constructFullName.displayText", "constructAssociationSubject.constructFullName.formatText", "constructAssociationSubject.modEntityId", - "constructAssociationSubject.curie_keyword", "constructAssociationSubject.constructSymbol.displayText_keyword", "constructAssociationSubject.constructSymbol.formatText_keyword", - "constructAssociationSubject.constructFullName.displayText_keyword", "constructAssociationSubject.constructFullName.formatText_keyword", "constructAssociationSubject.modEntityId_keyword" - }) - @OneToMany(mappedBy = "constructGenomicEntityAssociationObject", cascade = CascadeType.ALL, orphanRemoval = true) - @JsonView({ View.FieldsAndLists.class, View.GeneDetailView.class }) - private List constructGenomicEntityAssociations; } diff --git a/src/main/java/org/alliancegenome/curation_api/model/entities/associations/constructAssociations/ConstructGenomicEntityAssociation.java b/src/main/java/org/alliancegenome/curation_api/model/entities/associations/constructAssociations/ConstructGenomicEntityAssociation.java index bee923f50..67b208014 100644 --- a/src/main/java/org/alliancegenome/curation_api/model/entities/associations/constructAssociations/ConstructGenomicEntityAssociation.java +++ b/src/main/java/org/alliancegenome/curation_api/model/entities/associations/constructAssociations/ConstructGenomicEntityAssociation.java @@ -1,14 +1,14 @@ package org.alliancegenome.curation_api.model.entities.associations.constructAssociations; -import java.util.List; - +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonView; +import jakarta.persistence.*; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import org.alliancegenome.curation_api.constants.LinkMLSchemaConstants; import org.alliancegenome.curation_api.interfaces.AGRCurationSchemaVersion; -import org.alliancegenome.curation_api.model.entities.Construct; -import org.alliancegenome.curation_api.model.entities.EvidenceAssociation; -import org.alliancegenome.curation_api.model.entities.GenomicEntity; -import org.alliancegenome.curation_api.model.entities.Note; -import org.alliancegenome.curation_api.model.entities.VocabularyTerm; +import org.alliancegenome.curation_api.model.entities.*; import org.alliancegenome.curation_api.view.View; import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.hibernate.annotations.Fetch; @@ -17,26 +17,13 @@ import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexedEmbedded; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IndexingDependency; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonView; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.Entity; -import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.JoinTable; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToMany; -import jakarta.persistence.Table; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; +import java.util.List; @Entity @Data @EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true) @ToString(callSuper = true) -@AGRCurationSchemaVersion(min = "2.2.0", max = LinkMLSchemaConstants.LATEST_RELEASE, dependencies = { EvidenceAssociation.class }) +@AGRCurationSchemaVersion(min = "2.2.0", max = LinkMLSchemaConstants.LATEST_RELEASE, dependencies = {EvidenceAssociation.class}) @Schema(name = "ConstructGenomicEntityAssociation", description = "POJO representing an association between a construct and a genomic entity") @Table(indexes = { @@ -57,21 +44,21 @@ public class ConstructGenomicEntityAssociation extends EvidenceAssociation { "curie_keyword", "constructSymbol.displayText_keyword", "constructSymbol.formatText_keyword", "constructFullName.displayText_keyword", "constructFullName.formatText_keyword", "modEntityId_keyword", "modInternalId_keyword"}) @ManyToOne - @JsonView({ View.FieldsOnly.class }) + @JsonView({View.FieldsOnly.class}) @JsonIgnoreProperties("constructGenomicEntityAssociations") @Fetch(FetchMode.JOIN) private Construct constructAssociationSubject; - + @IndexedEmbedded(includePaths = {"name", "name_keyword"}) @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW) @ManyToOne - @JsonView({ View.FieldsOnly.class }) + @JsonView({View.FieldsOnly.class}) private VocabularyTerm relation; - + @IndexedEmbedded(includeDepth = 1) @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW) @ManyToOne - @JsonView({ View.FieldsOnly.class }) + @JsonView({View.FieldsOnly.class}) @JsonIgnoreProperties({ "alleleGeneAssociations", "constructGenomicEntityAssociations", "sequenceTargetingReagentGeneAssociations", "transcriptGenomicLocationAssociations", "exonGenomicLocationAssociations", "codingSequenceGenomicLocationAssociations", @@ -85,7 +72,7 @@ public class ConstructGenomicEntityAssociation extends EvidenceAssociation { }) @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW) @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JsonView({ View.FieldsAndLists.class, View.ConstructView.class }) + @JsonView({View.FieldsAndLists.class, View.ConstructView.class}) @JoinTable( joinColumns = @JoinColumn(name = "constructgenomicentityassociation_id"), inverseJoinColumns = @JoinColumn(name = "relatedNotes_id"), diff --git a/src/main/java/org/alliancegenome/curation_api/services/InformationContentEntityService.java b/src/main/java/org/alliancegenome/curation_api/services/InformationContentEntityService.java index 645bdacb0..2f74097e0 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/InformationContentEntityService.java +++ b/src/main/java/org/alliancegenome/curation_api/services/InformationContentEntityService.java @@ -28,4 +28,5 @@ public InformationContentEntity retrieveFromDbOrLiteratureService(String curieOr return ice; } + } diff --git a/src/main/java/org/alliancegenome/curation_api/services/ReferenceService.java b/src/main/java/org/alliancegenome/curation_api/services/ReferenceService.java index 4d8d97576..daa706d9f 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/ReferenceService.java +++ b/src/main/java/org/alliancegenome/curation_api/services/ReferenceService.java @@ -1,10 +1,10 @@ package org.alliancegenome.curation_api.services; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; - +import io.quarkus.logging.Log; +import jakarta.annotation.PostConstruct; +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Inject; +import jakarta.transaction.Transactional; import org.alliancegenome.curation_api.dao.ReferenceDAO; import org.alliancegenome.curation_api.model.entities.Reference; import org.alliancegenome.curation_api.response.ObjectResponse; @@ -12,20 +12,23 @@ import org.alliancegenome.curation_api.services.base.BaseEntityCrudService; import org.alliancegenome.curation_api.services.helpers.references.ReferenceSynchronisationHelper; -import io.quarkus.logging.Log; -import jakarta.annotation.PostConstruct; -import jakarta.enterprise.context.RequestScoped; -import jakarta.inject.Inject; -import jakarta.transaction.Transactional; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; @RequestScoped public class ReferenceService extends BaseEntityCrudService { - @Inject ReferenceDAO referenceDAO; - @Inject ReferenceSynchronisationHelper refSyncHelper; - + @Inject + ReferenceDAO referenceDAO; + @Inject + ReferenceSynchronisationHelper refSyncHelper; + Date referenceRequest; + Date referenceRequestShallow; HashMap referenceCacheMap = new HashMap<>(); + HashMap shallowReferenceCacheMap = new HashMap<>(); @Override @PostConstruct @@ -52,6 +55,9 @@ public ObjectResponse getByCurie(String curie) { public Reference retrieveFromDbOrLiteratureService(String curieOrXref) { Reference reference = null; if (referenceRequest != null) { + if (referenceCacheMap.isEmpty()) { + referenceCacheMap = referenceDAO.getReferenceMap(); + } if (referenceCacheMap.containsKey(curieOrXref)) { reference = referenceCacheMap.get(curieOrXref); } else { @@ -65,7 +71,25 @@ public Reference retrieveFromDbOrLiteratureService(String curieOrXref) { } return reference; } - + + @Transactional + public Reference retrieveShallowReferenceFromDbOrLiteratureService(String curieOrXref) { + Reference reference = null; + if (shallowReferenceCacheMap.containsKey(curieOrXref)) { + reference = shallowReferenceCacheMap.get(curieOrXref); + } else { + Log.debug("Reference not cached, caching reference: (" + curieOrXref + ")"); + if (shallowReferenceCacheMap.isEmpty()) { + shallowReferenceCacheMap = referenceDAO.getShallowReferenceMap(); + reference = shallowReferenceCacheMap.get(curieOrXref); + } else { + reference = findOrCreateReference(curieOrXref); + referenceCacheMap.put(curieOrXref, reference); + } + } + return reference; + } + private Reference findOrCreateReference(String curieOrXref) { Reference reference = null; diff --git a/src/main/java/org/alliancegenome/curation_api/services/associations/constructAssociations/ConstructGenomicEntityAssociationService.java b/src/main/java/org/alliancegenome/curation_api/services/associations/constructAssociations/ConstructGenomicEntityAssociationService.java index 7a0098d77..258396355 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/associations/constructAssociations/ConstructGenomicEntityAssociationService.java +++ b/src/main/java/org/alliancegenome/curation_api/services/associations/constructAssociations/ConstructGenomicEntityAssociationService.java @@ -1,13 +1,10 @@ package org.alliancegenome.curation_api.services.associations.constructAssociations; -import java.time.OffsetDateTime; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; - +import io.quarkus.logging.Log; +import jakarta.annotation.PostConstruct; +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Inject; +import jakarta.transaction.Transactional; import org.alliancegenome.curation_api.constants.EntityFieldConstants; import org.alliancegenome.curation_api.dao.ConstructDAO; import org.alliancegenome.curation_api.dao.GenomicEntityDAO; @@ -18,7 +15,6 @@ import org.alliancegenome.curation_api.exceptions.ValidationException; import org.alliancegenome.curation_api.interfaces.crud.BaseUpsertServiceInterface; import org.alliancegenome.curation_api.model.entities.Construct; -import org.alliancegenome.curation_api.model.entities.GenomicEntity; import org.alliancegenome.curation_api.model.entities.associations.constructAssociations.ConstructGenomicEntityAssociation; import org.alliancegenome.curation_api.model.ingest.dto.associations.constructAssociations.ConstructGenomicEntityAssociationDTO; import org.alliancegenome.curation_api.response.ObjectResponse; @@ -28,23 +24,27 @@ import org.alliancegenome.curation_api.services.validation.associations.constructAssociations.ConstructGenomicEntityAssociationValidator; import org.alliancegenome.curation_api.services.validation.dto.associations.constructAssociations.ConstructGenomicEntityAssociationDTOValidator; -import io.quarkus.logging.Log; -import jakarta.annotation.PostConstruct; -import jakarta.enterprise.context.RequestScoped; -import jakarta.inject.Inject; -import jakarta.transaction.Transactional; +import java.util.*; +import java.util.stream.Collectors; @RequestScoped public class ConstructGenomicEntityAssociationService extends BaseAssociationDTOCrudService implements BaseUpsertServiceInterface { - @Inject ConstructGenomicEntityAssociationDAO constructGenomicEntityAssociationDAO; - @Inject ConstructGenomicEntityAssociationValidator constructGenomicEntityAssociationValidator; - @Inject ConstructGenomicEntityAssociationDTOValidator constructGenomicEntityAssociationDtoValidator; - @Inject ConstructDAO constructDAO; - @Inject GenomicEntityDAO genomicEntityDAO; - @Inject PersonService personService; - @Inject PersonDAO personDAO; + @Inject + ConstructGenomicEntityAssociationDAO constructGenomicEntityAssociationDAO; + @Inject + ConstructGenomicEntityAssociationValidator constructGenomicEntityAssociationValidator; + @Inject + ConstructGenomicEntityAssociationDTOValidator constructGenomicEntityAssociationDtoValidator; + @Inject + ConstructDAO constructDAO; + @Inject + GenomicEntityDAO genomicEntityDAO; + @Inject + PersonService personService; + @Inject + PersonDAO personDAO; @Override @PostConstruct @@ -59,9 +59,11 @@ public ObjectResponse upsert(ConstructGenomic return null; } dbEntity = constructGenomicEntityAssociationDAO.persist(dbEntity); +/* addAssociationToConstruct(dbEntity); addAssociationToGenomicEntity(dbEntity); - return new ObjectResponse(dbEntity); +*/ + return new ObjectResponse<>(dbEntity); } public ObjectResponse validate(ConstructGenomicEntityAssociation uiEntity) { @@ -85,11 +87,11 @@ public List getAssociationsByDataProvider(BackendBulkDataProvider dataProv } @Transactional - public ConstructGenomicEntityAssociation deprecateOrDeleteAssociation(Long id, Boolean throwApiError, String loadDescription, Boolean deprecate) { - ConstructGenomicEntityAssociation association = constructGenomicEntityAssociationDAO.find(id); + public ConstructGenomicEntityAssociation deprecateOrDelete(Long id, Boolean throwApiError, String requestSource, Boolean deprecate) { + ConstructGenomicEntityAssociation object = dao.getShallowEntity(ConstructGenomicEntityAssociation.class, id); - if (association == null) { - String errorMessage = "Could not find ConstructGenomicEntityAssociation with id: " + id; + if (object == null) { + String errorMessage = "Could not find entity with id: " + id; if (throwApiError) { ObjectResponse response = new ObjectResponse<>(); response.addErrorMessage("id", errorMessage); @@ -98,21 +100,7 @@ public ConstructGenomicEntityAssociation deprecateOrDeleteAssociation(Long id, B Log.error(errorMessage); return null; } - if (deprecate) { - if (!association.getObsolete()) { - association.setObsolete(true); - if (authenticatedPerson != null) { - association.setUpdatedBy(personDAO.find(authenticatedPerson.getId())); - } else { - association.setUpdatedBy(personService.fetchByUniqueIdOrCreate(loadDescription)); - } - association.setDateUpdated(OffsetDateTime.now()); - return constructGenomicEntityAssociationDAO.persist(association); - } - } - - constructGenomicEntityAssociationDAO.remove(association.getId()); - + dao.remove(id); return null; } @@ -150,6 +138,7 @@ private void addAssociationToConstruct(ConstructGenomicEntityAssociation associa constructDAO.persist(construct); } +/* private void addAssociationToGenomicEntity(ConstructGenomicEntityAssociation association) { GenomicEntity genomicEntity = association.getConstructGenomicEntityAssociationObject(); List currentAssociations = genomicEntity.getConstructGenomicEntityAssociations(); @@ -164,4 +153,5 @@ private void addAssociationToGenomicEntity(ConstructGenomicEntityAssociation ass genomicEntity.setConstructGenomicEntityAssociations(currentAssociations); genomicEntityDAO.persist(genomicEntity); } +*/ } diff --git a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/associations/EvidenceAssociationDTOValidator.java b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/associations/EvidenceAssociationDTOValidator.java index 4441063db..cdddf074d 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/associations/EvidenceAssociationDTOValidator.java +++ b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/associations/EvidenceAssociationDTOValidator.java @@ -1,8 +1,7 @@ package org.alliancegenome.curation_api.services.validation.dto.associations; -import java.util.ArrayList; -import java.util.List; - +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Inject; import org.alliancegenome.curation_api.constants.ValidationConstants; import org.alliancegenome.curation_api.model.entities.EvidenceAssociation; import org.alliancegenome.curation_api.model.entities.InformationContentEntity; @@ -12,18 +11,19 @@ import org.alliancegenome.curation_api.services.validation.dto.base.BaseDTOValidator; import org.apache.commons.collections.CollectionUtils; -import jakarta.enterprise.context.RequestScoped; -import jakarta.inject.Inject; +import java.util.ArrayList; +import java.util.List; @RequestScoped public class EvidenceAssociationDTOValidator extends BaseDTOValidator { - @Inject InformationContentEntityService informationContentEntityService; + @Inject + InformationContentEntityService informationContentEntityService; public ObjectResponse validateEvidenceAssociationDTO(E association, D dto) { ObjectResponse assocResponse = validateAuditedObjectDTO(association, dto); association = assocResponse.getEntity(); - + if (CollectionUtils.isNotEmpty(dto.getEvidenceCuries())) { List evidence = new ArrayList<>(); for (String evidenceCurie : dto.getEvidenceCuries()) { diff --git a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/associations/constructAssociations/ConstructGenomicEntityAssociationDTOValidator.java b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/associations/constructAssociations/ConstructGenomicEntityAssociationDTOValidator.java index d5b8a7c31..39b11c42e 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/validation/dto/associations/constructAssociations/ConstructGenomicEntityAssociationDTOValidator.java +++ b/src/main/java/org/alliancegenome/curation_api/services/validation/dto/associations/constructAssociations/ConstructGenomicEntityAssociationDTOValidator.java @@ -1,9 +1,7 @@ package org.alliancegenome.curation_api.services.validation.dto.associations.constructAssociations; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Inject; import org.alliancegenome.curation_api.constants.ValidationConstants; import org.alliancegenome.curation_api.constants.VocabularyConstants; import org.alliancegenome.curation_api.dao.associations.constructAssociations.ConstructGenomicEntityAssociationDAO; @@ -27,17 +25,23 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import jakarta.enterprise.context.RequestScoped; -import jakarta.inject.Inject; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; @RequestScoped public class ConstructGenomicEntityAssociationDTOValidator extends EvidenceAssociationDTOValidator { - @Inject ConstructService constructService; - @Inject GenomicEntityService genomicEntityService; - @Inject NoteDTOValidator noteDtoValidator; - @Inject VocabularyTermService vocabularyTermService; - @Inject ConstructGenomicEntityAssociationDAO constructGenomicEntityAssociationDAO; + @Inject + ConstructService constructService; + @Inject + GenomicEntityService genomicEntityService; + @Inject + NoteDTOValidator noteDtoValidator; + @Inject + VocabularyTermService vocabularyTermService; + @Inject + ConstructGenomicEntityAssociationDAO constructGenomicEntityAssociationDAO; private ObjectResponse assocResponse; @@ -47,15 +51,13 @@ public ConstructGenomicEntityAssociation validateConstructGenomicEntityAssociati Construct construct = null; if (StringUtils.isNotBlank(dto.getConstructIdentifier())) { - Long constructId = constructService.getIdByModID(dto.getConstructIdentifier()); - if (constructId != null) { - construct = constructService.getShallowEntity(constructId); - } + construct = constructService.getShallowEntity(constructService.getIdByModID(dto.getConstructIdentifier())); if (construct == null) { assocResponse.addErrorMessage("construct_identifier", ValidationConstants.INVALID_MESSAGE); } else { if (beDataProvider != null && !construct.getDataProvider().getSourceOrganization().getAbbreviation().equals(beDataProvider.sourceOrganization)) { assocResponse.addErrorMessage("construct_identifier", ValidationConstants.INVALID_MESSAGE + " for " + beDataProvider.name() + " load"); + return null; } } } else { @@ -66,15 +68,11 @@ public ConstructGenomicEntityAssociation validateConstructGenomicEntityAssociati if (StringUtils.isBlank(dto.getGenomicEntityIdentifier())) { assocResponse.addErrorMessage("genomic_entity_identifier", ValidationConstants.REQUIRED_MESSAGE); } else { - Long genomicEntityId = genomicEntityService.getIdByModID(dto.getGenomicEntityIdentifier()); - if (genomicEntityId != null) { - genomicEntity = genomicEntityService.getShallowEntity(genomicEntityId); - } + genomicEntity = genomicEntityService.getShallowEntity(genomicEntityService.getIdByModID(dto.getGenomicEntityIdentifier())); if (genomicEntity == null) { assocResponse.addErrorMessage("genomic_entity_identifier", ValidationConstants.INVALID_MESSAGE + " (" + dto.getGenomicEntityIdentifier() + ")"); } } - ConstructGenomicEntityAssociation association = null; if (construct != null && StringUtils.isNotBlank(dto.getGenomicEntityRelationName()) && genomicEntity != null) { HashMap params = new HashMap<>();