ExecutionDimension.java

  1. /**
  2.  * Copyright 2014 Global Crop Diversity Trust
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */

  16. package org.genesys.server.model.kpi;

  17. import javax.persistence.Column;
  18. import javax.persistence.Entity;
  19. import javax.persistence.JoinColumn;
  20. import javax.persistence.ManyToOne;
  21. import javax.persistence.PrePersist;
  22. import javax.persistence.PreUpdate;
  23. import javax.persistence.Table;
  24. import javax.validation.constraints.NotNull;
  25. import javax.validation.constraints.Pattern;
  26. import javax.validation.constraints.Size;

  27. import lombok.Getter;
  28. import lombok.Setter;
  29. import org.genesys.blocks.model.BasicModel;
  30. import org.genesys.blocks.model.SelfCleaning;

  31. @Entity
  32. @Table(name = "kpiexecutiondimension")
  33. @Getter
  34. @Setter
  35. public class ExecutionDimension extends BasicModel implements SelfCleaning {

  36.     /**
  37.      *
  38.      */
  39.     private static final long serialVersionUID = 5401855589899745004L;

  40.     @NotNull
  41.     @ManyToOne(cascade = {}, optional = false)
  42.     @JoinColumn(name = "dimensionId")
  43.     private Dimension<?> dimension;

  44.     /** Linked entity from the Parameter to inner join directly (e.g. accession.institute) **/
  45.     @Size(max=100)
  46.     @Pattern(regexp = "[a-z][a-zA-Z0-9_\\.\\(\\)]*")
  47.     @Column(length = 100, nullable = true)
  48.     private String link;

  49.     /** Field in the Parameter (e.g. accession.instCode) or Linked entity ({@link #link} (e.g. accession.institute.code) **/
  50.     @Size(max=100)
  51.     @Pattern(regexp = "[_a-z][a-zA-Z0-9_\\.\\(\\)]*")
  52.     @Column(length = 100, nullable = false)
  53.     private String field;

  54.     /** Alias: how we store the key name in the observation **/
  55.     @Size(max=100)
  56.     @Pattern(regexp = "[_a-z][a-zA-Z0-9_\\.]*")
  57.     @Column(length = 100)
  58.     private String alias;
  59.    
  60.     @PrePersist
  61.     @PreUpdate
  62.     private void preupdate() {
  63.         trimStringsToNull();
  64.     }

  65.     @Override
  66.     public String toString() {
  67.         return "id=" + getId() + " link=" + link + " field=" + field + " alias=" + alias + " dim=" + dimension.getName();
  68.     }

  69.     public String toName() {
  70.         return alias == null ? ((link == null ? "" : link + ".") + field) : alias;
  71.     }

  72.     @Override
  73.     public boolean canEqual(Object other) {
  74.         return other instanceof ExecutionDimension;
  75.     }
  76. }