Commit ce00839a authored by Matija Obreza's avatar Matija Obreza
Browse files

Added SvalbardData entity

parent 4811cb80
......@@ -20,6 +20,7 @@ package org.genesys2.rest.common.model.genesys;
import java.text.MessageFormat;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
......@@ -65,6 +66,7 @@ public class Accession implements java.io.Serializable {
private AllAcqCollect accessionCollection;
private AllAcqExchange accessionExchange;
private AllEnvironment accessionEnvironment;
private SvalbardData svalbardData;
public Accession() {
}
......@@ -278,6 +280,16 @@ public class Accession implements java.io.Serializable {
this.accessionEnvironment = accessionEnvironment;
}
@OneToOne(orphanRemoval = true, cascade = CascadeType.REMOVE, optional = true)
@JoinColumn(name = "id", referencedColumnName = "id")
public SvalbardData getSvalbardData() {
return svalbardData;
}
public void setSvalbardData(SvalbardData svalbardData) {
this.svalbardData = svalbardData;
}
@Override
public String toString() {
return MessageFormat.format("Accession id={0,number,#} A={3} inst={1} genus={2}", id, institute.getCode(), genus, accNumbHi);
......
/**
* Copyright 2013 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.rest.common.model.genesys;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name = "svalbard")
public class SvalbardData implements java.io.Serializable {
private static final long serialVersionUID = -5015395025122055617L;
private Long id;
private Float quantity;
private String depositDate;
private String boxNo;
private String taxonomy;
private int version;
@Id
@Column(name = "id")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Float getQuantity() {
return quantity;
}
public void setQuantity(Float quantity) {
this.quantity = quantity;
}
@Column(length = 20)
public String getDepositDate() {
return depositDate;
}
public void setDepositDate(String depositDate) {
this.depositDate = depositDate;
}
@Column(length = 20)
public String getBoxNumber() {
return boxNo;
}
public void setBoxNumber(String boxNo) {
this.boxNo = boxNo;
}
@Column(length = 200)
public String getTaxonomy() {
return taxonomy;
}
public void setTaxonomy(String taxonomy) {
this.taxonomy = taxonomy;
}
@Version
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
}
/**
* Copyright 2013 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.rest.common.persistence.domain;
import org.genesys2.rest.common.model.genesys.SvalbardData;
import org.springframework.data.jpa.repository.JpaRepository;
public interface SvalbardRepository extends JpaRepository<SvalbardData, Long> {
}
......@@ -29,6 +29,7 @@ import org.genesys2.rest.common.model.genesys.AllEnvironment;
import org.genesys2.rest.common.model.genesys.ExperimentTrait;
import org.genesys2.rest.common.model.genesys.Metadata;
import org.genesys2.rest.common.model.genesys.Method;
import org.genesys2.rest.common.model.genesys.SvalbardData;
import org.genesys2.rest.common.model.genesys.Taxonomy;
import org.genesys2.rest.common.model.impl.AccessionIdentifier2;
import org.genesys2.rest.common.model.impl.Country;
......@@ -105,4 +106,6 @@ public interface GenesysService {
void saveAccessions(List<Accession> matching);
void saveSvalbards(List<SvalbardData> svalbards);
}
......@@ -33,6 +33,7 @@ import org.genesys2.rest.common.model.genesys.ExperimentTrait;
import org.genesys2.rest.common.model.genesys.Metadata;
import org.genesys2.rest.common.model.genesys.Method;
import org.genesys2.rest.common.model.genesys.Parameter;
import org.genesys2.rest.common.model.genesys.SvalbardData;
import org.genesys2.rest.common.model.genesys.Taxonomy;
import org.genesys2.rest.common.model.impl.AccessionIdentifier2;
import org.genesys2.rest.common.model.impl.Country;
......@@ -54,6 +55,7 @@ import org.genesys2.rest.common.persistence.domain.MetadataRepository;
import org.genesys2.rest.common.persistence.domain.MethodRepository;
import org.genesys2.rest.common.persistence.domain.OrganizationRepository;
import org.genesys2.rest.common.persistence.domain.ParameterRepository;
import org.genesys2.rest.common.persistence.domain.SvalbardRepository;
import org.genesys2.rest.common.persistence.domain.TraitValueRepository;
import org.genesys2.rest.common.service.GenesysService;
import org.genesys2.rest.common.service.TraitService;
......@@ -110,6 +112,9 @@ public class GenesysServiceImpl implements GenesysService, TraitService {
@Autowired
private GenesysLowlevelRepository genesysLowlevelRepository;
@Autowired
private SvalbardRepository svalbardRepository;
@Override
public long countByInstitute(FaoInstitute institute) {
return accessionRepository.countByInstitute(institute);
......@@ -318,8 +323,16 @@ public class GenesysServiceImpl implements GenesysService, TraitService {
@Override
@Transactional(readOnly = false)
public void saveAccessions(List<Accession> accessions) {
LOG.info("Saving " + accessions.size() + " accessions");
if (LOG.isDebugEnabled()) {
LOG.debug("Saving " + accessions.size() + " accessions");
}
accessionRepository.save(accessions);
}
@Override
@Transactional(readOnly = false)
public void saveSvalbards(List<SvalbardData> svalbards) {
svalbardRepository.save(svalbards);
}
}
......@@ -44,8 +44,10 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.genesys2.rest.common.model.genesys.Accession;
import org.genesys2.rest.common.model.genesys.SvalbardData;
import org.genesys2.rest.common.model.impl.AccessionIdentifier2;
import org.genesys2.rest.common.service.GenesysService;
import org.hibernate.exception.ConstraintViolationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
......@@ -175,7 +177,7 @@ public class SGSVUpdate {
String[] line = null;
while ((line = reader.readNext()) != null) {
if (counter % 1000 == 0) {
LOG.debug(counter + ": " + ArrayUtils.toString(line));
LOG.info(counter + ": " + ArrayUtils.toString(line));
}
// Clean up
......@@ -246,6 +248,8 @@ public class SGSVUpdate {
// Check if they match (Genus, OrigCty) for now
List<Accession> matching = new ArrayList<Accession>(accessions.size());
List<SvalbardData> svalbards = new ArrayList<SvalbardData>(accessions.size());
for (int i = accns.size() - 1; i >= 0; i--) {
Accession accn = accessions.get(i);
SGSVEntry entry = accns.get(i);
......@@ -255,6 +259,23 @@ public class SGSVUpdate {
if (accn.getOrigin().equalsIgnoreCase(entry.origCty) && accn.getTaxonomy().getGenus().equals(entry.genus)) {
if (accn.getAccessionName().equalsIgnoreCase(entry.acceNumb) && accn.getInstituteCode().equals(entry.instCode)) {
if (true != accn.getInSvalbard()) {
LOG.info("Found one in SGSV: " + accn);
}
accn.setInSvalbard(true);
SvalbardData svalbardData = accn.getSvalbardData();
if (svalbardData == null) {
svalbardData = new SvalbardData();
accn.setSvalbardData(svalbardData);
}
svalbardData.setId(accn.getId());
svalbardData.setBoxNumber(entry.boxNo);
svalbardData.setDepositDate(entry.depositDate);
svalbardData.setQuantity(entry.quantity);
svalbardData.setTaxonomy(entry.fullTaxa);
svalbards.add(svalbardData);
matching.add(accn);
} else {
LOG.warn("This should not be");
......@@ -264,18 +285,20 @@ public class SGSVUpdate {
}
}
// If matching, update SGSV data
for (Accession accn : matching) {
if (true != accn.getInSvalbard()) {
LOG.info("Found one in SGSV: " + accn);
}
accn.setInSvalbard(true);
}
// Save data
if (matching.size() > 0) {
genesysService.saveAccessions(matching);
}
if (svalbards.size() > 0) {
try {
genesysService.saveSvalbards(svalbards);
} catch (ConstraintViolationException e) {
LOG.warn(e.getMessage());
for (Accession a : matching) {
LOG.warn("\t" + a);
}
}
}
}
});
}
......@@ -303,12 +326,22 @@ public class SGSVUpdate {
String acceNumb;
String origCty;
String genus;
String fullTaxa;
String boxNo;
String depositDate;
Float quantity;
public SGSVEntry(String[] entry) {
instCode = entry[1];
acceNumb = entry[4];
fullTaxa = entry[5];
origCty = entry[12];
genus = entry[16];
depositDate = entry[20];
if (entry[7] != null) {
quantity = Float.parseFloat(entry[7]);
}
boxNo = entry[2];
}
@Override
......
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