Commit 177d6dc1 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '327-subsets-model' into 'master'

Resolve "Subsets model"

Closes #327

See merge request genesys-pgr/genesys-server!224
parents a556927c 14706a15
...@@ -856,7 +856,7 @@ ...@@ -856,7 +856,7 @@
<plugin> <plugin>
<groupId>org.liquibase</groupId> <groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId> <artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version> <version>${liquibase.version}.2</version>
<configuration> <configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile> <propertyFile>src/main/resources/liquibase.properties</propertyFile>
<verbose>true</verbose> <verbose>true</verbose>
......
...@@ -29,6 +29,7 @@ import org.genesys.catalog.model.traits.Descriptor; ...@@ -29,6 +29,7 @@ import org.genesys.catalog.model.traits.Descriptor;
import org.genesys.catalog.service.PublishValidationInterface; import org.genesys.catalog.service.PublishValidationInterface;
import org.genesys.filerepository.model.RepositoryFile; import org.genesys.filerepository.model.RepositoryFile;
import org.genesys2.server.model.PublishState; import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.impl.Crop;
import org.genesys2.util.MCPDUtil; import org.genesys2.util.MCPDUtil;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.Field;
...@@ -132,7 +133,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub ...@@ -132,7 +133,7 @@ public class Dataset extends UuidModel implements Publishable, SelfCleaning, Pub
@CollectionTable(name = "dataset_crops", joinColumns = @JoinColumn(name = "datasetId"), @CollectionTable(name = "dataset_crops", joinColumns = @JoinColumn(name = "datasetId"),
// index // index
indexes = { @Index(columnList = "datasetId, crop") }) indexes = { @Index(columnList = "datasetId, crop") })
@Column(name = "crop", nullable = false, length = 20) @Column(name = "crop", nullable = false, length = Crop.CROP_SHORTNAME_LENGTH)
@JsonView({ JsonViews.Minimal.class }) @JsonView({ JsonViews.Minimal.class })
private Set<String> crops; private Set<String> crops;
......
...@@ -24,6 +24,7 @@ import org.genesys.catalog.model.dataset.Dataset; ...@@ -24,6 +24,7 @@ import org.genesys.catalog.model.dataset.Dataset;
import org.genesys.catalog.model.vocab.ControlledVocabulary; import org.genesys.catalog.model.vocab.ControlledVocabulary;
import org.genesys.catalog.model.vocab.VocabularyTerm; import org.genesys.catalog.model.vocab.VocabularyTerm;
import org.genesys2.server.model.PublishState; import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.impl.Crop;
import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.Field;
...@@ -200,7 +201,7 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable, ...@@ -200,7 +201,7 @@ public class Descriptor extends UuidModel implements SelfCleaning, Publishable,
private List<Dataset> datasets; private List<Dataset> datasets;
/** The crop. */ /** The crop. */
@Column(name = "crop", length = 100, nullable = true) @Column(name = "crop", length = Crop.CROP_SHORTNAME_LENGTH, nullable = true)
private String crop; private String crop;
/** Descriptor classification. */ /** Descriptor classification. */
......
...@@ -27,6 +27,7 @@ import org.genesys.blocks.model.UuidModel; ...@@ -27,6 +27,7 @@ import org.genesys.blocks.model.UuidModel;
import org.genesys.blocks.security.model.AclAwareModel; import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.catalog.model.Partner; import org.genesys.catalog.model.Partner;
import org.genesys2.server.model.PublishState; import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.impl.Crop;
import org.springframework.data.elasticsearch.annotations.Document; import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field; import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType; import org.springframework.data.elasticsearch.annotations.FieldType;
...@@ -108,7 +109,7 @@ public class DescriptorList extends UuidModel implements Publishable, SelfCleani ...@@ -108,7 +109,7 @@ public class DescriptorList extends UuidModel implements Publishable, SelfCleani
private String publisher; private String publisher;
/** The crop. */ /** The crop. */
@Column(name = "crop", length = 100, nullable = true) @Column(name = "crop", length = Crop.CROP_SHORTNAME_LENGTH, nullable = true)
private String crop; private String crop;
/** Extra information associated with the descriptor list */ /** Extra information associated with the descriptor list */
......
...@@ -61,11 +61,13 @@ public class Crop extends GlobalVersionedAuditedModel implements AclAwareModel { ...@@ -61,11 +61,13 @@ public class Crop extends GlobalVersionedAuditedModel implements AclAwareModel {
public static final Logger LOG = LoggerFactory.getLogger(Crop.class); public static final Logger LOG = LoggerFactory.getLogger(Crop.class);
public static final int CROP_SHORTNAME_LENGTH = 50;
/** /**
* Crop short name used as short name in URLs * Crop short name used as short name in URLs
*/ */
@Column(nullable = false, length = 50, unique = true) @Column(nullable = false, length = CROP_SHORTNAME_LENGTH, unique = true)
private String shortName; private String shortName;
@Column(name = "otherName", nullable = false, unique = true, length = 255) @Column(name = "otherName", nullable = false, unique = true, length = 255)
......
...@@ -17,23 +17,40 @@ ...@@ -17,23 +17,40 @@
package org.genesys2.server.model.impl; package org.genesys2.server.model.impl;
import java.util.List; import java.util.List;
import java.util.Set;
import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import org.genesys.blocks.model.JsonViews; import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.model.SelfCleaning; import org.genesys.blocks.model.SelfCleaning;
import org.genesys.blocks.model.UuidModel; import org.genesys.blocks.model.UuidModel;
import org.genesys.blocks.security.model.AclAwareModel; import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.catalog.annotations.PublishValidation;
import org.genesys2.server.model.PublishState; import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.AccessionId; import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.util.MCPDUtil;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonIdentityReference; import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
// TODO: Auto-generated Javadoc // TODO: Auto-generated Javadoc
/** /**
...@@ -99,6 +116,22 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning { ...@@ -99,6 +116,22 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
private List<SubsetCreator> creators; private List<SubsetCreator> creators;
/** The crops. */
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "subset_crops", joinColumns = @JoinColumn(name = "subsetId"),
indexes = { @Index(columnList = "subsetId, crop") })
@Column(name = "crop", nullable = false, length = Crop.CROP_SHORTNAME_LENGTH)
@JsonView({ JsonViews.Minimal.class })
private Set<String> crops;
/** The date when subset was authored. */
@Column(length = 8)
private String date;
/** The source. */
@Column(length = 200)
private String source;
/** /**
* Generate UUID if missing. * Generate UUID if missing.
*/ */
...@@ -114,6 +147,9 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning { ...@@ -114,6 +147,9 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
} }
} }
/* (non-Javadoc)
* @see org.genesys.blocks.security.model.AclAwareModel#aclParentObject()
*/
@Override @Override
public AclAwareModel aclParentObject() { public AclAwareModel aclParentObject() {
return institute; return institute;
...@@ -300,7 +336,7 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning { ...@@ -300,7 +336,7 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
} }
/** /**
* Gets subset creators * Gets subset creators.
* *
* @return subset creators * @return subset creators
*/ */
...@@ -309,11 +345,67 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning { ...@@ -309,11 +345,67 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
} }
/** /**
* Sets subset creators * Sets subset creators.
* *
* @param creators new creators * @param creators new creators
*/ */
public void setCreators(List<SubsetCreator> creators) { public void setCreators(List<SubsetCreator> creators) {
this.creators = creators; this.creators = creators;
} }
/**
* Gets the crops.
*
* @return the crops
*/
public Set<String> getCrops() {
return crops;
}
/**
* Sets the crops.
*
* @param crops the new crops
*/
public void setCrops(Set<String> crops) {
this.crops = crops;
}
/**
* Gets the date when subset was authored
*
* @return the date
*/
public String getDate() {
return date;
}
/**
* Sets the date when subset was authored
*
* @param date the new date
*/
public void setDate(String date) {
if (MCPDUtil.isMcpdDate(date)) {
this.date = date;
}
}
/**
* Gets the source.
*
* @return the source
*/
public String getSource() {
return source;
}
/**
* Sets the source.
*
* @param source the new source
*/
public void setSource(String source) {
this.source = source;
}
} }
...@@ -56,6 +56,8 @@ public class SubsetFilter extends UuidModelFilter<SubsetFilter, Subset> { ...@@ -56,6 +56,8 @@ public class SubsetFilter extends UuidModelFilter<SubsetFilter, Subset> {
/** The publish state. */ /** The publish state. */
public Set<PublishState> state; public Set<PublishState> state;
public Set<String> crop;
/** /**
* Builds the query. * Builds the query.
* *
...@@ -86,6 +88,9 @@ public class SubsetFilter extends UuidModelFilter<SubsetFilter, Subset> { ...@@ -86,6 +88,9 @@ public class SubsetFilter extends UuidModelFilter<SubsetFilter, Subset> {
if (state != null && !state.isEmpty()) { if (state != null && !state.isEmpty()) {
and.and(subset.state.in(state)); and.and(subset.state.in(state));
} }
if (crop != null && !crop.isEmpty()) {
and.and(subset.crops.any().in(crop));
}
return and; return and;
} }
} }
...@@ -93,9 +93,7 @@ public class SubsetServiceImpl implements SubsetService { ...@@ -93,9 +93,7 @@ public class SubsetServiceImpl implements SubsetService {
@Override @Override
public Page<Subset> list(final SubsetFilter filter, final Pageable page) { public Page<Subset> list(final SubsetFilter filter, final Pageable page) {
final BooleanBuilder published = new BooleanBuilder(); final BooleanBuilder published = new BooleanBuilder();
if (!securityUtils.hasRole(UserRole.ADMINISTRATOR)) { published.and(QSubset.subset.state.eq(PublishState.PUBLISHED));
published.and(QSubset.subset.state.eq(PublishState.PUBLISHED));
}
published.and(filter.buildQuery()); published.and(filter.buildQuery());
return subsetRepository.findAll(published, page); return subsetRepository.findAll(published, page);
} }
...@@ -167,6 +165,16 @@ public class SubsetServiceImpl implements SubsetService { ...@@ -167,6 +165,16 @@ public class SubsetServiceImpl implements SubsetService {
target.setDateCreated(source.getDateCreated()); target.setDateCreated(source.getDateCreated());
target.setRights(source.getRights()); target.setRights(source.getRights());
target.setUuid(source.getUuid()); target.setUuid(source.getUuid());
target.setDate(source.getDate());
target.setSource(source.getSource());
if (source.getCrops() != null) {
if (target.getCrops() == null) {
target.setCrops(new HashSet<>());
}
target.getCrops().clear();
target.getCrops().addAll(source.getCrops());
}
} }
/** /**
...@@ -180,6 +188,8 @@ public class SubsetServiceImpl implements SubsetService { ...@@ -180,6 +188,8 @@ public class SubsetServiceImpl implements SubsetService {
throw new NotFoundElement("No such subset"); throw new NotFoundElement("No such subset");
subset.getInstitute().getId(); subset.getInstitute().getId();
if (subset.getCrops() != null)
subset.getCrops().size();
if (subset.getAccessionIds() != null) if (subset.getAccessionIds() != null)
subset.getAccessionIds().size(); subset.getAccessionIds().size();
if (subset.getCreators() != null) if (subset.getCreators() != null)
......
...@@ -3875,3 +3875,63 @@ databaseChangeLog: ...@@ -3875,3 +3875,63 @@ databaseChangeLog:
onUpdate: NO ACTION onUpdate: NO ACTION
referencedColumnNames: id referencedColumnNames: id
referencedTableName: subset referencedTableName: subset
- changeSet:
id: 1536945927974-1
author: mobreza (generated)
comment: Fix crop shortName (code) to 50
changes:
- modifyDataType:
columnName: crop
newDataType: varchar(50)
tableName: dataset_crops
- modifyDataType:
columnName: crop
newDataType: varchar(50)
tableName: descriptor
- modifyDataType:
columnName: crop
newDataType: varchar(50)
tableName: descriptorlist
- changeSet:
id: 1536945927974-4
author: vpavlov
comment: Add crops to Subset
changes:
- addColumn:
columns:
- column:
name: date
type: VARCHAR(8)
tableName: subset
- addColumn:
columns:
- column:
name: source
type: VARCHAR(200)
tableName: subset
- createTable:
columns:
- column:
constraints:
primaryKey: true
name: subsetId
type: BIGINT
- column:
constraints:
primaryKey: true
name: crop
type: VARCHAR(50)
tableName: subset_crops
- addForeignKeyConstraint:
baseColumnNames: subsetId
baseTableName: subset_crops
constraintName: FK_hny3je51ro3jv72dubq9lt4o2
deferrable: false
initiallyDeferred: false
onDelete: NO ACTION
onUpdate: NO ACTION
referencedColumnNames: id
referencedTableName: subset
validate: true
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