Commit 74c575e7 authored by Matija Obreza's avatar Matija Obreza
Browse files

Increased Accession#cropName field size and added REST API taxonomy record 'sanitizer'

parent 7565e69f
......@@ -94,7 +94,7 @@ public abstract class AccessionData implements IdUUID, Serializable {
@Column(name = "seqNo", nullable = false)
private float seqNo = 0;
@Column(name = "cropName", nullable = true, length = 50)
@Column(name = "cropName", nullable = true, length = 100)
private String cropName;
@ManyToOne(cascade = {}, optional = true, fetch = FetchType.LAZY)
......
......@@ -65,7 +65,7 @@ public class Crop extends GlobalVersionedAuditedModel implements AclAwareModel {
@Column(nullable = false, length = 50, unique = true)
private String shortName;
@Column(name = "otherName", nullable = false, unique = true)
@Column(name = "otherName", nullable = false, unique = true, length = 255)
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "cropname", joinColumns = @JoinColumn(name = "cropId", referencedColumnName = "id"), uniqueConstraints = { @UniqueConstraint(columnNames = "otherName") })
@OrderBy("otherName")
......
......@@ -55,6 +55,7 @@ import org.genesys2.server.service.GeoService;
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.PleaseRetryException;
import org.genesys2.server.servlet.controller.rest.model.AccessionAliasJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson;
......@@ -116,6 +117,9 @@ public class BatchRESTServiceImpl implements BatchRESTService {
throw new RESTApiException("GENUS cannot contain 'sp.'. Offending genus: " + current.getGenus());
}
// Sanitize
sanitizeTaxonomy(current);
if (LOG.isDebugEnabled()) {
LOG.debug("Ensuring " + current);
}
......@@ -139,12 +143,25 @@ public class BatchRESTServiceImpl implements BatchRESTService {
current.getSubtAuthor());
if (ensuredTaxonomy == null) {
throw new RuntimeException("Something is seriously wrong with taxonomyManager!");
throw new PleaseRetryException("Something is wrong with taxonomyManager for " + current.toString());
}
}
}
}
/**
* Sanitize incoming taxonomy record
*/
private void sanitizeTaxonomy(Taxonomy2 taxonomy) {
if (taxonomy == null) {
return;
}
if ("sp".equalsIgnoreCase(taxonomy.getSpecies())) {
taxonomy.setSpecies("sp.");
}
}
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE') or hasPermission(#institute, 'CREATE')")
......@@ -798,6 +815,8 @@ public class BatchRESTServiceImpl implements BatchRESTService {
current.setSubtaxa(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get(Api1Constants.Accession.SUBTAXA), StringUtils.EMPTY), StringUtils.EMPTY));
current.setSubtAuthor(StringUtils.defaultIfBlank(stringIfProvided(accnJson.get(Api1Constants.Accession.SUBTAUTHOR), StringUtils.EMPTY), StringUtils.EMPTY));
sanitizeTaxonomy(current);
Taxonomy2 ensuredTaxonomy = null;
try {
ensuredTaxonomy = taxonomyService.find(current.getGenus(), current.getSpecies(), current.getSpAuthor(), current.getSubtaxa(),
......
......@@ -228,8 +228,10 @@ public class AccessionController extends RestController {
for (int i = 0; i < 10; i++) {
try {
// Step 1: Ensure all taxonomic data provided by client is
// persisted
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;
......
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