KPIParameter.java
/*
* 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.kpi;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.genesys.blocks.model.Copyable;
import org.genesys.blocks.model.SelfCleaning;
import org.gringlobal.model.CooperatorOwnedModel;
import org.hibernate.annotations.Type;
/**
* {@link KPIParameter} defines a the basic JPA query for KPI metrics.
*
* <p><b>Example:</b> KPIParameter with name = "accessionCount" would select records from
* "Accession" {@link #entity} without any condition.
* </p>
*
* <p><b>Example:</b> KPIParameter with {@link #name} = "historicAccessions" would select
* records from "Accession" {@link #entity} with {@link #condition} =
* "historic = true".
* </p>
*
* @author mobreza
*
*/
@Entity
@Table(name = "kpi_parameter", uniqueConstraints = { @UniqueConstraint(name = "UQ_kpiparameter_name", columnNames = { "name" }) })
@Getter
@Setter
@NoArgsConstructor
public class KPIParameter extends CooperatorOwnedModel implements SelfCleaning, Copyable<KPIParameter> {
private static final long serialVersionUID = -4806317990618480686L;
@Id
@JsonProperty
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@NotNull
@Size(max = 100)
@Column(length = 100, nullable = false)
private String name;
@NotNull
@Size(max = 100)
@Column(length = 100, nullable = false)
private String title;
@NotNull
@Pattern(regexp = "[A-Z][a-zA-Z0-9_]*")
@Size(min = 1, max = 100)
@Column(length = 100, nullable = false)
private String entity;
@Size(max = 300)
@Column(name = "`condition`", length = 300)
private String condition;
@Lob
@Type(type = "org.hibernate.type.TextType")
private String description;
@PrePersist
@PreUpdate
private void preupdate() {
trimStringsToNull();
}
public KPIParameter(Long id) {
this.id = id;
}
@Override
public boolean canEqual(Object other) {
return other instanceof KPIParameter;
}
@Override
public KPIParameter apply(KPIParameter source) {
this.setName(source.getName());
this.setTitle(source.getTitle());
this.setEntity(source.getEntity());
this.setCondition(source.getCondition());
this.setDescription(source.getDescription());
return this;
}
}