minor
[cdmlib.git] / cdmlib-model / src / main / java / eu / etaxonomy / cdm / model / description / MediaKey.java
index 3036e4c5d167687612d2e3697aa9bd108242d2b9..5388848f3aa3ec56975ebe0218c4c540ebb77996 100644 (file)
@@ -17,6 +17,7 @@ import javax.persistence.FetchType;
 import javax.persistence.JoinColumn;
 import javax.persistence.JoinTable;
 import javax.persistence.ManyToMany;
+import javax.validation.constraints.NotNull;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
@@ -27,13 +28,14 @@ import javax.xml.bind.annotation.XmlSchemaType;
 import javax.xml.bind.annotation.XmlType;
 
 import org.apache.log4j.Logger;
+import org.hibernate.annotations.Cascade;
+import org.hibernate.annotations.CascadeType;
 import org.hibernate.envers.Audited;
 import org.hibernate.search.annotations.Indexed;
 
 import eu.etaxonomy.cdm.model.common.Representation;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.media.Media;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 
 /**
@@ -61,7 +63,6 @@ import eu.etaxonomy.cdm.model.taxon.Taxon;
 @Indexed(index = "eu.etaxonomy.cdm.model.media.Media")
 @Audited
 public class MediaKey extends Media implements IIdentificationKey{
-
        private static final long serialVersionUID = -29095811051894471L;
        @SuppressWarnings("unused")
        private static final Logger logger = Logger.getLogger(MediaKey.class);
@@ -71,6 +72,7 @@ public class MediaKey extends Media implements IIdentificationKey{
        @XmlIDREF
        @XmlSchemaType(name = "IDREF")
        @ManyToMany(fetch = FetchType.LAZY)
+       @NotNull
        private Set<Taxon> coveredTaxa = new HashSet<Taxon>();
        
        @XmlElementWrapper( name = "GeographicalScope")
@@ -78,6 +80,8 @@ public class MediaKey extends Media implements IIdentificationKey{
        @XmlIDREF
        @XmlSchemaType(name = "IDREF")
        @ManyToMany(fetch = FetchType.LAZY)
+       @JoinTable(name="MediaKey_NamedArea")
+       @NotNull
        private Set<NamedArea> geographicalScope = new HashSet<NamedArea>();
        
        @XmlElementWrapper(name = "TaxonomicScope")
@@ -90,6 +94,7 @@ public class MediaKey extends Media implements IIdentificationKey{
                joinColumns=@JoinColumn(name="mediaKey_fk"),
                inverseJoinColumns=@JoinColumn(name="taxon_fk")
        )
+       @NotNull
        private Set<Taxon> taxonomicScope = new HashSet<Taxon>();
        
        @XmlElementWrapper( name = "ScopeRestrictions")
@@ -97,6 +102,8 @@ public class MediaKey extends Media implements IIdentificationKey{
        @XmlIDREF
        @XmlSchemaType(name = "IDREF")
        @ManyToMany(fetch = FetchType.LAZY)
+       @JoinTable(name="MediaKey_Scope")
+       @NotNull
        private Set<Scope> scopeRestrictions = new HashSet<Scope>();
        
        @XmlElementWrapper( name = "KeyRepresentations")
@@ -104,6 +111,8 @@ public class MediaKey extends Media implements IIdentificationKey{
        @XmlIDREF
        @XmlSchemaType(name = "IDREF")
        @ManyToMany(fetch = FetchType.LAZY)
+       @Cascade({CascadeType.SAVE_UPDATE, CascadeType.MERGE,CascadeType.DELETE, CascadeType.DELETE_ORPHAN})
+       @NotNull
        private Set<Representation> keyRepresentations = new HashSet<Representation>();
        
        /** 
@@ -126,6 +135,9 @@ public class MediaKey extends Media implements IIdentificationKey{
         * <i>this</i> identification key.
         */
        public Set<Taxon> getCoveredTaxa() {
+               if(coveredTaxa == null) {
+                       this.coveredTaxa = new HashSet<Taxon>();
+               }
                return coveredTaxa;
        }
        /**
@@ -163,6 +175,9 @@ public class MediaKey extends Media implements IIdentificationKey{
         * data where <i>this</i> identification key is valid.
         */
        public Set<NamedArea> getGeographicalScope() {
+               if(geographicalScope == null) {
+                       this.geographicalScope = new HashSet<NamedArea>();
+               }
                return geographicalScope;
        }
        
@@ -193,6 +208,9 @@ public class MediaKey extends Media implements IIdentificationKey{
         * scope of <i>this</i> identification key 
         */
        public Set<Taxon> getTaxonomicScope() {
+               if(taxonomicScope == null) {
+                       this.taxonomicScope = new HashSet<Taxon>();
+               }
                return taxonomicScope;
        }
        
@@ -224,6 +242,9 @@ public class MediaKey extends Media implements IIdentificationKey{
         * <i>this</i> identification key 
         */
        public Set<Representation> getKeyRepresentations() {
+               if(keyRepresentations == null) {
+                       this.keyRepresentations = new HashSet<Representation>();
+               }
                return keyRepresentations;
        }
        
@@ -255,6 +276,9 @@ public class MediaKey extends Media implements IIdentificationKey{
         * <i>this</i> identification key 
         */
        public Set<Scope> getScopeRestrictions() {
+               if(scopeRestrictions == null) {
+                       this.scopeRestrictions = new HashSet<Scope>();
+               }
                return scopeRestrictions;
        }