diff --git a/src/main/java/org/genesys2/server/model/genesys/AccessionData.java b/src/main/java/org/genesys2/server/model/genesys/AccessionData.java index 8b22ed8738424c40a3bbf8bd39e2c9aaaa3ba295..e5cbefcd003bfc2bbe58093eb93373c63a06021c 100644 --- a/src/main/java/org/genesys2/server/model/genesys/AccessionData.java +++ b/src/main/java/org/genesys2/server/model/genesys/AccessionData.java @@ -32,17 +32,18 @@ import javax.persistence.MapsId; import javax.persistence.OneToOne; import javax.persistence.PrePersist; import javax.persistence.PreUpdate; +import javax.persistence.PostLoad; import javax.persistence.Transient; import javax.validation.Valid; import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; import javax.validation.constraints.Size; -import com.fasterxml.jackson.annotation.JsonGetter; import org.genesys.blocks.model.AuditedVersionedModel; import org.genesys.blocks.model.IdUUID; import org.genesys.blocks.model.JsonViews; import org.genesys.blocks.model.SelfCleaning; +import org.genesys2.server.model.genesys.AccessionAlias.AliasType; import org.genesys2.server.model.impl.AccessionIdentifier3; import org.genesys2.server.model.impl.Country; import org.genesys2.server.model.impl.Crop; @@ -54,6 +55,7 @@ import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.FieldIndex; import org.springframework.data.elasticsearch.annotations.FieldType; +import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; @@ -230,6 +232,11 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU this.duplSiteStr = MCPDUtil.toMcpdArray(accessionId.getDuplSite()); } + @PostLoad + private void lazyInit() { + getAccessionName(); + } + public FaoInstitute getInstitute() { return this.institute; } @@ -343,11 +350,11 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU public void setInTrust(final Boolean inTrust) { this.inTrust = inTrust; } - + public Boolean isAvailable() { return available; } - + public void setAvailable(Boolean available) { this.available = available; } @@ -443,7 +450,7 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU public void setDoi(final String doi) { this.doi = doi; } - + public String getAccNames() { return accNames; } @@ -492,11 +499,11 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU this.donorNumb = donorNumb; } - @Transient - @JsonIgnore - // TODO Remove + @JsonGetter public String getAccessionName() { - return this.accessionNumber; + return this.accessionId.getAliases() != null && this.accessionId.getAliases().size() > 0 + ? this.accessionId.getAliases().stream().filter(alias -> alias.getAliasType() == AliasType.ACCENAME).map(alias -> alias.getName()).findFirst().orElse(null) + : null; } @Transient diff --git a/src/main/java/org/genesys2/server/mvc/SelectionController.java b/src/main/java/org/genesys2/server/mvc/SelectionController.java index b1d7b1618d098ac0d69370dbf5b3fe0666b04a08..32867abad56d7afecaa9d62f16b98ed6d8e93d30 100644 --- a/src/main/java/org/genesys2/server/mvc/SelectionController.java +++ b/src/main/java/org/genesys2/server/mvc/SelectionController.java @@ -260,7 +260,7 @@ public class SelectionController extends BaseController { g.lng = acnGeo.getLongitude(); AccessionData a = genesysService.getAccession(g.id); g.uuid = a.getUuid().toString(); - g.accessionName = a.getAccessionNumber(); + g.acccessionNumber = a.getAccessionNumber(); g.instCode = a.getInstituteCode(); geo.add(g); } @@ -299,7 +299,7 @@ public class SelectionController extends BaseController { public long id; public Double lat; public Double lng; - public String accessionName; + public String acccessionNumber; public String instCode; } diff --git a/src/main/java/org/genesys2/server/service/impl/AccessionServiceImpl.java b/src/main/java/org/genesys2/server/service/impl/AccessionServiceImpl.java index cff6af536abb8ee233bca039291bca16e06861f9..7dbb650a91a7e20510ee1c36ed832324b8a17cf9 100644 --- a/src/main/java/org/genesys2/server/service/impl/AccessionServiceImpl.java +++ b/src/main/java/org/genesys2/server/service/impl/AccessionServiceImpl.java @@ -373,6 +373,7 @@ public class AccessionServiceImpl implements AccessionService { } List content = accessionRepository.findAll(filter, page); + content.forEach(accession -> lazyLoad(accession)); long total = countAccessions(filter); diff --git a/src/main/webapp/WEB-INF/jsp/accession/details.jsp b/src/main/webapp/WEB-INF/jsp/accession/details.jsp index 6ea520ec9a42e62c33a765650e5698a879271844..a02ced124916d8b4c0b60c461732c2c57f834d96 100644 --- a/src/main/webapp/WEB-INF/jsp/accession/details.jsp +++ b/src/main/webapp/WEB-INF/jsp/accession/details.jsp @@ -4,21 +4,21 @@ - <spring:message code="accession.page.profile.title" arguments="${accession.accessionName}" argumentSeparator="|"/> - + <spring:message code="accession.page.profile.title" arguments="${accession.accessionNumber}" argumentSeparator="|"/> +

- +

- - + +
@@ -55,7 +55,7 @@

-

+
@@ -404,7 +404,7 @@
diff --git a/src/main/webapp/WEB-INF/jsp/resolver/reverse.jsp b/src/main/webapp/WEB-INF/jsp/resolver/reverse.jsp index 5fe9313c4f44e4008e18ec9319ef49924df9ff1f..96f77244236e9dfa5a6984697ed77d14f6d07bed 100644 --- a/src/main/webapp/WEB-INF/jsp/resolver/reverse.jsp +++ b/src/main/webapp/WEB-INF/jsp/resolver/reverse.jsp @@ -31,7 +31,7 @@
- "> + "> diff --git a/src/main/webapp/WEB-INF/jsp/selection/map.jsp b/src/main/webapp/WEB-INF/jsp/selection/map.jsp index 6fa67164e976f389bccf5adf8bac44b6dca7860b..945831b3cb1bbb64207fab1cf1bd73a211ee2ec9 100644 --- a/src/main/webapp/WEB-INF/jsp/selection/map.jsp +++ b/src/main/webapp/WEB-INF/jsp/selection/map.jsp @@ -30,7 +30,7 @@ respObject.forEach(function(acn) { if (acn.lat!=null && acn.lng!=null) { var marker = L.marker([acn.lat, acn.lng]).addTo(map); - marker.bindPopup(""+acn.accessionName+""); + marker.bindPopup(""+acn.acccessionNumber+""); bounds.add([acn.lat, acn.lng]); } }); diff --git a/src/test/java/org/genesys/test/server/api/v1/AccessionControllerTest.java b/src/test/java/org/genesys/test/server/api/v1/AccessionControllerTest.java index f6e6df9b863a34c4b905aa6a59177c7b80e4124b..42aec11d38bfa05b9016643da3273ffaca27892b 100644 --- a/src/test/java/org/genesys/test/server/api/v1/AccessionControllerTest.java +++ b/src/test/java/org/genesys/test/server/api/v1/AccessionControllerTest.java @@ -18,6 +18,7 @@ package org.genesys.test.server.api.v1; import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertNull; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ -401,6 +402,32 @@ public class AccessionControllerTest extends AbstractApiTest { assertThat("acceName must be an empty array", result.getAccessionId().getAliases().size(), is(0)); } + @Test + public void testAccessionName() throws Exception { + ObjectNode accessionJson = setUpAccession(); + + upsert(accessionJson); + assertThat(accessionRepository.count(), is(1L)); + + accessionJson.put("acceName", "ACCENAME1"); + /*@formatter:off*/ + upsert(accessionJson) + .andExpect(jsonPath("$[0].result.action", equalTo("UPDATE"))); + /*@formatter:on*/ + + assertThat(accessionRepository.count(), is(1L)); + UUID uuid = accessionRepository.findAll().get(0).getUuid(); + Accession result = fetch(uuid); + assertThat(result.getAccessionName(), is("ACCENAME1")); + assertThat(result.getAccessionName(), is(result.getAccessionId().getAliases().get(0).getName())); + + accessionJson.set("acceName", null); + upsert(accessionJson); + result = fetch(uuid); + assertThat("aliases must be an empty array", result.getAccessionId().getAliases().size(), is(0)); + assertNull("acceName must be null", result.getAccessionName()); + } + @Test public void testCollNumb() throws Exception { ObjectNode accessionJson = setUpAccession(); diff --git a/src/test/java/org/genesys/test/server/services/AccessionUploaderTest.java b/src/test/java/org/genesys/test/server/services/AccessionUploaderTest.java index 2ed385296e764eab92bd9ea1cc719aa2303616e2..29c0c77caf5776b28a4f21829c87958652dd5975 100644 --- a/src/test/java/org/genesys/test/server/services/AccessionUploaderTest.java +++ b/src/test/java/org/genesys/test/server/services/AccessionUploaderTest.java @@ -446,7 +446,7 @@ public class AccessionUploaderTest extends AbstractServicesTest { AccessionHistoric accession1Historic = accessionHistoricRepository.findOneByUuid(accWithoutDoi.getUuid()); assertNotNull(accession1Historic); - assertEquals(accession1Historic.getAccessionName(), accWithoutDoi.getAccessionName()); + assertEquals(accession1Historic.getAccessionNumber(), accWithoutDoi.getAccessionNumber()); Accession accWithDoiOut = accessionRepository.findByInstituteCodeAndAccessionNumber(institute.getCode(), ACCENUMB_2); assertEquals(accWithDoiOut.getUuid(), accWithDoi.getUuid());