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

More error data included in REST API exception

parent 1ba29462
......@@ -113,8 +113,12 @@ public class BatchRESTServiceImpl implements BatchRESTService {
current.setSubtaxa(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get(Api1Constants.Accession.SUBTAXA), current.getSubtaxa()), StringUtils.EMPTY));
current.setSubtAuthor(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get(Api1Constants.Accession.SUBTAUTHOR), current.getSubtAuthor()), StringUtils.EMPTY));
if (current.getGenus() == null) {
throw new RESTApiException("'genus' must be provided. Offending JSON = " + accnJson.toString());
}
if (current.getGenus().contains("sp.")) {
throw new RESTApiException("GENUS cannot contain 'sp.'. Offending genus: " + current.getGenus());
throw new RESTApiException("'genus' cannot contain 'sp.' text. Offending JSON = " + accnJson.toString());
}
// Sanitize
......@@ -239,7 +243,7 @@ public class BatchRESTServiceImpl implements BatchRESTService {
accession.setAccessionName(dataJson.acceNumb);
if (accnJson.get(Api1Constants.Accession.GENUS) == null && accnJson.get(Api1Constants.Accession.GENUS_NEW) == null) {
throw new RESTApiException("Cannot create new accession without specifying genus");
throw new RESTApiException("Cannot create new accession without specifying genus. Offending JSON = " + accnJson.toString());
}
upsertResult = new UpsertResult(UpsertResult.Type.INSERT);
......
......@@ -226,32 +226,37 @@ public class AccessionController extends RestController {
Throwable cause = null;
for (int i = 0; i < 10; i++) {
try {
if (i > 0) {
LOG.info("Retry " + i + " of 10");
}
// Step 1: Ensure all taxonomic data provided by client is persisted
batchRESTService.ensureTaxonomies(institute, batch);
// Step 2: Upsert data
List<AccessionOpResponse> response = null;
try {
for (int i = 0; i < 10; i++) {
try {
response = batchRESTService.upsertAccessionData(institute, batch);
} catch (RESTApiException e) {
LOG.info("Retrying upsert one by one due to " + e.getMessage());
response = upsertAccessionData1by1(institute, batch);
if (i > 0) {
LOG.info("Retry " + i + " of 10");
}
// Step 1: Ensure all taxonomic data provided by client is persisted
batchRESTService.ensureTaxonomies(institute, batch);
// Step 2: Upsert data
List<AccessionOpResponse> response = null;
try {
response = batchRESTService.upsertAccessionData(institute, batch);
} catch (RESTApiException e) {
LOG.info("Retrying upsert one by one due to " + e.getMessage());
response = upsertAccessionData1by1(institute, batch);
}
// Force update institute#accessionCount (outside previous
// transaction)
genesysService.updateAccessionCount(institute);
return response;
} catch (PleaseRetryException | HibernateOptimisticLockingFailureException | org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException e) {
LOG.info("Will retry upsert. Error: " + e.getMessage());
cause = e;
}
// Force update institute#accessionCount (outside previous
// transaction)
genesysService.updateAccessionCount(institute);
return response;
} catch (PleaseRetryException | HibernateOptimisticLockingFailureException
| org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException e) {
LOG.info("Will retry upsert. Error: " + e.getMessage());
cause = e;
}
} catch (RESTApiException e) {
throw e;
} catch (Throwable e) {
LOG.error("Failed to upsert accession data", e);
cause = e;
}
throw new RESTApiException("Could not upsert accession data. " + cause.getMessage(), cause);
}
......
Supports Markdown
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