BrightSide Workbench Full Report + Source Code
AxStudent.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.util.Map;
23 import java.util.Objects;
24 import javax.json.JsonValue;
25 import javax.persistence.EmbeddedId;
26 import javax.persistence.Entity;
27 import org.hibernate.annotations.Formula;
28 import org.turro.action.Contacts;
29 import org.turro.contacts.BusinessRelation;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.jpa.entity.IDaoEntity;
32 import org.turro.json.IJSONizable;
33 import org.turro.plugin.contacts.IContact;
34 import org.turro.plugin.contacts.IContactRelation;
35 import org.turro.string.Phrases;
36 import org.turro.string.Strings;
37 
42 @Entity
43 public class AxStudent implements Serializable, IDaoEntity, IJSONizable {
44 
45  @EmbeddedId private ProcedenceId studentId;
46 
47  @Formula("concat(entityId,'##',memberId)")
48  private String id; /* Widgets compatibility */
49 
50  private String name, email;
51  private String center, course;
52  private String face, centerFace;
53 
54  private boolean active;
55 
57  return studentId;
58  }
59 
60  public void setStudentId(ProcedenceId studentId) {
61  this.studentId = studentId;
62  }
63 
64  public String getId() {
65  return id;
66  }
67 
68  public String getName() {
69  return name;
70  }
71 
72  public void setName(String name) {
73  this.name = name;
74  }
75 
76  public String getEmail() {
77  return email;
78  }
79 
80  public void setEmail(String email) {
81  this.email = email;
82  }
83 
84  public String getCenter() {
85  return center;
86  }
87 
88  public void setCenter(String center) {
89  this.center = center;
90  }
91 
92  public String getCourse() {
93  return course;
94  }
95 
96  public void setCourse(String course) {
97  this.course = course;
98  }
99 
100  public String getFace() {
101  return face;
102  }
103 
104  public void setFace(String face) {
105  this.face = face;
106  }
107 
108  public String getCenterFace() {
109  return centerFace;
110  }
111 
112  public void setCenterFace(String centerFace) {
113  this.centerFace = centerFace;
114  }
115 
116  public boolean isActive() {
117  return active;
118  }
119 
120  public void setActive(boolean active) {
121  this.active = active;
122  }
123 
124  /* Factory */
125 
126  public static AxStudent from(long memberId, String contactId) {
127  if(!Strings.isBlank(contactId)) {
128  return from(memberId, Contacts.getContactById(contactId));
129  }
130  return null;
131  }
132 
133  public static AxStudent from(long memberId, IContact contact) {
134  if(contact.isValid()) {
135  AxStudent axc = new AxStudent();
136  ProcedenceId id = new ProcedenceId();
137  id.setMemberId(memberId);
138  id.setEntityId(contact.getId());
139  axc.setStudentId(id);
140  axc.setName(contact.getName());
141  axc.setEmail(contact.getEmail());
142  axc.setActive(!contact.isDeactivated());
143  String serverURL = ElephantContext.getServerUrl("http");
144  axc.setFace(Strings.isBlank(contact.getFace()) ? null : serverURL + contact.getFace());
146  if(cr != null) {
147  IContact business = cr.getRelatedIContact();
149  axc.setCenter(business.getName());
150  axc.setCourse(Phrases.start(cr.getDatesString()).add(br.getDescription()).toString());
151  axc.setCenterFace(Strings.isBlank(business.getFace()) ? null : serverURL + business.getFace());
152  }
153  return axc;
154  }
155  return null;
156  }
157 
158  /* IDaoEntity */
159 
160  @Override
161  public Object entityId() {
162  return studentId;
163  }
164 
165  @Override
166  public boolean isEmpty() {
167  return studentId.isEmpty() ||
168  Strings.isBlank(name);
169  }
170 
171  /* JSONizable */
172 
173  @Override
174  public String toJson() {
175  return toJson(this);
176  }
177 
178  @Override
179  public String toJson(Map<String, Object> properties) {
180  return toJson(this, properties);
181  }
182 
183  public static AxStudent fromJson(JsonValue value) {
184  return IJSONizable.fromJson(value.toString(), AxStudent.class);
185  }
186 
187  /* Utils */
188 
189  @Override
190  public int hashCode() {
191  int hash = 7;
192  hash = 83 * hash + Objects.hashCode(this.studentId);
193  return hash;
194  }
195 
196  @Override
197  public boolean equals(Object obj) {
198  if (this == obj) {
199  return true;
200  }
201  if (obj == null) {
202  return false;
203  }
204  if (getClass() != obj.getClass()) {
205  return false;
206  }
207  final AxStudent other = (AxStudent) obj;
208  return Objects.equals(this.studentId, other.studentId);
209  }
210 
211 }
static IContact getContactById(String id)
Definition: Contacts.java:72
static AxStudent from(long memberId, String contactId)
Definition: AxStudent.java:126
static AxStudent fromJson(JsonValue value)
Definition: AxStudent.java:183
String toJson(Map< String, Object > properties)
Definition: AxStudent.java:179
void setCenterFace(String centerFace)
Definition: AxStudent.java:112
void setStudentId(ProcedenceId studentId)
Definition: AxStudent.java:60
static AxStudent from(long memberId, IContact contact)
Definition: AxStudent.java:133
static String getServerUrl(String scheme)
IContactRelation getCompanyRelation()