Commit 3b06011f authored by Matija Obreza's avatar Matija Obreza
Browse files

REST API updated for donorCode, donorNumb, donorName

parent 5fd3b72c
......@@ -31,7 +31,7 @@ import org.genesys2.server.model.BusinessModel;
*/
@Entity
@Table(name = "accessionexchange")
public class AllAcqExchange extends BusinessModel{
public class AccessionExchange extends BusinessModel{
@Version
private long version = 0;
......@@ -43,10 +43,13 @@ public class AllAcqExchange extends BusinessModel{
@Column(name = "donorInst", length = 8)
private String donorInstitute;
@Column(name = "donorName", length = 200)
private String donorName;
@Column(name = "acceNumb", length = 36)
private String accNumbDonor;
public AllAcqExchange() {
public AccessionExchange() {
}
public long getVersion() {
......@@ -82,4 +85,11 @@ public class AllAcqExchange extends BusinessModel{
this.accNumbDonor = accNumbDonor;
}
public String getDonorName() {
return donorName;
}
public void setDonorName(String donorName) {
this.donorName = donorName;
}
}
......@@ -17,11 +17,11 @@
package org.genesys2.server.persistence.domain;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AllAcqExchange;
import org.genesys2.server.model.genesys.AccessionExchange;
import org.springframework.data.jpa.repository.JpaRepository;
public interface AccessionExchangeRepository extends JpaRepository<AllAcqExchange, Long> {
public interface AccessionExchangeRepository extends JpaRepository<AccessionExchange, Long> {
AllAcqExchange findByAccession(Accession accession);
AccessionExchange findByAccession(Accession accession);
}
......@@ -29,7 +29,7 @@ import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AllAccnames;
import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AllAcqExchange;
import org.genesys2.server.model.genesys.AccessionExchange;
import org.genesys2.server.model.genesys.ExperimentTrait;
import org.genesys2.server.model.genesys.Metadata;
import org.genesys2.server.model.genesys.Method;
......@@ -63,7 +63,7 @@ public interface GenesysService {
List<AccessionAlias> listAccessionAliases(Accession accession);
AllAcqExchange listAccessionExchange(Accession accession);
AccessionExchange listAccessionExchange(Accession accession);
AccessionCollect listAccessionCollect(Accession accession);
......@@ -134,6 +134,7 @@ public interface GenesysService {
void saveCollecting(List<AccessionCollect> all);
void saveGeo(List<AccessionGeo> all);
void saveBreeding(List<AccessionBreeding> all);
void saveExchange(List<AccessionExchange> all);
void refreshMetadataMethods();
......@@ -146,4 +147,5 @@ public interface GenesysService {
void removeAliases(List<AccessionAlias> aliases);
}
......@@ -28,11 +28,12 @@ import org.apache.commons.logging.Log;
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.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionAlias.AliasType;
import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionExchange;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.Taxonomy;
import org.genesys2.server.model.genesys.AccessionAlias.AliasType;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.service.BatchRESTService;
......@@ -42,8 +43,8 @@ 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.AccessionNamesJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
......@@ -82,6 +83,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
List<AccessionCollect> toSaveColl = new ArrayList<AccessionCollect>();
List<AccessionGeo> toSaveGeo = new ArrayList<AccessionGeo>();
List<AccessionBreeding> toSaveBreed = new ArrayList<AccessionBreeding>();
List<AccessionExchange> toSaveExch = new ArrayList<AccessionExchange>();
for (AccessionJson dataJson : batch.keySet()) {
if (LOG.isDebugEnabled())
......@@ -325,6 +327,27 @@ public class BatchRESTServiceImpl implements BatchRESTService {
toSaveBreed.add(accnBred);
}
if (accnJson.has("donorCode") || accnJson.has("donorNumb") || accnJson.has("donorName")) {
AccessionExchange accnExch = genesysService.listAccessionExchange(accession);
if (accnExch == null) {
accnExch = new AccessionExchange();
accnExch.setAccession(accession);
}
value = accnJson.get("donorCode");
if (value != null) {
accnExch.setDonorInstitute(value.isTextual() ? value.asText() : null);
}
value = accnJson.get("donorNumb");
if (value != null) {
accnExch.setAccNumbDonor(value.isTextual() ? value.asText() : null);
}
value = accnJson.get("donorName");
if (value != null) {
accnExch.setDonorName(value.isTextual() ? value.asText() : null);
}
toSaveExch.add(accnExch);
}
if (updated) {
toSave.add(accession);
}
......@@ -348,7 +371,11 @@ public class BatchRESTServiceImpl implements BatchRESTService {
genesysService.saveBreeding(toSaveBreed);
}
return toSave.size() > 0 || toSaveColl.size() > 0 || toSaveGeo.size() > 0 || toSaveBreed.size() > 0;
if (toSaveExch.size() > 0) {
genesysService.saveExchange(toSaveExch);
}
return toSave.size() > 0 || toSaveColl.size() > 0 || toSaveGeo.size() > 0 || toSaveBreed.size() > 0 || toSaveExch.size() > 0;
}
@Override
......
......@@ -41,7 +41,7 @@ import org.genesys2.server.model.genesys.AccessionTrait;
import org.genesys2.server.model.genesys.AllAccnames;
import org.genesys2.server.model.genesys.AccessionBreeding;
import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AllAcqExchange;
import org.genesys2.server.model.genesys.AccessionExchange;
import org.genesys2.server.model.genesys.ExperimentAccessionTrait;
import org.genesys2.server.model.genesys.ExperimentTrait;
import org.genesys2.server.model.genesys.Metadata;
......@@ -253,7 +253,7 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
}
@Override
public AllAcqExchange listAccessionExchange(Accession accession) {
public AccessionExchange listAccessionExchange(Accession accession) {
if (accession == null || accession.getId() == null)
return null;
return accessionExchangeRepository.findByAccession(accession);
......@@ -477,6 +477,12 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
accessionBreedingRepository.save(all);
}
@Override
@Transactional(readOnly = false)
public void saveExchange(List<AccessionExchange> all) {
accessionExchangeRepository.save(all);
}
@Override
public long countAvailable(Set<Long> accessionIds) {
if (accessionIds == null || accessionIds.size() == 0)
......
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