Commit 3412bfc2 authored by Matija Obreza's avatar Matija Obreza

Merge branch '444-accename-in-accessiondata' into 'master'

Resolve "ACCENAME in AccessionData"

Closes #444

See merge request genesys-pgr/genesys-server!397
parents e8d8529d eb156533
......@@ -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;
}
......@@ -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
......
......@@ -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;
}
......
......@@ -373,6 +373,7 @@ public class AccessionServiceImpl implements AccessionService {
}
List<Accession> content = accessionRepository.findAll(filter, page);
content.forEach(accession -> lazyLoad(accession));
long total = countAccessions(filter);
......
......@@ -4,21 +4,21 @@
<html>
<head>
<title><spring:message code="accession.page.profile.title" arguments="${accession.accessionName}" argumentSeparator="|"/></title>
<local:content-headers description="${jspHelper.htmlToText(blurb.summary, 150)}" title="${accession.accessionName} | ${accession.instituteCode}" keywords="${accession.accessionName}"/>
<title><spring:message code="accession.page.profile.title" arguments="${accession.accessionNumber}" argumentSeparator="|"/></title>
<local:content-headers description="${jspHelper.htmlToText(blurb.summary, 150)}" title="${accession.accessionNumber} | ${accession.instituteCode}" keywords="${accession.accessionNumber}"/>
</head>
<body class="accession-page" typeof="germplasm:GermplasmAccession">
<h1 class="green-bg">
<span property="dwc:catalogNumber">
<c:out value="${accession.accessionName}"/>
<c:out value="${accession.accessionNumber}"/>
</span>
<small property="dwc:institutionCode" datatype="germplasmType:wiewsInstituteID"><c:out value="${accession.instituteCode}"/></small>
</h1>
<div class="row main-col-header acn">
<div class="sel" x-aid="${accession.id}">
<a class="add" href=""><spring:message code="selection.add" arguments="${accession.accessionName}"/></a>
<a class="remove" href=""><spring:message code="selection.remove" 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.accessionNumber}"/></a>
</div>
</div>
......@@ -55,7 +55,7 @@
<div class="crop-details">
<div class="collect-info basic-info">
<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">
<c:if test="${accession.doi ne null}">
......@@ -404,7 +404,7 @@
<security:authorize access="hasRole('ADMINISTRATOR') or hasPermission(#accession.institute, 'ADMINISTRATION')">
<div class="row">
<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"/>
</a>
</div>
......
......@@ -31,7 +31,7 @@
<div class="col-sm-2">
<c:choose>
<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:otherwise>
<local:accession-details-link accession="${accession}" />
......
......@@ -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("<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]);
}
});
......
......@@ -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();
......
......@@ -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());
......
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