import eu.etaxonomy.cdm.jaxb.FormattedTextAdapter;
import eu.etaxonomy.cdm.jaxb.LSIDAdapter;
import eu.etaxonomy.cdm.model.media.Rights;
+import eu.etaxonomy.cdm.model.name.BotanicalName;
import eu.etaxonomy.cdm.model.name.NonViralName;
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
import eu.etaxonomy.cdm.model.reference.Reference;
@XmlElement(name = "TitleCache", required = true)
@XmlJavaTypeAdapter(FormattedTextAdapter.class)
- @Column(length=255, name="titleCache")
+ @Column(name="titleCache")
@Match(value=MatchMode.CACHE, cacheReplaceMode=ReplaceMode.ALL)
@NotEmpty(groups = Level2.class) // implictly NotNull
@Size(max = 800) //see #1592
@NotNull
private Set<Extension> extensions = new HashSet<Extension>();
+ @XmlElementWrapper(name = "Identifiers", nillable = true)
+ @XmlElement(name = "Identifier")
+ @OneToMany(fetch = FetchType.LAZY, orphanRemoval=true)
+ @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE, CascadeType.DELETE})
+ @Merge(MergeMode.ADD_CLONE)
+ @NotNull
+ private Set<Identifier> identifiers = new HashSet<Identifier>();
+
@XmlElementWrapper(name = "Sources", nillable = true)
@XmlElement(name = "IdentifiableSource")
@OneToMany(fetch = FetchType.LAZY, orphanRemoval=true)
protected void initListener(){
PropertyChangeListener listener = new PropertyChangeListener() {
@Override
- public void propertyChange(PropertyChangeEvent e) {
- if (!e.getPropertyName().equals("titleCache") && !e.getPropertyName().equals("cacheStrategy") && ! isProtectedTitleCache()){
+ public void propertyChange(PropertyChangeEvent ev) {
+ if (!ev.getPropertyName().equals("titleCache") && !ev.getPropertyName().equals("cacheStrategy") && ! isProtectedTitleCache()){
titleCache = null;
}
}
//******************************** CACHE *****************************************************/
-
- /* (non-Javadoc)
- * @see eu.etaxonomy.cdm.model.common.IIdentifiableEntity#getTitleCache()
- */
// @Transient - must not be transient, since this property needs to to be included in all serializations produced by the remote layer
@Override
public String getTitleCache(){
@Deprecated
@Override
public void setTitleCache(String titleCache){
- //TODO shouldn't we call setTitleCache(String, boolean),but is this conformant with Java Bean Specification?
+ //TODO shouldn't we call setTitleCache(String, boolean),but is this conformant with Java Bean Specification?
this.titleCache = getTruncatedCache(titleCache);
}
getCredits().remove(index);
}
+ @Override
+ public Set<Identifier> getIdentifiers(){
+ if(this.identifiers == null) {
+ this.identifiers = new HashSet<Identifier>();
+ }
+ return this.identifiers;
+ }
+ /**
+ * @param type
+ * @return a Set of extension value strings
+ */
+ public Set<String> getIdentifiers(DefinedTerm type){
+ return getIdentifiers(type.getUuid());
+ }
+ /**
+ * @param extensionTypeUuid
+ * @return a Set of extension value strings
+ */
+ public Set<String> getIdentifiers(UUID identifierTypeUuid){
+ Set<String> result = new HashSet<String>();
+ for (Identifier identifier : getIdentifiers()){
+ if (identifier.getType().getUuid().equals(identifierTypeUuid)){
+ result.add(identifier.getIdentifier());
+ }
+ }
+ return result;
+ }
+
+ public Identifier addIdentifier(String identifier, DefinedTerm identifierType){
+ Identifier result = Identifier.NewInstance(this, identifier, identifierType);
+ return result;
+ }
+
+ @Override
+ public void addIdentifier(Identifier identifier){
+ if (identifier != null){
+ identifier.setIdentifiedObj(this);
+ getIdentifiers().add(identifier);
+ }
+ }
+ @Override
+ public void removeIdentifier(Identifier identifier){
+ if (identifier != null){
+ logger.warn("TODO");
+// identifier.setExtendedObj(null);
+ getIdentifiers().remove(identifier);
+ }
+ }
+
@Override
public Set<Extension> getExtensions(){
if(extensions == null) {
}
}
+ @Override
+ public void addSources(Set<IdentifiableSource> sources) {
+ if (sources != null){
+ for (IdentifiableSource source: sources){
+ IdentifiableEntity<?> oldSourcedObj = source.getSourcedObj();
+ if (oldSourcedObj != null && oldSourcedObj != this){
+ oldSourcedObj.getSources().remove(source);
+ }
+ getSources().add(source);
+ source.setSourcedObj(this);
+ }
+ }
+ }
+
+ @Override
+ public void removeSources() {
+ this.sources.clear();
+ }
+
@Override
public IdentifiableSource addSource(OriginalSourceType type, String id, String idNamespace, Reference citation, String microCitation) {
if (id == null && idNamespace == null && citation == null && microCitation == null){
addSource(source);
return source;
}
-
-
+
+
@Override
public IdentifiableSource addImportSource(String id, String idNamespace, Reference<?> citation, String microCitation) {
if (id == null && idNamespace == null && citation == null && microCitation == null){
if(identifiableEntity instanceof NonViralName) {
specifiedNameCache = HibernateProxyHelper.deproxy(identifiableEntity, NonViralName.class).getNameCache();
specifiedTitleCache = identifiableEntity.getTitleCache();
+ if (identifiableEntity instanceof BotanicalName){
+ if (((BotanicalName)identifiableEntity).isAutonym()){
+ boolean isProtected = false;
+ String oldNameCache = ((BotanicalName) identifiableEntity).getNameCache();
+ if ( ((BotanicalName)identifiableEntity).isProtectedNameCache()){
+ isProtected = true;
+ }
+ ((BotanicalName)identifiableEntity).setProtectedNameCache(false);
+ ((BotanicalName)identifiableEntity).setNameCache(null, false);
+ specifiedNameCache = ((BotanicalName) identifiableEntity).getNameCache();
+ ((BotanicalName)identifiableEntity).setNameCache(oldNameCache, isProtected);
+
+ }
+ }
} else if(identifiableEntity instanceof TaxonBase) {
TaxonBase taxonBase = HibernateProxyHelper.deproxy(identifiableEntity, TaxonBase.class);
if(this.isInstanceOf(NonViralName.class)) {
thisNameCache = HibernateProxyHelper.deproxy(this, NonViralName.class).getNameCache();
thisTitleCache = getTitleCache();
+
+ if (this instanceof BotanicalName){
+ if (((BotanicalName)this).isAutonym()){
+ boolean isProtected = false;
+ String oldNameCache = ((BotanicalName) this).getNameCache();
+ if ( ((BotanicalName)this).isProtectedNameCache()){
+ isProtected = true;
+ }
+ ((BotanicalName)this).setProtectedNameCache(false);
+ ((BotanicalName)this).setNameCache(null, false);
+ thisNameCache = ((BotanicalName) this).getNameCache();
+ ((BotanicalName)this).setNameCache(oldNameCache, isProtected);
+ }
+ }
} else if(this.isInstanceOf(TaxonBase.class)) {
TaxonNameBase<?,?> taxonNameBase= HibernateProxyHelper.deproxy(this, TaxonBase.class).getName();
NonViralName nonViralName = HibernateProxyHelper.deproxy(taxonNameBase, NonViralName.class);
// Compare name cache of taxon names
+
+
if (!specifiedNameCache.equals("") && !thisNameCache.equals("")) {
result = thisNameCache.compareTo(specifiedNameCache);
}
@Override
public String generateTitle() {
- if (cacheStrategy == null){
+ if (getCacheStrategy() == null){
//logger.warn("No CacheStrategy defined for "+ this.getClass() + ": " + this.getUuid());
return this.getClass() + ": " + this.getUuid();
}else{
- return cacheStrategy.getTitleCache(this);
+ return getCacheStrategy().getTitleCache(this);
}
}