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 {
List<AccessionAlias> toSave = new ArrayList<AccessionAlias>();
List<AccessionAlias> toRemove = new ArrayList<AccessionAlias>();
boolean useUniqueAcceNumbs = institute.hasUniqueAcceNumbs();
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) {
LOG.warn("No such accession " + dataJson);
continue;
......@@ -664,6 +670,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
public int deleteAccessions(FaoInstitute institute, List<AccessionJson> batch) {
LOG.info("Batch deleting " + batch.size() + " entries for " + institute);
List<Accession> toDelete = new ArrayList<Accession>(batch.size());
boolean useUniqueAcceNumbs = institute.hasUniqueAcceNumbs();
for (AccessionJson dataJson : batch) {
if (LOG.isDebugEnabled())
......@@ -673,7 +680,12 @@ public class BatchRESTServiceImpl implements BatchRESTService {
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) {
toDelete.add(accession);
}
......
......@@ -234,6 +234,8 @@ public class GenesysServiceImpl implements GenesysService, TraitService, Dataset
@Override
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);
}
......
......@@ -210,6 +210,12 @@ public class AccessionController extends RestController {
if (institute == null) {
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);
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