BrightSide Workbench Full Report + Source Code
AxProjectGrant.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2024 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.time.Instant;
23 import java.util.Date;
24 import java.util.Map;
25 import java.util.Objects;
26 import javax.json.JsonValue;
27 import javax.persistence.Column;
28 import javax.persistence.EmbeddedId;
29 import javax.persistence.Entity;
30 import javax.persistence.Lob;
31 import javax.persistence.Temporal;
32 import org.hibernate.annotations.Formula;
33 import org.turro.dossier.entity.ProjectGrant;
34 import org.turro.elephant.context.ElephantContext;
35 import org.turro.entities.Entities;
36 import org.turro.html.HtmlContent;
37 import org.turro.jpa.embeddables.Wiki;
38 import org.turro.jpa.entity.IDaoEntity;
39 import org.turro.json.IJSONizable;
40 import org.turro.string.Strings;
41 
46 @Entity
47 public class AxProjectGrant implements Serializable, IDaoEntity, IJSONizable {
48 
49  @EmbeddedId private ProcedenceId projectGrantId;
50 
51  @Formula("concat(entityId,'##',memberId)")
52  private String id; /* Widgets compatibility */
53 
54  private String title;
55 
56  @Temporal(value = javax.persistence.TemporalType.TIMESTAMP)
57  private java.util.Date endDate;
58 
59  private boolean recurrent, endOfBudget;
60 
61  private boolean micro, small, medium, big, otherOrgs;
62 
63  private double budget;
64 
65  private boolean subvention, loan, inKind;
66  private boolean collaboration;
67 
68  private boolean minimis;
69 
70  private String source;
71 
72  private String convocation, basis;
73 
74  private boolean hiring, idi, investment, startUp, formation;
75 
76  @Lob
77  @Column(length=4096)
78  private String goal;
79 
80  @Lob
81  @Column(length=4096)
82  private String deadline;
83 
84  @Lob
85  @Column(length=4096)
86  private String elegible;
87 
88  @Lob
89  @Column(length=4096)
90  private String beneficiaries;
91 
92  @Lob
93  @Column(length=4096)
94  private String features;
95 
96  @Lob
97  @Column(length=4096)
98  private String intensity;
99 
100  private String sourceLink;
101 
103  return projectGrantId;
104  }
105 
106  public void setProjectGrantId(ProcedenceId projectGrantId) {
107  this.projectGrantId = projectGrantId;
108  }
109 
110  public String getId() {
111  // Workaround for self-cached grants
112  return id == null ? projectGrantId.stringify() : id;
113  }
114 
115  public String getTitle() {
116  return title;
117  }
118 
119  public void setTitle(String title) {
120  this.title = title;
121  }
122 
123  public Date getEndDate() {
124  return endDate;
125  }
126 
127  public void setEndDate(Date endDate) {
128  this.endDate = endDate;
129  }
130 
131  public boolean isRecurrent() {
132  return recurrent;
133  }
134 
135  public void setRecurrent(boolean recurrent) {
136  this.recurrent = recurrent;
137  }
138 
139  public boolean isEndOfBudget() {
140  return endOfBudget;
141  }
142 
143  public void setEndOfBudget(boolean endOfBudget) {
144  this.endOfBudget = endOfBudget;
145  }
146 
147  public boolean isMicro() {
148  return micro;
149  }
150 
151  public void setMicro(boolean micro) {
152  this.micro = micro;
153  }
154 
155  public boolean isSmall() {
156  return small;
157  }
158 
159  public void setSmall(boolean small) {
160  this.small = small;
161  }
162 
163  public boolean isMedium() {
164  return medium;
165  }
166 
167  public void setMedium(boolean medium) {
168  this.medium = medium;
169  }
170 
171  public boolean isBig() {
172  return big;
173  }
174 
175  public void setBig(boolean big) {
176  this.big = big;
177  }
178 
179  public boolean isOtherOrgs() {
180  return otherOrgs;
181  }
182 
183  public void setOtherOrgs(boolean otherOrgs) {
184  this.otherOrgs = otherOrgs;
185  }
186 
187  public double getBudget() {
188  return budget;
189  }
190 
191  public void setBudget(double budget) {
192  this.budget = budget;
193  }
194 
195  public boolean isSubvention() {
196  return subvention;
197  }
198 
199  public void setSubvention(boolean subvention) {
200  this.subvention = subvention;
201  }
202 
203  public boolean isLoan() {
204  return loan;
205  }
206 
207  public void setLoan(boolean loan) {
208  this.loan = loan;
209  }
210 
211  public boolean isInKind() {
212  return inKind;
213  }
214 
215  public void setInKind(boolean inKind) {
216  this.inKind = inKind;
217  }
218 
219  public boolean isCollaboration() {
220  return collaboration;
221  }
222 
223  public void setCollaboration(boolean collaboration) {
224  this.collaboration = collaboration;
225  }
226 
227  public boolean isMinimis() {
228  return minimis;
229  }
230 
231  public void setMinimis(boolean minimis) {
232  this.minimis = minimis;
233  }
234 
235  public String getSource() {
236  return source;
237  }
238 
239  public void setSource(String source) {
240  this.source = source;
241  }
242 
243  public String getConvocation() {
244  return convocation;
245  }
246 
247  public void setConvocation(String convocation) {
248  this.convocation = convocation;
249  }
250 
251  public String getBasis() {
252  return basis;
253  }
254 
255  public void setBasis(String basis) {
256  this.basis = basis;
257  }
258 
259  public boolean isHiring() {
260  return hiring;
261  }
262 
263  public void setHiring(boolean hiring) {
264  this.hiring = hiring;
265  }
266 
267  public boolean isIdi() {
268  return idi;
269  }
270 
271  public void setIdi(boolean idi) {
272  this.idi = idi;
273  }
274 
275  public boolean isInvestment() {
276  return investment;
277  }
278 
279  public void setInvestment(boolean investment) {
280  this.investment = investment;
281  }
282 
283  public boolean isStartUp() {
284  return startUp;
285  }
286 
287  public void setStartUp(boolean startUp) {
288  this.startUp = startUp;
289  }
290 
291  public boolean isFormation() {
292  return formation;
293  }
294 
295  public void setFormation(boolean formation) {
296  this.formation = formation;
297  }
298 
299  public String getGoal() {
300  return goal;
301  }
302 
303  public void setGoal(String goal) {
304  this.goal = goal;
305  }
306 
307  public String getDeadline() {
308  return deadline;
309  }
310 
311  public void setDeadline(String deadline) {
312  this.deadline = deadline;
313  }
314 
315  public String getElegible() {
316  return elegible;
317  }
318 
319  public void setElegible(String elegible) {
320  this.elegible = elegible;
321  }
322 
323  public String getBeneficiaries() {
324  return beneficiaries;
325  }
326 
327  public void setBeneficiaries(String beneficiaries) {
328  this.beneficiaries = beneficiaries;
329  }
330 
331  public String getFeatures() {
332  return features;
333  }
334 
335  public void setFeatures(String features) {
336  this.features = features;
337  }
338 
339  public String getIntensity() {
340  return intensity;
341  }
342 
343  public void setIntensity(String intensity) {
344  this.intensity = intensity;
345  }
346 
347  public String getSourceLink() {
348  return sourceLink;
349  }
350 
351  public void setSourceLink(String sourceLink) {
352  this.sourceLink = sourceLink;
353  }
354 
355  /* Factory */
356 
357  public static AxProjectGrant from(long memberId, ProjectGrant projectGrant) {
358  AxProjectGrant axpg = new AxProjectGrant();
359  ProcedenceId id = new ProcedenceId();
360  id.setMemberId(memberId);
361  id.setEntityId(Long.toString(projectGrant.getId()));
362  axpg.setProjectGrantId(id);
363  axpg.setBasis(projectGrant.getBasis());
364  axpg.setBeneficiaries(getTextFromWiki(projectGrant.getBeneficiaries()));
365  axpg.setBig(projectGrant.isBig());
366  axpg.setBudget(projectGrant.getBudget());
367  axpg.setCollaboration(projectGrant.isCollaboration());
368  axpg.setConvocation(projectGrant.getConvocation());
369  axpg.setDeadline(getTextFromWiki(projectGrant.getDeadline()));
370  axpg.setElegible(getTextFromWiki(projectGrant.getElegible()));
371  axpg.setEndDate(projectGrant.getEndDate());
372  axpg.setEndOfBudget(projectGrant.isEndOfBudget());
373  axpg.setFeatures(getTextFromWiki(projectGrant.getFeatures()));
374  axpg.setGoal(getTextFromWiki(projectGrant.getGoal()));
375  axpg.setHiring(projectGrant.getMatchCriteria().isHiring());
376  axpg.setIdi(projectGrant.getMatchCriteria().isIdi());
377  axpg.setInKind(projectGrant.isInKind());
378  axpg.setInvestment(projectGrant.getMatchCriteria().isInvestment());
379  axpg.setStartUp(projectGrant.getMatchCriteria().isStartUp());
380  axpg.setFormation(projectGrant.getMatchCriteria().isFormation());
381  axpg.setIntensity(getTextFromWiki(projectGrant.getIntensity()));
382  axpg.setLoan(projectGrant.isLoan());
383  axpg.setMedium(projectGrant.isMedium());
384  axpg.setMicro(projectGrant.isMicro());
385  axpg.setMinimis(projectGrant.isMinimis());
386  axpg.setOtherOrgs(projectGrant.isOtherOrgs());
387  axpg.setRecurrent(projectGrant.isRecurrent());
388  axpg.setSmall(projectGrant.isSmall());
389  axpg.setSource(projectGrant.getSource());
390  axpg.setSubvention(projectGrant.isSubvention());
391  axpg.setTitle(projectGrant.getTitle());
393  return axpg;
394  }
395 
396  private static String getTextFromWiki(Wiki wiki) {
397  return wiki == null ? null : wiki.getText();
398  }
399 
400  /* IDaoEntity */
401 
402  @Override
403  public Object entityId() {
404  return projectGrantId;
405  }
406 
407  @Override
408  public boolean isEmpty() {
409  return projectGrantId.isEmpty() ||
410  Strings.isBlank(title);
411  }
412 
413  /* JSONizable */
414 
415  @Override
416  public String toJson() {
417  return toJson(this);
418  }
419 
420  @Override
421  public String toJson(Map<String, Object> properties) {
422  return toJson(this, properties);
423  }
424 
425  public static AxProjectGrant fromJson(JsonValue value) {
426  return IJSONizable.fromJson(value.toString(), AxProjectGrant.class);
427  }
428 
429  /* Helpers */
430 
431  public String getName() {
432  return title == null ? "!***" : title;
433  }
434 
435  public String getDescription() {
436  return goal == null ? "!***" : HtmlContent.plain(goal, 250);
437  }
438 
439  public boolean isCompanyType() {
440  return micro | small | medium | big;
441  }
442 
443  public boolean isActive() {
444  return endDate == null || endDate.toInstant().isAfter(Instant.now());
445  }
446 
447  /* Utils */
448 
449  @Override
450  public int hashCode() {
451  int hash = 3;
452  hash = 79 * hash + Objects.hashCode(this.projectGrantId);
453  return hash;
454  }
455 
456  @Override
457  public boolean equals(Object obj) {
458  if (this == obj) {
459  return true;
460  }
461  if (obj == null) {
462  return false;
463  }
464  if (getClass() != obj.getClass()) {
465  return false;
466  }
467  final AxProjectGrant other = (AxProjectGrant) obj;
468  return Objects.equals(this.projectGrantId, other.projectGrantId);
469  }
470 
471 }
static AxProjectGrant fromJson(JsonValue value)
void setProjectGrantId(ProcedenceId projectGrantId)
String toJson(Map< String, Object > properties)
static AxProjectGrant from(long memberId, ProjectGrant projectGrant)
static String getServerUrl(String scheme)
static IElephantEntity getController(String path)
Definition: Entities.java:78