Commit c11fb1cf authored by Matija Obreza's avatar Matija Obreza

ElasticSearch

parent f2f4e14a
......@@ -337,6 +337,12 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<version>4.5.1.Final</version>
<exclusions>
<exclusion>
<artifactId>solr-analysis-extras</artifactId>
<groupId>org.apache.solr</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
......@@ -419,6 +425,66 @@
<version>${jetty.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>1.0.2.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>lucene-core</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-sandbox</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-queries</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-codecs</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-grouping</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-memory</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-spatial</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-suggest</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-queryparser</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-misc</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-join</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-highlighter</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
<exclusion>
<artifactId>lucene-analyzers-common</artifactId>
<groupId>org.apache.lucene</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
......
package org.apache.lucene.util;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.Locale;
/**
* Use by certain classes to match version compatibility across releases of
* Lucene.
*
* <p>
* <b>WARNING</b>: When changing the version parameter that you supply to
* components in Lucene, do not simply change the version at search-time, but
* instead also adjust your indexing code to match, and re-index.
*/
public enum Version {
/**
* Match settings and bugs in Lucene's 2.0 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_20,
/**
* Match settings and bugs in Lucene's 2.1 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_21,
/**
* Match settings and bugs in Lucene's 2.2 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_22,
/**
* Match settings and bugs in Lucene's 2.3 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_23,
/**
* Match settings and bugs in Lucene's 2.4 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_24,
/**
* Match settings and bugs in Lucene's 2.9 release.
*
* @deprecated (3.1) Use latest
*/
@Deprecated
LUCENE_29,
/**
* Match settings and bugs in Lucene's 3.0 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_30,
/**
* Match settings and bugs in Lucene's 3.1 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_31,
/**
* Match settings and bugs in Lucene's 3.2 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_32,
/**
* Match settings and bugs in Lucene's 3.3 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_33,
/**
* Match settings and bugs in Lucene's 3.4 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_34,
/**
* Match settings and bugs in Lucene's 3.5 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_35,
/**
* Match settings and bugs in Lucene's 3.6 release.
*
* @deprecated (4.0) Use latest
*/
@Deprecated
LUCENE_36,
/**
* Match settings and bugs in Lucene's 3.6 release.
*
* @deprecated (4.1) Use latest
*/
@Deprecated
LUCENE_40,
/**
* Match settings and bugs in Lucene's 4.1 release.
*
* @deprecated (4.2) Use latest
*/
@Deprecated
LUCENE_41,
/**
* Match settings and bugs in Lucene's 4.2 release.
*
* @deprecated (4.3) Use latest
*/
@Deprecated
LUCENE_42,
/**
* Match settings and bugs in Lucene's 4.3 release.
*
* @deprecated (4.4) Use latest
*/
@Deprecated
LUCENE_43,
/**
* Match settings and bugs in Lucene's 4.4 release.
*
* @deprecated (4.5) Use latest
*/
@Deprecated
LUCENE_44,
/**
* Match settings and bugs in Lucene's 4.5 release.
*
* @deprecated (4.6) Use latest
*/
@Deprecated
LUCENE_45,
/**
* Match settings and bugs in Lucene's 4.6 release.
*
* @deprecated (4.7) Use latest
*/
@Deprecated
LUCENE_46,
/**
* Match settings and bugs in Lucene's 4.7 release.
*
* @deprecated (4.8) Use latest
*/
@Deprecated
LUCENE_47,
/**
* Match settings and bugs in Lucene's 4.8 release.
* <p>
* Use this to get the latest &amp; greatest settings, bug fixes, etc, for
* Lucene.
*/
LUCENE_48,
/* Add new constants for later versions **here** to respect order! */
/**
* <p>
* <b>WARNING</b>: if you use this setting, and then upgrade to a newer
* release of Lucene, sizable changes may happen. If backwards compatibility
* is important then you should instead explicitly specify an actual
* version.
* <p>
* If you use this constant then you may need to <b>re-index all of your
* documents</b> when upgrading Lucene, as the way text is indexed may have
* changed. Additionally, you may need to <b>re-test your entire
* application</b> to ensure it behaves as expected, as some defaults may
* have changed and may break functionality in your application.
*
* @deprecated Use an actual version instead.
*/
@Deprecated
LUCENE_CURRENT;
public boolean onOrAfter(Version other) {
return compareTo(other) >= 0;
}
public static Version parseLeniently(String version) {
String parsedMatchVersion = version.toUpperCase(Locale.ROOT);
return Version.valueOf(parsedMatchVersion.replaceFirst("^(\\d)\\.(\\d)$", "LUCENE_$1$2"));
}
}
package org.genesys2.server.servlet.controller.rest;
package org.genesys2.server.model.elastic;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionAlias;
import org.genesys2.server.model.genesys.AccessionBreeding;
......@@ -14,117 +15,95 @@ import org.genesys2.server.model.genesys.AccessionCollect;
import org.genesys2.server.model.genesys.AccessionExchange;
import org.genesys2.server.model.genesys.AccessionGeo;
import org.genesys2.server.model.genesys.AccessionRemark;
import org.genesys2.server.model.genesys.ExperimentTrait;
import org.genesys2.server.model.genesys.Method;
import org.genesys2.server.model.genesys.SvalbardData;
import org.genesys2.server.model.genesys.Taxonomy2;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.server.model.impl.FaoInstitute;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
@Document(indexName = "genesys", type = "mcpd", refreshInterval = "-1")
public class AccessionDetails {
public long version;
public Long id;
public String uuid;
public String acceNumb;
public String acqDate;
public String acqSrc;
public Boolean availability;
public Date createdDate;
public String duplSite;
public Boolean mlsStatus;
public Integer sampStat;
public List<Integer> storage;
public Institute institute;
public Country orgCty;
public Taxonomy taxonomy;
public ArrayList<Alias> aliases;
public Svalbard sgsv;
public ArrayList<Remark> remarks;
public ArrayList<String> crops;
public Geo geo;
public Collect coll;
public String pedigree;
public String donorCode;
public String donorName;
public String donorNumb;
public HashMap<String, List<Object>> traits;
private static final Logger LOG = Logger.getLogger(AccessionDetails.class);
private static Pattern mcpdSplit = Pattern.compile("\\w*;\\w*");
@Version
private Long version;
@Id
private Long id;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String uuid;
@Field(type = FieldType.String)
private String acceNumb;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String acqDate;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String acqSrc;
private Boolean availability;
private Date createdDate;
private List<String> duplSite;
private Boolean mlsStatus;
private Integer sampStat;
private List<Integer> storage;
@Field(type = FieldType.Object)
private Institute institute;
@Field(type = FieldType.Object)
private Country orgCty;
@Field(type = FieldType.Object)
private Taxonomy taxonomy;
@Field(type = FieldType.Nested)
private ArrayList<Alias> aliases;
private Svalbard sgsv;
@Field(type = FieldType.Nested, store = false)
private ArrayList<Remark> remarks;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private ArrayList<String> crops;
@Field(type = FieldType.Object)
private Geo geo;
@Field(type = FieldType.Object)
private Collect coll;
private String pedigree;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String donorCode;
private String donorName;
@Field(index = FieldIndex.not_analyzed, type = FieldType.String)
private String donorNumb;
private Date modifiedDate;
private Date acqusitionDate;
public static AccessionDetails from(Accession accession) {
AccessionDetails ad = new AccessionDetails();
ad.version = accession.getVersion();
ad.id = accession.getId();
ad.uuid = accession.getUuid();
ad.createdDate = accession.getCreatedDate();
ad.modifiedDate = accession.getLastModifiedDate();
ad.acceNumb = accession.getAccessionName();
ad.acqDate = accession.getAcquisitionDate();
ad.acqSrc = accession.getAcquisitionSource();
ad.availability = accession.getAvailability();
ad.orgCty = Country.from(accession.getCountryOfOrigin());
ad.createdDate = accession.getCreatedDate();
ad.duplSite = accession.getDuplSite();
ad.institute = AccessionDetails.Institute.from(accession.getInstitute());
if (StringUtils.isNotBlank(accession.getDuplSite()))
ad.duplSite = Arrays.asList(mcpdSplit.split(accession.getDuplSite()));
ad.institute = Institute.from(accession.getInstitute());
ad.mlsStatus = accession.getMlsStatus();
ad.sampStat = accession.getSampleStatus();
ad.storage = accession.getStoRage();
ad.taxonomy = Taxonomy.from(accession.getTaxonomy());
return ad;
}
public static class Institute {
public Long id;
public String acronym;
public String code;
public Country country;
public String fullName;
public static Institute from(FaoInstitute institute) {
Institute i = new Institute();
i.id = institute.getId();
i.acronym = institute.getAcronym();
i.code = institute.getCode();
i.country = Country.from(institute.getCountry());
i.fullName = institute.getFullName();
return i;
}
}
public static class Country {
public String iso3;
public String iso2;
public String name;
public static Country from(org.genesys2.server.model.impl.Country country) {
Country c = new Country();
c.iso3 = country.getCode3();
c.iso2 = country.getCode2();
c.name = country.getName();
return c;
}
}
public static class Taxonomy {
public String sciName;
public String genus;
public String species;
public String spAuthor;
public String subtax;
public String subtAuthor;
public static Taxonomy from(Taxonomy2 taxonomy) {
Taxonomy t = new Taxonomy();
t.sciName = taxonomy.getTaxonName();
t.genus = taxonomy.getGenus();
t.species = taxonomy.getSpecies();
t.spAuthor = StringUtils.defaultIfBlank(taxonomy.getSpAuthor(), null);
t.subtax = StringUtils.defaultIfBlank(taxonomy.getSubtaxa(), null);
t.subtAuthor = StringUtils.defaultIfBlank(taxonomy.getSubtAuthor(), null);
return t;
if (ad.taxonomy == null) {
LOG.warn("Go check " + ad.id);
}
return ad;
}
public void aliases(List<AccessionAlias> listAccessionAliases) {
......@@ -136,44 +115,10 @@ public class AccessionDetails {
}
}
public static class Alias {
public String name;
public String lang;
public String usedBy;
public static Alias from(AccessionAlias aa) {
Alias a = new Alias();
a.name = aa.getName();
a.lang = StringUtils.defaultIfBlank(aa.getLang(), null);
a.usedBy = StringUtils.defaultIfBlank(aa.getUsedBy(), null);
return a;
}
}
public void svalbard(SvalbardData svalbardData) {
this.sgsv = Svalbard.from(svalbardData);
}
public static class Svalbard {
public Float qty;
public String boxNo;
public String depositDate;
public static Svalbard from(SvalbardData svalbardData) {
if (svalbardData == null)
return null;
Svalbard s = new Svalbard();
s.boxNo = svalbardData.getBoxNumber();
s.qty = svalbardData.getQuantity();
s.depositDate = svalbardData.getDepositDate();
return s;
}
}
public void remarks(List<AccessionRemark> listAccessionRemarks) {
if (listAccessionRemarks == null || listAccessionRemarks.isEmpty())
return;
......@@ -183,20 +128,6 @@ public class AccessionDetails {
}
}
public static class Remark {
public String field;
public String remark;
public static Remark from(AccessionRemark ar) {
Remark r = new Remark();
r.field = StringUtils.defaultIfBlank(ar.getFieldName(), null);
r.remark = StringUtils.defaultIfBlank(ar.getRemark(), null);
return r;
}
}
public void crops(List<Crop> crops) {
if (crops == null || crops.isEmpty())
return;
......@@ -212,65 +143,10 @@ public class AccessionDetails {
this.geo = Geo.from(ag);
}
public static class Geo {
public String method;
public Double uncertainty;
public Double latitude;
public Double longitude;
public Double[] coordinates;
public Double elevation;
public String datum;
public static Geo from(AccessionGeo ag) {
if (ag == null)
return null;
Geo g = new Geo();
g.datum = StringUtils.defaultIfBlank(ag.getDatum(), null);
g.elevation = ag.getElevation();
g.coordinates = new Double[] { ag.getLongitude(), ag.getLatitude() };
g.longitude = ag.getLongitude();
g.latitude = ag.getLatitude();
g.uncertainty = ag.getUncertainty();
g.method = StringUtils.defaultIfBlank(ag.getMethod(), null);
return g;
}
}
public void collect(AccessionCollect collect) {
this.coll = Collect.from(collect);
}