1 package eu
.etaxonomy
.cdm
.model
.common
;
3 import java
.util
.HashSet
;
7 import javax
.persistence
.JoinTable
;
8 import javax
.persistence
.MappedSuperclass
;
9 import javax
.persistence
.OneToMany
;
10 import javax
.persistence
.Transient
;
11 import javax
.xml
.bind
.annotation
.XmlRootElement
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.hibernate
.annotations
.Cascade
;
15 import org
.hibernate
.annotations
.CascadeType
;
17 import au
.com
.bytecode
.opencsv
.CSVWriter
;
19 @XmlRootElement(name
= "RelationshipTermBase")
21 public abstract class RelationshipTermBase
<T
extends RelationshipTermBase
> extends OrderedTermBase
<T
> {
22 static Logger logger
= Logger
.getLogger(RelationshipTermBase
.class);
24 private boolean symmetric
;
25 private boolean transitive
;
26 private Set
<Representation
> inverseRepresentations
= new HashSet();
28 public RelationshipTermBase() {
31 public RelationshipTermBase(String term
, String label
, String labelAbbrev
, boolean symmetric
, boolean transitive
) {
32 super(term
, label
, labelAbbrev
);
33 setSymmetric(symmetric
);
34 setTransitive(transitive
);
38 public boolean isSymmetric() {
41 public void setSymmetric(boolean symmetric
) {
42 this.symmetric
= symmetric
;
45 public boolean isTransitive() {
48 public void setTransitive(boolean transitive
) {
49 this.transitive
= transitive
;
54 @JoinTable(name
="RelationshipTermBase_inverseRepresentation")
55 @Cascade({CascadeType
.SAVE_UPDATE
, CascadeType
.DELETE
})
56 public Set
<Representation
> getInverseRepresentations() {
57 return inverseRepresentations
;
59 protected void setInverseRepresentations(
60 Set
<Representation
> inverseRepresentations
) {
61 this.inverseRepresentations
= inverseRepresentations
;
63 public void addInverseRepresentation(Representation inverseRepresentation
) {
64 this.inverseRepresentations
.add(inverseRepresentation
);
66 public void removeInverseRepresentation(Representation inverseRepresentation
) {
67 this.inverseRepresentations
.remove(inverseRepresentation
);
69 public void addRepresentation(Representation representation
, Representation inverseRepresentation
) {
70 this.addRepresentation(representation
);
71 this.addInverseRepresentation(inverseRepresentation
);
75 public Representation
getInverseRepresentation(Language lang
) {
76 Representation result
= null;
77 if (this.isSymmetric()){
78 for (Representation repr
: this.getRepresentations()){
79 if (repr
.getLanguage() == lang
){
84 for (Representation repr
: this.getInverseRepresentations()){
85 if (repr
.getLanguage() == lang
){
94 * Inverse representation convenience methods similar to TermBase.xxx
95 * @see eu.etaxonomy.cdm.model.common.TermBase#getLabel()
98 public String
getInverseLabel() {
99 if(getInverseLabel(Language
.DEFAULT())!=null){
100 return this.getInverseRepresentation(Language
.DEFAULT()).getLabel();
102 for (Representation r
: inverseRepresentations
){
106 return super.getUuid().toString();
110 public String
getInverseLabel(Language lang
) {
111 Representation r
= this.getInverseRepresentation(lang
);
120 public String
getInverseDescription() {
121 return this.getInverseRepresentation(Language
.DEFAULT()).getDescription();
125 public String
getInverseDescription(Language lang
) {
126 return this.getInverseRepresentation(lang
).getDescription();
129 public ILoadableTerm
readCsvLine(List csvLine
) {
130 RelationshipTermBase result
;
131 // read UUID, URI, english label+description
132 List
<String
> csvLineString
= (List
<String
>)csvLine
;
133 result
= (RelationshipTermBase
)super.readCsvLine(csvLineString
);
134 // inverse label + 2 booleans
135 String inverseText
= csvLineString
.get(5).trim();
136 String inverseLabel
= csvLineString
.get(4).trim();
137 String inverseLabelAbbrev
= null;
138 result
.addInverseRepresentation(new Representation(inverseText
, inverseLabel
, inverseLabelAbbrev
, 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
);