package eu.etaxonomy.cdm.model.common;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToMany;
-import javax.persistence.PrePersist;
-import javax.persistence.PreUpdate;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import org.apache.log4j.Logger;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
+import org.hibernate.annotations.IndexColumn;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.FieldBridge;
import org.hibernate.search.annotations.Fields;
import eu.etaxonomy.cdm.jaxb.LSIDAdapter;
import eu.etaxonomy.cdm.model.media.Rights;
import eu.etaxonomy.cdm.model.name.NonViralName;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
/**
* Superclass for the primary CDM classes that can be referenced from outside via LSIDs and contain a simple generated title string as a label for human reading.
"protectedTitleCache",
"rights",
"extensions",
+ "credits",
"sources"
})
@MappedSuperclass
@OneToMany(fetch = FetchType.LAZY)
@Cascade({CascadeType.SAVE_UPDATE})
private Set<Rights> rights = new HashSet<Rights>();
+
+ @XmlElementWrapper(name = "Credits")
+ @XmlElement(name = "Credit")
+ @IndexColumn(name="sortIndex", base = 0)
+ @OneToMany(fetch = FetchType.LAZY)
+ @Cascade({CascadeType.SAVE_UPDATE})
+ private List<Credit> credits = new ArrayList<Credit>();
@XmlElementWrapper(name = "Extensions")
@XmlElement(name = "Extension")
/* (non-Javadoc)
* @see eu.etaxonomy.cdm.model.common.IIdentifiableEntity#getTitleCache()
*/
+ //@Transient
public String getTitleCache(){
if (protectedTitleCache){
return this.titleCache;
this.rights.remove(right);
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.model.common.IIdentifiableEntity#getCredits()
+ */
+ public List<Credit> getCredits() {
+ return this.credits;
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.model.common.IIdentifiableEntity#getCredits(int)
+ */
+ public Credit getCredits(int index){
+ return this.credits.get(index);
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.model.common.IIdentifiableEntity#addCredit(eu.etaxonomy.cdm.model.common.Credit)
+ */
+ public void addCredit(Credit credit){
+ this.credits.add(credit);
+ }
+
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.model.common.IIdentifiableEntity#addCredit(eu.etaxonomy.cdm.model.common.Credit, int)
+ */
+ public void addCredit(Credit credit, int index){
+ this.credits.add(index, credit);
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.model.common.IIdentifiableEntity#removeCredit(eu.etaxonomy.cdm.model.common.Credit)
+ */
+ public void removeCredit(Credit credit){
+ this.credits.remove(credit);
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.model.common.IIdentifiableEntity#removeCredit(int)
+ */
+ public void removeCredit(int index){
+ this.credits.remove(index);
+ }
+
+
/* (non-Javadoc)
* @see eu.etaxonomy.cdm.model.common.IIdentifiableEntity#getExtensions()
*/
// TODO: Avoid using instanceof operator
// Use Class.getDeclaredMethod() instead to find out whether class has getNameCache() method?
- if ((identifiableEntity instanceof NonViralName) && (this instanceof NonViralName)) {
-
- String thisNameCache = ((NonViralName<?>)this).getNameCache();
- String specifiedNameCache = ((NonViralName<?>)identifiableEntity).getNameCache();
+ // Compare name cache
+ String specifiedNameCache = "";
+ String thisNameCache = "";
+
+ if(identifiableEntity instanceof NonViralName) {
+ specifiedNameCache = ((NonViralName<?>)identifiableEntity).getNameCache();
+ } else if(identifiableEntity instanceof TaxonBase) {
+ TaxonNameBase<?,?> taxonNameBase= ((TaxonBase)identifiableEntity).getName();
+ specifiedNameCache = ((NonViralName<?>)taxonNameBase).getNameCache();
+ }
+
+ if(this instanceof NonViralName) {
+ thisNameCache = ((NonViralName<?>)this).getNameCache();
+ } else if(this instanceof TaxonBase) {
+ TaxonNameBase<?,?> taxonNameBase= ((TaxonBase)this).getName();
+ thisNameCache = ((NonViralName<?>)taxonNameBase).getNameCache();
+ }
+
+ if (!specifiedNameCache.equals("") && !thisNameCache.equals("")) {
result = thisNameCache.compareTo(specifiedNameCache);
}
- // Compare the title cache if name cache is equal
+ // Compare title cache
if (result == 0) {
String thisTitleCache = getTitleCache();
String specifiedTitleCache = identifiableEntity.getTitleCache();
result = thisTitleCache.compareTo(specifiedTitleCache);
-
}
return result;
}
+
//****************** CLONE ************************************************/
/* (non-Javadoc)