BrightSide Workbench Full Report + Source Code
AxParticipation.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.Date;
23 import java.util.Map;
24 import java.util.Objects;
25 import java.util.Set;
26 import javax.json.JsonValue;
27 import javax.persistence.EmbeddedId;
28 import javax.persistence.Entity;
29 import javax.persistence.Temporal;
30 import org.turro.string.Strings;
31 import org.turro.alliance.contact.AllianceContact;
32 import org.turro.alliance.db.AlliancePU;
33 import org.turro.alliance.model.AxParticipationSet;
34 import org.turro.dossier.entity.Dossier;
35 import org.turro.elephant.context.ElephantContext;
36 import org.turro.importer.ImporterRegister;
37 import org.turro.jpa.entity.IDaoEntity;
38 import org.turro.json.IJSONizable;
39 import org.turro.plugin.contacts.IContact;
40 import org.turro.plugin.contacts.IContactRelation;
41 
46 @Entity
47 public class AxParticipation implements Serializable, IDaoEntity, IJSONizable {
48 
49  @EmbeddedId private RelationId relation;
50 
51  @Temporal(value = javax.persistence.TemporalType.TIMESTAMP)
52  private java.util.Date creation;
53 
54  private boolean driver, coordinator, beneficiary, offerer, research, funding, support, consortium, admin;
55 
56  private String company, companyFace;
57 
59  return relation;
60  }
61 
62  public void setRelation(RelationId relation) {
63  this.relation = relation;
64  }
65 
66  public Date getCreation() {
67  return creation;
68  }
69 
70  public void setCreation(Date creation) {
71  this.creation = creation;
72  }
73 
74  public boolean isDriver() {
75  return driver;
76  }
77 
78  public void setDriver(boolean driver) {
79  this.driver = driver;
80  }
81 
82  public boolean isCoordinator() {
83  return coordinator;
84  }
85 
86  public void setCoordinator(boolean coordinator) {
87  this.coordinator = coordinator;
88  }
89 
90  public boolean isBeneficiary() {
91  return beneficiary;
92  }
93 
94  public void setBeneficiary(boolean beneficiary) {
95  this.beneficiary = beneficiary;
96  }
97 
98  public boolean isOfferer() {
99  return offerer;
100  }
101 
102  public void setOfferer(boolean offerer) {
103  this.offerer = offerer;
104  }
105 
106  public boolean isResearch() {
107  return research;
108  }
109 
110  public void setResearch(boolean research) {
111  this.research = research;
112  }
113 
114  public boolean isFunding() {
115  return funding;
116  }
117 
118  public void setFunding(boolean funding) {
119  this.funding = funding;
120  }
121 
122  public boolean isSupport() {
123  return support;
124  }
125 
126  public void setSupport(boolean support) {
127  this.support = support;
128  }
129 
130  public boolean isConsortium() {
131  return consortium;
132  }
133 
134  public void setConsortium(boolean consortium) {
135  this.consortium = consortium;
136  }
137 
138  public boolean isAdmin() {
139  return admin;
140  }
141 
142  public void setAdmin(boolean admin) {
143  this.admin = admin;
144  }
145 
146  public String getCompany() {
147  return company;
148  }
149 
150  public void setCompany(String company) {
151  this.company = company;
152  }
153 
154  public String getCompanyFace() {
155  return companyFace;
156  }
157 
158  public void setCompanyFace(String companyFace) {
159  this.companyFace = companyFace;
160  }
161 
162  /* Project */
163 
165  return new AlliancePU().find(AxProject.class, relation.getMainProcedenceId());
166  }
167 
168  /* Contact */
169 
171  return new AlliancePU().find(AxContact.class, relation.getRelatedProcedenceId());
172  }
173 
175  return new AllianceContact(getContact());
176  }
177 
178  /* Factory */
179 
180  public static Set<AxParticipation> from(long memberId, Dossier dossier) {
181  AxParticipationSet participations = new AxParticipationSet();
182  dossier.getFullParticipants().forEach(participant -> {
183  RelationId relation = new RelationId();
184  relation.setMainEntityId(Long.toString(dossier.getId()));
185  relation.setMainMemberId(memberId);
186  relation.setRelatedEntityId(participant.getIdContact());
187  relation.setRelatedMemberId(memberId);
188  AxParticipation participation = new AxParticipation();
189  participation.setRelation(relation);
190  participation.setCreation(participant.getCreation());
191  participation.setAdmin(participant.isAdmin());
192  participation.setBeneficiary(participant.isBeneficiary());
193  participation.setConsortium(participant.isConsortium());
194  participation.setCoordinator(participant.isCoordinator());
195  participation.setDriver(participant.isDriver());
196  participation.setFunding(participant.isFunding());
197  participation.setOfferer(participant.isOfferer());
198  participation.setResearch(participant.isResearch());
199  participation.setSupport(participant.isSupport());
200  IContactRelation cr = participant.getIContact().getCompanyRelations()
201  .date(participant.getCreation()).getCompanyRelation();
202  if(cr != null) {
203  IContact business = cr.getRelatedIContact();
204  participation.setCompany(business.getName());
205  if(!Strings.isBlank(business.getFace())) {
206  String serverURL = ElephantContext.getServerUrl("http");
207  participation.setCompanyFace(serverURL + business.getFace());
208  }
209  }
210  participations.add(participation);
211  });
212  return participations;
213  }
214 
215  public static AxParticipation from(long memberId, ImporterRegister register) {
216  RelationId relation = new RelationId();
217  relation.setMainEntityId(register.getString("projectId"));
218  relation.setMainMemberId(memberId);
219  relation.setRelatedEntityId(register.getString("contactId"));
220  relation.setRelatedMemberId(memberId);
221  AxParticipation participation = new AxParticipation();
222  participation.setRelation(relation);
223  participation.setCreation(register.getDate("creation"));
224  participation.setAdmin(register.getBoolean("admin"));
225  participation.setBeneficiary(register.getBoolean("beneficiary"));
226  participation.setConsortium(register.getBoolean("consortium"));
227  participation.setCoordinator(register.getBoolean("coordinator"));
228  participation.setDriver(register.getBoolean("driver"));
229  participation.setFunding(register.getBoolean("funding"));
230  participation.setOfferer(register.getBoolean("offerer"));
231  participation.setResearch(register.getBoolean("research"));
232  participation.setSupport(register.getBoolean("support"));
233  participation.setCompany(register.getString("company"));
234  participation.setCompanyFace(register.getString("companyFace"));
235  return participation;
236  }
237 
238  /* IDaoEntity */
239 
240  @Override
241  public Object entityId() {
242  return relation;
243  }
244 
245  @Override
246  public boolean isEmpty() {
247  return relation.isEmpty();
248  }
249 
250  /* JSONizable */
251 
252  @Override
253  public String toJson() {
254  return toJson(this);
255  }
256 
257  @Override
258  public String toJson(Map<String, Object> properties) {
259  return toJson(this, properties);
260  }
261 
262  public static AxParticipation fromJson(JsonValue value) {
263  return IJSONizable.fromJson(value.toString(), AxParticipation.class);
264  }
265 
266  @Override
267  public int hashCode() {
268  int hash = 3;
269  hash = 97 * hash + Objects.hashCode(this.relation);
270  return hash;
271  }
272 
273  @Override
274  public boolean equals(Object obj) {
275  if (this == obj) {
276  return true;
277  }
278  if (obj == null) {
279  return false;
280  }
281  if (getClass() != obj.getClass()) {
282  return false;
283  }
284  final AxParticipation other = (AxParticipation) obj;
285  return Objects.equals(this.relation, other.relation);
286  }
287 
288 }
String toJson(Map< String, Object > properties)
static AxParticipation fromJson(JsonValue value)
static Set< AxParticipation > from(long memberId, Dossier dossier)
static AxParticipation from(long memberId, ImporterRegister register)
void setRelatedMemberId(Long relatedMemberId)
Definition: RelationId.java:70
void setMainMemberId(Long mainMemberId)
Definition: RelationId.java:54
void setRelatedEntityId(String relatedEntityId)
Definition: RelationId.java:62
void setMainEntityId(String mainEntityId)
Definition: RelationId.java:46
ParticipantSet< IDossierParticipant > getFullParticipants()
Definition: Dossier.java:399
static String getServerUrl(String scheme)