KPIParameter.java
/**
* Copyright 2014 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.genesys.server.model.kpi;
import javax.persistence.Column;
import javax.persistence.Entity;
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 lombok.Getter;
import lombok.Setter;
import org.genesys.blocks.model.AuditedVersionedModel;
import org.genesys.blocks.model.Copyable;
import org.genesys.blocks.model.SelfCleaning;
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 = "kpiparameter", uniqueConstraints = { @UniqueConstraint(name = "UQ_kpiparameter_name", columnNames = { "name" }) })
@Getter
@Setter
public class KPIParameter extends AuditedVersionedModel implements SelfCleaning, Copyable<KPIParameter> {
/**
*
*/
private static final long serialVersionUID = 5773482399613068571L;
@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();
}
@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;
}
}