BrightSide Workbench Full Report + Source Code
DescriptorDefinition.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2016 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.dossier.entity;
20 
21 import java.util.Objects;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.GeneratedValue;
25 import javax.persistence.GenerationType;
26 import javax.persistence.Id;
27 import javax.persistence.ManyToOne;
28 import org.turro.string.Strings;
29 import org.turro.jpa.entity.IDaoEntity;
30 
35 @Entity
36 public class DescriptorDefinition implements java.io.Serializable, IDaoEntity {
37 
38  @Id
39  @GeneratedValue(strategy=GenerationType.IDENTITY)
40  @Column(name="IDENTIFIER")
41  private Long id;
42 
43  private String grouping, title;
44 
45  private int orderNumber, minChars;
46 
47  private boolean required;
48 
49  private DescriptorType type;
50 
51  @ManyToOne
52  private Category category;
53 
54  public Long getId() {
55  return id;
56  }
57 
58  public void setId(Long id) {
59  this.id = id;
60  }
61 
62  public String getGrouping() {
63  return grouping;
64  }
65 
66  public void setGrouping(String grouping) {
67  this.grouping = grouping;
68  }
69 
70  public String getTitle() {
71  return title;
72  }
73 
74  public void setTitle(String title) {
75  this.title = title;
76  }
77 
78  public int getOrderNumber() {
79  return orderNumber;
80  }
81 
82  public void setOrderNumber(int orderNumber) {
83  this.orderNumber = orderNumber;
84  }
85 
86  public int getMinChars() {
87  return minChars;
88  }
89 
90  public void setMinChars(int minChars) {
91  this.minChars = minChars;
92  }
93 
94  public boolean isRequired() {
95  return required;
96  }
97 
98  public void setRequired(boolean required) {
99  this.required = required;
100  }
101 
103  return category;
104  }
105 
106  public void setCategory(Category category) {
107  this.category = category;
108  }
109 
111  return type;
112  }
113 
114  public void setType(DescriptorType type) {
115  this.type = type;
116  }
117 
118  /* Value helpers */
119 
120  transient DescriptorValue _value;
121  transient Dossier _dossier;
122 
123  public void assignDossier(Dossier dossier) {
124  _dossier = dossier;
125  }
126 
128  return _dossier;
129  }
130 
132  if(_value == null) {
133  for(DescriptorValue v : _dossier.getDescriptors()) {
134  if(Objects.equals(v.getDescriptorDefinition().getId(), id)) {
135  _value = v;
136  break;
137  }
138  }
139  }
140  return _value;
141  }
142 
143  public void setValue(DescriptorValue descriptorValue) {
144  _value = descriptorValue;
145  _value.setDescriptorDefinition(this);
146  if(_dossier != null && descriptorValue.getDossier() == null) {
147  descriptorValue.setDossier(_dossier);
148  _dossier.getDescriptors().add(_value);
149  }
150  }
151 
152  /* IDaoEntity */
153 
154  @Override
155  public Object entityId() {
156  return id;
157  }
158 
159  @Override
160  public boolean isEmpty() {
161  return Strings.isBlank(title) || type == null;
162  }
163 
164 }
void setValue(DescriptorValue descriptorValue)
void setDescriptorDefinition(DescriptorDefinition descriptorDefinition)
Set< DescriptorValue > getDescriptors()
Definition: Dossier.java:231