Commit 3023a192 authored by Matija Obreza's avatar Matija Obreza

AccessionJson model

parent 51e41fb6
package org.genesys2.server.model.json;
public class AccessionJson {
private long version = 0;
private Long genesysId;
private String instCode;
private String acceNumb;
private String genus;
private String species;
private String spauthor;
private String subtaxa;
private String subtauthor;
private String uuid;
private String orgCty;
private String acqDate;
private Boolean mlsStat;
private Boolean inTrust;
private Boolean available;
private int[] storage;
private Integer sampStat;
private String[] duplSite;
private String bredCode;
private String ancest;
private String donorCode;
private String donorNumb;
private String donorName;
private CollectingJson coll;
private GeoJson geo;
public long getVersion() {
return version;
}
public void setVersion(long l) {
this.version = l;
}
public Long getGenesysId() {
return genesysId;
}
public void setGenesysId(Long genesysId) {
this.genesysId = genesysId;
}
public String getInstCode() {
return instCode;
}
public void setInstCode(String instCode) {
this.instCode = instCode;
}
public String getAcceNumb() {
return acceNumb;
}
public void setAcceNumb(String acceNumb) {
this.acceNumb = acceNumb;
}
public String getGenus() {
return genus;
}
public void setGenus(String genus) {
this.genus = genus;
}
public String getSpecies() {
return species;
}
public void setSpecies(String species) {
this.species = species;
}
public String getSpauthor() {
return spauthor;
}
public void setSpauthor(String spauthor) {
this.spauthor = spauthor;
}
public String getSubtaxa() {
return subtaxa;
}
public void setSubtaxa(String subtaxa) {
this.subtaxa = subtaxa;
}
public String getSubtauthor() {
return subtauthor;
}
public void setSubtauthor(String subtauthor) {
this.subtauthor = subtauthor;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getOrgCty() {
return orgCty;
}
public void setOrgCty(String orgCty) {
this.orgCty = orgCty;
}
public String getAcqDate() {
return acqDate;
}
public void setAcqDate(String acqDate) {
this.acqDate = acqDate;
}
public Boolean getMlsStat() {
return mlsStat;
}
public void setMlsStat(Boolean mlsStat) {
this.mlsStat = mlsStat;
}
public Boolean getInTrust() {
return inTrust;
}
public void setInTrust(Boolean inTrust) {
this.inTrust = inTrust;
}
public Boolean getAvailable() {
return available;
}
public void setAvailable(Boolean available) {
this.available = available;
}
public int[] getStorage() {
return storage;
}
public void setStorage(int[] storage) {
this.storage = storage;
}
public Integer getSampStat() {
return sampStat;
}
public void setSampStat(Integer sampStat) {
this.sampStat = sampStat;
}
public String[] getDuplSite() {
return duplSite;
}
public void setDuplSite(String[] duplSite) {
this.duplSite = duplSite;
}
public String getBredCode() {
return bredCode;
}
public void setBredCode(String bredCode) {
this.bredCode = bredCode;
}
public String getAncest() {
return ancest;
}
public void setAncest(String ancest) {
this.ancest = ancest;
}
public String getDonorCode() {
return donorCode;
}
public void setDonorCode(String donorCode) {
this.donorCode = donorCode;
}
public String getDonorNumb() {
return donorNumb;
}
public void setDonorNumb(String donorNumb) {
this.donorNumb = donorNumb;
}
public String getDonorName() {
return donorName;
}
public void setDonorName(String donorName) {
this.donorName = donorName;
}
public CollectingJson getColl() {
return coll;
}
public void setColl(CollectingJson coll) {
this.coll = coll;
}
public GeoJson getGeo() {
return geo;
}
public void setGeo(GeoJson geo) {
this.geo = geo;
}
}
package org.genesys2.server.model.json;
public class CollectingJson {
private String collDate;
private String collSite;
private String collNumb;
private Integer collSrc;
private String collCode;
private String collName;
private String collInstAddress;
private String collMissId;
public String getCollDate() {
return collDate;
}
public void setCollDate(String collDate) {
this.collDate = collDate;
}
public String getCollSite() {
return collSite;
}
public void setCollSite(String collSite) {
this.collSite = collSite;
}
public String getCollNumb() {
return collNumb;
}
public void setCollNumb(String collNumb) {
this.collNumb = collNumb;
}
public Integer getCollSrc() {
return collSrc;
}
public void setCollSrc(Integer integer) {
this.collSrc = integer;
}
public String getCollCode() {
return collCode;
}
public void setCollCode(String collCode) {
this.collCode = collCode;
}
public String getCollName() {
return collName;
}
public void setCollName(String collName) {
this.collName = collName;
}
public String getCollInstAddress() {
return collInstAddress;
}
public void setCollInstAddress(String collInstAddress) {
this.collInstAddress = collInstAddress;
}
public String getCollMissId() {
return collMissId;
}
public void setCollMissId(String collMissId) {
this.collMissId = collMissId;
}
}
package org.genesys2.server.model.json;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.Taxonomy2;
public class GenesysJsonFactory {
public static AccessionJson from(Accession accession) {
if (accession == null)
return null;
AccessionJson aj = new AccessionJson();
aj.setVersion(accession.getVersion());
aj.setGenesysId(accession.getId());
aj.setInstCode(accession.getInstitute().getCode());
aj.setAcceNumb(accession.getAccessionName());
aj.setUuid(accession.getUuid());
Taxonomy2 tax = accession.getTaxonomy();
aj.setGenus(tax.getGenus());
aj.setSpecies(tax.getSpecies());
aj.setSpauthor(tax.getSpAuthor());
aj.setSubtaxa(tax.getSubtaxa());
aj.setSubtauthor(tax.getSubtAuthor());
aj.setOrgCty(accession.getCountryOfOrigin().getCode3());
aj.setAcqDate(accession.getAcquisitionDate());
aj.setMlsStat(accession.getMlsStatus());
aj.setInTrust(accession.getInTrust());
aj.setAvailable(accession.getAvailability());
// private int[] storage;
aj.setStorage(toIntArray(accession.getStorage()));
// private Integer sampStat;
aj.setSampStat(accession.getSampleStatus());
// private String[] duplSite;
aj.setDuplSite(toStrArr(accession.getDuplSite()));
// private String bredCode;
// private String ancest;
// private String donorCode;
// private String donorNumb;
// private String donorName;
// private CollectingJson coll;
// private GeoJson geo;
return aj;
}
private static String[] toStrArr(String arrString) {
if (StringUtils.isBlank(arrString))
return null;
return arrString.split("\\s*;\\s*");
}
private static int[] toIntArray(String arrString) {
if (StringUtils.isBlank(arrString))
return null;
String[] split = arrString.trim().split(";");
int[] intArr = new int[split.length];
for (int i = 0; i < split.length; i++) {
// TODO Could throw NFE
intArr[i] = Integer.parseInt(split[i]);
}
return intArr;
}
public static GeoJson from(AccessionGeo geo) {
if (geo == null)
return null;
GeoJson gj = new GeoJson();
gj.setCoordDatum(geo.getDatum());
gj.setCoordUncert(geo.getUncertainty());
gj.setElevation(geo.getElevation());
gj.setGeorefMeth(geo.getMethod());
gj.setLatitude(geo.getLatitude());
gj.setLongitude(geo.getLongitude());
return gj;
}
public static CollectingJson from(AccessionCollect collect) {
if (collect == null)
return null;
CollectingJson col = new CollectingJson();
col.setCollCode(collect.getCollCode());
col.setCollDate(collect.getCollDate());
col.setCollInstAddress(collect.getCollInstAddress());
col.setCollMissId(collect.getCollMissId());
col.setCollName(collect.getCollName());
col.setCollNumb(collect.getCollNumb());
col.setCollSite(collect.getCollSite());
col.setCollSrc(collect.getCollSrc());
return col;
}
}
package org.genesys2.server.model.json;
public class GeoJson {
private Double latitude;
private Double longitude;
private Double elevation;
private Double coordUncert;
private String coordDatum;
private String georefMeth;
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
public Double getElevation() {
return elevation;
}
public void setElevation(Double elevation) {
this.elevation = elevation;
}
public Double getCoordUncert() {
return coordUncert;
}
public void setCoordUncert(Double coordUncert) {
this.coordUncert = coordUncert;
}
public String getCoordDatum() {
return coordDatum;
}
public void setCoordDatum(String coordDatum) {
this.coordDatum = coordDatum;
}
public String getGeorefMeth() {
return georefMeth;
}
public void setGeorefMeth(String georefMeth) {
this.georefMeth = georefMeth;
}
}
......@@ -21,16 +21,16 @@ import java.util.Map;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.impl.RESTApiException;
import org.genesys2.server.servlet.controller.rest.model.AccessionJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson;
import com.fasterxml.jackson.databind.node.ObjectNode;
public interface BatchRESTService {
boolean upsertAccessionData(FaoInstitute institute, Map<AccessionJson, ObjectNode> batch) throws RESTApiException;
boolean upsertAccessionData(FaoInstitute institute, Map<AccessionHeaderJson, ObjectNode> batch) throws RESTApiException;
void upsertAccessionNames(FaoInstitute institute, List<AccessionNamesJson> batch);
int deleteAccessions(FaoInstitute institute, List<AccessionJson> batch);
int deleteAccessions(FaoInstitute institute, List<AccessionHeaderJson> batch);
}
package org.genesys2.server.service;
import org.genesys2.server.model.json.AccessionJson;
public interface GenesysRESTService {
AccessionJson getAccessionJSON(String instCode, long accessionId);
}
......@@ -46,7 +46,7 @@ import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.servlet.controller.rest.model.AccessionAliasJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -81,7 +81,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
public boolean upsertAccessionData(FaoInstitute institute, Map<AccessionJson, ObjectNode> batch) throws RESTApiException {
public boolean upsertAccessionData(FaoInstitute institute, Map<AccessionHeaderJson, ObjectNode> batch) throws RESTApiException {
LOG.info("Batch processing " + batch.size() + " entries for " + institute);
boolean useUniqueAcceNumbs = institute.hasUniqueAcceNumbs();
......@@ -97,7 +97,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
Map<Accession, ArrayNode> donorNumbs = new HashMap<Accession, ArrayNode>();
Map<Accession, ArrayNode> collNumbs = new HashMap<Accession, ArrayNode>();
for (AccessionJson dataJson : batch.keySet()) {
for (AccessionHeaderJson dataJson : batch.keySet()) {
if (LOG.isDebugEnabled())
LOG.debug("Loading accession " + dataJson);
......@@ -666,12 +666,12 @@ public class BatchRESTServiceImpl implements BatchRESTService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'DELETE') or hasPermission(#institute, 'MANAGE')")
public int deleteAccessions(FaoInstitute institute, List<AccessionJson> batch) {
public int deleteAccessions(FaoInstitute institute, List<AccessionHeaderJson> batch) {
LOG.info("Batch deleting " + batch.size() + " entries for " + institute);
List<Accession> toDelete = new ArrayList<Accession>(batch.size());
boolean useUniqueAcceNumbs = institute.hasUniqueAcceNumbs();
for (AccessionJson dataJson : batch) {
for (AccessionHeaderJson dataJson : batch) {
if (LOG.isDebugEnabled())
LOG.debug("Loading accession " + dataJson);
......
package org.genesys2.server.service.impl;
import org.apache.commons.lang3.StringUtils;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.json.AccessionJson;
import org.genesys2.server.model.json.GenesysJsonFactory;
import org.genesys2.server.service.GenesysRESTService;
import org.genesys2.server.service.GenesysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional(readOnly = true)
public class GenesysRESTServiceImpl implements GenesysRESTService {
@Autowired
private GenesysService genesysService;
@Override
public AccessionJson getAccessionJSON(String instCode, long accessionId) {
Accession accession = genesysService.getAccession(accessionId);
if (accession == null) {
return null;
}
if (!StringUtils.equalsIgnoreCase(accession.getInstituteCode(), instCode)) {
throw new RuntimeException("Accession " + accessionId + " does not belong to " + instCode);
}
AccessionJson aj = GenesysJsonFactory.from(accession);
AccessionBreeding breeding = genesysService.listAccessionBreeding(accession);
if (breeding != null) {
aj.setBredCode(breeding.getBreederCode());
aj.setAncest(breeding.getPedigree());
}
AccessionCollect collect = genesysService.listAccessionCollect(accession);
aj.setColl(GenesysJsonFactory.from(collect));
AccessionGeo geo = genesysService.listAccessionGeo(accession);
aj.setGeo(GenesysJsonFactory.from(geo));
return aj;
}
}
......@@ -24,14 +24,16 @@ import java.util.Map;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.json.AccessionJson;
import org.genesys2.server.service.BatchRESTService;
import org.genesys2.server.service.GenesysRESTService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.impl.RESTApiException;
import org.genesys2.server.service.impl.RESTApiValueException;
import org.genesys2.server.servlet.controller.rest.model.AccessionJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson;
import org.genesys2.spring.ResourceNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -73,6 +75,9 @@ public class AccessionController extends RestController {
@Autowired
TaxonomyService taxonomyService;
@Autowired
GenesysRESTService restService;