...
 
Commits (197)
......@@ -2,6 +2,19 @@ variables:
GENESYS_VERSION: "2.3"
DOCKER_HOST: genesys1.swarm.genesys-pgr.org
DOCKER_VERSION: latest
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
# As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
# when running from the command line.
# `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
cache:
paths:
- .m2/repository
stages:
# - compile
......@@ -19,12 +32,12 @@ stages:
# script:
# - echo "CI_COMMIT_REF_SLUG ${CI_COMMIT_REF_SLUG}"
# - echo "CI_ENVIRONMENT_SLUG ${CI_ENVIRONMENT_SLUG}"
# - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn compile test -B -U
# - mvn compile test -B -U
.package_template: &maven_package
image: dockerhub.croptrust.org/docker/custom/maven-with-compass:latest
script:
- MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn package -B -U
- mvn package -B -U
artifacts:
name: "${CI_PROJECT_NAME}-${CI_COMMIT_REF_NAME}"
expire_in: 1 day
......
......@@ -80,7 +80,7 @@
<hibernate.version>4.3.11.Final</hibernate.version>
<hibernate.validator.version>5.2.5.Final</hibernate.validator.version>
<hsqldb.version>2.3.6</hsqldb.version>
<hsqldb.version>2.4.1</hsqldb.version>
<ehcache.version>2.7.4</ehcache.version>
<slf4j.version>1.7.25</slf4j.version>
......@@ -233,6 +233,12 @@
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jsonSchema</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate4</artifactId>
......@@ -631,6 +637,21 @@
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>${hibernate.validator.version}</version>
</dependency>
<dependency>
<groupId>cz.jirutka.validator</groupId>
<artifactId>validator-collection</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>amphibian-client-resttemplate</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.hashids</groupId>
<artifactId>hashids</artifactId>
<version>1.0.3</version>
</dependency>
</dependencies>
<build>
......
......@@ -2,8 +2,11 @@
== Authentication
All BrAPI requests can be made anonymously, without providing the OAuth2
*Bearer: <TOKEN>* authentication header.
All BrAPI requests require OAuth2 authentication header in HTTP requests:
----
Authorization: Bearer <TOKEN>
----
=== Login
......
......@@ -3,7 +3,8 @@
== Multi-crop Passport Descriptors
The http://www.bioversityinternational.org/e-library/publications/detail/faobioversity-multi-crop-passport-descriptors-v21-mcpd-v21/[Multi-crop Passport Descriptors (MCPD) V.2.1]
were released in 2012 as an update to the MCPD V.2. The MCPD V.2, in turn, was a 2001 revision of the first FAO/IPGRI publication,
were released in 2015 as an update to the MCPD V.2 from 2012.
The MCPD V.2, in turn, was a 2001 revision of the first FAO/IPGRI publication,
expanded to accommodate emerging needs such as the broader use of GPS tools and the
implementation of the http://www.planttreaty.org[International Treaty on Plant Genetic Resources for
Food and Agriculture] Multilateral System for access and benefit sharing.
......
......@@ -51,6 +51,13 @@ public class MapColorsFilter extends PointFilter {
public int filterRGB(int x, int y, int rgb) {
if (rgb == oldColor) {
return newColor;
} else if (rgb != 0) {
int alpha = (rgb >> 24) & 0xFF; // isolate alpha
alpha &= 0xff; //keeps alpha in 0-255 range
int newRGB = newColor;
newRGB &= 0x00ffffff; //remove old alpha info
newRGB |= (alpha << 24); //add new alpha info
return newRGB;
}
return rgb;
}
......
......@@ -45,8 +45,8 @@ import java.util.Set;
@Entity
@Table(name = "partner")
@Cacheable
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid")
@Document(indexName = "catalog")
@Document(indexName = "partner")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid", scope = Partner.class)
public class Partner extends UuidModel implements SelfCleaning, AclAwareModel {
private static final ClassAclOid<Partner> PARENT_OID = ClassAclOid.forClass(Partner.class);
......@@ -96,7 +96,7 @@ public class Partner extends UuidModel implements SelfCleaning, AclAwareModel {
@OneToMany(mappedBy = "owner", fetch = FetchType.LAZY)
private List<FaoInstitute> institutes;
@ElementCollection
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "partner_country", joinColumns = @JoinColumn(name = "partnerId"), uniqueConstraints = { @UniqueConstraint(columnNames = { "partnerId", "code" }) })
@Column(name = "code", length = 3, nullable = false)
private Set<String> countryCodes;
......
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -18,6 +18,8 @@ package org.genesys.catalog.model;
import org.genesys.blocks.model.EntityId;
import org.hibernate.annotations.Type;
import com.fasterxml.jackson.annotation.JsonIgnore;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
......@@ -53,6 +55,15 @@ public class ShortFilter implements Serializable, EntityId {
@Type(type = "org.hibernate.type.TextType")
private String json;
/**
* The new code to use for an old filter.
*
* Filters with {@link #redirect} == null are using the current shortCode syntax.
*/
@JsonIgnore
@Column(length = 50, nullable = true, name = "redir")
private String redirect;
/**
* Default constructor.
*/
......@@ -125,4 +136,12 @@ public class ShortFilter implements Serializable, EntityId {
public int hashCode() {
return Objects.hash(id, code, json);
}
public void setRedirect(String redirectCode) {
this.redirect = redirectCode;
}
public String getRedirect() {
return redirect;
}
}
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -17,6 +17,7 @@ package org.genesys.catalog.model.dataset;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import javax.persistence.Cacheable;
import javax.persistence.CascadeType;
......@@ -35,22 +36,26 @@ import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonGetter;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import org.genesys.blocks.auditlog.annotations.Audited;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.model.Publishable;
import org.genesys.blocks.model.SelfCleaning;
import org.genesys.blocks.model.UuidModel;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.catalog.annotations.PublishValidation;
import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.PublishValidationInterface;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.impl.Crop;
......@@ -61,6 +66,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
/**
* {@link Dataset} captures the metadata information as a snapshot. Multiple
......@@ -68,31 +74,33 @@ import com.fasterxml.jackson.annotation.JsonView;
*
* @author Matija Obreza
* @author Andrey Lugovskoy
* @author Maxim Borodenko
* @author Maxym Borodenko
*/
@Entity
@Table(name = "dataset")
@Table(name = "dataset", uniqueConstraints = @UniqueConstraint(name = "UQ_current_dataset_version", columnNames={"versionsId", "current"}))
@Cacheable
@Audited
@Document(indexName = "catalog")
public class Dataset extends UuidModel implements Publishable, SelfCleaning, PublishValidationInterface, AclAwareModel {
@Document(indexName = "dataset")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid", scope = Dataset.class)
public class Dataset extends UuidModel implements Publishable, SelfCleaning, AclAwareModel {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -4601980446454791177L;
/** The versions. */
@PublishValidation
@ManyToOne(cascade = CascadeType.ALL, optional = false)
@ManyToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH }, optional = false)
@JoinColumn(name = "versionsId", updatable = false)
@JsonIgnore
private DatasetVersions versions;
private Boolean current;
/** The owner. */
@PublishValidation
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "partnerId", updatable = false)
@JsonView({ JsonViews.Public.class })
@NotNull
@Field(type = FieldType.Object)
private Partner owner;
/** The accession identifiers. */
......@@ -105,11 +113,11 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@ManyToMany(fetch = FetchType.LAZY, cascade = {})
@JoinTable(name = "dataset_descriptor", joinColumns = @JoinColumn(name = "datasetId", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "descriptorId", referencedColumnName = "id"))
@OrderColumn(name = "position")
@Field(type = FieldType.Object)
@JsonView({ JsonViews.Public.class })
private List<Descriptor> descriptors;
/** The repository files. */
@PublishValidation
@OneToMany(fetch = FetchType.LAZY, cascade = {})
@JoinTable(name = "dataset_repositoryfile", joinColumns = @JoinColumn(name = "datasetId", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "repositoryfileId", referencedColumnName = "id"))
@OrderColumn(name = "position")
......@@ -118,14 +126,12 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
private List<RepositoryFile> repositoryFiles;
/** The creators. */
@PublishValidation(innerCheck = true)
@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "dataset", orphanRemoval = true, fetch = FetchType.LAZY)
@Field(type = FieldType.Object)
@JsonView({ JsonViews.Public.class })
private List<DatasetCreator> creators;
/** The locations. */
@PublishValidation(innerCheck = true)
@OneToMany(cascade = { CascadeType.ALL }, mappedBy = "dataset", orphanRemoval = true, fetch = FetchType.LAZY)
@Field(type = FieldType.Object)
@JsonView({ JsonViews.Public.class })
......@@ -168,13 +174,11 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
/**
* DatasetVersions title in English.
*/
@PublishValidation
private String title;
/**
* DatasetVersions description in English.
*/
@PublishValidation
@Lob
private String description;
......@@ -184,14 +188,12 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
private String format;
/** Language used in the versions. */
@PublishValidation
private String language;
/** The subject of the versions. */
private String subject;
/** The rights. */
@PublishValidation
private String rights;
/** The source. */
......@@ -206,6 +208,16 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@Enumerated(EnumType.ORDINAL)
private PublishState state = PublishState.DRAFT;
@Transient
private UUID currentVersion;
@PostLoad
protected void postLoad() {
if (this.versions != null && versions.getCurrentVersion() != null && !this.uuid.equals(versions.getCurrentVersion().getUuid())) {
this.currentVersion = versions.getCurrentVersion().getUuid();
}
}
/**
* Preupdate.
*/
......@@ -226,6 +238,43 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
trimStringsToNull();
}
/**
* Gets the current.
*
* @return the current
*/
public Boolean getCurrent() {
return current;
}
/**
* Sets current value
*
* @param current the new value of current
*/
public void setCurrent(final Boolean current) {
this.current = current;
}
/**
* Gets the UUID of current dataset
*
* @return the UUID of current dataset
*/
@JsonGetter
public UUID getCurrentVersion() {
return currentVersion;
}
/**
* Sets the UUID of current dataset
*
* @param currentVersion the UUID of current dataset
*/
public void setCurrentVersion(final UUID currentVersion) {
this.currentVersion = currentVersion;
}
/**
* Owner is the ACL parent object for the dataset
*/
......
......@@ -17,8 +17,6 @@ package org.genesys.catalog.model.dataset;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.genesys.blocks.model.UuidModel;
import org.genesys.catalog.annotations.PublishValidation;
import org.genesys.catalog.service.PublishValidationInterface;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
......@@ -32,7 +30,7 @@ import java.util.Map;
*/
@Entity
@Table(name="dataset_creator")
public class DatasetCreator extends UuidModel implements PublishValidationInterface {
public class DatasetCreator extends UuidModel {
/**
*
......@@ -58,35 +56,28 @@ public class DatasetCreator extends UuidModel implements PublishValidationInterf
}
/** The full name. */
@PublishValidation
@NotNull
@Size(max = 200)
@Column(length = 200, nullable = false)
private String fullName;
/** The email. */
@PublishValidation
private String email;
/** The phone number. */
@PublishValidation
private String phoneNumber;
/** The fax. */
@PublishValidation
private String fax;
/** The institutional affiliation. */
@PublishValidation
private String institutionalAffiliation;
/** The institute address. */
@PublishValidation
private String instituteAddress;
/** The role. */
@Enumerated(EnumType.STRING)
@PublishValidation
private DatasetCreatorRole role;
/** The dataset. */
......@@ -238,13 +229,4 @@ public class DatasetCreator extends UuidModel implements PublishValidationInterf
public void setInstituteAddress(final String instituteAddress) {
this.instituteAddress = instituteAddress;
}
/*
* (non-Javadoc)
* @see org.genesys.catalog.service.PublishValidationInterface#validation()
*/
@Override
public Map<String, String> validation() {
return PublishValidationInterface.super.validation();
}
}
......@@ -17,8 +17,6 @@ package org.genesys.catalog.model.dataset;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.genesys.blocks.model.UuidModel;
import org.genesys.catalog.annotations.PublishValidation;
import org.genesys.catalog.service.PublishValidationInterface;
import org.genesys2.util.MCPDUtil;
import javax.persistence.*;
......@@ -32,7 +30,7 @@ import java.util.Map;
*/
@Entity
@Table(name="dataset_location")
public class DatasetLocation extends UuidModel implements PublishValidationInterface {
public class DatasetLocation extends UuidModel {
/**
*
......@@ -46,26 +44,21 @@ public class DatasetLocation extends UuidModel implements PublishValidationInter
private Dataset dataset;
/** The user-provided country name. */
@PublishValidation
private String userCountry;
/** Country as detected from coordinates. */
@PublishValidation
private String mapCountry;
/** The state province. */
@PublishValidation
private String stateProvince;
/** The verbatim locality. */
private String verbatimLocality;
/** The decimal latitude. */
@PublishValidation
private Double decimalLatitude;
/** The decimal longitude. */
@PublishValidation
private Double decimalLongitude;
/** ISO3 country code of the location */
......@@ -294,13 +287,4 @@ public class DatasetLocation extends UuidModel implements PublishValidationInter
public void setDescription(String description) {
this.description = description;
}
/*
* (non-Javadoc)
* @see org.genesys.catalog.service.PublishValidationInterface#validation()
*/
@Override
public Map<String, String> validation() {
return PublishValidationInterface.super.validation();
}
}
......@@ -16,7 +16,8 @@
package org.genesys.catalog.model.dataset;
import org.genesys.blocks.model.UuidModel;
import org.genesys.catalog.annotations.PublishValidation;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import javax.persistence.Entity;
import javax.persistence.FetchType;
......@@ -40,13 +41,12 @@ public class DatasetVersions extends UuidModel {
private static final long serialVersionUID = 7307818236681549484L;
/** The current version. */
@PublishValidation(ignoreValidation = true)
@OneToOne(cascade = {}, orphanRemoval = true)
private Dataset currentVersion;
/** The all versions. */
@PublishValidation
@OneToMany(cascade = {}, fetch = FetchType.LAZY, mappedBy = "versions", orphanRemoval = true)
@JsonIdentityReference(alwaysAsId = true)
private List<Dataset> allVersions;
/**
......
......@@ -19,12 +19,10 @@ import static org.genesys.catalog.model.vocab.QControlledVocabulary.controlledVo
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.blocks.model.filters.UuidModelFilter;
import org.genesys.catalog.model.QPartner;
import org.genesys.catalog.model.vocab.ControlledVocabulary;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.JPAExpressions;
public class ControlledVocabularyFilter extends UuidModelFilter<ControlledVocabularyFilter, ControlledVocabulary> {
......@@ -60,7 +58,7 @@ public class ControlledVocabularyFilter extends UuidModelFilter<ControlledVocabu
and.and(description.buildQuery(controlledVocabulary.description));
}
if (owner != null) {
and.and(controlledVocabulary.owner.in(JPAExpressions.selectFrom(QPartner.partner).where(owner.buildPredicate())));
and.and(owner.buildQuery(controlledVocabulary.owner));
}
return and;
}
......
......@@ -21,15 +21,14 @@ import java.util.HashSet;
import java.util.Set;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.blocks.model.filters.UuidModelFilter;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.service.filter.IFullTextFilter;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import org.genesys2.server.model.PublishState;
/**
* The Class DatasetFilter.
......@@ -37,7 +36,7 @@ import org.genesys2.server.model.PublishState;
* @author Andrey Lugovskoy
* @author Matija Obreza
*/
public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> {
public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> implements IFullTextFilter {
/** Any text. */
public String _text;
......@@ -46,13 +45,13 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> {
public PartnerFilter owner;
/** The accession reference. */
public AccessionRefFilter accessionRef;
public AccessionRefFilter accessionRefs;
/** Dataset location filter */
public DatasetLocationFilter location;
public DatasetLocationFilter locations;
/** Descriptor filter */
public DescriptorFilter descriptor;
public DescriptorFilter descriptors;
/** The title. */
public StringFilter title;
......@@ -67,10 +66,13 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> {
public Set<PublishState> state;
/** The crop. */
public Set<String> crop;
public Set<String> crops;
public Set<String> rights;
/** Is current version */
public Boolean current;
/**
* Builds the query.
*
......@@ -92,50 +94,51 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> {
if (owner != null) {
and.and(owner.buildQuery(dataset.owner));
}
if (accessionRef != null) {
and.and(accessionRef.buildQuery(dataset.accessionRefs));
if (accessionRefs != null) {
and.and(accessionRefs.buildQuery(dataset.accessionRefs));
}
if (descriptor != null) {
and.and(descriptor.buildQuery(dataset.descriptors.any()));
if (descriptors != null) {
and.and(descriptors.buildQuery(dataset.descriptors.any()));
}
if (CollectionUtils.isNotEmpty(language)) {
and.and(dataset.language.in(language));
}
if (crop != null && !crop.isEmpty()) {
and.and(dataset.crops.any().in(crop));
if (crops != null && !crops.isEmpty()) {
and.and(dataset.crops.any().in(crops));
}
if (location != null) {
and.and(location.buildQuery(dataset.locations.any()));
if (locations != null) {
and.and(locations.buildQuery(dataset.locations.any()));
}
if (CollectionUtils.isNotEmpty(rights)) {
and.and(dataset.rights.in(rights));
}
if (StringUtils.isNotBlank(_text)) {
/*@formatter:off*/
and.andAnyOf(
ArrayUtils.addAll(
FilterHelpers.equalsAny(_text,
dataset.versionTag,
dataset.owner.shortName,
dataset.crops.any(),
dataset.descriptors.any().crop,
dataset.accessionRefs.any().genus, dataset.accessionRefs.any().instCode, dataset.accessionRefs.any().acceNumb
),
FilterHelpers.containsAll(_text,
dataset.title, dataset.description,
dataset.creators.any().fullName,
dataset.locations.any().verbatimLocality,
dataset.repositoryFiles.any().title, dataset.repositoryFiles.any().originalFilename,
dataset.owner.name,
dataset.descriptors.any().title
)
)
);
/*@formatter:on*/
if (current != null) {
and.and(dataset.current.eq(current));
}
// if (StringUtils.isNotBlank(_text)) {
// /*@formatter:off*/
// and.andAnyOf(
// ArrayUtils.addAll(
// FilterHelpers.equalsAny(_text,
// dataset.versionTag,
// dataset.owner.shortName,
// dataset.crops.any(),
// dataset.descriptors.any().crop,
// dataset.accessionRefs.any().genus, dataset.accessionRefs.any().instCode, dataset.accessionRefs.any().acceNumb
// ),
// FilterHelpers.containsAll(_text,
// dataset.title, dataset.description,
// dataset.creators.any().fullName,
// dataset.locations.any().verbatimLocality,
// dataset.repositoryFiles.any().title, dataset.repositoryFiles.any().originalFilename,
// dataset.owner.name,
// dataset.descriptors.any().title
// )
// )
// );
// /*@formatter:on*/
// }
return and;
}
......@@ -149,4 +152,16 @@ public class DatasetFilter extends UuidModelFilter<DatasetFilter, Dataset> {
}
return this;
}
@Override
public String get_text() {
return _text;
}
public PartnerFilter owner() {
if (this.owner == null) {
return this.owner = new PartnerFilter();
}
return this.owner;
}
}
......@@ -20,17 +20,17 @@ public class DatasetLocationFilter extends UuidModelFilter<DatasetLocationFilter
/**
* The longitude.
*/
public NumberFilter<Double> longitude;
public NumberFilter<Double> decimalLongitude;
/**
* The latitude.
*/
public NumberFilter<Double> latitude;
public NumberFilter<Double> decimalLatitude;
/**
* The elevation.
*/
public Set<String> country;
public Set<String> userCountry;
/**
......@@ -52,14 +52,14 @@ public class DatasetLocationFilter extends UuidModelFilter<DatasetLocationFilter
final BooleanBuilder and = new BooleanBuilder();
super.buildQuery(datasetLocation, datasetLocation._super, and);
if (longitude != null) {
and.and(longitude.buildQuery(datasetLocation.decimalLongitude));
if (decimalLongitude != null) {
and.and(decimalLongitude.buildQuery(datasetLocation.decimalLongitude));
}
if (latitude != null) {
and.and(latitude.buildQuery(datasetLocation.decimalLatitude));
if (decimalLatitude != null) {
and.and(decimalLatitude.buildQuery(datasetLocation.decimalLatitude));
}
if (CollectionUtils.isNotEmpty(country)) {
and.and(datasetLocation.userCountry.in(country));
if (CollectionUtils.isNotEmpty(userCountry)) {
and.and(datasetLocation.userCountry.in(userCountry));
}
return and;
......
......@@ -20,20 +20,16 @@ import static org.genesys.catalog.model.traits.QDescriptor.descriptor;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.filters.NumberFilter;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.blocks.model.filters.UuidModelFilter;
import org.genesys.catalog.model.QPartner;
import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.model.traits.QDescriptor;
import org.genesys.catalog.model.traits.QDescriptorList;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.service.filter.IFullTextFilter;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.JPAExpressions;
import org.genesys2.server.model.PublishState;
/**
* The Class DescriptorFilter.
......@@ -41,7 +37,7 @@ import org.genesys2.server.model.PublishState;
* @author Andrey Lugovskoy
* @author Matija Obreza
*/
public class DescriptorFilter extends UuidModelFilter<DescriptorFilter, Descriptor> {
public class DescriptorFilter extends UuidModelFilter<DescriptorFilter, Descriptor> implements IFullTextFilter {
/** Any text. */
public String _text;
......@@ -89,7 +85,7 @@ public class DescriptorFilter extends UuidModelFilter<DescriptorFilter, Descript
public NumberFilter<Double> maxValue;
/** Descriptor list filter */
public DescriptorListFilter list;
public DescriptorListFilter descriptorLists;
/** Descriptor is in use: referenced in Dataset or DescriptorList. */
public Boolean used;
......@@ -141,7 +137,7 @@ public class DescriptorFilter extends UuidModelFilter<DescriptorFilter, Descript
and.and(bibliographicCitation.buildQuery(descriptorPath.bibliographicCitation));
}
if (owner != null) {
and.and(descriptorPath.owner.in(JPAExpressions.selectFrom(QPartner.partner).where(owner.buildPredicate())));
and.and(owner.buildQuery(descriptorPath.owner));
}
if (minValue != null) {
and.and(minValue.buildQuery(descriptorPath.minValue));
......@@ -149,8 +145,8 @@ public class DescriptorFilter extends UuidModelFilter<DescriptorFilter, Descript
if (maxValue != null) {
and.and(maxValue.buildQuery(descriptorPath.maxValue));
}
if (list != null) {
and.and(descriptorPath.descriptorLists.any().in(JPAExpressions.selectFrom(QDescriptorList.descriptorList).where(list.buildPredicate())));
if (descriptorLists != null) {
and.and(descriptorLists.buildQuery(descriptorPath.descriptorLists.any()));
}
if (used != null) {
if (used.booleanValue()==true) {
......@@ -160,24 +156,24 @@ public class DescriptorFilter extends UuidModelFilter<DescriptorFilter, Descript
}
}
if (StringUtils.isNotBlank(_text)) {
/*@formatter:off*/
and.andAnyOf(
ArrayUtils.addAll(
FilterHelpers.equalsAny(_text,
descriptorPath.crop, descriptorPath.versionTag, descriptorPath.publisher,
descriptorPath.owner.shortName,
descriptorPath.descriptorLists.any().publisher, descriptorPath.descriptorLists.any().versionTag, descriptorPath.descriptorLists.any().crop
),
FilterHelpers.containsAll(_text,
descriptorPath.title, descriptorPath.description, descriptorPath.bibliographicCitation,
descriptorPath.owner.name,
descriptorPath.descriptorLists.any().title
)
)
);
/*@formatter:on*/
}
// if (StringUtils.isNotBlank(_text)) {
// /*@formatter:off*/
// and.andAnyOf(
// ArrayUtils.addAll(
// FilterHelpers.equalsAny(_text,
// descriptorPath.crop, descriptorPath.versionTag, descriptorPath.publisher,
// descriptorPath.owner.shortName,
// descriptorPath.descriptorLists.any().publisher, descriptorPath.descriptorLists.any().versionTag, descriptorPath.descriptorLists.any().crop
// ),
// FilterHelpers.containsAll(_text,
// descriptorPath.title, descriptorPath.description, descriptorPath.bibliographicCitation,
// descriptorPath.owner.name,
// descriptorPath.descriptorLists.any().title
// )
// )
// );
// /*@formatter:on*/
// }
return and;
}
......@@ -200,4 +196,8 @@ public class DescriptorFilter extends UuidModelFilter<DescriptorFilter, Descript
}
}
@Override
public String get_text() {
return _text;
}
}
......@@ -20,12 +20,12 @@ import static org.genesys.catalog.model.traits.QDescriptorList.descriptorList;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.filters.StringFilter;
import org.genesys.blocks.model.filters.UuidModelFilter;
import org.genesys.catalog.model.traits.DescriptorList;
import org.genesys.catalog.model.traits.QDescriptorList;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.service.filter.IFullTextFilter;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
......@@ -36,7 +36,7 @@ import com.querydsl.core.types.Predicate;
* @author Andrey Lugovskoy
* @author Matija Obreza
*/
public class DescriptorListFilter extends UuidModelFilter<DescriptorListFilter, DescriptorList> {
public class DescriptorListFilter extends UuidModelFilter<DescriptorListFilter, DescriptorList> implements IFullTextFilter {
/** Any text. */
public String _text;
......@@ -68,6 +68,10 @@ public class DescriptorListFilter extends UuidModelFilter<DescriptorListFilter,
* @return the predicate
*/
public Predicate buildPredicate() {
return buildQuery(descriptorList);
}
public Predicate buildQuery(QDescriptorList descriptorList) {
final BooleanBuilder and = new BooleanBuilder();
super.buildQuery(descriptorList, descriptorList._super, and);
......@@ -93,24 +97,24 @@ public class DescriptorListFilter extends UuidModelFilter<DescriptorListFilter,
and.and(owner.buildQuery(descriptorList.owner));
}
if (StringUtils.isNotBlank(_text)) {
/*@formatter:off*/
and.andAnyOf(
ArrayUtils.addAll(
FilterHelpers.equalsAny(_text,
descriptorList.crop, descriptorList.versionTag, descriptorList.publisher,
descriptorList.owner.shortName,
descriptorList.descriptors.any().crop, descriptorList.descriptors.any().versionTag, descriptorList.descriptors.any().publisher
),
FilterHelpers.containsAll(_text,
descriptorList.title, descriptorList.description, descriptorList.bibliographicCitation,
descriptorList.owner.name,
descriptorList.descriptors.any().title
)
)
);
/*@formatter:on*/
}
// if (StringUtils.isNotBlank(_text)) {
// /*@formatter:off*/
// and.andAnyOf(
// ArrayUtils.addAll(
// FilterHelpers.equalsAny(_text,
// descriptorList.crop, descriptorList.versionTag, descriptorList.publisher,
// descriptorList.owner.shortName,
// descriptorList.descriptors.any().crop, descriptorList.descriptors.any().versionTag, descriptorList.descriptors.any().publisher
// ),
// FilterHelpers.containsAll(_text,
// descriptorList.title, descriptorList.description, descriptorList.bibliographicCitation,
// descriptorList.owner.name,
// descriptorList.descriptors.any().title
// )
// )
// );
// /*@formatter:on*/
// }
return and;
}
......@@ -124,4 +128,16 @@ public class DescriptorListFilter extends UuidModelFilter<DescriptorListFilter,
}
return this;
}
@Override
public String get_text() {
return _text;
}
public PartnerFilter owner() {
if (this.owner == null) {
return this.owner = new PartnerFilter();
}
return this.owner;
}
}
......@@ -23,6 +23,7 @@ import org.genesys.catalog.model.Partner;
import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.vocab.ControlledVocabulary;
import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys.filerepository.model.RepositoryImage;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.impl.Crop;
import org.springframework.dao.DataIntegrityViolationException;
......@@ -45,8 +46,8 @@ import java.util.List;
@Cacheable
@Table(name = "descriptor")
@Audited
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid")
@Document(indexName = "catalog")
@Document(indexName = "descriptor")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid", scope = Descriptor.class)
public class Descriptor extends UuidModel implements SelfCleaning, Publishable, Copyable<Descriptor>, AclAwareModel {
/** The Constant serialVersionUID. */
......@@ -221,6 +222,13 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
@Column(length = 20, nullable = false)
private Category category;
@Size(max = 2)
private String lang;
@OneToOne(fetch = FetchType.LAZY, cascade = { }, optional = true, orphanRemoval = false)
@JoinColumn(name = "imageId", unique = true)
private RepositoryImage image;
/**
* Instantiates a new descriptor.
*/
......@@ -235,6 +243,13 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
private void preupdate() {
trimStringsToNull();
}
@PreRemove
private void preventRemoveWithImage() {
if (image != null) {
throw new DataIntegrityViolationException("Refusing to delete Descriptor with image");
}
}
/**
* Owner is the ACL parent object for the descriptor
......@@ -252,7 +267,7 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
public Descriptor(final Descriptor descriptor) {
this(descriptor.getVersionTag(), descriptor.getTitle(), descriptor.description, descriptor.getDataType(), descriptor.getState(), descriptor.isKey(), descriptor
.getIntegerOnly(), descriptor.getMinValue(), descriptor.getMaxValue(), descriptor.getColumnName(), descriptor.getUom(), descriptor.getVocabulary(), descriptor
.getOwner(), descriptor.getDescriptorLists());
.getOwner(), descriptor.getDescriptorLists(), descriptor.getImage());
}
/**
......@@ -272,10 +287,11 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
* @param vocabulary the vocabulary
* @param owner the owner
* @param descriptorLists the descriptor lists
* @param image the image
*/
public Descriptor(final String versionTag, final String title, final String description, final DataType dataType, final PublishState state, final boolean key,
final Boolean integerOnly, final Double minValue, final Double maxValue, final String columnName, final String uom, final ControlledVocabulary vocabulary,
final Partner owner, final List<DescriptorList> descriptorLists) {
final Partner owner, final List<DescriptorList> descriptorLists, final RepositoryImage image) {
this.versionTag = versionTag;
this.title = title;
this.description = description;
......@@ -290,6 +306,7 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
this.vocabulary = vocabulary;
this.owner = owner;
this.descriptorLists = descriptorLists;
this.image = image;
}
/**
......@@ -674,6 +691,42 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
this.category = category;
}
/**
* Gets the lang.
*
* @return the lang
*/
public String getLang() {
return lang;
}
/**
* Sets the lang.
*
* @param lang the new lang
*/
public void setLang(final String lang) {
this.lang = lang;
}
/**
* Gets the image.
*
* @return the image
*/
public RepositoryImage getImage() {
return image;
}
/**
* Sets the image.
*
* @param image the new repository image
*/
public void setImage(final RepositoryImage image) {
this.image = image;
}
/*
* (non-Javadoc)
* @see org.genesys.blocks.model.Copyable#copy()
......
......@@ -47,8 +47,8 @@ import java.util.Map;
@Table(name="descriptorlist")
@Audited
@Cacheable
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid")
@Document(indexName = "catalog")
@Document(indexName = "descriptorlist")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid", scope = DescriptorList.class)
public class DescriptorList extends UuidModel implements Publishable, SelfCleaning, AclAwareModel {
/** The Constant serialVersionUID. */
......@@ -98,7 +98,7 @@ public class DescriptorList extends UuidModel implements Publishable, SelfCleani
@JoinTable(name = "descriptorlist_descriptor", joinColumns = @JoinColumn(name = "descriptorListId", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "descriptorId", referencedColumnName = "id"))
@OrderColumn(name = "position")
@JsonView({ JsonViews.Public.class })
@JsonIgnoreProperties(value = { "descriptorLists", "datasets", "owner", "vocabulary", "terms" })
@JsonIgnoreProperties(value = { "descriptorLists", "datasets", "owner", "vocabulary" })
@Field(type = FieldType.Nested)
List<Descriptor> descriptors;
......@@ -107,7 +107,7 @@ public class DescriptorList extends UuidModel implements Publishable, SelfCleani
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "partnerId", updatable = false)
@JsonView({ JsonViews.Public.class })
@Field(type = FieldType.Nested)
@Field(type = FieldType.Object)
private Partner owner;
/** The publisher. */
......
......@@ -43,8 +43,8 @@ import java.util.List;
*/
@Entity
@Table(name = "vocabulary")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid")
@Document(indexName = "catalog")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "uuid", scope = ControlledVocabulary.class)
@Document(indexName = "controlledvocabulary")
public class ControlledVocabulary extends UuidModel implements Publishable, SelfCleaning, AclAwareModel {
/** The Constant serialVersionUID. */
......
......@@ -46,7 +46,7 @@ import java.text.MessageFormat;
*/
@Entity
@Table(name = "term")
@Document(indexName = "catalog")
@Document(indexName = "vocabularyterm")
public class VocabularyTerm extends BasicModel implements SelfCleaning {
/** The Constant serialVersionUID. */
......
/*
* Copyright 2018 Global Crop Diversity Trust
* Copyright 2019 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -15,8 +15,11 @@
*/
package org.genesys.catalog.persistence;
import java.util.List;
import org.genesys.catalog.model.ShortFilter;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.stereotype.Repository;
......@@ -35,10 +38,19 @@ public interface ShortFilterRepository extends JpaRepository<ShortFilter, Long>,
ShortFilter findByCode(String shortName);