BrightSide Workbench Full Report + Source Code
AxDescriptor.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2023 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.alliance.db.entities;
20 
21 import java.io.Serializable;
22 import java.util.Map;
23 import java.util.Objects;
24 import java.util.Set;
25 import java.util.TreeSet;
26 import javax.json.JsonValue;
27 import javax.persistence.Column;
28 import javax.persistence.Entity;
29 import javax.persistence.Id;
30 import javax.persistence.Lob;
31 import org.turro.dossier.entity.DescriptorType;
32 import org.turro.dossier.entity.Dossier;
33 import org.turro.jpa.entity.IDaoEntity;
34 import org.turro.json.IJSONizable;
35 import org.turro.string.Strings;
36 import org.turro.util.Comparison;
37 
42 @Entity
43 public class AxDescriptor implements Serializable, Comparable<AxDescriptor>, IDaoEntity, IJSONizable {
44 
45  @Id private Long memberId;
46  @Id private String entityId;
47  @Id private String grouping, title;
48  @Id private int orderNumber;
49 
50  @Lob
51  @Column(length=4096)
52  private String text;
53 
54  public Long getMemberId() {
55  return memberId;
56  }
57 
58  public void setMemberId(Long memberId) {
59  this.memberId = memberId;
60  }
61 
62  public String getEntityId() {
63  return entityId;
64  }
65 
66  public void setEntityId(String entityId) {
67  this.entityId = entityId;
68  }
69 
70  public String getGrouping() {
71  return grouping;
72  }
73 
74  public void setGrouping(String grouping) {
75  this.grouping = grouping;
76  }
77 
78  public String getTitle() {
79  return title;
80  }
81 
82  public void setTitle(String title) {
83  this.title = title;
84  }
85 
86  public int getOrderNumber() {
87  return orderNumber;
88  }
89 
90  public void setOrderNumber(int orderNumber) {
91  this.orderNumber = orderNumber;
92  }
93 
94  public String getText() {
95  return text;
96  }
97 
98  public void setText(String text) {
99  this.text = text;
100  }
101 
102  /* Factory */
103 
104  public static Set<AxDescriptor> from(AxProject project, Dossier dossier) {
105  TreeSet<AxDescriptor> descriptors = new TreeSet<>();
106  dossier.getDescriptors().stream()
107  .filter(d -> DescriptorType.OPENING_DESCRIPTOR.equals(d.getDescriptorDefinition().getType()))
108  .filter(d -> d.getDescriptorDefinition().isRequired())
109  .forEach(descriptor -> {
110  AxDescriptor axDescriptor = new AxDescriptor();
111  axDescriptor.setEntityId(project.getProjectId().getEntityId());
112  axDescriptor.setMemberId(project.getProjectId().getMemberId());
113  axDescriptor.setGrouping(descriptor.getDescriptorDefinition().getGrouping());
114  axDescriptor.setOrderNumber(descriptor.getDescriptorDefinition().getOrderNumber());
115  axDescriptor.setTitle(descriptor.getDescriptorDefinition().getTitle());
116  axDescriptor.setText(descriptor.getText());
117  if(!axDescriptor.isEmpty()) descriptors.add(axDescriptor);
118  });
119  return descriptors;
120  }
121 
122  /* IDaoEntity */
123 
124  @Override
125  public Object entityId() {
126  return memberId + entityId + grouping + title;
127  }
128 
129  @Override
130  public boolean isEmpty() {
131  return memberId == null || Strings.anyBlank(entityId, grouping, title, text);
132  }
133 
134  /* JSONizable */
135 
136  @Override
137  public String toJson() {
138  return toJsonExcluding(this, AxProject.class);
139  }
140 
141  @Override
142  public String toJson(Map<String, Object> properties) {
143  return toJsonExcluding(this, properties, AxProject.class);
144  }
145 
146  public static AxDescriptor fromJson(JsonValue value) {
147  return IJSONizable.fromJson(value.toString(), AxDescriptor.class);
148  }
149 
150  @Override
151  public int compareTo(AxDescriptor o) {
152  return Comparison.ascendant()
153  .compare(memberId, o.memberId)
154  .compare(entityId, o.entityId)
155  .compare(grouping, o.grouping)
156  .compare(orderNumber, o.orderNumber)
157  .compare(title, o.title)
158  .get();
159  }
160 
161  @Override
162  public int hashCode() {
163  int hash = 7;
164  hash = 59 * hash + Objects.hashCode(this.memberId);
165  hash = 59 * hash + Objects.hashCode(this.entityId);
166  hash = 59 * hash + Objects.hashCode(this.grouping);
167  hash = 59 * hash + Objects.hashCode(this.title);
168  hash = 59 * hash + this.orderNumber;
169  return hash;
170  }
171 
172  @Override
173  public boolean equals(Object obj) {
174  if (this == obj) {
175  return true;
176  }
177  if (obj == null) {
178  return false;
179  }
180  if (getClass() != obj.getClass()) {
181  return false;
182  }
183  final AxDescriptor other = (AxDescriptor) obj;
184  if (this.orderNumber != other.orderNumber) {
185  return false;
186  }
187  if (!Objects.equals(this.entityId, other.entityId)) {
188  return false;
189  }
190  if (!Objects.equals(this.grouping, other.grouping)) {
191  return false;
192  }
193  if (!Objects.equals(this.title, other.title)) {
194  return false;
195  }
196  return Objects.equals(this.memberId, other.memberId);
197  }
198 
199 }
static Set< AxDescriptor > from(AxProject project, Dossier dossier)
static AxDescriptor fromJson(JsonValue value)
String toJson(Map< String, Object > properties)
Set< DescriptorValue > getDescriptors()
Definition: Dossier.java:231