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
extends OrderedTermBase
{
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 void readCsvLine(List
<String
> csvLine
) {
133 // read UUID, URI, english label+description
134 super.readCsvLine(csvLine
);
135 // inverse label + 2 booleans
136 this.addInverseRepresentation(new Representation(csvLine
.get(4).trim(), csvLine
.get(5).trim(), Language
.ENGLISH()) );
137 this.setSymmetric(Boolean
.parseBoolean(csvLine
.get(6)));
138 this.setTransitive(Boolean
.parseBoolean(csvLine
.get(7)));
141 public void writeCsvLine(CSVWriter writer
) {
142 String
[] line
= new String
[8];
143 line
[0] = getUuid().toString();
145 line
[2] = getLabel();
146 line
[3] = getDescription();
147 line
[4] = getInverseLabel();
148 line
[5] = getInverseDescription();
149 line
[6] = String
.valueOf(this.isSymmetric());
150 line
[7] = String
.valueOf(this.isTransitive());
151 writer
.writeNext(line
);