Commit 3fb2db33 authored by Matija Obreza's avatar Matija Obreza

Merge branch '103-crop-trait-api' into 'master'

Resolve "Crop trait API"

Closes #103

See merge request !111
parents c89b2e84 19b3171e
......@@ -20,8 +20,6 @@ import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import org.hibernate.validator.internal.engine.path.PathImpl;
/**
* @author Maxym Borodenko
*/
......@@ -72,8 +70,9 @@ public class DetailedConstraintViolationException extends ConstraintViolationExc
final StringBuilder message = new StringBuilder("Validation failed: ");
if (super.getConstraintViolations() != null) {
for (final ConstraintViolation<?> cv : super.getConstraintViolations()) {
final PathImpl path = (PathImpl) cv.getPropertyPath();
message.append(path.getLeafNode().getName());
String[] pathParts = cv.getPropertyPath().toString().split("\\.");
String prop = pathParts[pathParts.length - 1];
message.append(prop);
message.append(" -> ");
message.append(cv.getMessage());
message.append("; ");
......
......@@ -30,7 +30,7 @@ import com.fasterxml.jackson.annotation.JsonUnwrapped;
*
* @param <T> the generic type
*/
public class FilteredPage<T, F extends SuperModelFilter<?, T>> implements Iterable<T>, Serializable {
public class FilteredPage<T, F extends SuperModelFilter<?, ?>> implements Iterable<T>, Serializable {
private static final long serialVersionUID = 6965069448240229428L;
......
......@@ -65,7 +65,7 @@ public class CodeValue extends CooperatorOwnedModel {
@OneLine
private String value;
@OneToMany(fetch = FetchType.LAZY, cascade = {}, mappedBy = "codeValue")
@OneToMany(fetch = FetchType.LAZY, cascade = {}, mappedBy = "entity")
@JsonIgnore
private List<CodeValueLang> langs;
......
......@@ -28,32 +28,16 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name = "code_value_lang")
@JsonIdentityInfo(scope = CodeValueLang.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class CodeValueLang extends CooperatorOwnedModel {
@AssociationOverride(name = "entity", joinColumns = { @JoinColumn(name = "code_value_id", nullable = false) })
public class CodeValueLang extends CooperatorOwnedLang<CodeValue> {
private static final long serialVersionUID = -8056778240683451739L;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "code_value_id", nullable = false)
private CodeValue codeValue;
@Basic
@Column
@Lob
private String description;
@Id
@JsonProperty
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "code_value_lang_id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "sys_lang_id", nullable = false)
private SysLang sysLang;
@Basic
@Column(nullable = false, length = 500)
private String title;
public CodeValueLang() {
}
......@@ -61,22 +45,6 @@ public class CodeValueLang extends CooperatorOwnedModel {
this.id = id;
}
public CodeValue getCodeValue() {
return codeValue;
}
public void setCodeValue(final CodeValue codeValue) {
this.codeValue = codeValue;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
public Long getId() {
return id;
}
......@@ -85,19 +53,4 @@ public class CodeValueLang extends CooperatorOwnedModel {
this.id = id;
}
public SysLang getSysLang() {
return sysLang;
}
public void setSysLang(final SysLang sysLang) {
this.sysLang = sysLang;
}
public String getTitle() {
return title;
}
public void setTitle(final String title) {
this.title = title;
}
}
\ No newline at end of file
/*
* Copyright 2020 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.
* 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.
*/
package org.gringlobal.model;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* The Class CooperatorLang.
*
* @author Maxym Borodenko
*/
@MappedSuperclass
public abstract class CooperatorOwnedLang<T extends CooperatorOwnedModel> extends CooperatorOwnedModel {
private static final long serialVersionUID = -8074420732594755502L;
@NotNull
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn
protected T entity;
@Basic
@Column
@Lob
protected String description;
@NotNull
@Size(min = 1, max = 500)
@Basic
@Column(nullable = false, length = 500)
protected String title;
@NotNull
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "sys_lang_id", nullable = false)
protected SysLang sysLang;
public T getEntity() {
return entity;
}
public void setEntity(final T entity) {
this.entity = entity;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
public String getTitle() {
return title;
}
public void setTitle(final String title) {
this.title = title;
}
public SysLang getSysLang() {
return sysLang;
}
public void setSysLang(final SysLang sysLang) {
this.sysLang = sysLang;
}
}
......@@ -16,10 +16,17 @@
package org.gringlobal.model;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.genesys.blocks.model.Copyable;
import org.gringlobal.custom.validation.javax.CodeValueField;
/**
* Auto-generated by:
......@@ -28,22 +35,28 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name = "crop_trait")
@JsonIdentityInfo(scope = CropTrait.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class CropTrait extends CooperatorOwnedModel {
public class CropTrait extends CooperatorOwnedModel implements Copyable<CropTrait> {
private static final long serialVersionUID = -368513465504238634L;
@Basic
@CodeValueField("DESCRIPTOR_CATEGORY")
@Column(name = "category_code", nullable = false, length = 20)
private String categoryCode;
@NotNull
@Size(min = 1, max = 30)
@Basic
@Column(name = "coded_name", nullable = false, length = 30)
private String codedName;
@NotNull
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "crop_id", nullable = false)
private Crop crop;
@NotNull
@Basic
@CodeValueField("CROP_TRAIT_DATA_TYPE")
@Column(name = "data_type_code", nullable = false, length = 20)
private String dataTypeCode;
......@@ -53,14 +66,20 @@ public class CropTrait extends CooperatorOwnedModel {
@Column(name = "crop_trait_id")
private Long id;
@NotNull
@Size(min = 1, max = 1)
@Basic
@Column(name = "is_archived", nullable = false, length = 1)
private String isArchived;
@NotNull
@Size(min = 1, max = 1)
@Basic
@Column(name = "is_coded", nullable = false, length = 1)
private String isCoded;
@NotNull
@Size(min = 1, max = 1)
@Basic
@Column(name = "is_peer_reviewed", nullable = false, length = 1)
private String isPeerReviewed;
......@@ -74,6 +93,7 @@ public class CropTrait extends CooperatorOwnedModel {
@Lob
private String note;
@Size(max = 15)
@Basic
@Column(name = "numeric_format", length = 15)
private String numericFormat;
......@@ -86,18 +106,29 @@ public class CropTrait extends CooperatorOwnedModel {
@Column(name = "numeric_minimum")
private Double numericMinimum;
@Size(max = 300)
@Basic
@Column(name = "ontology_url", length = 300)
private String ontologyUrl;
@Size(max = 50)
@Basic
@Column(name = "original_value_format", length = 50)
private String originalValueFormat;
@Basic
@CodeValueField("CROP_TRAIT_DATA_TYPE")
@Column(name = "original_value_type_code", length = 20)
private String originalValueTypeCode;
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }, mappedBy = "entity")
@JsonIgnore
private List<CropTraitLang> cropTraitLangs;
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }, mappedBy = "cropTrait")
@JsonIgnore
private List<CropTraitCode> codes;
public CropTrait() {
}
......@@ -232,4 +263,29 @@ public class CropTrait extends CooperatorOwnedModel {
public void setOriginalValueTypeCode(final String originalValueTypeCode) {
this.originalValueTypeCode = originalValueTypeCode;
}
public List<CropTraitLang> getCropTraitLangs() {
return cropTraitLangs;
}
public void setCropTraitLangs(final List<CropTraitLang> cropTraitLangs) {
this.cropTraitLangs = cropTraitLangs;
}
public List<CropTraitCode> getCodes() {
return codes;
}
public void setCodes(final List<CropTraitCode> codes) {
this.codes = codes;
}
@Override
public CropTrait lazyLoad() {
super.lazyLoad();
if (this.crop != null) {
this.crop.getId();
}
return this;
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ import javax.persistence.*;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.genesys.blocks.model.Copyable;
import org.gringlobal.custom.validation.javax.CodeValueField;
import org.gringlobal.model.community.CommunityCodeValues;
......@@ -32,7 +33,7 @@ import org.gringlobal.model.community.CommunityCodeValues;
@Entity
@Table(name = "crop_trait_attach")
@JsonIdentityInfo(scope = CropTraitAttach.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class CropTraitAttach extends CooperatorAttachment {
public class CropTraitAttach extends CooperatorAttachment implements Copyable<CropTraitAttach> {
private static final long serialVersionUID = 8275278678243646534L;
@Id
......
......@@ -15,9 +15,14 @@
*/
package org.gringlobal.model;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
......@@ -31,10 +36,13 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
public class CropTraitCode extends CooperatorOwnedModel {
private static final long serialVersionUID = 3419091039669933935L;
@NotNull
@Size(min = 1, max = 30)
@Basic
@Column(nullable = false, length = 30)
private String code;
@NotNull
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "crop_trait_id", nullable = false)
private CropTrait cropTrait;
......@@ -45,6 +53,10 @@ public class CropTraitCode extends CooperatorOwnedModel {
@Column(name = "crop_trait_code_id")
private Long id;
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE }, mappedBy = "entity")
@JsonIgnore
private List<CropTraitCodeLang> codeLangs;
public CropTraitCode() {
}
......@@ -75,4 +87,12 @@ public class CropTraitCode extends CooperatorOwnedModel {
public void setId(final Long id) {
this.id = id;
}
public List<CropTraitCodeLang> getCodeLangs() {
return codeLangs;
}
public void setCodeLangs(final List<CropTraitCodeLang> codeLangs) {
this.codeLangs = codeLangs;
}
}
\ No newline at end of file
......@@ -22,6 +22,7 @@ import javax.persistence.*;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.genesys.blocks.model.Copyable;
import org.gringlobal.custom.validation.javax.CodeValueField;
import org.gringlobal.model.community.CommunityCodeValues;
......@@ -32,7 +33,7 @@ import org.gringlobal.model.community.CommunityCodeValues;
@Entity
@Table(name = "crop_trait_code_attach")
@JsonIdentityInfo(scope = CropTraitCodeAttach.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class CropTraitCodeAttach extends CooperatorAttachment {
public class CropTraitCodeAttach extends CooperatorAttachment implements Copyable<CropTraitCodeAttach> {
private static final long serialVersionUID = 8125365963724877174L;
@Id
......
......@@ -28,32 +28,16 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name = "crop_trait_code_lang")
@JsonIdentityInfo(scope = CropTraitCodeLang.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class CropTraitCodeLang extends CooperatorOwnedModel {
@AssociationOverride(name = "entity", joinColumns = { @JoinColumn(name = "crop_trait_code_id", nullable = false) })
public class CropTraitCodeLang extends CooperatorOwnedLang<CropTraitCode> {
private static final long serialVersionUID = 8734983132443264074L;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "crop_trait_code_id", nullable = false)
private CropTraitCode cropTraitCode;
@Basic
@Column
@Lob
private String description;
@Id
@JsonProperty
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "crop_trait_code_lang_id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "sys_lang_id", nullable = false)
private SysLang sysLang;
@Basic
@Column(length = 500)
private String title;
public CropTraitCodeLang() {
}
......@@ -61,22 +45,6 @@ public class CropTraitCodeLang extends CooperatorOwnedModel {
this.id = id;
}
public CropTraitCode getCropTraitCode() {
return cropTraitCode;
}
public void setCropTraitCode(final CropTraitCode cropTraitCode) {
this.cropTraitCode = cropTraitCode;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
public Long getId() {
return id;
}
......@@ -85,19 +53,4 @@ public class CropTraitCodeLang extends CooperatorOwnedModel {
this.id = id;
}
public SysLang getSysLang() {
return sysLang;
}
public void setSysLang(final SysLang sysLang) {
this.sysLang = sysLang;
}
public String getTitle() {
return title;
}
public void setTitle(final String title) {
this.title = title;
}
}
\ No newline at end of file
......@@ -28,32 +28,16 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name = "crop_trait_lang")
@JsonIdentityInfo(scope = CropTraitLang.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class CropTraitLang extends CooperatorOwnedModel {
@AssociationOverride(name = "entity", joinColumns = { @JoinColumn(name = "crop_trait_id", nullable = false) })
public class CropTraitLang extends CooperatorOwnedLang<CropTrait> {
private static final long serialVersionUID = 1415634897733917322L;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "crop_trait_id", nullable = false)
private CropTrait cropTrait;
@Basic
@Column
@Lob
private String description;
@Id
@JsonProperty
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "crop_trait_lang_id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "sys_lang_id", nullable = false)
private SysLang sysLang;
@Basic
@Column(length = 500)
private String title;
public CropTraitLang() {
}
......@@ -61,22 +45,6 @@ public class CropTraitLang extends CooperatorOwnedModel {
this.id = id;
}
public CropTrait getCropTrait() {
return cropTrait;
}
public void setCropTrait(final CropTrait cropTrait) {
this.cropTrait = cropTrait;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
public Long getId() {
return id;
}
......@@ -85,19 +53,4 @@ public class CropTraitLang extends CooperatorOwnedModel {
this.id = id;
}
public SysLang getSysLang() {
return sysLang;
}
public void setSysLang(final SysLang sysLang) {
this.sysLang = sysLang;
}
public String getTitle() {
return title;
}
public void setTitle(final String title) {
this.title = title;
}
}
\ No newline at end of file
......@@ -28,32 +28,16 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators;
@Entity
@Table(name = "source_descriptor_code_lang")
@JsonIdentityInfo(scope = SourceDescriptorCodeLang.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
public class SourceDescriptorCodeLang extends CooperatorOwnedModel {
@AssociationOverride(name = "entity", joinColumns = { @JoinColumn(name = "source_descriptor_code_id", nullable = false) })
public class SourceDescriptorCodeLang extends CooperatorOwnedLang<SourceDescriptorCode> {
private static final long serialVersionUID = -6651240212098239872L;
@Basic
@Column
@Lob
private String description;
@Id
@JsonProperty
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "source_descriptor_code_lang_id")
private Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "source_descriptor_code_id", nullable = false)
private SourceDescriptorCode sourceDescriptorCode;
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "sys_lang_id", nullable = false)
private SysLang sysLang;