BrightSide Workbench Full Report + Source Code
RelationId.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.Objects;
23 import javax.persistence.Embeddable;
24 import org.turro.string.Strings;
25 import org.turro.math.Zero;
26 import org.turro.util.Converter;
27 import org.turro.ws.WsMember;
28 import org.turro.ws.service.server.Clients;
29 
34 @Embeddable
35 public class RelationId implements Serializable {
36 
37  private String mainEntityId;
38  private Long mainMemberId;
39  private String relatedEntityId;
40  private Long relatedMemberId;
41 
42  public String getMainEntityId() {
43  return mainEntityId;
44  }
45 
46  public void setMainEntityId(String mainEntityId) {
47  this.mainEntityId = mainEntityId;
48  }
49 
50  public Long getMainMemberId() {
51  return mainMemberId;
52  }
53 
54  public void setMainMemberId(Long mainMemberId) {
55  this.mainMemberId = mainMemberId;
56  }
57 
58  public String getRelatedEntityId() {
59  return relatedEntityId;
60  }
61 
62  public void setRelatedEntityId(String relatedEntityId) {
63  this.relatedEntityId = relatedEntityId;
64  }
65 
66  public Long getRelatedMemberId() {
67  return relatedMemberId;
68  }
69 
70  public void setRelatedMemberId(Long relatedMemberId) {
71  this.relatedMemberId = relatedMemberId;
72  }
73 
74  /* Convertions */
75 
76  public void setMainEntityId(Long mainEntityId) {
77  this.mainEntityId = Converter.STANDARD.convert(mainEntityId, String.class);
78  }
79 
80  public void setRelatedEntityId(Long relatedEntityId) {
81  this.relatedEntityId = Converter.STANDARD.convert(relatedEntityId, String.class);
82  }
83 
84  /* Utils */
85 
86  public boolean isEmpty() {
87  return Strings.isBlank(mainEntityId) || Zero.orNull(mainMemberId) ||
88  Strings.isBlank(relatedEntityId) || Zero.orNull(relatedMemberId);
89  }
90 
92  ProcedenceId mainId = new ProcedenceId();
93  mainId.setEntityId(getMainEntityId());
94  mainId.setMemberId(getMainMemberId());
95  return mainId;
96  }
97 
99  ProcedenceId relatedId = new ProcedenceId();
100  relatedId.setEntityId(getRelatedEntityId());
101  relatedId.setMemberId(getRelatedMemberId());
102  return relatedId;
103  }
104 
105  public WsMember getMember() {
106  return Clients.getMember(mainMemberId);
107  }
108 
110  return Clients.getMember(relatedMemberId);
111  }
112 
113  @Override
114  public int hashCode() {
115  int hash = 7;
116  hash = 79 * hash + Objects.hashCode(this.mainEntityId);
117  hash = 79 * hash + Objects.hashCode(this.mainMemberId);
118  hash = 79 * hash + Objects.hashCode(this.relatedEntityId);
119  hash = 79 * hash + Objects.hashCode(this.relatedMemberId);
120  return hash;
121  }
122 
123  @Override
124  public boolean equals(Object obj) {
125  if (this == obj) {
126  return true;
127  }
128  if (obj == null) {
129  return false;
130  }
131  if (getClass() != obj.getClass()) {
132  return false;
133  }
134  final RelationId other = (RelationId) obj;
135  if (!Objects.equals(this.mainEntityId, other.mainEntityId)) {
136  return false;
137  }
138  if (!Objects.equals(this.relatedEntityId, other.relatedEntityId)) {
139  return false;
140  }
141  if (!Objects.equals(this.mainMemberId, other.mainMemberId)) {
142  return false;
143  }
144  return Objects.equals(this.relatedMemberId, other.relatedMemberId);
145  }
146 
147 }
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 setRelatedEntityId(Long relatedEntityId)
Definition: RelationId.java:80
void setMainEntityId(Long mainEntityId)
Definition: RelationId.java:76
void setMainEntityId(String mainEntityId)
Definition: RelationId.java:46
static boolean orNull(Number value)
Definition: Zero.java:26