Commit 2aac80a8 authored by Matija Obreza's avatar Matija Obreza

REST genus not required for faoInstitute.uniqueAcceNumbs

parent 2d343e50
...@@ -586,9 +586,15 @@ public class BatchRESTServiceImpl implements BatchRESTService { ...@@ -586,9 +586,15 @@ public class BatchRESTServiceImpl implements BatchRESTService {
List<AccessionAlias> toSave = new ArrayList<AccessionAlias>(); List<AccessionAlias> toSave = new ArrayList<AccessionAlias>();
List<AccessionAlias> toRemove = new ArrayList<AccessionAlias>(); List<AccessionAlias> toRemove = new ArrayList<AccessionAlias>();
boolean useUniqueAcceNumbs = institute.hasUniqueAcceNumbs();
for (AccessionNamesJson dataJson : batch) { for (AccessionNamesJson dataJson : batch) {
Accession accession = genesysService.getAccession(institute.getCode(), dataJson.acceNumb, dataJson.genus); Accession accession = null;
if (useUniqueAcceNumbs)
accession = genesysService.getAccession(institute.getCode(), dataJson.acceNumb);
else
accession = genesysService.getAccession(institute.getCode(), dataJson.acceNumb, dataJson.genus);
if (accession == null) { if (accession == null) {
LOG.warn("No such accession " + dataJson); LOG.warn("No such accession " + dataJson);
continue; continue;
...@@ -664,6 +670,7 @@ public class BatchRESTServiceImpl implements BatchRESTService { ...@@ -664,6 +670,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
public int deleteAccessions(FaoInstitute institute, List<AccessionJson> batch) { public int deleteAccessions(FaoInstitute institute, List<AccessionJson> batch) {
LOG.info("Batch deleting " + batch.size() + " entries for " + institute); LOG.info("Batch deleting " + batch.size() + " entries for " + institute);
List<Accession> toDelete = new ArrayList<Accession>(batch.size()); List<Accession> toDelete = new ArrayList<Accession>(batch.size());
boolean useUniqueAcceNumbs = institute.hasUniqueAcceNumbs();
for (AccessionJson dataJson : batch) { for (AccessionJson dataJson : batch) {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
...@@ -673,7 +680,12 @@ public class BatchRESTServiceImpl implements BatchRESTService { ...@@ -673,7 +680,12 @@ public class BatchRESTServiceImpl implements BatchRESTService {
throw new RuntimeException("Accession does not belong to instCode=" + institute.getCode() + " acn=" + dataJson); throw new RuntimeException("Accession does not belong to instCode=" + institute.getCode() + " acn=" + dataJson);
} }
Accession accession = genesysService.getAccession(dataJson.instCode, dataJson.acceNumb, dataJson.genus); Accession accession;
if (useUniqueAcceNumbs)
accession = genesysService.getAccession(institute.getCode(), dataJson.acceNumb);
else
accession = genesysService.getAccession(institute.getCode(), dataJson.acceNumb, dataJson.genus);
if (accession != null) { if (accession != null) {
toDelete.add(accession); toDelete.add(accession);
} }
......
...@@ -234,6 +234,8 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset ...@@ -234,6 +234,8 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Override @Override
public Accession getAccession(String instCode, String acceNumb, String genus) { public Accession getAccession(String instCode, String acceNumb, String genus) {
if (genus == null)
throw new NullPointerException("Genus is required to load accession by instCode, acceNumb and genus");
return accessionRepository.findOne(instCode, acceNumb, genus); return accessionRepository.findOne(instCode, acceNumb, genus);
} }
......
...@@ -210,6 +210,12 @@ public class AccessionController extends RestController { ...@@ -210,6 +210,12 @@ public class AccessionController extends RestController {
if (institute == null) { if (institute == null) {
throw new ResourceNotFoundException(); throw new ResourceNotFoundException();
} }
for (AccessionNamesJson aid3 : batch) {
if (!instCode.equals(aid3.instCode)) {
throw new RuntimeException("Accession does not belong to instCode=" + instCode + " acn=" + aid3);
}
}
batchRESTService.upsertAccessionNames(institute, batch); batchRESTService.upsertAccessionNames(institute, batch);
return JSON_OK; return JSON_OK;
......
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