Commit e1bb7d98 authored by Matija Obreza's avatar Matija Obreza

PDCI calculation and display

parent 0d3b6c25
......@@ -85,6 +85,9 @@ public class AccessionDetails {
private boolean historic;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String bredCode;
public static AccessionDetails from(AccessionData accession) {
AccessionDetails ad = new AccessionDetails();
ad.version = accession.getVersion();
......@@ -159,6 +162,7 @@ public class AccessionDetails {
if (breeding == null)
return;
this.pedigree = StringUtils.defaultIfBlank(breeding.getPedigree(), null);
this.bredCode = StringUtils.defaultIfBlank(breeding.getBreederCode(), null);
}
public void exch(AccessionExchange exch) {
......@@ -188,7 +192,7 @@ public class AccessionDetails {
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
......@@ -337,6 +341,14 @@ public class AccessionDetails {
this.coll = coll;
}
public String getBredCode() {
return bredCode;
}
public void setBredCode(String bredCode) {
this.bredCode = bredCode;
}
public String getPedigree() {
return pedigree;
}
......@@ -404,11 +416,11 @@ public class AccessionDetails {
public boolean getHistoric() {
return historic;
}
public void setHistoric(boolean historic) {
this.historic = historic;
}
public void networks(List<Organization> organizations) {
if (organizations == null || organizations.isEmpty())
return;
......
/**
* Copyright 2015 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
package org.genesys2.server.model.genesys;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.PrePersist;
import javax.persistence.Transient;
public class PDCI implements Serializable {
public static final String[] independentItems = { "genus", "species", "spAuthor", "subTaxa", "subtAuthor", "cropName", "acqDate", "sampStat", "donorCode",
"donorNumb", "otherNumb", "duplSite", "storage", "donorName", "duplInstName", "acceUrl", "mlsStat" };
public static final String[] dependentItems = { "origCty", "collSite", "latitude", "longitude", "elevation", "collDate", "bredCode", "ancest", "collSrc",
"acceName", "collNumb", "collCode", "collName" };
private Float score = null;
private int acqDate = 0;
private int sampStat = 0;
private int donorCode = 0;
private int genus = 0;
private int species = 0;
private int spAuthor = 0;
private int subTaxa = 0;
private int subtAuthor = 0;
private int donorNumb = 0;
private int otherNumb = 0;
private int duplSite = 0;
private int storage = 0;
private int donorName = 0;
private int duplInstName = 0;
private int acceUrl = 0;
private int mlsStat = 0;
private int origCty = 0;
private int latitude = 0;
private int longitude = 0;
private int collSite = 0;
private int elevation = 0;
private int collDate = 0;
private int collSrc = 0;
private int collNumb = 0;
private int collCode = 0;
private int collName = 0;
private int ancest = 0;
private int acceName = 0;
private int bredCode = 0;
private int cropName = 0;
@PrePersist
protected void prePersist() {
this.score = calculateScore();
}
public int getAcqDate() {
return acqDate;
}
public int getSampStat() {
return sampStat;
}
public int getDonorCode() {
return donorCode;
}
public int getGenus() {
return genus;
}
public int getSpecies() {
return species;
}
public int getSpAuthor() {
return spAuthor;
}
public int getSubTaxa() {
return subTaxa;
}
public int getSubtAuthor() {
return subtAuthor;
}
public int getDonorNumb() {
return donorNumb;
}
public int getOtherNumb() {
return otherNumb;
}
public int getDuplSite() {
return duplSite;
}
public int getStorage() {
return storage;
}
public int getDonorName() {
return donorName;
}
public int getDuplInstName() {
return duplInstName;
}
public int getAcceUrl() {
return acceUrl;
}
public int getMlsStat() {
return mlsStat;
}
public int getOrigCty() {
return origCty;
}
public int getLatitude() {
return latitude;
}
public int getLongitude() {
return longitude;
}
public int getCollSite() {
return collSite;
}
public int getElevation() {
return elevation;
}
public int getCollDate() {
return collDate;
}
public int getCollSrc() {
return collSrc;
}
public int getCollNumb() {
return collNumb;
}
public int getCollCode() {
return collCode;
}
public int getCollName() {
return collName;
}
public int getAncest() {
return ancest;
}
public int getAcceName() {
return acceName;
}
public int getBredCode() {
return bredCode;
}
public void setAcqDate(int score) {
this.acqDate = score;
}
public void setSampStat(int score) {
this.sampStat = score;
}
public void setDonorCode(int score) {
this.donorCode = score;
}
public void setGenus(int score) {
this.genus = score;
}
public void setSpecies(int score) {
this.species = score;
}
public void setSpAuthor(int score) {
this.spAuthor = score;
}
public void setSubTaxa(int score) {
this.subTaxa = score;
}
public void setSubtAuthor(int score) {
this.subtAuthor = score;
}
public void setDonorNumb(int score) {
this.donorNumb = score;
}
public void setOtherNumb(int score) {
this.otherNumb = score;
}
public void setDuplSite(int score) {
this.duplSite = score;
}
public void setStorage(int score) {
this.storage = score;
}
public void setDonorName(int score) {
this.donorName = score;
}
public void setDuplInstName(int score) {
this.duplInstName = score;
}
public void setAcceUrl(int score) {
this.acceUrl = score;
}
public void setMlsStat(int score) {
this.mlsStat = score;
}
public void setOrigCty(int score) {
this.origCty = score;
}
public void setLatitude(int score) {
this.latitude = score;
}
public void setLongitude(int score) {
this.longitude = score;
}
public void setCollSite(int score) {
this.collSite = score;
}
public void setElevation(int score) {
this.elevation = score;
}
public void setCollDate(int score) {
this.collDate = score;
}
public void setCollSrc(int score) {
this.collSrc = score;
}
public void setCollNumb(int score) {
this.collNumb = score;
}
public void setCollCode(int score) {
this.collCode = score;
}
public void setCollName(int score) {
this.collName = score;
}
public void setAncest(int score) {
this.ancest = score;
}
public void setAcceName(int score) {
this.acceName = score;
}
public void setBredCode(int score) {
this.bredCode = score;
}
public Float getScore() {
if (score == null) {
score = calculateScore();
}
return score;
}
public void setScore(Float score) {
this.score = score;
}
private Float calculateScore() {
float total = getTotal();
return total / 100f;
}
@Transient
public float getTotal() {
float score = 0;
score += acqDate;
score += sampStat;
score += donorCode;
score += genus;
score += species;
score += spAuthor;
score += subTaxa;
score += subtAuthor;
score += donorNumb;
score += otherNumb;
score += duplSite;
score += storage;
score += donorName;
score += duplInstName;
score += acceUrl;
score += mlsStat;
score += origCty;
score += latitude;
score += longitude;
score += collSite;
score += elevation;
score += collDate;
score += collSrc;
score += collNumb;
score += collCode;
score += collName;
score += ancest;
score += acceName;
score += bredCode;
score += cropName;
return score;
}
public void setCropName(int score) {
this.cropName = score;
}
public int getCropName() {
return cropName;
}
public String[] getIndependentItems() {
return independentItems;
}
public String[] getDependentItems() {
return dependentItems;
}
public static Set<String> getPdciItems() {
Set<String> descriptors = new HashSet<String>();
for (java.lang.reflect.Method method : PDCI.class.getMethods()) {
if (method.getName().startsWith("get") && method.getReturnType() == int.class) {
String str = method.getName().substring(3);
descriptors.add(str.substring(0, 1).toLowerCase() + str.substring(1));
}
}
return descriptors;
}
}
......@@ -199,10 +199,15 @@ public interface GenesysService {
List<Long> listAccessionsIds(Taxonomy2 taxonomy);
public static class AllStuff {
public AllStuff(Long id) {
public AllStuff(long id) {
this.id = id;
}
public AllStuff(AccessionData accession) {
this.accession = accession;
this.id = accession.getId();
}
public Long id;
public AccessionData accession = null;
public AccessionGeo geo = null;
......
......@@ -319,14 +319,17 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
public AccessionDetails getAccessionDetails(long accessionId) {
AccessionData accession = getAccession(accessionId);
if (accession == null)
AccessionData accession = getAccessionData(accessionId);
if (accession == null) {
LOG.warn("No such accession with id=" + accessionId);
return null;
}
return toAccessionDetails(loadAllStuff(accession));
}
private AccessionDetails toAccessionDetails(AllStuff all) {
// LOG.info("Converting to AccessionDetails " + all);
if (all == null || all.accession == null)
return null;
......@@ -432,7 +435,7 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
public AllStuff loadAllStuff(AccessionData accession) {
if (accession == null)
return null;
AllStuff all = new AllStuff(accession.getAccessionId().getId());
AllStuff all = new AllStuff(accession);
all.bred = listAccessionBreeding(accession.getAccessionId());
all.collect = listAccessionCollect(accession.getAccessionId());
all.exch = listAccessionExchange(accession.getAccessionId());
......@@ -582,11 +585,17 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
private AccessionData getAccessionData(AccessionId accessionId) {
if (accessionId == null)
return null;
Accession a = accessionRepository.findOne(accessionId.getId());
if (a != null)
return getAccessionData(accessionId.getId());
}
private AccessionData getAccessionData(Long id) {
Accession a = accessionRepository.findOne(id);
if (a != null) {
return a;
AccessionHistoric ah = accessionHistoricRepository.findOne(accessionId.getId());
return ah;
} else {
AccessionHistoric ah = accessionHistoricRepository.findOne(id);
return ah;
}
}
@Override
......
......@@ -32,6 +32,7 @@ import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.impl.NonUniqueAccessionException;
import org.genesys2.server.service.impl.PDCICalculator;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
......@@ -64,6 +65,9 @@ public class AccessionController extends BaseController {
@Autowired
private DSService dsService;
@Autowired(required = false)
private PDCICalculator pdciCalculator;
@RequestMapping("/id/{accessionId}")
public String view(ModelMap model, @PathVariable(value = "accessionId") long accessionId) {
_logger.debug("Viewing ACN " + accessionId);
......@@ -96,6 +100,15 @@ public class AccessionController extends BaseController {
}
}
// PDCI
if (pdciCalculator != null) {
try {
model.addAttribute("pdci", pdciCalculator.getPdci(accession.getId()));
} catch (Throwable e) {
_logger.warn(e.getMessage(), e);
}
}
return "/accession/details";
}
......
......@@ -618,4 +618,13 @@ accession.purl=Permanent URL
menu.admin.kpi=KPI
admin.kpi.index.page=KPI
admin.kpi.execution.page=KPI Execution
admin.kpi.executionrun.page=Execution run details
\ No newline at end of file
admin.kpi.executionrun.page=Execution run details
accession.pdci=Passport Data Completeness Index
accession.pdci.jumbo=PDCI Score {0} of 10.0
accession.pdci.about-link=Read about Passport Data Completeness Index
accession.pdci.independent-items=Independent of the population type
accession.pdci.dependent-items=Depending on the population type
accession.donorNumb = WIEWS code of donor institute
......@@ -292,27 +292,27 @@
<div class="col-xs-8">${accessionExchange.accNumbDonor}</div>
</div>
</c:if>
<c:if test="${accession.uuid ne null}">
<div class="row text-muted">
<div class="col-xs-4">
<spring:message code="accession.uuid" />
</div>
<div class="col-xs-8">
<span property="dc:identifier">urn:uuid:<c:out value="${accession.uuid}" /></span>
</div>
<div class="row text-muted">
<div class="col-xs-4">
<spring:message code="accession.uuid" />
</div>
<div class="row">
<div class="col-xs-4">
<spring:message code="accession.purl" />
</div>
<div class="col-xs-8">
<span property="dc:identifier"><a href="https://purl.org/germplasm/id/${accession.uuid}"><c:out
value="https://purl.org/germplasm/id/${accession.uuid}"
/></a></span>
</div>
<div class="col-xs-8">
<span property="dc:identifier">urn:uuid:<c:out value="${accession.uuid}" /></span>
</div>
</c:if>
</div>
<div class="row">
<div class="col-xs-4">
<spring:message code="accession.purl" />
</div>
<div class="col-xs-8">
<span property="dc:identifier"><a href="https://purl.org/germplasm/id/${accession.uuid}"><c:out
value="https://purl.org/germplasm/id/${accession.uuid}"
/></a></span>
</div>
</div>
</c:if>
<c:if test="${accessionCollect ne null}">
<h4>
......@@ -599,6 +599,13 @@
</div>
<security:authorize access="isAuthenticated()">
<c:if test="${pdci ne null}">
<local:pdci value="${pdci}" />
</c:if>
</security:authorize>
<c:if test="${methods.size() gt 0}">
<div class="crop-details">
......
<%@ tag description="Display PDCI" pageEncoding="UTF-8"%>
<%@ tag body-content="tagdependent"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ attribute name="value" required="true" type="org.genesys2.server.model.genesys.PDCI"%>
<%