From c831a303785625c37d35fa26975ba60a740b7378 Mon Sep 17 00:00:00 2001 From: Christian Pich Date: Fri, 24 Jan 2025 20:58:51 +0100 Subject: [PATCH] SCRUM-4667 fix review suggestions --- .../model/entities/AffectedGenomicModel.java | 16 +------ .../agmAssociations/AgmAgmAssociation.java | 8 ++-- .../AgmAgmAssociationService.java | 8 ++-- ...0.38.0.30__agm_agm_association_loads_2.sql | 4 ++ .../AgmAgmAssociationBulkUploadITCase.java | 45 +++++++------------ ...D_01_update_all_except_default_fields.json | 4 +- 6 files changed, 33 insertions(+), 52 deletions(-) create mode 100644 src/main/resources/db/migration/v0.38.0.30__agm_agm_association_loads_2.sql 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 78392e389..cfde49efe 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 @@ -93,18 +93,6 @@ public class AffectedGenomicModel extends GenomicEntity { @OneToMany(mappedBy = "agmAssociationSubject", cascade = CascadeType.ALL, orphanRemoval = true) @JsonView({View.FieldsAndLists.class, View.AffectedGenomicModelDetailView.class}) private List components; - @IndexedEmbedded(includePaths = { - "agmAssociationSubject.name", - "agmAssociationSubject.name_keyword", - "agmAssociationSubject.synonyms", - "agmAssociationSubject.synonyms_keyword", - "agmAssociationSubject.secondaryIdentifiers", - "agmAssociationSubject.secondaryIdentifiers_keyword" - }) - @OneToMany(mappedBy = "agmAssociationSubject", cascade = CascadeType.ALL, orphanRemoval = true) - @JsonView({View.FieldsAndLists.class, View.AffectedGenomicModelDetailView.class}) - private List agmAgmAssociations; - @IndexedEmbedded(includePaths = { "agmAgmAssociationObject.name", "agmAgmAssociationObject.name_keyword", @@ -113,8 +101,8 @@ public class AffectedGenomicModel extends GenomicEntity { "agmAgmAssociationObject.secondaryIdentifiers", "agmAgmAssociationObject.secondaryIdentifiers_keyword" }) - @OneToMany(mappedBy = "agmAgmAssociationObject", cascade = CascadeType.ALL, orphanRemoval = true) + @OneToMany(mappedBy = "agmAssociationSubject", cascade = CascadeType.ALL, orphanRemoval = true) @JsonView({View.FieldsAndLists.class, View.AffectedGenomicModelDetailView.class}) - private List agmAgmObjectAssociations; + private List parentalPopulations; } diff --git a/src/main/java/org/alliancegenome/curation_api/model/entities/associations/agmAssociations/AgmAgmAssociation.java b/src/main/java/org/alliancegenome/curation_api/model/entities/associations/agmAssociations/AgmAgmAssociation.java index bf5488dbc..15fba8303 100644 --- a/src/main/java/org/alliancegenome/curation_api/model/entities/associations/agmAssociations/AgmAgmAssociation.java +++ b/src/main/java/org/alliancegenome/curation_api/model/entities/associations/agmAssociations/AgmAgmAssociation.java @@ -43,10 +43,10 @@ public class AgmAgmAssociation extends Association { @IndexedEmbedded(includePaths = { "curie", "name", "curie_keyword", "name_keyword", - "primaryExternalId", "perimaryExternalId_keyword", "modInternalId", "modInternalId_keyword"}) + "primaryExternalId", "primaryExternalId_keyword", "modInternalId", "modInternalId_keyword"}) @ManyToOne @JsonView({View.FieldsOnly.class}) - @JsonIgnoreProperties({"agmAgmAssociations", "agmAgmObjectAssociations", "agmSequenceTargetingReagentAssociations"}) + @JsonIgnoreProperties({"parentalPopulations", "agmSequenceTargetingReagentAssociations"}) @Fetch(FetchMode.JOIN) private AffectedGenomicModel agmAssociationSubject; @@ -56,10 +56,10 @@ public class AgmAgmAssociation extends Association { @JsonView({View.FieldsOnly.class}) private VocabularyTerm relation; - @IndexedEmbedded(includePaths = {"name", "synonyms", "secondaryIdentifiers"}) + @IndexedEmbedded(includePaths = {"name", "synonyms"}) @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW) @ManyToOne @JsonView({View.FieldsOnly.class}) - @JsonIgnoreProperties({"agmAgmAssociations", "agmAgmObjectAssociations", "agmSequenceTargetingReagentAssociations"}) + @JsonIgnoreProperties({"parentalPopulations", "agmSequenceTargetingReagentAssociations"}) private AffectedGenomicModel agmAgmAssociationObject; } diff --git a/src/main/java/org/alliancegenome/curation_api/services/associations/agmAssociations/AgmAgmAssociationService.java b/src/main/java/org/alliancegenome/curation_api/services/associations/agmAssociations/AgmAgmAssociationService.java index 907f8a112..2b517f17c 100644 --- a/src/main/java/org/alliancegenome/curation_api/services/associations/agmAssociations/AgmAgmAssociationService.java +++ b/src/main/java/org/alliancegenome/curation_api/services/associations/agmAssociations/AgmAgmAssociationService.java @@ -127,10 +127,10 @@ public ObjectResponse getAssociation(Long agmId, String relat private void addAssociationToAgm(AgmAgmAssociation association) { AffectedGenomicModel agm = association.getAgmAssociationSubject(); - List currentAssociations = agm.getAgmAgmAssociations(); + List currentAssociations = agm.getParentalPopulations(); if (currentAssociations == null) { currentAssociations = new ArrayList<>(); - agm.setAgmAgmAssociations(currentAssociations); + agm.setParentalPopulations(currentAssociations); } List currentAssociationIds = new ArrayList<>(); @@ -145,10 +145,10 @@ private void addAssociationToAgm(AgmAgmAssociation association) { private void addAssociationToStr(AgmAgmAssociation association) { AffectedGenomicModel str = association.getAgmAgmAssociationObject(); - List currentAssociations = str.getAgmAgmAssociations(); + List currentAssociations = str.getParentalPopulations(); if (currentAssociations == null) { currentAssociations = new ArrayList<>(); - str.setAgmAgmAssociations(currentAssociations); + str.setParentalPopulations(currentAssociations); } List currentAssociationIds = new ArrayList<>(); diff --git a/src/main/resources/db/migration/v0.38.0.30__agm_agm_association_loads_2.sql b/src/main/resources/db/migration/v0.38.0.30__agm_agm_association_loads_2.sql new file mode 100644 index 000000000..841b6d8e0 --- /dev/null +++ b/src/main/resources/db/migration/v0.38.0.30__agm_agm_association_loads_2.sql @@ -0,0 +1,4 @@ +drop INDEX agmagmassociation_agmassocobject_in; +ALTER TABLE public.agmagmassociation DROP CONSTRAINT agmstrassociation_agmassociationobject_fk; +CREATE INDEX agmagmassociation_agmassocobject_in ON public.agmagmassociation USING btree (agmAgmAssociationObject_id); +ALTER TABLE ONLY public.agmagmassociation ADD CONSTRAINT agmagmassociation_agmassociationobject_fk FOREIGN KEY (agmAgmAssociationObject_id) REFERENCES public.affectedgenomicmodel(id); diff --git a/src/test/java/org/alliancegenome/curation_api/AgmAgmAssociationBulkUploadITCase.java b/src/test/java/org/alliancegenome/curation_api/AgmAgmAssociationBulkUploadITCase.java index c17ae5f27..dea4ed731 100644 --- a/src/test/java/org/alliancegenome/curation_api/AgmAgmAssociationBulkUploadITCase.java +++ b/src/test/java/org/alliancegenome/curation_api/AgmAgmAssociationBulkUploadITCase.java @@ -26,8 +26,12 @@ public class AgmAgmAssociationBulkUploadITCase extends BaseITCase { private AffectedGenomicModel agmSubject; private AffectedGenomicModel agmObject; + private AffectedGenomicModel agmSubject2; + private AffectedGenomicModel agmObject2; private String agmSubjectCurie = "AMGTEST:AffectedGenomicModel0010"; private String agmObjectCurie = "AMGTEST:AffectedGenomicModel0020"; + private String agmSubjectCurie2 = "AMGTEST:AffectedGenomicModel00102"; + private String agmObjectCurie2 = "AMGTEST:AffectedGenomicModel00202"; private String relationName = "has_parental_population"; @BeforeEach @@ -55,14 +59,15 @@ public void agmAgmAssociationBulkUploadCheckFields() throws Exception { loadRequiredEntities(); checkSuccessfulBulkLoad(agmAgmAssociationBulkPostEndpoint, agmAgmAssociationTestFilePath + "AF_01_all_fields.json"); - + + String s = agmAgmAssociationGetEndpoint + "?agmSubjectId=" + agmSubject.getId() + "&relationName=" + relationName + "&agmObjectId=" + agmObject.getId(); + System.out.println(s); RestAssured.given(). when(). - get(agmAgmAssociationGetEndpoint + "?agmSubjectId=" + agmSubject.getId() + "&relationName=" + relationName + "&agmObjectId=" + agmObject.getId()). + get(s). then(). statusCode(200). body("entity.relation.name", is(relationName)). - body("entity.agmAgmAssociationObject.primaryExternalId", is(agmObjectCurie)). body("entity.agmAssociationSubject.primaryExternalId", is(agmSubjectCurie)). body("entity.internal", is(false)). body("entity.obsolete", is(false)). @@ -76,22 +81,14 @@ public void agmAgmAssociationBulkUploadCheckFields() throws Exception { get(agmGetEndpoint + agmSubjectCurie). then(). statusCode(200). - body("entity.agmAgmAssociations", hasSize(1)). - body("entity.agmAgmAssociations[0].relation.name", is(relationName)). - body("entity.agmAgmAssociations[0].agmAssociationSubject.primaryExternalId", is(agmSubjectCurie)). - body("entity.agmAgmAssociations[0].agmAssociationSubject", not(hasKey("agmAgmAssociationObject"))); + body("entity.parentalPopulations", hasSize(1)). + body("entity.parentalPopulations[0].relation.name", is(relationName)). + body("entity.parentalPopulations[0].agmAssociationSubject.primaryExternalId", is(agmSubjectCurie)). + body("entity.parentalPopulations[0].agmAssociationSubject", not(hasKey("agmAgmAssociationObject"))); - RestAssured.given(). - when(). - get(agmGetEndpoint + agmObjectCurie). - then(). - statusCode(200). - body("entity.agmAgmObjectAssociations", hasSize(1)). - body("entity.agmAgmObjectAssociations[0].relation.name", is(relationName)). - body("entity.agmAgmObjectAssociations[0].agmAssociationSubject.primaryExternalId", is(agmSubjectCurie)). - body("entity.agmAgmObjectAssociations[0].agmAgmAssociationObject", not(hasKey("agmAgmAssociations"))); } + @Test @Order(2) public void agmAgmAssociationBulkUploadUpdateCheckFields() throws Exception { @@ -99,12 +96,11 @@ public void agmAgmAssociationBulkUploadUpdateCheckFields() throws Exception { RestAssured.given(). when(). - get(agmAgmAssociationGetEndpoint + "?agmSubjectId=" + agmSubject.getId() + "&relationName=" + relationName + "&agmObjectId=" + agmObject.getId()). + get(agmAgmAssociationGetEndpoint + "?agmSubjectId=" + agmSubject2.getId() + "&relationName=" + relationName + "&agmObjectId=" + agmObject2.getId()). then(). statusCode(200). body("entity.relation.name", is(relationName)). - body("entity.agmAgmAssociationObject.primaryExternalId", is(agmObjectCurie)). - body("entity.agmAssociationSubject.primaryExternalId", is(agmSubjectCurie)). + body("entity.agmAssociationSubject.primaryExternalId", is(agmSubjectCurie2)). body("entity.internal", is(true)). body("entity.obsolete", is(true)). body("entity.createdBy.uniqueId", is("AGMTEST:Person0001")). @@ -115,17 +111,10 @@ public void agmAgmAssociationBulkUploadUpdateCheckFields() throws Exception { RestAssured.given(). when(). - get(agmGetEndpoint + agmSubjectCurie). - then(). - statusCode(200). - body("entity.agmSequenceTargetingReagentAssociations", hasSize(1)); - - RestAssured.given(). - when(). - get(agmGetEndpoint + agmObjectCurie). + get(agmGetEndpoint + agmSubjectCurie2). then(). statusCode(200). - body("entity.agmSequenceTargetingReagentAssociations", hasSize(1)); + body("entity.agmAgmAssociations", hasSize(1)); } @Test diff --git a/src/test/resources/bulk/AGMA01_agm_agm_association/UD_01_update_all_except_default_fields.json b/src/test/resources/bulk/AGMA01_agm_agm_association/UD_01_update_all_except_default_fields.json index 58d0c4956..c5b20a345 100644 --- a/src/test/resources/bulk/AGMA01_agm_agm_association/UD_01_update_all_except_default_fields.json +++ b/src/test/resources/bulk/AGMA01_agm_agm_association/UD_01_update_all_except_default_fields.json @@ -1,8 +1,8 @@ [ { - "agm_subject_identifier": "AMGTEST:AffectedGenomicModel0010", + "agm_subject_identifier": "AMGTEST:AffectedGenomicModel00102", "relation_name": "has_parental_population", - "agm_object_identifier": "AMGTEST:AffectedGenomicModel0020", + "agm_object_identifier": "AMGTEST:AffectedGenomicModel00202", "internal": true, "obsolete": true, "created_by_curie": "AGMTEST:Person0001",