Commit daeae654 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

Subsets model

parent a556927c
......@@ -17,23 +17,40 @@
package org.genesys2.server.model.impl;
import java.util.List;
import javax.persistence.*;
import java.util.Set;
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.SelfCleaning;
import org.genesys.blocks.model.UuidModel;
import org.genesys.blocks.security.model.AclAwareModel;
import org.genesys.catalog.annotations.PublishValidation;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.AccessionId;
import org.genesys2.util.MCPDUtil;
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.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonView;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
// TODO: Auto-generated Javadoc
/**
......@@ -99,6 +116,22 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
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 = 20)
@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.
*/
......@@ -114,6 +147,9 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
}
}
/* (non-Javadoc)
* @see org.genesys.blocks.security.model.AclAwareModel#aclParentObject()
*/
@Override
public AclAwareModel aclParentObject() {
return institute;
......@@ -300,7 +336,7 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
}
/**
* Gets subset creators
* Gets subset creators.
*
* @return subset creators
*/
......@@ -309,11 +345,67 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
}
/**
* Sets subset creators
* Sets subset creators.
*
* @param creators new creators
*/
public void setCreators(List<SubsetCreator> 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> {
/** The publish state. */
public Set<PublishState> state;
public Set<String> crop;
/**
* Builds the query.
*
......@@ -86,6 +88,9 @@ public class SubsetFilter extends UuidModelFilter<SubsetFilter, Subset> {
if (state != null && !state.isEmpty()) {
and.and(subset.state.in(state));
}
if (crop != null && !crop.isEmpty()) {
and.and(subset.crops.any().in(crop));
}
return and;
}
}
......@@ -93,9 +93,7 @@ public class SubsetServiceImpl implements SubsetService {
@Override
public Page<Subset> list(final SubsetFilter filter, final Pageable page) {
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());
return subsetRepository.findAll(published, page);
}
......@@ -167,6 +165,16 @@ public class SubsetServiceImpl implements SubsetService {
target.setDateCreated(source.getDateCreated());
target.setRights(source.getRights());
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 {
throw new NotFoundElement("No such subset");
subset.getInstitute().getId();
if (subset.getCrops() != null)
subset.getCrops().size();
if (subset.getAccessionIds() != null)
subset.getAccessionIds().size();
if (subset.getCreators() != null)
......
......@@ -3875,3 +3875,49 @@ databaseChangeLog:
onUpdate: NO ACTION
referencedColumnNames: id
referencedTableName: subset
- changeSet:
id: 1536939885074-68
author: vpavlov
comment: Add crops to Subset
changes:
- createTable:
columns:
- column:
constraints:
nullable: false
name: subsetId
type: BIGINT
- column:
constraints:
nullable: false
name: crop
type: VARCHAR(20)
tableName: subset_crops
- addPrimaryKey:
comment: subset_crops PK
columnNames: subsetId, crop
constraintName: PRIMARY
tableName: subset_crops
- addForeignKeyConstraint:
comment: subset_crops FK
baseColumnNames: subsetId
baseTableName: subset_crops
constraintName: FK_04466eb03847ac24cefb2f7ff
deferrable: false
initiallyDeferred: false
onDelete: NO ACTION
onUpdate: NO ACTION
referencedColumnNames: id
referencedTableName: subset
- addColumn:
comment: Add date and source to subset
columns:
- column:
name: date
type: varchar(8)
- column:
name: source
type: varchar(200)
tableName: subset
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