Commit eb156533 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

ACCENAME in AccessionData

- Fixed JSPs
- lazy init of aliases for accessionName
- added test for accessionName
parent e8d8529d
...@@ -32,17 +32,18 @@ import javax.persistence.MapsId; ...@@ -32,17 +32,18 @@ import javax.persistence.MapsId;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
import javax.persistence.PrePersist; import javax.persistence.PrePersist;
import javax.persistence.PreUpdate; import javax.persistence.PreUpdate;
import javax.persistence.PostLoad;
import javax.persistence.Transient; import javax.persistence.Transient;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern; import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonGetter;
import org.genesys.blocks.model.AuditedVersionedModel; import org.genesys.blocks.model.AuditedVersionedModel;
import org.genesys.blocks.model.IdUUID; import org.genesys.blocks.model.IdUUID;
import org.genesys.blocks.model.JsonViews; import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.model.SelfCleaning; 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.AccessionIdentifier3;
import org.genesys2.server.model.impl.Country; import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.Crop; import org.genesys2.server.model.impl.Crop;
...@@ -54,6 +55,7 @@ import org.springframework.data.elasticsearch.annotations.Field; ...@@ -54,6 +55,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex; import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType; import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
...@@ -230,6 +232,11 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU ...@@ -230,6 +232,11 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
this.duplSiteStr = MCPDUtil.toMcpdArray(accessionId.getDuplSite()); this.duplSiteStr = MCPDUtil.toMcpdArray(accessionId.getDuplSite());
} }
@PostLoad
private void lazyInit() {
getAccessionName();
}
public FaoInstitute getInstitute() { public FaoInstitute getInstitute() {
return this.institute; return this.institute;
} }
...@@ -343,11 +350,11 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU ...@@ -343,11 +350,11 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
public void setInTrust(final Boolean inTrust) { public void setInTrust(final Boolean inTrust) {
this.inTrust = inTrust; this.inTrust = inTrust;
} }
public Boolean isAvailable() { public Boolean isAvailable() {
return available; return available;
} }
public void setAvailable(Boolean available) { public void setAvailable(Boolean available) {
this.available = available; this.available = available;
} }
...@@ -443,7 +450,7 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU ...@@ -443,7 +450,7 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
public void setDoi(final String doi) { public void setDoi(final String doi) {
this.doi = doi; this.doi = doi;
} }
public String getAccNames() { public String getAccNames() {
return accNames; return accNames;
} }
...@@ -492,11 +499,11 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU ...@@ -492,11 +499,11 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
this.donorNumb = donorNumb; this.donorNumb = donorNumb;
} }
@Transient @JsonGetter
@JsonIgnore
// TODO Remove
public String getAccessionName() { 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 @Transient
......
...@@ -260,7 +260,7 @@ public class SelectionController extends BaseController { ...@@ -260,7 +260,7 @@ public class SelectionController extends BaseController {
g.lng = acnGeo.getLongitude(); g.lng = acnGeo.getLongitude();
AccessionData a = genesysService.getAccession(g.id); AccessionData a = genesysService.getAccession(g.id);
g.uuid = a.getUuid().toString(); g.uuid = a.getUuid().toString();
g.accessionName = a.getAccessionNumber(); g.acccessionNumber = a.getAccessionNumber();
g.instCode = a.getInstituteCode(); g.instCode = a.getInstituteCode();
geo.add(g); geo.add(g);
} }
...@@ -299,7 +299,7 @@ public class SelectionController extends BaseController { ...@@ -299,7 +299,7 @@ public class SelectionController extends BaseController {
public long id; public long id;
public Double lat; public Double lat;
public Double lng; public Double lng;
public String accessionName; public String acccessionNumber;
public String instCode; public String instCode;
} }
......
...@@ -373,6 +373,7 @@ public class AccessionServiceImpl implements AccessionService { ...@@ -373,6 +373,7 @@ public class AccessionServiceImpl implements AccessionService {
} }
List<Accession> content = accessionRepository.findAll(filter, page); List<Accession> content = accessionRepository.findAll(filter, page);
content.forEach(accession -> lazyLoad(accession));
long total = countAccessions(filter); long total = countAccessions(filter);
......
...@@ -4,21 +4,21 @@ ...@@ -4,21 +4,21 @@
<html> <html>
<head> <head>
<title><spring:message code="accession.page.profile.title" arguments="${accession.accessionName}" argumentSeparator="|"/></title> <title><spring:message code="accession.page.profile.title" arguments="${accession.accessionNumber}" argumentSeparator="|"/></title>
<local:content-headers description="${jspHelper.htmlToText(blurb.summary, 150)}" title="${accession.accessionName} | ${accession.instituteCode}" keywords="${accession.accessionName}"/> <local:content-headers description="${jspHelper.htmlToText(blurb.summary, 150)}" title="${accession.accessionNumber} | ${accession.instituteCode}" keywords="${accession.accessionNumber}"/>
</head> </head>
<body class="accession-page" typeof="germplasm:GermplasmAccession"> <body class="accession-page" typeof="germplasm:GermplasmAccession">
<h1 class="green-bg"> <h1 class="green-bg">
<span property="dwc:catalogNumber"> <span property="dwc:catalogNumber">
<c:out value="${accession.accessionName}"/> <c:out value="${accession.accessionNumber}"/>
</span> </span>
<small property="dwc:institutionCode" datatype="germplasmType:wiewsInstituteID"><c:out value="${accession.instituteCode}"/></small> <small property="dwc:institutionCode" datatype="germplasmType:wiewsInstituteID"><c:out value="${accession.instituteCode}"/></small>
</h1> </h1>
<div class="row main-col-header acn"> <div class="row main-col-header acn">
<div class="sel" x-aid="${accession.id}"> <div class="sel" x-aid="${accession.id}">
<a class="add" href=""><spring:message code="selection.add" arguments="${accession.accessionName}"/></a> <a class="add" href=""><spring:message code="selection.add" arguments="${accession.accessionNumber}"/></a>
<a class="remove" href=""><spring:message code="selection.remove" arguments="${accession.accessionName}"/></a> <a class="remove" href=""><spring:message code="selection.remove" arguments="${accession.accessionNumber}"/></a>
</div> </div>
</div> </div>
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
<div class="crop-details"> <div class="crop-details">
<div class="collect-info basic-info"> <div class="collect-info basic-info">
<h4 class="section-heading"> <h4 class="section-heading">
<spring:message code="accession.page.profile.title" arguments="${accession.accessionName}" argumentSeparator="|"/></h4> <spring:message code="accession.page.profile.title" arguments="${accession.accessionNumber}" argumentSeparator="|"/></h4>
<div class="section-inner-content"> <div class="section-inner-content">
<c:if test="${accession.doi ne null}"> <c:if test="${accession.doi ne null}">
...@@ -404,7 +404,7 @@ ...@@ -404,7 +404,7 @@
<security:authorize access="hasRole('ADMINISTRATOR') or hasPermission(#accession.institute, 'ADMINISTRATION')"> <security:authorize access="hasRole('ADMINISTRATOR') or hasPermission(#accession.institute, 'ADMINISTRATION')">
<div class="row"> <div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group"> <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 form-group">
<a href="<c:url value=" /wiews/${accession.institute.code}/files/acn/${accession.accessionName}" />" class="btn btn-default"> <a href="<c:url value=" /wiews/${accession.institute.code}/files/acn/${accession.accessionNumber}" />" class="btn btn-default">
<spring:message code="file.manage-files"/> <spring:message code="file.manage-files"/>
</a> </a>
</div> </div>
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<div class="col-sm-2"> <div class="col-sm-2">
<c:choose> <c:choose>
<c:when test="${accession.getClass().simpleName=='AccessionHistoric'}"> <c:when test="${accession.getClass().simpleName=='AccessionHistoric'}">
<a href="<c:url value="/archive/${accession.uuid}" />"><c:out value="${accession.accessionName}" /></a> <a href="<c:url value="/archive/${accession.uuid}" />"><c:out value="${accession.accessionNumber}" /></a>
</c:when> </c:when>
<c:otherwise> <c:otherwise>
<local:accession-details-link accession="${accession}" /> <local:accession-details-link accession="${accession}" />
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
respObject.forEach(function(acn) { respObject.forEach(function(acn) {
if (acn.lat!=null && acn.lng!=null) { if (acn.lat!=null && acn.lng!=null) {
var marker = L.marker([acn.lat, acn.lng]).addTo(map); var marker = L.marker([acn.lat, acn.lng]).addTo(map);
marker.bindPopup("<a href='<c:url value="/a/" />" + acn.uuid +"'>"+acn.accessionName+"</a>"); marker.bindPopup("<a href='<c:url value="/a/" />" + acn.uuid +"'>"+acn.acccessionNumber+"</a>");
bounds.add([acn.lat, acn.lng]); bounds.add([acn.lat, acn.lng]);
} }
}); });
......
...@@ -18,6 +18,7 @@ package org.genesys.test.server.api.v1; ...@@ -18,6 +18,7 @@ package org.genesys.test.server.api.v1;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertNull;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
...@@ -401,6 +402,32 @@ public class AccessionControllerTest extends AbstractApiTest { ...@@ -401,6 +402,32 @@ public class AccessionControllerTest extends AbstractApiTest {
assertThat("acceName must be an empty array", result.getAccessionId().getAliases().size(), is(0)); 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 @Test
public void testCollNumb() throws Exception { public void testCollNumb() throws Exception {
ObjectNode accessionJson = setUpAccession(); ObjectNode accessionJson = setUpAccession();
......
...@@ -446,7 +446,7 @@ public class AccessionUploaderTest extends AbstractServicesTest { ...@@ -446,7 +446,7 @@ public class AccessionUploaderTest extends AbstractServicesTest {
AccessionHistoric accession1Historic = accessionHistoricRepository.findOneByUuid(accWithoutDoi.getUuid()); AccessionHistoric accession1Historic = accessionHistoricRepository.findOneByUuid(accWithoutDoi.getUuid());
assertNotNull(accession1Historic); assertNotNull(accession1Historic);
assertEquals(accession1Historic.getAccessionName(), accWithoutDoi.getAccessionName()); assertEquals(accession1Historic.getAccessionNumber(), accWithoutDoi.getAccessionNumber());
Accession accWithDoiOut = accessionRepository.findByInstituteCodeAndAccessionNumber(institute.getCode(), ACCENUMB_2); Accession accWithDoiOut = accessionRepository.findByInstituteCodeAndAccessionNumber(institute.getCode(), ACCENUMB_2);
assertEquals(accWithDoiOut.getUuid(), accWithDoi.getUuid()); assertEquals(accWithDoiOut.getUuid(), accWithDoi.getUuid());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment