Commit efccf89d authored by Matija Obreza's avatar Matija Obreza

Finalized migration to updated data model

- Uploader
- JSPs
parent 82c8bf50
...@@ -645,6 +645,9 @@ ...@@ -645,6 +645,9 @@
<artifactId>jetty-maven-plugin</artifactId> <artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version> <version>${jetty.version}</version>
<configuration> <configuration>
<httpConnector>
<port>8080</port>
</httpConnector>
<stopPort>8888</stopPort> <stopPort>8888</stopPort>
<stopKey>stop</stopKey> <stopKey>stop</stopKey>
<jvmArgs>-Dspring.profiles.active=dev -Xmx2048M -Xms1024M -XX:MaxPermSize=128M -Djava.awt.headless=true -server -Dorg.eclipse.jetty.server.Request.maxFormContentSize=5000000</jvmArgs> <jvmArgs>-Dspring.profiles.active=dev -Xmx2048M -Xms1024M -XX:MaxPermSize=128M -Djava.awt.headless=true -server -Dorg.eclipse.jetty.server.Request.maxFormContentSize=5000000</jvmArgs>
......
...@@ -36,7 +36,13 @@ import org.springframework.data.elasticsearch.annotations.Document; ...@@ -36,7 +36,13 @@ import org.springframework.data.elasticsearch.annotations.Document;
uniqueConstraints = { @UniqueConstraint(name = "UQ_accession_genus_inst", columnNames = { "instituteId", "genus", "acceNumb" }), uniqueConstraints = { @UniqueConstraint(name = "UQ_accession_genus_inst", columnNames = { "instituteId", "genus", "acceNumb" }),
@UniqueConstraint(name = "UQ_accession_doi", columnNames = { "doi" }) }, @UniqueConstraint(name = "UQ_accession_doi", columnNames = { "doi" }) },
// Indexes // Indexes
indexes = { @Index(name = "IX_acceNumb", columnList = "acceNumb"), @Index(name = "IX_seqNo", columnList = "seqNo"), @Index(name = "IX_accession_lastModifiedDate", columnList = "lastModifiedDate") }) indexes = {
@Index(name = "IX_acceNumb", columnList = "acceNumb"),
@Index(name = "IX_inst_seqNo", columnList = "instituteId,seqNo"),
@Index(name = "IX_origcty_seqNo", columnList = "orgCtyId,seqNo"),
@Index(name = "IX_taxa_seq", columnList = "taxonomyId2,seqNo"),
@Index(name = "IX_seqNo", columnList = "seqNo"),
@Index(name = "IX_accession_lastModifiedDate", columnList = "lastModifiedDate") })
@Audited @Audited
@Document(indexName = "genesys") @Document(indexName = "genesys")
public class Accession extends AccessionData { public class Accession extends AccessionData {
......
...@@ -328,7 +328,7 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU ...@@ -328,7 +328,7 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
@Override @Override
public String toString() { public String toString() {
return MessageFormat.format("Accession id={0,number,##########} UUID={1}", accessionId.getId(), getUuid()); return MessageFormat.format("Accession id={0,number,##########} UUID={1} {2} {3} {4}", accessionId.getId(), getUuid(), instituteCode, accessionNumber, genus);
} }
public String getAcceUrl() { public String getAcceUrl() {
...@@ -431,18 +431,35 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU ...@@ -431,18 +431,35 @@ public abstract class AccessionData extends AuditedVersionedModel implements IdU
public Integer getSampleStatus() { public Integer getSampleStatus() {
return this.sampStat; return this.sampStat;
} }
@Transient @Transient
@JsonIgnore @JsonIgnore
// For EL // For EL
public Boolean getAvailable() { public Boolean getAvailable() {
return this.available; return this.available;
} }
@Transient
@JsonIgnore
// For EL
public Boolean getAvailability() {
return this.available;
}
@Transient @Transient
@JsonIgnore @JsonIgnore
// For EL // For EL
public Boolean getHistoric() { public Boolean getHistoric() {
return this.historic; return this.historic;
} }
@Transient
@JsonIgnore
// For EL
public String getInstCode() {
return this.instituteCode;
}
} }
...@@ -114,6 +114,11 @@ public class AccessionId extends AuditedVersionedModel implements IdUUID { ...@@ -114,6 +114,11 @@ public class AccessionId extends AuditedVersionedModel implements IdUUID {
@CollectionTable(name = "accession_breedercode", joinColumns = @JoinColumn(name = "accessionId", referencedColumnName = "id")) @CollectionTable(name = "accession_breedercode", joinColumns = @JoinColumn(name = "accessionId", referencedColumnName = "id"))
private Set<String> breederCode; private Set<String> breederCode;
@Column(name = "breederName", nullable = false, length = 250)
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "accession_breedername", joinColumns = @JoinColumn(name = "accessionId", referencedColumnName = "id"))
private Set<String> breederName;
@PrePersist @PrePersist
private void prepersist() { private void prepersist() {
if (uuid == null) { if (uuid == null) {
...@@ -193,6 +198,14 @@ public class AccessionId extends AuditedVersionedModel implements IdUUID { ...@@ -193,6 +198,14 @@ public class AccessionId extends AuditedVersionedModel implements IdUUID {
public void setBreederCode(Set<String> breederCode) { public void setBreederCode(Set<String> breederCode) {
this.breederCode = breederCode; this.breederCode = breederCode;
} }
public Set<String> getBreederName() {
return breederName;
}
public void setBreederName(Set<String> breederName) {
this.breederName = breederName;
}
public Set<String> getDuplSite() { public Set<String> getDuplSite() {
return duplSite; return duplSite;
......
...@@ -183,7 +183,7 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel { ...@@ -183,7 +183,7 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
} }
public Long getTaxGenus() { public Long getTaxGenus() {
return this.taxGenus; return this.taxGenus == null ? this.getId() : this.taxGenus;
} }
public void setTaxGenus(Long taxGenus) { public void setTaxGenus(Long taxGenus) {
...@@ -191,7 +191,7 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel { ...@@ -191,7 +191,7 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
} }
public Long getTaxSpecies() { public Long getTaxSpecies() {
return this.taxSpecies; return this.taxSpecies == null ? this.getId() : this.taxSpecies;
} }
public void setTaxSpecies(Long taxSpecies) { public void setTaxSpecies(Long taxSpecies) {
......
...@@ -97,10 +97,8 @@ public class FaoInstitute extends BasicModel implements GeoReferencedEntity, Acl ...@@ -97,10 +97,8 @@ public class FaoInstitute extends BasicModel implements GeoReferencedEntity, Acl
private Double latitude; private Double latitude;
private Double longitude; private Double longitude;
private Double elevation; private Double elevation;
private boolean uniqueAcceNumbs = true; private boolean uniqueAcceNumbs = false;
private boolean allowMaterialRequests = false;
@Column(name = "allowMaterialRequests", columnDefinition = "boolean default true", nullable = false)
private boolean allowMaterialRequests = true;
public FaoInstitute() { public FaoInstitute() {
} }
......
...@@ -162,12 +162,12 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom, ...@@ -162,12 +162,12 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom,
} }
if (uniqueAcceNumbs) { if (uniqueAcceNumbs) {
restrictions.add(root.get("accessionName").in(acceNumbs)); restrictions.add(root.get("accessionNumber").in(acceNumbs));
LOG.trace("*** {} accenumbs={}", institute.getCode(), acceNumbs); LOG.trace("*** {} accenumbs={}", institute.getCode(), acceNumbs);
} else { } else {
// A lot of .. (acceNumb=? and genus=?) // A lot of .. (acceNumb=? and genus=?)
for (AccessionIdentifier3 ah : accessionIds) { for (AccessionIdentifier3 ah : accessionIds) {
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("accessionName"), ah.getAccessionNumber()), criteriaBuilder.equal(tax.get("genus"), ah.getGenus()))); restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("accessionNumber"), ah.getAccessionNumber()), criteriaBuilder.equal(tax.get("genus"), ah.getGenus())));
} }
} }
cq.where(criteriaBuilder.and(criteriaBuilder.equal(root.get("institute"), institute), criteriaBuilder.or(restrictions.toArray(EMPTY_PREDICATE_ARRAY)))); cq.where(criteriaBuilder.and(criteriaBuilder.equal(root.get("institute"), institute), criteriaBuilder.or(restrictions.toArray(EMPTY_PREDICATE_ARRAY))));
...@@ -206,9 +206,9 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom, ...@@ -206,9 +206,9 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom,
if (doi != null) { if (doi != null) {
restrictions.add(criteriaBuilder.equal(root.get("doi"), doi)); restrictions.add(criteriaBuilder.equal(root.get("doi"), doi));
} else if (institute.hasUniqueAcceNumbs()) { } else if (institute.hasUniqueAcceNumbs()) {
restrictions.add(criteriaBuilder.equal(root.get("accessionName"), acceNumb)); restrictions.add(criteriaBuilder.equal(root.get("accessionNumber"), acceNumb));
} else { } else {
restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("accessionName"), acceNumb), criteriaBuilder.equal(tax.get("genus"), genus))); restrictions.add(criteriaBuilder.and(criteriaBuilder.equal(root.get("accessionNumber"), acceNumb), criteriaBuilder.equal(tax.get("genus"), genus)));
} }
cq.where(criteriaBuilder.and(criteriaBuilder.equal(root.get("institute"), institute), criteriaBuilder.or(restrictions.toArray(new Predicate[] {})))); cq.where(criteriaBuilder.and(criteriaBuilder.equal(root.get("institute"), institute), criteriaBuilder.or(restrictions.toArray(new Predicate[] {}))));
......
...@@ -47,6 +47,22 @@ public class DirectMysqlQuery { ...@@ -47,6 +47,22 @@ public class DirectMysqlQuery {
private static final Logger LOG = LoggerFactory.getLogger(DirectMysqlQuery.class); private static final Logger LOG = LoggerFactory.getLogger(DirectMysqlQuery.class);
private static final String SPACE = " "; private static final String SPACE = " ";
public static final String TABLE_ACCEID = "acce";
public static final String TABLE_ACCESSION = "accession";
public static final String TABLE_ACCESSION_STORAGE = "accession_storage";
public static final String TABLE_ACCESSION_COLLECT = "accession_collect";
public static final String TABLE_ACCESSION_ALIAS = "accession_alias";
public static final String TABLE_ACCESSION_GEO = "accession_geo";
public static final String TABLE_ACCESSION_LIST = "accession_list";
public static final String TABLE_ACCESION_LISTITEMS = "accession_listitem";
public static final String TABLE_ORGANIZATIONINSTITUTE = "organizationinstitute";
public static final String TABLE_CROP = "crop";
public static final String TABLE_PDCI = "pdci";
public static final String TABLE_TAXONOMY = "taxonomy2";
public static final String TABLE_ORGANIZATION = "organization";
public static final String TABLE_COUNTRY = "country";
public static final String TABLE_FAOINSTITUTE = "faoinstitute";
final Set<String> tables = new HashSet<String>(); final Set<String> tables = new HashSet<String>();
final List<Object> params = new ArrayList<Object>(); final List<Object> params = new ArrayList<Object>();
final StringBuffer sb, whereBuffer = new StringBuffer(), sortBuffer = new StringBuffer(); final StringBuffer sb, whereBuffer = new StringBuffer(), sortBuffer = new StringBuffer();
...@@ -105,63 +121,65 @@ public class DirectMysqlQuery { ...@@ -105,63 +121,65 @@ public class DirectMysqlQuery {
protected DirectMysqlQuery join(AppliedFilters filters) { protected DirectMysqlQuery join(AppliedFilters filters) {
if (filters.hasFilter(FilterConstants.UUID)) {
innerJoin(TABLE_ACCEID, null, "acce.id=a.id");
}
if (filters.hasFilter(FilterConstants.LISTS)) { if (filters.hasFilter(FilterConstants.LISTS)) {
innerJoin("accelistitems", "ali", "ali.acceid=a.id"); innerJoin(TABLE_ACCEID, null, "acce.id=a.id");
innerJoin("accelist", "al", "al.id=ali.listid"); innerJoin(TABLE_ACCESION_LISTITEMS, "ali", "ali.acceid=acce.id");
innerJoin(TABLE_ACCESSION_LIST, "al", "al.id=ali.listid");
} }
if (filters.hasFilter(FilterConstants.TAXONOMY_GENUS) || filters.hasFilter(FilterConstants.TAXONOMY_SPECIES) if (filters.hasFilter(FilterConstants.TAXONOMY_GENUS) || filters.hasFilter(FilterConstants.TAXONOMY_SPECIES) || filters.hasFilter(FilterConstants.TAXONOMY_SUBTAXA)
|| filters.hasFilter(FilterConstants.TAXONOMY_SUBTAXA) || filters.hasFilter(FilterConstants.TAXONOMY_SCINAME)) { || filters.hasFilter(FilterConstants.TAXONOMY_SCINAME)) {
innerJoin("taxonomy2", "t", "t.id=a.taxonomyId2"); innerJoin(TABLE_TAXONOMY, "t", "t.id=a.taxonomyId2");
} }
if (filters.hasFilter(FilterConstants.CROPS)) { if (filters.hasFilter(FilterConstants.CROPS)) {
innerJoin("crop", null, "crop.id=a.cropId"); innerJoin(TABLE_CROP, null, "crop.id=a.cropId");
} }
if (filters.hasFilter(FilterConstants.UUID)) {
innerJoin("acce", null, "acce.id=a.id");
}
if (filters.hasFilter(FilterConstants.PDCI)) { if (filters.hasFilter(FilterConstants.PDCI)) {
innerJoin("pdci", null, "pdci.accessionId=a.id"); innerJoin(TABLE_ACCEID, null, "acce.id=a.id");
innerJoin(TABLE_PDCI, null, "pdci.id=acce.pdciId");
} }
// if (filters.hasFilter(FilterConstants.ORGCTY_ISO3)) { // if (filters.hasFilter(FilterConstants.ORGCTY_ISO3)) {
// innerJoin("country", "cty", "cty.id=a.orgCtyId"); // innerJoin("country", "cty", "cty.id=a.orgCtyId");
// } // }
if (/* filters.hasFilter(FilterConstants.INSTCODE) || */filters.hasFilter(FilterConstants.INSTITUTE_COUNTRY_ISO3) if (filters.hasFilter(FilterConstants.INSTCODE) || filters.hasFilter(FilterConstants.INSTITUTE_COUNTRY_ISO3) || filters.hasFilter(FilterConstants.INSTITUTE_NETWORK)) {
|| filters.hasFilter(FilterConstants.INSTITUTE_NETWORK)) {
innerJoin("faoinstitute", "fao", "fao.id=a.instituteId"); innerJoin(TABLE_FAOINSTITUTE, "fao", "fao.id=a.instituteId");
if (filters.hasFilter(FilterConstants.INSTITUTE_COUNTRY_ISO3)) { if (filters.hasFilter(FilterConstants.INSTITUTE_COUNTRY_ISO3)) {
innerJoin("country", "faocty", "faocty.id=fao.countryId"); innerJoin(TABLE_COUNTRY, "faocty", "faocty.id=fao.countryId");
} }
if (filters.hasFilter(FilterConstants.INSTITUTE_NETWORK)) { if (filters.hasFilter(FilterConstants.INSTITUTE_NETWORK)) {
innerJoin("organizationinstitute", "oi", "oi.instituteId=fao.id"); innerJoin(TABLE_ORGANIZATIONINSTITUTE, "oi", "oi.instituteId=fao.id");
innerJoin("organization", "org", "org.id=oi.organizationId"); innerJoin(TABLE_ORGANIZATION, "org", "org.id=oi.organizationId");
} }
} }
if (filters.hasFilter(FilterConstants.GEO_LATITUDE) || filters.hasFilter(FilterConstants.GEO_LONGITUDE) if (filters.hasFilter(FilterConstants.GEO_LATITUDE) || filters.hasFilter(FilterConstants.GEO_LONGITUDE) || filters.hasFilter(FilterConstants.GEO_ELEVATION)) {
|| filters.hasFilter(FilterConstants.GEO_ELEVATION)) { innerJoin(TABLE_ACCESSION_GEO, "geo", "geo.id=acce.geoId");
innerJoin("accessiongeo", "geo", "geo.accessionId=a.id");
} }
if (filters.hasFilter(FilterConstants.ALIAS)) { if (filters.hasFilter(FilterConstants.ALIAS)) {
innerJoin("accessionalias", "accename", "accename.accessionId=a.id"); innerJoin(TABLE_ACCESSION_ALIAS, "accename", "accename.accessionId=acce.id");
} }
if (filters.hasFilter(FilterConstants.COLLMISSID)) { if (filters.hasFilter(FilterConstants.COLLMISSID)) {
innerJoin("accessioncollect", "col", "col.accessionId=a.id"); innerJoin(TABLE_ACCEID, null, "acce.id=a.id");
innerJoin(TABLE_ACCESSION_COLLECT, "col", "col.id=acce.collId");
} }
if (filters.hasFilter(FilterConstants.STORAGE)) { if (filters.hasFilter(FilterConstants.STORAGE)) {
outerJoin("accessionstorage", "storage", "storage.accessionId=a.id"); innerJoin(TABLE_ACCEID, null, "acce.id=a.id");
outerJoin(TABLE_ACCESSION_STORAGE, "storage", "storage.accessionId=acce.id");
} }
return this; return this;
...@@ -170,17 +188,12 @@ public class DirectMysqlQuery { ...@@ -170,17 +188,12 @@ public class DirectMysqlQuery {
protected DirectMysqlQuery filter(AppliedFilters filters, MethodResolver methodResolver) { protected DirectMysqlQuery filter(AppliedFilters filters, MethodResolver methodResolver) {
createQuery(whereBuffer, "a.id", filters.get(FilterConstants.ID), params); createQuery(whereBuffer, "a.id", filters.get(FilterConstants.ID), params);
createQuery(whereBuffer, "acce.uuid", filters.get(FilterConstants.UUID), params); createQuery(whereBuffer, "acce.uuid", filters.get(FilterConstants.UUID), params);
{
// FIXME Are these two still used?
createQuery(whereBuffer, "t.taxGenus", filters.get("genusId"), params);
createQuery(whereBuffer, "t.taxSpecies", filters.get("speciesId"), params);
}
createQuery(whereBuffer, "al.uuid", filters.get(FilterConstants.LISTS), params); createQuery(whereBuffer, "al.uuid", filters.get(FilterConstants.LISTS), params);
createQuery(whereBuffer, "a.acceNumb", filters.get(FilterConstants.ACCENUMB), params); createQuery(whereBuffer, "a.acceNumb", filters.get(FilterConstants.ACCENUMB), params);
createQuery(whereBuffer, "a.seqNo", filters.get(FilterConstants.SEQUENTIAL_NUMBER), params); createQuery(whereBuffer, "a.seqNo", filters.get(FilterConstants.SEQUENTIAL_NUMBER), params);
createQuery(whereBuffer, "a.lastModifiedDate", filters.get(FilterConstants.LAST_MODIFIED_DATE), params); createQuery(whereBuffer, "a.lastModifiedDate", filters.get(FilterConstants.LAST_MODIFIED_DATE), params);
createQuery(whereBuffer, "a.orgCty", filters.get(FilterConstants.ORGCTY_ISO3), params); createQuery(whereBuffer, "a.origCty", filters.get(FilterConstants.ORGCTY_ISO3), params);
createQuery(whereBuffer, "a.instCode", filters.get(FilterConstants.INSTCODE), params); createQuery(whereBuffer, "fao.code", filters.get(FilterConstants.INSTCODE), params);
createQuery(whereBuffer, "a.cropName", filters.get(FilterConstants.CROPNAME), params); createQuery(whereBuffer, "a.cropName", filters.get(FilterConstants.CROPNAME), params);
createQuery(whereBuffer, "faocty.code3", filters.get(FilterConstants.INSTITUTE_COUNTRY_ISO3), params); createQuery(whereBuffer, "faocty.code3", filters.get(FilterConstants.INSTITUTE_COUNTRY_ISO3), params);
createQuery(whereBuffer, "a.inSGSV", filters.get(FilterConstants.SGSV), params); createQuery(whereBuffer, "a.inSGSV", filters.get(FilterConstants.SGSV), params);
......
...@@ -123,7 +123,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -123,7 +123,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
throw new RuntimeException("Genesys does not support requests for data beyond " + PAGINATION_MAXPAGE_LIMIT + "th page."); throw new RuntimeException("Genesys does not support requests for data beyond " + PAGINATION_MAXPAGE_LIMIT + "th page.");
} }
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a"); final DirectMysqlQuery directQuery = new DirectMysqlQuery(DirectMysqlQuery.TABLE_ACCESSION, "a");
directQuery.jsonFilter(filters, new MethodResolver() { directQuery.jsonFilter(filters, new MethodResolver() {
@Override @Override
public Method getMethod(long methodId) { public Method getMethod(long methodId) {
...@@ -170,7 +170,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -170,7 +170,7 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
throw new MaxPageLimitException(PAGINATION_MAXPAGE_LIMIT, pageable.getPageNumber() + 1); throw new MaxPageLimitException(PAGINATION_MAXPAGE_LIMIT, pageable.getPageNumber() + 1);
} }
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accession", "a"); final DirectMysqlQuery directQuery = new DirectMysqlQuery(DirectMysqlQuery.TABLE_ACCESSION, "a");
directQuery.jsonFilter(filters, new MethodResolver() { directQuery.jsonFilter(filters, new MethodResolver() {
@Override @Override
public Method getMethod(long methodId) { public Method getMethod(long methodId) {
...@@ -394,14 +394,16 @@ public class GenesysFilterServiceImpl implements GenesysFilterService { ...@@ -394,14 +394,16 @@ public class GenesysFilterServiceImpl implements GenesysFilterService {
} }
} }
final DirectMysqlQuery directQuery = new DirectMysqlQuery("accessiongeo", "geo"); final DirectMysqlQuery directQuery = new DirectMysqlQuery(DirectMysqlQuery.TABLE_ACCESSION_GEO, "geo");
directQuery.filterTile(zoom, xtile, ytile);
if (!filters.isEmpty() || !distinct) { if (!filters.isEmpty() || !distinct) {
// Join accession table when we have filters or looking at details // Join accession table when we have filters or looking at details
directQuery.innerJoin("accession", "a", "a.id=geo.accessionId"); directQuery.innerJoin(DirectMysqlQuery.TABLE_ACCEID, null, "acce.geoId=geo.id");
directQuery.innerJoin(DirectMysqlQuery.TABLE_ACCESSION, "a", "a.id=acce.id");
} }
directQuery.filterTile(zoom, xtile, ytile);
if (!filters.isEmpty()) { if (!filters.isEmpty()) {
directQuery.join(filters); directQuery.join(filters);
directQuery.filter(filters, new MethodResolver() { directQuery.filter(filters, new MethodResolver() {
......
...@@ -355,6 +355,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService { ...@@ -355,6 +355,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
accessionId.getAliases().size(); accessionId.getAliases().size();
if (accessionId.getBreederCode() != null) if (accessionId.getBreederCode() != null)
accessionId.getBreederCode().size(); accessionId.getBreederCode().size();
if (accessionId.getBreederName() != null)
accessionId.getBreederName().size();
if (accessionId.getDuplSite() != null) if (accessionId.getDuplSite() != null)
accessionId.getDuplSite().size(); accessionId.getDuplSite().size();
if (accessionId.getRemarks() != null) if (accessionId.getRemarks() != null)
......
...@@ -208,7 +208,7 @@ public class TaxonomyServiceImpl implements TaxonomyService { ...@@ -208,7 +208,7 @@ public class TaxonomyServiceImpl implements TaxonomyService {
public void cleanupTaxonomies() { public void cleanupTaxonomies() {
Set<BigInteger> referencedIds = taxonomy2Repository.findTaxonomyReferencedIds(); Set<BigInteger> referencedIds = taxonomy2Repository.findTaxonomyReferencedIds();
Set<Long> allIds = taxonomy2Repository.findTaxonomyIds(); Set<Long> allIds = taxonomy2Repository.findTaxonomyIds();
for (BigInteger integer: referencedIds) { for (BigInteger integer : referencedIds) {
allIds.remove(integer.longValue()); allIds.remove(integer.longValue());
} }
...@@ -216,13 +216,13 @@ public class TaxonomyServiceImpl implements TaxonomyService { ...@@ -216,13 +216,13 @@ public class TaxonomyServiceImpl implements TaxonomyService {
taxonomy2Repository.removeUnusedIds(allIds); taxonomy2Repository.removeUnusedIds(allIds);
} }
} }
@Override @Override
@Transactional(timeout = 50, isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED) @Transactional(timeout = 50, isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED)
public Taxonomy2 ensureTaxonomy(Taxonomy2 example) { public Taxonomy2 ensureTaxonomy(Taxonomy2 example) {
example.sanitize(); example.sanitize();
Taxonomy2 existing = taxonomy2Repository.findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor(example.getGenus(), example.getSpecies(), example.getSpAuthor(), example.getSubtaxa(), example.getSubtAuthor()); Taxonomy2 existing = taxonomy2Repository.findByGenusAndSpeciesAndSpAuthorAndSubtaxaAndSubtAuthor(example.getGenus(), example.getSpecies(), example.getSpAuthor(), example
.getSubtaxa(), example.getSubtAuthor());
if (existing == null) { if (existing == null) {
LOG.debug("Adding taxonomy {} {} {} {} {}", example.getGenus(), example.getSpecies(), example.getSpAuthor(), example.getSubtaxa(), example.getSubtAuthor()); LOG.debug("Adding taxonomy {} {} {} {} {}", example.getGenus(), example.getSpecies(), example.getSpAuthor(), example.getSubtaxa(), example.getSubtAuthor());
Taxonomy2 newTaxa = new Taxonomy2(); Taxonomy2 newTaxa = new Taxonomy2();
...@@ -231,7 +231,35 @@ public class TaxonomyServiceImpl implements TaxonomyService { ...@@ -231,7 +231,35 @@ public class TaxonomyServiceImpl implements TaxonomyService {
newTaxa.setSpAuthor(example.getSpAuthor()); newTaxa.setSpAuthor(example.getSpAuthor());
newTaxa.setSubtaxa(example.getSubtaxa()); newTaxa.setSubtaxa(example.getSubtaxa());
newTaxa.setSubtAuthor(example.getSubtAuthor()); newTaxa.setSubtAuthor(example.getSubtAuthor());
return taxonomy2Repository.save(newTaxa.sanitize());
Taxonomy2 tsP = new Taxonomy2();
tsP.setGenus(newTaxa.getGenus());
tsP.setSpecies(newTaxa.getSpecies());
tsP.sanitize();
if (tsP.equalTo(newTaxa)) {
// equal to species level
tsP.setSpecies(null);
tsP.sanitize();
// get genus id
if (!tsP.equalTo(newTaxa)) {
tsP = ensureTaxonomy(tsP);
newTaxa.setTaxGenus(tsP.getTaxGenus());
} else {
// incoming taxonomy is genus level only.
// System.err.println("What now " + newTaxa + " == " + tsP);
}
} else {
// not equal to species level, ensure taxSpecies
tsP = ensureTaxonomy(tsP);
newTaxa.setTaxGenus(tsP.getTaxGenus());
newTaxa.setTaxSpecies(tsP.getId());
}
Taxonomy2 t = taxonomy2Repository.save(newTaxa.sanitize());
// self-references
t.setTaxGenus(t.getTaxGenus());
t.setTaxSpecies(t.getTaxSpecies());
return taxonomy2Repository.save(t);
} else { } else {
return existing; return existing;
} }
......
...@@ -18,11 +18,13 @@ package org.genesys2.server.service.worker; ...@@ -18,11 +18,13 @@ package org.genesys2.server.service.worker;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.elasticsearch.common.lang3.StringUtils;
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.AccessionAlias.AliasType; import org.genesys2.server.model.genesys.AccessionAlias.AliasType;
...@@ -112,6 +114,7 @@ public class AccessionUploader implements InitializingBean { ...@@ -112,6 +114,7 @@ public class AccessionUploader implements InitializingBean {
assert (updates.isArray()); assert (updates.isArray());
ObjectReader reader = objectMapper.readerFor(Accession.class); ObjectReader reader = objectMapper.readerFor(Accession.class);
Date batchDate = new Date();
final List<Accession> accessions = new ArrayList<>(updates.size()); final List<Accession> accessions = new ArrayList<>(updates.size());
final List<AccessionOpResponse> responses = new ArrayList<>(updates.size());