BrightSide Workbench Full Report + Source Code
AxProjectCategory.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.member.db.entities;
20 
21 import java.io.Serializable;
22 import javax.persistence.Entity;
23 import javax.persistence.Id;
24 import javax.persistence.IdClass;
25 import org.turro.alliance.service.AxConstants;
26 import org.turro.alliance.service.AxServer;
27 import org.turro.string.Strings;
28 import org.turro.dossier.db.DossierPU;
29 import org.turro.dossier.entity.Dossier;
30 import org.turro.jpa.entity.IDaoEntity;
31 import org.turro.json.Jsons;
32 import org.turro.json.Structure;
33 import org.turro.math.Zero;
34 import org.turro.ws.WsServer;
35 import org.turro.ws.service.member.Servers;
36 
41 @Entity
42 @IdClass(AxProjectCategoryPK.class)
43 public class AxProjectCategory implements Serializable, IDaoEntity {
44 
45  @Id private String serverDomain;
46  @Id private String projectId;
47 
48  private Long categoryId;
49 
50  public String getServerDomain() {
51  return serverDomain;
52  }
53 
54  public void setServerDomain(String serverDomain) {
55  this.serverDomain = serverDomain;
56  }
57 
58  public String getProjectId() {
59  return projectId;
60  }
61 
62  public void setProjectId(String projectId) {
63  this.projectId = projectId;
64  }
65 
66  public Long getCategoryId() {
67  return categoryId;
68  }
69 
70  public void setCategoryId(Long categoryId) {
71  this.categoryId = categoryId;
72  }
73 
74  /* Utils */
75 
76  private transient Dossier dossier;
77 
78  public Dossier getDossier() {
79  return Strings.isBlank(projectId) ? null :
80  (dossier == null ? new DossierPU().find(Dossier.class, Long.valueOf(projectId)) : dossier);
81  }
82 
83  public void setDossier(Dossier dossier) {
84  this.dossier = dossier;
85  this.projectId = dossier == null ? null : Long.toString(dossier.getId());
86  }
87 
88  private transient Structure category;
89 
90  public Structure getCategory() {
91  return Zero.orNull(categoryId) ? null :
92  (category == null ? Servers.getData(WsServer.from(getServerDomain(), AxServer.SERVER_SERVICE), AxConstants.CATEGORY,
93  Jsons.object().add("id", categoryId)).getStructure() : category);
94  }
95 
96  public void setCategory(Structure category) {
97  this.category = category;
98  this.categoryId = category == null ? null : category.getLong("categoryId");
99  }
100 
101  /* IDaoEntity */
102 
103  @Override
104  public Object entityId() {
105  return AxProjectCategoryPK.from(this);
106  }
107 
108  @Override
109  public boolean isEmpty() {
110  return Strings.isBlank(serverDomain) ||
111  Strings.isBlank(projectId) ||
112  Zero.orNull(categoryId);
113  }
114 
115 }
static final String SERVER_SERVICE
Definition: AxServer.java:51
static boolean orNull(Number value)
Definition: Zero.java:26
static AxProjectCategoryPK from(AxProjectCategory pc)
static WsServer from(String serverDomain, String service)
Definition: WsServer.java:149