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.common;
017
018import org.gbif.api.vocabulary.MediaType;
019
020import java.net.URI;
021import java.util.Date;
022import javax.annotation.Nullable;
023import javax.validation.constraints.NotNull;
024
025import com.google.common.base.Objects;
026import org.codehaus.jackson.annotate.JsonProperty;
027
028/**
029 * Metadata for a multimedia object representing an image, video or audio file.
030 * Based on DublinCore and the Simple Multimedia dwc archive extension:
031 * @see <a href="http://rs.gbif.org/extension/gbif/1.0/multimedia.xml">Multimedia Definition</a>
032 */
033public class MediaObject {
034  private MediaType type;
035  private String format;
036  private URI identifier;
037  private URI references;
038  private String title;
039  private String description;
040  private String source;
041  private String audience;
042  private Date created;
043  private String creator;
044  private String contributor;
045  private String publisher;
046  private String license;
047  private String rightsHolder;
048
049  /**
050   * @return mime type of the file
051   */
052  public String getFormat() {
053    return format;
054  }
055
056  public void setFormat(String format) {
057    this.format = format;
058  }
059
060  /**
061   * The date and time this media item was taken.
062   * <blockquote>
063   * <p>
064   * <i>Example:</i> 2010-09-29.
065   * </p>
066   * </blockquote>
067   *
068   * @return the created
069   */
070  @Nullable
071  public Date getCreated() {
072    return created;
073  }
074
075  /**
076   * @param created the created to set
077   */
078  public void setCreated(Date created) {
079    this.created = created;
080  }
081
082  /**
083   * The person that created the media item.
084   * <blockquote>
085   * <p>
086   * <i>Example:</i> David Remsen.
087   * </p>
088   * </blockquote>
089   *
090   * @return the creator
091   */
092  @Nullable
093  public String getCreator() {
094    return creator;
095  }
096
097  /**
098   * @param creator the creator to set
099   */
100  public void setCreator(String creator) {
101    this.creator = creator;
102  }
103
104  /**
105   * A longer description for this media item.
106   * <blockquote>
107   * <p>
108   * <i>Example:</i> Female Tachycineta albiventer photographed in the Amazon, Brazil, in November 2010.
109   * </p>
110   * </blockquote>
111   *
112   * @return the description
113   */
114  @Nullable
115  public String getDescription() {
116    return description;
117  }
118
119  /**
120   * @param description the description to set
121   */
122  public void setDescription(String description) {
123    this.description = description;
124  }
125
126  @NotNull
127  public MediaType getType() {
128    return type;
129  }
130
131  public void setType(MediaType type) {
132    this.type = type;
133  }
134
135  /**
136   * The public URL that identifies and locates the media item.
137   * <blockquote>
138   * <p>
139   * <i>Example:</i> <a
140   * href="http://farm6.static.flickr.com/5127/5242866958_98afd8cbce_o.jpg">http://farm6.static.flickr.com/5127/5242866958_98afd8cbce_o.jpg</a>
141   * </p>
142   * </blockquote>
143   */
144  @NotNull
145  @JsonProperty("identifier")
146  public URI getIdentifier() {
147    return identifier;
148  }
149
150  public void setIdentifier(URI identifier) {
151    this.identifier = identifier;
152  }
153
154  /**
155   * License for this media item.
156   * Can be text or a identifier like creative commons uses.
157   * <blockquote>
158   * <p>
159   * <i>Example:</i> <a
160   * href="http://creativecommons.org/licenses/by-nc-sa/2.0/deed.en">http://creativecommons.org/licenses
161   * /by-nc-sa/2.0/deed.en</a>
162   * </p>
163   * </blockquote>
164   *
165   * @return the license
166   */
167  @Nullable
168  public String getLicense() {
169    return license;
170  }
171
172  /**
173   * @param license the license to set
174   */
175  public void setLicense(String license) {
176    this.license = license;
177  }
178
179  /**
180   * @return link to html webpage with the media item on
181   */
182  public URI getReferences() {
183    return references;
184  }
185
186  public void setReferences(URI references) {
187    this.references = references;
188  }
189
190  /**
191   * An entity responsible for making the media item available.
192   * <blockquote>
193   * <p>
194   * <i>Example:</i> Encyclopedia of Life.
195   * </p>
196   * </blockquote>
197   *
198   * @return the publisher
199   */
200  @Nullable
201  public String getPublisher() {
202    return publisher;
203  }
204
205  /**
206   * @param publisher the publisher to set
207   */
208  public void setPublisher(String publisher) {
209    this.publisher = publisher;
210  }
211
212  /**
213   * The media item title.
214   * <blockquote>
215   * <p>
216   * <i>Example:</i> Andorinha-do-rio (Tachycineta albiventer).
217   * </p>
218   * </blockquote>
219   *
220   * @return the title.
221   */
222  @Nullable
223  public String getTitle() {
224    return title;
225  }
226
227  /**
228   * @param title the title to set
229   */
230  public void setTitle(String title) {
231    this.title = title;
232  }
233
234  public String getSource() {
235    return source;
236  }
237
238  public void setSource(String source) {
239    this.source = source;
240  }
241
242  public String getAudience() {
243    return audience;
244  }
245
246  public void setAudience(String audience) {
247    this.audience = audience;
248  }
249
250  public String getContributor() {
251    return contributor;
252  }
253
254  public void setContributor(String contributor) {
255    this.contributor = contributor;
256  }
257
258  public String getRightsHolder() {
259    return rightsHolder;
260  }
261
262  public void setRightsHolder(String rightsHolder) {
263    this.rightsHolder = rightsHolder;
264  }
265
266  @Override
267  public boolean equals(Object obj) {
268    if (this == obj) {
269      return true;
270    }
271    if (!(obj instanceof MediaObject)) {
272      return false;
273    }
274    MediaObject that = (MediaObject) obj;
275    return Objects.equal(this.identifier, that.identifier)
276           && Objects.equal(this.type, that.type)
277           && Objects.equal(this.format, that.format)
278           && Objects.equal(this.references, that.references)
279           && Objects.equal(this.title, that.title)
280           && Objects.equal(this.description, that.description)
281           && Objects.equal(this.license, that.license)
282           && Objects.equal(this.publisher, that.publisher)
283           && Objects.equal(this.source, that.source)
284           && Objects.equal(this.audience, that.audience)
285           && Objects.equal(this.contributor, that.contributor)
286           && Objects.equal(this.rightsHolder, that.rightsHolder)
287           && Objects.equal(this.creator, that.creator)
288           && Objects.equal(this.created, that.created);
289  }
290
291  @Override
292  public int hashCode() {
293    return Objects.hashCode(type,
294                            format, identifier,
295                            references,
296                            title,
297                            description,
298                            license,
299                            publisher,
300                            source,
301                            audience, contributor,
302                            rightsHolder,
303                            creator,
304                            created);
305  }
306
307  @Override
308  public String toString() {
309    return Objects.toStringHelper(this)
310      .add("type", type)
311      .add("format", format)
312      .add("identifier", identifier)
313      .add("references", references)
314      .add("title", title)
315      .add("description", description)
316      .add("license", license)
317      .add("publisher", publisher)
318      .add("source", source)
319      .add("audience", audience)
320      .add("contributor", contributor)
321      .add("rightsHolder", rightsHolder)
322      .add("creator", creator)
323      .add("created", created)
324      .toString();
325  }
326
327}