001/*
002 * Copyright 2014 Global Biodiversity Information Facility (GBIF)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.gbif.api.model.registry.eml;
017
018import org.gbif.api.model.registry.eml.curatorial.CuratorialUnitComposite;
019import org.gbif.api.vocabulary.PreservationMethodType;
020
021import java.io.Serializable;
022import java.util.ArrayList;
023import java.util.List;
024
025import com.google.common.base.Objects;
026import com.google.common.collect.Lists;
027
028/**
029 * Collection data for the Dataset.
030 */
031public class Collection implements Serializable {
032
033  private static final long serialVersionUID = 3259062777751953305L;
034
035  private String name;
036  private String identifier;
037  private String parentIdentifier;
038  private PreservationMethodType specimenPreservationMethod;
039  private List<CuratorialUnitComposite> curatorialUnits = Lists.newArrayList();
040
041  public Collection() {
042  }
043
044  public Collection(
045    String name,
046    String parentIdentifier,
047    String identifier,
048    PreservationMethodType specimenPreservationMethod,
049    List<CuratorialUnitComposite> curatorialUnits
050  ) {
051    this.name = name;
052    this.parentIdentifier = parentIdentifier;
053    this.identifier = identifier;
054    this.specimenPreservationMethod = specimenPreservationMethod;
055    this.curatorialUnits = curatorialUnits;
056  }
057
058  /**
059   * The URI (LSID or URL) of the collection. In RDF, used as URI of the collection resource.
060   *
061   * @return the collection identifier
062   */
063  public String getIdentifier() {
064    return identifier;
065  }
066
067  public void setIdentifier(String identifier) {
068    this.identifier = identifier;
069  }
070
071  /**
072   * The official name of the Collection in the local language.
073   *
074   * @return the collection name.
075   */
076  public String getName() {
077    return name;
078  }
079
080  public void setName(String name) {
081    this.name = name;
082  }
083
084  /**
085   * The quantitative descriptor (number of specimens, samples or batches). The actual quantification could be covered
086   * by 1) an exact number of “JGI-units” in the collection plus a measure of uncertainty (+/- x); 2) a range of
087   * numbers
088   * (x to x), with the lower value representing an exact number, when the higher value is omitted. The discussion
089   * concluded that the quantification should encompass all specimens, not only those that have not yet been digitised.
090   * This is to avoid having to update the numbers too often. The number of non-public data (not digitised or not
091   * accessible) can be calculated from the GBIF numbers as opposed to the JGTI-data.
092   *
093   * @return the list of curatorial units
094   */
095  public List<CuratorialUnitComposite> getCuratorialUnits() {
096    return curatorialUnits;
097  }
098
099  public void setCuratorialUnits(List<CuratorialUnitComposite> curatorialUnits) {
100    this.curatorialUnits = curatorialUnits;
101  }
102
103  /**
104   * The identifier for the parent collection for this sub-collection. Enables a hierarchy of collections and sub
105   * collections to be built.
106   *
107   * @return the parent collection identifier
108   */
109  public String getParentIdentifier() {
110    return parentIdentifier;
111  }
112
113  public void setParentIdentifier(String parentIdentifier) {
114    this.parentIdentifier = parentIdentifier;
115  }
116
117  /**
118   * Picklist keyword indicating the process or technique used to prevent physical deterioration of non-living
119   * collections. Expected to contain an instance from the Specimen Preservation Method Type Term vocabulary.
120   *
121   * @return the preservation method type
122   */
123  public PreservationMethodType getSpecimenPreservationMethod() {
124    return specimenPreservationMethod;
125  }
126
127  public void setSpecimenPreservationMethod(PreservationMethodType specimenPreservationMethod) {
128    this.specimenPreservationMethod = specimenPreservationMethod;
129  }
130
131  /**
132   * Adds a CuratorialUnitComposite to the Collection's list of CuratorialUnitComposit.
133   *
134   * @param curatorialUnitComposite curatorial unit
135   */
136  public void addCuratorialUnitComposite(CuratorialUnitComposite curatorialUnitComposite) {
137    if (curatorialUnits == null) {
138      List<CuratorialUnitComposite> list = new ArrayList<CuratorialUnitComposite>();
139      list.add(curatorialUnitComposite);
140      curatorialUnits = list;
141    }
142    curatorialUnits.add(curatorialUnitComposite);
143  }
144
145  @Override
146  public boolean equals(Object obj) {
147    if (this == obj) {
148      return true;
149    }
150    if (!(obj instanceof Collection)) {
151      return false;
152    }
153
154    final Collection other = (Collection) obj;
155    return Objects.equal(this.name, other.name)
156           && Objects.equal(this.identifier, other.identifier)
157           && Objects.equal(this.parentIdentifier, other.parentIdentifier)
158           && Objects.equal(this.specimenPreservationMethod, other.specimenPreservationMethod)
159           && Objects.equal(this.curatorialUnits, other.curatorialUnits);
160  }
161
162  @Override
163  public int hashCode() {
164    return Objects
165      .hashCode(name, identifier, parentIdentifier, specimenPreservationMethod,
166        curatorialUnits);
167  }
168
169  @Override
170  public String toString() {
171    return "Collection{" +
172           "name='" + name + '\'' +
173           ", identifier='" + identifier + '\'' +
174           ", parentIdentifier='" + parentIdentifier + '\'' +
175           ", specimenPreservationMethod=" + specimenPreservationMethod +
176           ", curatorialUnits=" + curatorialUnits +
177           '}';
178  }
179
180}