001/*
002 * Copyright 2020 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;
024import java.util.Objects;
025import java.util.StringJoiner;
026
027/**
028 * Collection data for the Dataset.
029 */
030public class Collection implements Serializable {
031
032  private static final long serialVersionUID = 3259062777751953305L;
033
034  private String name;
035  private String identifier;
036  private String parentIdentifier;
037  private PreservationMethodType specimenPreservationMethod;
038  private List<CuratorialUnitComposite> curatorialUnits = new ArrayList<>();
039
040  public Collection() {
041  }
042
043  public Collection(
044    String name,
045    String parentIdentifier,
046    String identifier,
047    PreservationMethodType specimenPreservationMethod,
048    List<CuratorialUnitComposite> curatorialUnits
049  ) {
050    this.name = name;
051    this.parentIdentifier = parentIdentifier;
052    this.identifier = identifier;
053    this.specimenPreservationMethod = specimenPreservationMethod;
054    this.curatorialUnits = curatorialUnits;
055  }
056
057  /**
058   * The URI (LSID or URL) of the collection. In RDF, used as URI of the collection resource.
059   *
060   * @return the collection identifier
061   */
062  public String getIdentifier() {
063    return identifier;
064  }
065
066  public void setIdentifier(String identifier) {
067    this.identifier = identifier;
068  }
069
070  /**
071   * The official name of the Collection in the local language.
072   *
073   * @return the collection name.
074   */
075  public String getName() {
076    return name;
077  }
078
079  public void setName(String name) {
080    this.name = name;
081  }
082
083  /**
084   * The quantitative descriptor (number of specimens, samples or batches). The actual quantification could be covered
085   * by 1) an exact number of “JGI-units” in the collection plus a measure of uncertainty (+/- x); 2) a range of
086   * numbers
087   * (x to x), with the lower value representing an exact number, when the higher value is omitted. The discussion
088   * concluded that the quantification should encompass all specimens, not only those that have not yet been digitised.
089   * This is to avoid having to update the numbers too often. The number of non-public data (not digitised or not
090   * accessible) can be calculated from the GBIF numbers as opposed to the JGTI-data.
091   *
092   * @return the list of curatorial units
093   */
094  public List<CuratorialUnitComposite> getCuratorialUnits() {
095    return curatorialUnits;
096  }
097
098  public void setCuratorialUnits(List<CuratorialUnitComposite> curatorialUnits) {
099    this.curatorialUnits = curatorialUnits;
100  }
101
102  /**
103   * The identifier for the parent collection for this sub-collection. Enables a hierarchy of collections and sub
104   * collections to be built.
105   *
106   * @return the parent collection identifier
107   */
108  public String getParentIdentifier() {
109    return parentIdentifier;
110  }
111
112  public void setParentIdentifier(String parentIdentifier) {
113    this.parentIdentifier = parentIdentifier;
114  }
115
116  /**
117   * Picklist keyword indicating the process or technique used to prevent physical deterioration of non-living
118   * collections. Expected to contain an instance from the Specimen Preservation Method Type Term vocabulary.
119   *
120   * @return the preservation method type
121   */
122  public PreservationMethodType getSpecimenPreservationMethod() {
123    return specimenPreservationMethod;
124  }
125
126  public void setSpecimenPreservationMethod(PreservationMethodType specimenPreservationMethod) {
127    this.specimenPreservationMethod = specimenPreservationMethod;
128  }
129
130  /**
131   * Adds a CuratorialUnitComposite to the Collection's list of CuratorialUnitComposit.
132   *
133   * @param curatorialUnitComposite curatorial unit
134   */
135  public void addCuratorialUnitComposite(CuratorialUnitComposite curatorialUnitComposite) {
136    if (curatorialUnits == null) {
137      List<CuratorialUnitComposite> list = new ArrayList<CuratorialUnitComposite>();
138      list.add(curatorialUnitComposite);
139      curatorialUnits = list;
140    }
141    curatorialUnits.add(curatorialUnitComposite);
142  }
143
144  @Override
145  public boolean equals(Object o) {
146    if (this == o) {
147      return true;
148    }
149    if (o == null || getClass() != o.getClass()) {
150      return false;
151    }
152    Collection that = (Collection) o;
153    return Objects.equals(name, that.name) &&
154      Objects.equals(identifier, that.identifier) &&
155      Objects.equals(parentIdentifier, that.parentIdentifier) &&
156      specimenPreservationMethod == that.specimenPreservationMethod &&
157      Objects.equals(curatorialUnits, that.curatorialUnits);
158  }
159
160  @Override
161  public int hashCode() {
162    return Objects
163      .hash(name, identifier, parentIdentifier, specimenPreservationMethod, curatorialUnits);
164  }
165
166  @Override
167  public String toString() {
168    return new StringJoiner(", ", Collection.class.getSimpleName() + "[", "]")
169      .add("name='" + name + "'")
170      .add("identifier='" + identifier + "'")
171      .add("parentIdentifier='" + parentIdentifier + "'")
172      .add("specimenPreservationMethod=" + specimenPreservationMethod)
173      .add("curatorialUnits=" + curatorialUnits)
174      .toString();
175  }
176}