X-Git-Url: https://dev.e-taxonomy.eu/gitweb/cdmlib.git/blobdiff_plain/17f0cc4b15eabb34717d24ef162171782c14679a..ad19055268784af0658b8f9db4a5a6111a1c1f4b:/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/WorkingSet.java diff --git a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/WorkingSet.java b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/WorkingSet.java index 0bac724a2b..0a761a8b97 100644 --- a/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/WorkingSet.java +++ b/cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/WorkingSet.java @@ -10,17 +10,23 @@ package eu.etaxonomy.cdm.model.description; +import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; +import java.util.Map.Entry; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Transient; +import javax.validation.constraints.NotNull; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -37,9 +43,8 @@ import org.hibernate.envers.Audited; import eu.etaxonomy.cdm.model.common.AnnotatableEntity; import eu.etaxonomy.cdm.model.common.Language; +import eu.etaxonomy.cdm.model.common.LanguageString; import eu.etaxonomy.cdm.model.common.Representation; -import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; -import eu.etaxonomy.cdm.model.taxon.TaxonNode; /** * @@ -62,9 +67,8 @@ import eu.etaxonomy.cdm.model.taxon.TaxonNode; @Entity @Audited -public class WorkingSet extends AnnotatableEntity { +public class WorkingSet extends AnnotatableEntity { private static final long serialVersionUID = 3256448866757415686L; - @SuppressWarnings("unused") private static final Logger logger = Logger.getLogger(WorkingSet.class); @XmlElementWrapper(name = "Representations") @@ -85,8 +89,14 @@ public class WorkingSet extends AnnotatableEntity { @XmlIDREF @XmlSchemaType(name = "IDREF") @ManyToMany(fetch = FetchType.LAZY) + @JoinTable( + name="WorkingSet_DescriptionBase", + joinColumns=@JoinColumn(name="WorkingSet_id"), + inverseJoinColumns=@JoinColumn(name="descriptions_id") + ) @Cascade(CascadeType.SAVE_UPDATE) - private Set descriptions = new HashSet(); + @NotNull + private Set descriptions = new HashSet(); /** * Class constructor: creates a new empty working set instance. @@ -214,7 +224,7 @@ public class WorkingSet extends AnnotatableEntity { public FeatureTree getDescriptiveSystem() { return descriptiveSystem; } - protected void setDescriptiveSystem(FeatureTree descriptiveSystem) { + public void setDescriptiveSystem(FeatureTree descriptiveSystem) { this.descriptiveSystem = descriptiveSystem; } @@ -222,10 +232,10 @@ public class WorkingSet extends AnnotatableEntity { * Returns the {@link DescriptionBase descriptions} of * this working set. * - * @see #addDescription(S) - * @see #removeDescription(S) + * @see #addDescription(DescriptionBase) + * @see #removeDescription(DescriptionBase) */ - public Set getDescriptions() { + public Set getDescriptions() { return descriptions; } @@ -235,25 +245,68 @@ public class WorkingSet extends AnnotatableEntity { * working set. * * @param description the description to be added to this working set - * @see #getDescriptions() - * @see WorkingSet#addDescription(S) + * @see #getDescriptions() + * @see WorkingSet#addDescription(DescriptionBase) */ - public void addDescription(S description) { - logger.debug("addDescription"); - this.descriptions.add(description); + public boolean addDescription(DescriptionBase description) { + boolean result = this.descriptions.add(description); + if (! description.getWorkingSets().contains(this)){ + description.addWorkingSet(this); + } + return result; } /** * Removes one element from the set of {@link #getDescriptions() descriptions} involved * in this working set.
* - * @param description the description which should be removed - * @see #getDescriptions() - * @see #addDescription(S) - * @see WorkingSet#removeDescription(S) + * @param description the description which should be removed + * @see #getDescriptions() + * @see #addDescription(DescriptionBase) + * @see WorkingSet#removeDescription(DescriptionBase) */ - public void removeDescription(S description) { - this.descriptions.remove(description); + public boolean removeDescription(DescriptionBase description) { + boolean result = this.descriptions.remove(description); + if (description.getWorkingSets().contains(this)){ + description.removeWorkingSet(this); + } + return result; + } + + //*********************** CLONE ********************************************************/ + + /** + * Clones this WorkingSet. This is a shortcut that enables to create + * a new instance that differs only slightly from this WorkingSet by + * modifying only some of the attributes. + * The descriptions and the descriptive system are the same, the representations + * are cloned. + * + * @see eu.etaxonomy.cdm.model.common.AnnotatableEntity#clone() + * @see java.lang.Object#clone() + */ + @Override + public Object clone() { + WorkingSet result; + try { + result = (WorkingSet)super.clone(); + result.descriptions = new HashSet(); + + for (DescriptionBase desc: this.descriptions){ + result.addDescription(desc); + } + + result.representations = new HashSet(); + for (Representation rep : this.representations){ + result.addRepresentation((Representation)rep.clone()); + } + + return result; + }catch (CloneNotSupportedException e) { + logger.warn("Object does not implement cloneable"); + e.printStackTrace(); + return null; + } } }