BrightSide Workbench Full Report + Source Code
Relation.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.contacts ;
19 
20 import javax.persistence.*;
21 import org.turro.string.Strings;
22 import org.turro.contacts.organigram.RelationType;
23 import org.turro.elephant.util.Images;
24 import org.turro.i18n.I_;
25 import org.turro.util.Chars;
26 import org.turro.util.PhraseBuilder;
27 
28 @Deprecated
29 @Entity
30 @org.hibernate.annotations.GenericGenerator(name = "hibernate-uuid", strategy = "uuid")
31 public class Relation implements java.io.Serializable {
32 
33  @Id
34  @GeneratedValue(generator = "hibernate-uuid")
35  @Column(name="IDENTIFIER")
36  private String id;
37 
38  private String owner;
39 
40  private boolean onlyOwner;
41 
42  private String description;
43 
44  private String relationType;
45 
46  private boolean preferential;
47 
48  private transient String related;
49 
50  @ManyToOne
51  @JoinColumn(name="Contact1_FK")
52  private org.turro.contacts.Contact contact1;
53 
54  @ManyToOne
55  @JoinColumn(name="Contact2_FK")
56  private org.turro.contacts.Contact contact2;
57 
58  public String getFullRelation2() {
59  String result = "";
60  if(getFormattedDescription() != null) result += getFormattedDescription() + Chars.forward().spaced();
61  if(getContact2() != null) result += " " + getContact2().getName();
62  return result;
63  }
64 
65  public String getFullRelation1() {
66  String result = "";
67  if(getFormattedDescription() != null) result += getFormattedDescription() + Chars.backward().spaced();
68  if(getContact1() != null) result += " " + getContact1().getName();
69  return result;
70  }
71 
72  public String getId() {
73  return id;
74  }
75 
76  protected void setId(String id) {
77  this.id = id;
78  }
79 
80  public String getOwner() {
81  return owner;
82  }
83 
84  public void setOwner(String owner) {
85  this.owner = owner;
86  }
87 
88  public boolean isOnlyOwner() {
89  return onlyOwner;
90  }
91 
92  public void setOnlyOwner(boolean onlyOwner) {
93  this.onlyOwner = onlyOwner;
94  }
95 
96  public String getDescription() {
97  return description;
98  }
99 
100  public void setDescription(String description) {
101  this.description = description;
102  }
103 
104  public org.turro.contacts.Contact getContact1() {
105  return contact1;
106  }
107 
108  public void setContact1(org.turro.contacts.Contact contact1) {
109  this.contact1 = contact1;
110  }
111 
112  public org.turro.contacts.Contact getContact2() {
113  return contact2;
114  }
115 
116  public void setContact2(org.turro.contacts.Contact contact2) {
117  this.contact2 = contact2;
118  }
119 
120  public String getRelated() {
121  return related;
122  }
123 
124  public void setRelated(String related) {
125  this.related = related;
126  }
127 
128  public String getRelationType() {
129  return relationType;
130  }
131 
132  public void setRelationType(String relationType) {
133  this.relationType = relationType;
134  }
135 
136  public boolean isPreferential() {
137  return preferential;
138  }
139 
140  public void setPreferential(boolean preferential) {
141  this.preferential = preferential;
142  }
143 
144  public boolean getCanShow(String userId) {
145  return true;
146  }
147 
148  public boolean isEmpty() {
149  return (Strings.isEmpty(description) && Strings.isEmpty(relationType)) ||
150  contact1 == null || contact2 == null;
151  }
152 
153  /* Description helper */
154 
155  public boolean isTyped() {
156  return !Strings.isBlank(relationType) && relationType.startsWith("$");
157  }
158 
159  public String getFormattedDescription() {
160  PhraseBuilder pb = new PhraseBuilder();
161  if(!Strings.isBlank(relationType)) {
162  pb.addWord(I_.byKey(relationType.substring(1)));
163  }
164  pb.addWord(description);
165  if(!pb.isBlank()) {
166  return pb.toString();
167  } else {
168  return "";
169  }
170  }
171 
172  public String getImage() {
173  if(!Strings.isBlank(relationType)) {
174  if(relationType.startsWith("$INT")) {
175  return Images.getImage("contract");
176  }
177  RelationType rt = RelationType.getFromString(relationType);
178  if(rt != null) {
179  return rt.getImage();
180  }
181  }
182  return null;
183  }
184 
185 }
void setOwner(String owner)
Definition: Relation.java:84
void setContact2(org.turro.contacts.Contact contact2)
Definition: Relation.java:116
void setId(String id)
Definition: Relation.java:76
void setDescription(String description)
Definition: Relation.java:100
void setPreferential(boolean preferential)
Definition: Relation.java:140
void setRelated(String related)
Definition: Relation.java:124
void setOnlyOwner(boolean onlyOwner)
Definition: Relation.java:92
org.turro.contacts.Contact getContact2()
Definition: Relation.java:112
boolean getCanShow(String userId)
Definition: Relation.java:144
org.turro.contacts.Contact getContact1()
Definition: Relation.java:104
void setRelationType(String relationType)
Definition: Relation.java:132
void setContact1(org.turro.contacts.Contact contact1)
Definition: Relation.java:108
static String getImage(String image)
Definition: Images.java:36
static String byKey(String key)
Definition: I_.java:83
static RelationType getFromString(String relation)