001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *     http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.gbif.api.model.common;
015
016import org.gbif.api.vocabulary.MediaType;
017
018import java.net.URI;
019import java.util.Date;
020import java.util.Objects;
021import java.util.StringJoiner;
022
023import javax.annotation.Nullable;
024import javax.validation.constraints.NotNull;
025
026import com.fasterxml.jackson.annotation.JsonProperty;
027
028import io.swagger.v3.oas.annotations.media.Schema;
029
030/**
031 * Metadata for a multimedia object representing an image, video or audio file.
032 * Based on DublinCore and the Simple Multimedia dwc archive extension:
033 *
034 * @see <a href="https://rs.gbif.org/terms/1.0/Multimedia">Multimedia Definition</a>
035 */
036public class MediaObject {
037  @Schema(
038    description = "The type of media object, based on the [Dublin Core types vocabulary](https://rs.gbif.org/vocabulary/dcterms/type)."
039  )
040  private MediaType type;
041  private String format;
042  private URI identifier;
043  private URI references;
044  private String title;
045  private String description;
046  private String source;
047  private String audience;
048  private Date created;
049  private String creator;
050  private String contributor;
051  private String publisher;
052  private String license;
053  private String rightsHolder;
054
055  /**
056   * @return mime type of the file
057   */
058  @Schema(description = "The format the image is exposed in.")
059  public String getFormat() {
060    return format;
061  }
062
063  public void setFormat(String format) {
064    this.format = format;
065  }
066
067  /**
068   * The date and time this media item was taken.
069   * <blockquote>
070   * <p>
071   * <i>Example:</i> 2010-09-29.
072   * </p>
073   * </blockquote>
074   *
075   * @return the created
076   */
077  @Schema(description = "The date and time this media item was created.")
078  @Nullable
079  public Date getCreated() {
080    return created;
081  }
082
083  /**
084   * @param created the created to set
085   */
086  public void setCreated(Date created) {
087    this.created = created;
088  }
089
090  /**
091   * The person that created the media item.
092   * <blockquote>
093   * <p>
094   * <i>Example:</i> David Remsen.
095   * </p>
096   * </blockquote>
097   *
098   * @return the creator
099   */
100  @Schema(description = "The person that created the media item.")
101  @Nullable
102  public String getCreator() {
103    return creator;
104  }
105
106  /**
107   * @param creator the creator to set
108   */
109  public void setCreator(String creator) {
110    this.creator = creator;
111  }
112
113  /**
114   * A longer description for this media item.
115   * <blockquote>
116   * <p>
117   * <i>Example:</i> Female Tachycineta albiventer photographed in the Amazon, Brazil, in November 2010.
118   * </p>
119   * </blockquote>
120   *
121   * @return the description
122   */
123  @Schema(description = "A longer description for this media item.")
124  @Nullable
125  public String getDescription() {
126    return description;
127  }
128
129  /**
130   * @param description the description to set
131   */
132  public void setDescription(String description) {
133    this.description = description;
134  }
135
136  @Schema(description = "The kind of media object.")
137  @NotNull
138  public MediaType getType() {
139    return type;
140  }
141
142  public void setType(MediaType type) {
143    this.type = type;
144  }
145
146  /**
147   * The public URL that identifies and locates the media item.
148   * <blockquote>
149   * <p>
150   * <i>Example:</i> <a
151   * href="http://farm6.static.flickr.com/5127/5242866958_98afd8cbce_o.jpg">http://farm6.static.flickr.com/5127/5242866958_98afd8cbce_o.jpg</a>
152   * </p>
153   * </blockquote>
154   */
155  @Schema(description = "The public URL that identifies and locates the media item.")
156  @NotNull
157  @JsonProperty("identifier")
158  public URI getIdentifier() {
159    return identifier;
160  }
161
162  public void setIdentifier(URI identifier) {
163    this.identifier = identifier;
164  }
165
166  /**
167   * Licence for this media item.
168   * Can be text or an identifier like Creative Commons uses.
169   * <blockquote>
170   * <p>
171   * <i>Example:</i> <a
172   * href="http://creativecommons.org/licenses/by-nc-sa/2.0/deed.en">http://creativecommons.org/licenses
173   * /by-nc-sa/2.0/deed.en</a>
174   * </p>
175   * </blockquote>
176   *
177   * @return the license
178   */
179  @Schema(description = "Licence for this media item.")
180  @Nullable
181  public String getLicense() {
182    return license;
183  }
184
185  /**
186   * @param license the license to set
187   */
188  public void setLicense(String license) {
189    this.license = license;
190  }
191
192  /**
193   * @return link to html webpage with the media item on
194   */
195  @Schema(description = "An HTML webpage that shows the image or its metadata.")
196  public URI getReferences() {
197    return references;
198  }
199
200  public void setReferences(URI references) {
201    this.references = references;
202  }
203
204  /**
205   * An entity responsible for making the media item available.
206   * <blockquote>
207   * <p>
208   * <i>Example:</i> Encyclopedia of Life.
209   * </p>
210   * </blockquote>
211   *
212   * @return the publisher
213   */
214  @Schema(description = "An entity responsible for making the media item available.")
215  @Nullable
216  public String getPublisher() {
217    return publisher;
218  }
219
220  /**
221   * @param publisher the publisher to set
222   */
223  public void setPublisher(String publisher) {
224    this.publisher = publisher;
225  }
226
227  /**
228   * The media item title.
229   * <blockquote>
230   * <p>
231   * <i>Example:</i> Andorinha-do-rio (Tachycineta albiventer).
232   * </p>
233   * </blockquote>
234   *
235   * @return the title.
236   */
237  @Schema(description = "The media item title.")
238  @Nullable
239  public String getTitle() {
240    return title;
241  }
242
243  /**
244   * @param title the title to set
245   */
246  public void setTitle(String title) {
247    this.title = title;
248  }
249
250  public String getSource() {
251    return source;
252  }
253
254  public void setSource(String source) {
255    this.source = source;
256  }
257
258  @Schema(description = "A class or description for whom the image is intended or useful.")
259  public String getAudience() {
260    return audience;
261  }
262
263  public void setAudience(String audience) {
264    this.audience = audience;
265  }
266
267  @Schema(description = "Any contributor in addition to the creator that helped in recording the media item.")
268  public String getContributor() {
269    return contributor;
270  }
271
272  public void setContributor(String contributor) {
273    this.contributor = contributor;
274  }
275
276  @Schema(description = "A person or organization owning or managing rights over the media item.")
277  public String getRightsHolder() {
278    return rightsHolder;
279  }
280
281  public void setRightsHolder(String rightsHolder) {
282    this.rightsHolder = rightsHolder;
283  }
284
285  @Override
286  public boolean equals(Object o) {
287    if (this == o) {
288      return true;
289    }
290    if (o == null || getClass() != o.getClass()) {
291      return false;
292    }
293    MediaObject that = (MediaObject) o;
294    return type == that.type &&
295      Objects.equals(format, that.format) &&
296      Objects.equals(identifier, that.identifier) &&
297      Objects.equals(references, that.references) &&
298      Objects.equals(title, that.title) &&
299      Objects.equals(description, that.description) &&
300      Objects.equals(source, that.source) &&
301      Objects.equals(audience, that.audience) &&
302      Objects.equals(created, that.created) &&
303      Objects.equals(creator, that.creator) &&
304      Objects.equals(contributor, that.contributor) &&
305      Objects.equals(publisher, that.publisher) &&
306      Objects.equals(license, that.license) &&
307      Objects.equals(rightsHolder, that.rightsHolder);
308  }
309
310  @Override
311  public int hashCode() {
312    return Objects
313      .hash(type, format, identifier, references, title, description, source, audience, created,
314        creator, contributor, publisher, license, rightsHolder);
315  }
316
317  @Override
318  public String toString() {
319    return new StringJoiner(", ", MediaObject.class.getSimpleName() + "[", "]")
320      .add("type=" + type)
321      .add("format='" + format + "'")
322      .add("identifier=" + identifier)
323      .add("references=" + references)
324      .add("title='" + title + "'")
325      .add("description='" + description + "'")
326      .add("source='" + source + "'")
327      .add("audience='" + audience + "'")
328      .add("created=" + created)
329      .add("creator='" + creator + "'")
330      .add("contributor='" + contributor + "'")
331      .add("publisher='" + publisher + "'")
332      .add("license='" + license + "'")
333      .add("rightsHolder='" + rightsHolder + "'")
334      .toString();
335  }
336}