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