Commit c4557538 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Added @Validated to Subsets

parent 0337d424
......@@ -22,6 +22,8 @@ import javax.persistence.Embeddable;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.genesys.blocks.model.JsonViews;
import org.genesys2.server.model.impl.AccessionIdentifier3;
......@@ -43,22 +45,30 @@ public class AccessionRef implements AccessionIdentifier3, Serializable {
private static final long serialVersionUID = 1L;
/** The DOI. */
@Size(max = 100)
@Column(length = 100)
private String doi;
/** The inst code. */
@NotNull
@Size(max = 10)
@Column(length = 10, nullable = false)
private String instCode;
/** The acce numb. */
@NotNull
@Size(max = 50)
@Column(nullable = false, length = 50)
private String acceNumb;
/** The genus. */
@NotNull
@Size(max = 100)
@Column(nullable = false, length = 100)
private String genus;
/** The species. */
@Size(max = 100)
@Column(nullable = true, length = 100)
private String species;
......
......@@ -35,6 +35,9 @@ import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.genesys.blocks.model.JsonViews;
import org.genesys.blocks.model.SelfCleaning;
......@@ -61,6 +64,8 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
private static final long serialVersionUID = 7021405309572916429L;
/** The title. */
@NotNull
@Size(max = 250)
@Column(length = 250, nullable = false)
protected String title;
......@@ -71,19 +76,24 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
protected String description;
/** The publisher. */
@Size(max = 250)
@Column(length = 250)
protected String publisher;
/** The date created. */
@Size(max = 100)
@Column(length = 100)
protected String dateCreated;
/** The wiews code. */
@NotNull
@Size(max = 8)
@Column(name = "wiews_code", length = 8, nullable = false)
private String wiewsCode;
/** The institute. */
@NotNull
@ManyToOne(cascade = {}, optional = false)
@JoinColumn(name = "institute_id", updatable = false)
@JsonView({ JsonViews.Public.class })
......@@ -96,9 +106,11 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
indexes = { @Index(columnList = "subsetId, instCode, acceNumb"), @Index(columnList = "subsetId, genus") })
@Field(type = FieldType.Object)
@JsonIgnore
@Valid
private Set<AccessionRef> accessionRefs;
/** The accession count. */
@NotNull
@Column(name = "accession_count", nullable = false)
private int accessionCount = 0;
......@@ -120,10 +132,12 @@ public class Subset extends UuidModel implements AclAwareModel, SelfCleaning {
private Set<String> crops;
/** The date when subset was authored. */
@Size(max = 8)
@Column(length = 8)
private String date;
/** The source. */
@Size(max = 200)
@Column(length = 200)
private String source;
......
......@@ -65,9 +65,11 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import javax.validation.Valid;
/**
* The Class SubsetServiceImpl.
......@@ -150,7 +152,8 @@ public class SubsetServiceImpl implements SubsetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#institute, 'WRITE')")
public Subset create(final FaoInstitute institute, final Subset source) {
@Validated
public Subset create(final FaoInstitute institute, @Valid final Subset source) {
LOG.info("Create Subset.");
if (! StringUtils.equals(institute.getCode(), source.getWiewsCode())) {
throw new InvalidApiUsageException("Institute code of the subset does not match the code of Institute");
......@@ -251,7 +254,8 @@ public class SubsetServiceImpl implements SubsetService {
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#source, 'WRITE')")
public Subset update(final Subset source) {
@Validated
public Subset update(@Valid final Subset source) {
LOG.info("Update Subset.");
final Subset subset = loadSubset(source);
copyValues(subset, source);
......
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