BrightSide Workbench Full Report + Source Code
PracticalWork.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.students.entities;
20 
21 import java.util.Date;
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.Lob;
28 import javax.persistence.Temporal;
29 import org.turro.string.Strings;
30 import org.turro.action.Contacts;
31 import org.turro.html.HtmlContent;
32 import org.turro.jpa.entity.IDaoEntity;
33 import org.turro.parser.wiki.WikiCompiler;
34 import org.turro.plugin.contacts.IContact;
35 import org.turro.reflection.MappingSet;
36 
41 @Entity
42 public class PracticalWork implements java.io.Serializable, IDaoEntity {
43 
44  @Id
45  @GeneratedValue(strategy=GenerationType.IDENTITY)
46  @Column(name="IDENTIFIER")
47  private Long id;
48 
49  private String title;
50 
51  private PracticalWorkRole role;
52 
53  private String type;
54 
55  @Temporal(value = javax.persistence.TemporalType.TIMESTAMP)
56  private java.util.Date creation, startDate, endDate;
57 
58  private double hours, price;
59 
60  private String zipCode, relatedURL;
61 
62  private String idContact, idResponsible;
63 
64  private boolean immediate, published;
65 
66  @Lob
67  @Column(length=4096)
68  private String text;
69 
70  @Lob
71  @Column(length=4096)
72  private String wiki;
73 
74  public Long getId() {
75  return id;
76  }
77 
78  public void setId(Long id) {
79  this.id = id;
80  }
81 
82  public String getTitle() {
83  return title;
84  }
85 
86  public void setTitle(String title) {
87  this.title = title;
88  }
89 
91  return role;
92  }
93 
94  public void setRole(PracticalWorkRole role) {
95  this.role = role;
96  }
97 
98  public String getType() {
99  return type;
100  }
101 
102  public void setType(String type) {
103  this.type = type;
104  }
105 
106  public Date getCreation() {
107  return creation;
108  }
109 
110  public void setCreation(Date creation) {
111  this.creation = creation;
112  }
113 
114  public Date getStartDate() {
115  return startDate;
116  }
117 
118  public void setStartDate(Date startDate) {
119  this.startDate = startDate;
120  }
121 
122  public Date getEndDate() {
123  return endDate;
124  }
125 
126  public void setEndDate(Date endDate) {
127  this.endDate = endDate;
128  }
129 
130  public double getHours() {
131  return hours;
132  }
133 
134  public void setHours(double hours) {
135  this.hours = hours;
136  }
137 
138  public double getPrice() {
139  return price;
140  }
141 
142  public void setPrice(double price) {
143  this.price = price;
144  }
145 
146  public String getZipCode() {
147  return zipCode;
148  }
149 
150  public void setZipCode(String zipCode) {
151  this.zipCode = zipCode;
152  }
153 
154  public String getRelatedURL() {
155  return relatedURL;
156  }
157 
158  public void setRelatedURL(String relatedURL) {
159  this.relatedURL = relatedURL;
160  }
161 
162  public String getIdContact() {
163  return idContact;
164  }
165 
166  public void setIdContact(String idContact) {
167  this.idContact = idContact;
168  }
169 
170  public String getIdResponsible() {
171  return idResponsible;
172  }
173 
174  public void setIdResponsible(String idResponsible) {
175  this.idResponsible = idResponsible;
176  }
177 
178  public boolean isImmediate() {
179  return immediate;
180  }
181 
182  public void setImmediate(boolean immediate) {
183  this.immediate = immediate;
184  }
185 
186  public boolean isPublished() {
187  return published;
188  }
189 
190  public void setPublished(boolean published) {
191  this.published = published;
192  }
193 
194  public String getText() {
195  return text;
196  }
197 
198  public void setText(String text) {
199  this.text = text;
200  }
201 
202  public String getWiki() {
203  // Compatible with non wiki version
204  if(Strings.isEmpty(wiki) && !Strings.isEmpty(text)) {
205  wiki = text;
206  }
207  return wiki;
208  }
209 
210  public void setWiki(String wiki) {
211  this.wiki = wiki;
212  this.text = WikiCompiler.source(this.wiki).html();
213  }
214 
215  /* IDaoEntity */
216 
217  @Override
218  public Object entityId() {
219  return id;
220  }
221 
222  @Override
223  public boolean isEmpty() {
224  return Strings.isBlank(title) || Strings.isBlank(text) || role == null ||
225  Strings.isBlank(type) || Strings.isBlank(idContact) || Strings.isBlank(idResponsible);
226  }
227 
228  /* Helpers */
229 
230  public String getPlainText() {
231  return HtmlContent.text(getText());
232  }
233 
234  public boolean isInBusiness(IContact worker) {
235  return getIContact().isInBusiness(worker);
236  }
237 
238  public void setRoleByContact() {
240  }
241 
242  /* Contacts */
243 
245  return Contacts.getContactById(idContact);
246  }
247 
249  return Contacts.getContactById(idResponsible);
250  }
251 
252  public void setIContact(IContact contact) {
253  if(contact != null) idContact = contact.getId();
254  }
255 
256  public void setIResponsible(IContact responsible) {
257  if(responsible != null) idResponsible = responsible.getId();
258  }
259 
260  /* XML Serializer */
261 
262  public MappingSet getSerializerMappings() {
263  MappingSet set = new MappingSet();
264  set.addMapping(PracticalWork.class, 1,
265  new String[] { "title", "creation", "startDate", "endDate", "role", "type", "published" },
266  new String[] { "hours", "price", "zipCode", "text", "relatedURL", "idContact", "idResponsible" });
267  return set;
268  }
269 
270 }
static IContact getContactById(String id)
Definition: Contacts.java:72
void setIdResponsible(String idResponsible)
void setRole(PracticalWorkRole role)
void setIResponsible(IContact responsible)
boolean isInBusiness(IContact worker)