1 package eu
.etaxonomy
.cdm
.model
.common
;
3 import java
.util
.ArrayList
;
4 import java
.util
.HashSet
;
8 import javax
.persistence
.Entity
;
9 import javax
.persistence
.Inheritance
;
10 import javax
.persistence
.InheritanceType
;
11 import javax
.persistence
.JoinTable
;
12 import javax
.persistence
.MappedSuperclass
;
13 import javax
.persistence
.OneToMany
;
14 import javax
.persistence
.Table
;
15 import javax
.persistence
.Transient
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.hibernate
.annotations
.Cascade
;
19 import org
.hibernate
.annotations
.CascadeType
;
21 import au
.com
.bytecode
.opencsv
.CSVWriter
;
24 public abstract class RelationshipTermBase
<T
extends RelationshipTermBase
> extends OrderedTermBase
<T
> {
25 static Logger logger
= Logger
.getLogger(RelationshipTermBase
.class);
27 private boolean symmetric
;
28 private boolean transitive
;
29 private Set
<Representation
> inverseRepresentations
= new HashSet();
31 public RelationshipTermBase() {
34 public RelationshipTermBase(String term
, String label
, boolean symmetric
, boolean transitive
) {
36 setSymmetric(symmetric
);
37 setTransitive(transitive
);
41 public boolean isSymmetric() {
44 public void setSymmetric(boolean symmetric
) {
45 this.symmetric
= symmetric
;
48 public boolean isTransitive() {
51 public void setTransitive(boolean transitive
) {
52 this.transitive
= transitive
;
57 @JoinTable(name
="RelationshipTermBase_inverseRepresentation")
58 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.DELETE
})
59 public Set
<Representation
> getInverseRepresentations() {
60 return inverseRepresentations
;
62 protected void setInverseRepresentations(
63 Set
<Representation
> inverseRepresentations
) {
64 this.inverseRepresentations
= inverseRepresentations
;
66 public void addInverseRepresentation(Representation inverseRepresentation
) {
67 this.inverseRepresentations
.add(inverseRepresentation
);
69 public void removeInverseRepresentation(Representation inverseRepresentation
) {
70 this.inverseRepresentations
.remove(inverseRepresentation
);
72 public void addRepresentation(Representation representation
, Representation inverseRepresentation
) {
73 this.addRepresentation(representation
);
74 this.addInverseRepresentation(inverseRepresentation
);
78 public Representation
getInverseRepresentation(Language lang
) {
79 Representation result
= null;
80 if (this.isSymmetric()){
81 for (Representation repr
: this.getRepresentations()){
82 if (repr
.getLanguage() == lang
){
87 for (Representation repr
: this.getInverseRepresentations()){
88 if (repr
.getLanguage() == lang
){
97 * Inverse representation convenience methods similar to TermBase.xxx
98 * @see eu.etaxonomy.cdm.model.common.TermBase#getLabel()
101 public String
getInverseLabel() {
102 if(getInverseLabel(Language
.DEFAULT())!=null){
103 return this.getInverseRepresentation(Language
.DEFAULT()).getLabel();
105 for (Representation r
: inverseRepresentations
){
109 return super.getUuid().toString();
113 public String
getInverseLabel(Language lang
) {
114 Representation r
= this.getInverseRepresentation(lang
);
123 public String
getInverseDescription() {
124 return this.getInverseRepresentation(Language
.DEFAULT()).getDescription();
128 public String
getInverseDescription(Language lang
) {
129 return this.getInverseRepresentation(lang
).getDescription();
132 public ILoadableTerm
readCsvLine(List csvLine
) {
133 RelationshipTermBase result
;
134 // read UUID, URI, english label+description
135 List
<String
> csvLineString
= (List
<String
>)csvLine
;
136 result
= (RelationshipTermBase
)super.readCsvLine(csvLineString
);
137 // inverse label + 2 booleans
138 result
.addInverseRepresentation(new Representation(csvLineString
.get(4).trim(), csvLineString
.get(5).trim(), Language
.ENGLISH()) );
139 result
.setSymmetric(Boolean
.parseBoolean(csvLineString
.get(6)));
140 result
.setTransitive(Boolean
.parseBoolean(csvLineString
.get(7)));
144 public void writeCsvLine(CSVWriter writer
) {
145 String
[] line
= new String
[8];
146 line
[0] = getUuid().toString();
148 line
[2] = getLabel();
149 line
[3] = getDescription();
150 line
[4] = getInverseLabel();
151 line
[5] = getInverseDescription();
152 line
[6] = String
.valueOf(this.isSymmetric());
153 line
[7] = String
.valueOf(this.isTransitive());
154 writer
.writeNext(line
);