Commit 399e4046 authored by Matija Obreza's avatar Matija Obreza

Added missing MCPD V2 to AccessionCollect and AccessionGeo, allowing for

"newAcceNumb" and "newGenus" in accession upsert
parent dd68999f
......@@ -16,8 +16,6 @@
package org.genesys2.server.model.genesys;
// Generated Apr 24, 2013 10:08:59 AM by Hibernate Tools 4.0.0
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
......@@ -30,11 +28,11 @@ import javax.persistence.Version;
import org.genesys2.server.model.BusinessModel;
/**
* AllAcqCollect generated by hbm2java
* Collecting data
*/
@Entity
@Table(name = "accessioncollect")
public class AllAcqCollect extends BusinessModel {
public class AccessionCollect extends BusinessModel {
@Version
private long version = 0;
......@@ -43,21 +41,32 @@ public class AllAcqCollect extends BusinessModel {
@JoinColumn(name = "accessionId", unique = true, nullable = false, updatable = false)
private Accession accession;
@Column(name = "date", length = 8)
private String collectDate;
@Column(name = "collDate", length = 8)
private String collDate;
@Column(name = "collNumb", length = 64)
private String collNumb;
@Column(name = "collNumb", length = 24)
private String collectorsNumb;
@Column(name = "collMissId", length = 128)
private String collMissId;
@Column(name = "instCode", length = 8)
private String collectingInstitute;
@Column(name = "collCode", length = 128)
private String collCode;
@Column(name = "site")
@Column(name = "collName")
@Lob
private String collectSite;
private String collName;
public AllAcqCollect() {
}
@Column(name = "collInstAddress")
@Lob
private String collInstAddress;
@Column(name = "collSite")
@Lob
private String collSite;
@Column
private Integer collSrc;
public long getVersion() {
return version;
......@@ -75,36 +84,68 @@ public class AllAcqCollect extends BusinessModel {
this.accession = accession;
}
public String getCollectDate() {
return this.collectDate;
public String getCollDate() {
return collDate;
}
public void setCollDate(String collDate) {
this.collDate = collDate;
}
public String getCollNumb() {
return collNumb;
}
public void setCollNumb(String collNumb) {
this.collNumb = collNumb;
}
public String getCollMissId() {
return collMissId;
}
public void setCollMissId(String collMissId) {
this.collMissId = collMissId;
}
public String getCollCode() {
return collCode;
}
public void setCollCode(String collCode) {
this.collCode = collCode;
}
public String getCollName() {
return collName;
}
public void setCollectDate(final String collectDate) {
this.collectDate = collectDate;
public void setCollName(String collName) {
this.collName = collName;
}
public String getCollectorsNumb() {
return this.collectorsNumb;
public String getCollInstAddress() {
return collInstAddress;
}
public void setCollectorsNumb(final String collectorsNumb) {
this.collectorsNumb = collectorsNumb;
public void setCollInstAddress(String collInstAddress) {
this.collInstAddress = collInstAddress;
}
public String getCollectingInstitute() {
return this.collectingInstitute;
public String getCollSite() {
return collSite;
}
public void setCollectingInstitute(final String collectingInstitute) {
this.collectingInstitute = collectingInstitute;
public void setCollSite(String collSite) {
this.collSite = collSite;
}
public String getCollectSite() {
return this.collectSite;
public Integer getCollSrc() {
return collSrc;
}
public void setCollectSite(final String collectSite) {
this.collectSite = collectSite;
public void setCollSrc(Integer collSrc) {
this.collSrc = collSrc;
}
}
......@@ -45,6 +45,10 @@ public class AccessionGeo extends BusinessModel implements GeoReferencedEntity {
@Column(name = "elevation")
private Double elevation;
private Double uncertainty;
private String datum;
private String method;
public long getVersion() {
return version;
}
......@@ -80,9 +84,37 @@ public class AccessionGeo extends BusinessModel implements GeoReferencedEntity {
public Double getElevation() {
return elevation;
}
public void setElevation(Double elevation) {
this.elevation = elevation;
}
public void setUncertainty(Double uncertainty) {
this.uncertainty = uncertainty;
}
public Double getUncertainty() {
return uncertainty;
}
public void setDatum(String datum) {
this.datum = datum;
}
public String getDatum() {
return datum;
}
/**
* Set geodetic method
*
* @param method
*/
public void setMethod(String method) {
this.method = method;
}
public String getMethod() {
return method;
}
}
......@@ -17,11 +17,11 @@
package org.genesys2.server.persistence.domain;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AllAcqCollect;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.springframework.data.jpa.repository.JpaRepository;
public interface AccessionCollectRepository extends JpaRepository<AllAcqCollect, Long> {
public interface AccessionCollectRepository extends JpaRepository<AccessionCollect, Long> {
AllAcqCollect findByAccession(Accession accession);
AccessionCollect findByAccession(Accession accession);
}
......@@ -224,7 +224,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement stmt = con
.prepareStatement("select a.id, g.latitude, g.longitude, g.elevation, g.version from accessiongeo g inner join accession a on a.id=g.accessionId where a.instCode = ?");
.prepareStatement("select a.id, g.latitude, g.longitude, g.elevation, g.datum, g.uncertainty, g.method, g.version from accessiongeo g inner join accession a on a.id=g.accessionId where a.instCode = ?");
stmt.setString(1, instCode);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
......@@ -240,7 +240,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement stmt = con
.prepareStatement("select a.id, coll.instCode, coll.collNumb, coll.date, coll.site, coll.version from accessioncollect coll inner join accession a on a.id=coll.accessionId where a.instCode = ?");
.prepareStatement("select a.id, coll.collMissId, coll.collNumb, coll.collDate, coll.collSrc, coll.collSite, coll.collCode, coll.collName, coll.collInstAddress, coll.version from accessioncollect coll inner join accession a on a.id=coll.accessionId where a.instCode = ?");
stmt.setString(1, instCode);
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
......
......@@ -28,7 +28,7 @@ import org.genesys2.server.model.genesys.AccessionAlias;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AllAccnames;
import org.genesys2.server.model.genesys.AllAcqBreeding;
import org.genesys2.server.model.genesys.AllAcqCollect;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AllAcqExchange;
import org.genesys2.server.model.genesys.ExperimentTrait;
import org.genesys2.server.model.genesys.Metadata;
......@@ -65,7 +65,7 @@ public interface GenesysService {
AllAcqExchange listAccessionExchange(Accession accession);
AllAcqCollect listAccessionCollect(Accession accession);
AccessionCollect listAccessionCollect(Accession accession);
AllAcqBreeding listAccessionBreeding(Accession accession);
......@@ -131,7 +131,7 @@ public interface GenesysService {
SvalbardData getSvalbardData(Accession accession);
void saveCollecting(List<AllAcqCollect> all);
void saveCollecting(List<AccessionCollect> all);
void saveGeo(List<AccessionGeo> all);
......
......@@ -29,7 +29,7 @@ import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionAlias;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AllAcqCollect;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.Taxonomy;
import org.genesys2.server.model.genesys.AccessionAlias.AliasType;
import org.genesys2.server.model.impl.Country;
......@@ -78,7 +78,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
public boolean upsertAccessionData(FaoInstitute institute, Map<AccessionJson, ObjectNode> batch) {
LOG.info("Batch processing " + batch.size() + " entries for " + institute);
List<Accession> toSave = new ArrayList<Accession>();
List<AllAcqCollect> toSaveColl = new ArrayList<AllAcqCollect>();
List<AccessionCollect> toSaveColl = new ArrayList<AccessionCollect>();
List<AccessionGeo> toSaveGeo = new ArrayList<AccessionGeo>();
for (AccessionJson dataJson : batch.keySet()) {
......@@ -118,6 +118,51 @@ public class BatchRESTServiceImpl implements BatchRESTService {
}
}
/* Allow updating AcceNumb */
value = accnJson.get("newAcceNumb");
if (value != null) {
String newAcceNumb = value.isNull() ? null : value.textValue();
if (!StringUtils.equals(newAcceNumb, accession.getAccessionName())) {
accession.setAccessionName(newAcceNumb);
updated = true;
}
}
/* Allow updating Genus */
value = accnJson.get("newGenus");
if (value != null) {
String newGenus = value.isNull() ? null : value.textValue();
if (!StringUtils.equals(newGenus, accession.getGenus())) {
accession.setGenus(newGenus);
updated = true;
// Need to do taxonomy
String species = null;
if (accession.getTaxonomy() != null)
species = accession.getTaxonomy().getSpecies();
value = accnJson.get("species");
if (value != null) {
species = value.isNull() ? null : value.textValue();
}
Taxonomy taxonomy = taxonomyService.ensureTaxonomy(accession.getGenus(), species);
if (!taxonomy.sameAs(accession.getTaxonomy())) {
accession.setTaxonomy(taxonomy);
}
}
}
value = accnJson.get("species");
if (value != null) {
String species = value.isNull() ? null : value.textValue();
Taxonomy taxonomy = taxonomyService.ensureTaxonomy(accession.getGenus(), species);
if (!taxonomy.sameAs(accession.getTaxonomy())) {
accession.setTaxonomy(taxonomy);
updated = true;
}
}
value = accnJson.get("uuid");
if (value != null) {
String uuid = value.isNull() ? null : value.textValue();
......@@ -157,15 +202,6 @@ public class BatchRESTServiceImpl implements BatchRESTService {
updated = true;
}
}
value = accnJson.get("species");
if (value != null) {
String species = value.isNull() ? null : value.textValue();
Taxonomy taxonomy = taxonomyService.ensureTaxonomy(accession.getGenus(), species);
if (!taxonomy.sameAs(accession.getTaxonomy())) {
accession.setTaxonomy(taxonomy);
updated = true;
}
}
value = accnJson.get("storage");
if (value != null) {
......@@ -195,19 +231,44 @@ public class BatchRESTServiceImpl implements BatchRESTService {
if (accnJson.has("coll")) {
ObjectNode collecting = (ObjectNode) accnJson.get("coll");
AllAcqCollect accnColl = genesysService.listAccessionCollect(accession);
AccessionCollect accnColl = genesysService.listAccessionCollect(accession);
if (accnColl == null) {
accnColl = new AllAcqCollect();
accnColl = new AccessionCollect();
accnColl.setAccession(accession);
}
value = collecting.get("date");
value = collecting.get("collDate");
if (value != null) {
accnColl.setCollDate(StringUtils.defaultIfBlank(value.textValue(), null));
}
value = collecting.get("collNumb");
if (value != null) {
accnColl.setCollNumb(StringUtils.defaultIfBlank(value.textValue(), null));
}
value = collecting.get("collSrc");
if (value != null) {
accnColl.setCollSrc(value.isNumber() ? value.intValue() : null);
}
value = collecting.get("collCode");
if (value != null) {
accnColl.setCollectDate(StringUtils.defaultIfBlank(value.textValue(), null));
accnColl.setCollCode(StringUtils.defaultIfBlank(value.textValue(), null));
}
value = collecting.get("site");
value = collecting.get("collName");
if (value != null) {
accnColl.setCollectSite(StringUtils.defaultIfBlank(value.textValue(), null));
accnColl.setCollName(StringUtils.defaultIfBlank(value.textValue(), null));
}
value = collecting.get("collInstAddress");
if (value != null) {
accnColl.setCollInstAddress(StringUtils.defaultIfBlank(value.textValue(), null));
}
value = collecting.get("collSite");
if (value != null) {
accnColl.setCollSite(StringUtils.defaultIfBlank(value.textValue(), null));
}
value = collecting.get("collMissId");
if (value != null) {
accnColl.setCollMissId(StringUtils.defaultIfBlank(value.textValue(), null));
}
toSaveColl.add(accnColl);
}
......@@ -230,6 +291,18 @@ public class BatchRESTServiceImpl implements BatchRESTService {
if (value != null) {
accnGeo.setElevation(value.isNumber() ? value.asDouble() : null);
}
value = geo.get("coordUncert");
if (value != null) {
accnGeo.setUncertainty(value.isNumber() ? value.asDouble() : null);
}
value = geo.get("coordDatum");
if (value != null) {
accnGeo.setDatum(value.isTextual() ? value.asText() : null);
}
value = geo.get("georefMeth");
if (value != null) {
accnGeo.setMethod(value.isTextual() ? value.asText() : null);
}
toSaveGeo.add(accnGeo);
}
......
......@@ -77,7 +77,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
this.availableFilters.add(new GenesysFilterImpl("organization", FilterType.STRING));
this.availableFilters.add(new GenesysFilterImpl("lat", FilterType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("lon", FilterType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("alt", FilterType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("elevation", FilterType.NUMERIC));
this.availableFilters.add(new GenesysFilterImpl("genus", FilterType.STRING));
this.availableFilters.add(new GenesysFilterImpl("taxon", FilterType.STRING));
this.availableFilters.add(new GenesysFilterImpl("crop", FilterType.STRING));
......
......@@ -40,7 +40,7 @@ import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionTrait;
import org.genesys2.server.model.genesys.AllAccnames;
import org.genesys2.server.model.genesys.AllAcqBreeding;
import org.genesys2.server.model.genesys.AllAcqCollect;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AllAcqExchange;
import org.genesys2.server.model.genesys.ExperimentAccessionTrait;
import org.genesys2.server.model.genesys.ExperimentTrait;
......@@ -246,7 +246,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
}
@Override
public AllAcqCollect listAccessionCollect(Accession accession) {
public AccessionCollect listAccessionCollect(Accession accession) {
if (accession == null || accession.getId() == null)
return null;
return accessionCollectRepository.findByAccession(accession);
......@@ -461,7 +461,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Override
@Transactional(readOnly = false)
public void saveCollecting(List<AllAcqCollect> all) {
public void saveCollecting(List<AccessionCollect> all) {
accessionCollectRepository.save(all);
}
......@@ -710,7 +710,10 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
osw.write("\t<field index=\"1\" term=\"latitude\"/>\n");
osw.write("\t<field index=\"2\" term=\"longitude\"/>\n");
osw.write("\t<field index=\"3\" term=\"elevation\"/>\n");
osw.write("\t<field index=\"4\" term=\"version\"/>\n");
osw.write("\t<field index=\"4\" term=\"datum\"/>\n");
osw.write("\t<field index=\"5\" term=\"uncertainty\"/>\n");
osw.write("\t<field index=\"6\" term=\"method\"/>\n");
osw.write("\t<field index=\"7\" term=\"version\"/>\n");
osw.write("</extension>\n");
osw.write("<extension encoding=\"UTF-8\" fieldsTerminatedBy=\",\" linesTerminatedBy=\"\\n\" fieldsEnclosedBy=\"&quot;\" ignoreHeaderLines=\"0\">\n");
......@@ -718,11 +721,15 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
osw.write("coll.csv");
osw.write("</location></files>\n");
osw.write("\t<coreid index=\"0\" />\n");
osw.write("\t<field index=\"1\" term=\"collCode\"/>\n");
osw.write("\t<field index=\"1\" term=\"collMissId\"/>\n");
osw.write("\t<field index=\"2\" term=\"collNumb\"/>\n");
osw.write("\t<field index=\"3\" term=\"collDate\"/>\n");
osw.write("\t<field index=\"4\" term=\"collSite\"/>\n");
osw.write("\t<field index=\"5\" term=\"version\"/>\n");
osw.write("\t<field index=\"4\" term=\"collSrc\"/>\n");
osw.write("\t<field index=\"5\" term=\"collSite\"/>\n");
osw.write("\t<field index=\"6\" term=\"collCode\"/>\n");
osw.write("\t<field index=\"7\" term=\"collName\"/>\n");
osw.write("\t<field index=\"8\" term=\"collInstAddress\"/>\n");
osw.write("\t<field index=\"9\" term=\"version\"/>\n");
osw.write("</extension>\n");
osw.write("</archive>\n");
......@@ -764,7 +771,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
private void writeAccessionsGeo(final FaoInstitute faoInstitute, ZipOutputStream zos) throws IOException {
@SuppressWarnings("resource")
final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n");
csv.writeNext(new String[] { "genesysId", "latitude", "longitude", "elevation", "version" });
csv.writeNext(new String[] { "genesysId", "latitude", "longitude", "elevation", "datum", "uncertainty", "method", "version" });
final ResultSetHelper csvResultsetHelper = new ResultSetHelperService();
......@@ -792,7 +799,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
private void writeAccessionsColl(final FaoInstitute faoInstitute, ZipOutputStream zos) throws IOException {
@SuppressWarnings("resource")
final CSVWriter csv = new CSVWriter(new BufferedWriter(new OutputStreamWriter(zos)), ',', '"', '\\', "\n");
csv.writeNext(new String[] { "genesysId", "collCode", "collNumb", "collDate", "collSite", "version" });
csv.writeNext(new String[] { "genesysId", "collMissId", "collNumb", "collDate", "collSrc", "collSite", "collCode", "collName", "collInstAddress", "version" });
final ResultSetHelper csvResultsetHelper = new ResultSetHelperService();
......
......@@ -175,14 +175,22 @@ accession.not-available-for-distribution=The accession is NOT available for dist
accession.available-for-distribution=The accession is available for distribution.
accession.elevation=Elevation
accession.geolocation=Geolocation (lat, long)
accession.breeding=Breeder information
accession.breederCode=Breeder Code
accession.pedigree=Pedigree
accession.collecting=Collecting information
accession.collecting.site=Collecting site
accession.collecting.institute=Collecting institute
accession.collecting.number=Collecting number
accession.collecting.date=Collecting date
accession.collecting.mission=Collecting mission ID
accession.collecting.source=Collecting source
accession.donor.institute=Donor institute
accession.donor.accessionNumber=Donor accession ID
accession.geo=Geographic information
accession.geo.datum=Coordinate datum
accession.geo.method=Georeferencing method
accession.geo.uncertainty=Coordinate uncertainty
accession.sampleStatus=Sample status
accession.sampleStatus.=
accession.sampleStatus.100=Wild
......
......@@ -148,24 +148,49 @@
<c:if test="${accessionCollect ne null}">
<tr>
<td><spring:message code="accession.collecting.date" /></td>
<td>${accessionCollect.collectDate}</td>
<td colspan="2">
<h4><spring:message code="accession.collecting" /></h4>
</td>
</tr>
<tr>
<td><spring:message code="accession.collecting.number" /></td>
<td>${accessionCollect.collectorsNumb}</td>
<td><spring:message code="accession.collecting.institute" /></td>
<td>${accessionCollect.collCode}</td>
</tr>
<c:if test="${accessionCollect.collName ne null}">
<tr>
<td><spring:message code="accession.collecting.institute" /></td>
<td>${accessionCollect.collectingInstitute}</td>
<td>${accessionCollect.collName}
${accessionCollect.collInstAddress}</td>
</tr>
</c:if>
<tr>
<td><spring:message code="accession.collecting.mission" /></td>
<td>${accessionCollect.collMissId}</td>
</tr>
<tr>
<td><spring:message code="accession.collecting.date" /></td>
<td>${accessionCollect.collDate}</td>
</tr>
<tr>
<td><spring:message code="accession.collecting.number" /></td>
<td>${accessionCollect.collNumb}</td>
</tr>
<tr>
<td><spring:message code="accession.collecting.site" /></td>
<td>${accessionCollect.collectSite}</td>
<td>${accessionCollect.collSite}</td>
</tr>
<tr>
<td><spring:message code="accession.collecting.source" /></td>
<td>${accessionCollect.collSrc}</td>
</tr>
</c:if>
<c:if test="${accessionBreeding ne null}">
<tr>
<td colspan="2">
<h4><spring:message code="accession.breeding" /></h4>
</td>
</tr>
<tr>
<td><spring:message code="accession.breederCode" /></td>
<td>${accessionBreeding.breederCode}</td>
......@@ -178,11 +203,30 @@