View Javadoc
1   /*
2    * Licensed to The Apereo Foundation under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional
4    * information regarding copyright ownership.
5    *
6    *
7    * The Apereo Foundation licenses this file to you under the Educational
8    * Community License, Version 2.0 (the "License"); you may not use this file
9    * except in compliance with the License. You may obtain a copy of the License
10   * at:
11   *
12   *   http://opensource.org/licenses/ecl2.txt
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
17   * License for the specific language governing permissions and limitations under
18   * the License.
19   *
20   */
21  package org.opencastproject.assetmanager.api.storage;
22  
23  import static java.lang.String.format;
24  
25  import org.opencastproject.assetmanager.api.Version;
26  
27  import java.io.Serializable;
28  import java.util.Objects;
29  import java.util.Optional;
30  
31  import javax.annotation.ParametersAreNonnullByDefault;
32  import javax.annotation.concurrent.Immutable;
33  
34  @ParametersAreNonnullByDefault
35  @Immutable
36  public final class DeletionSelector implements Serializable {
37    private static final long serialVersionUID = 217139112650188934L;
38  
39    private final String mediaPackageId;
40    private final String organizationId;
41    private final Optional<Version> version;
42  
43    public DeletionSelector(String organizationId, String mediaPackageId, Optional<Version> version) {
44      this.mediaPackageId = mediaPackageId;
45      this.organizationId = organizationId;
46      this.version = version;
47    }
48  
49    public static DeletionSelector delete(String organizationId, String mediaPackageId, Version version) {
50      return new DeletionSelector(organizationId, mediaPackageId, Optional.of(version));
51    }
52  
53    public static DeletionSelector deleteAll(String organizationId, String mediaPackageId) {
54      return new DeletionSelector(organizationId, mediaPackageId, Optional.<Version>empty());
55    }
56  
57    public String getMediaPackageId() {
58      return mediaPackageId;
59    }
60  
61    public String getOrganizationId() {
62      return organizationId;
63    }
64  
65    public Optional<Version> getVersion() {
66      return version;
67    }
68  
69    @Override
70    public boolean equals(Object that) {
71      return (this == that) || (that instanceof DeletionSelector && eqFields((DeletionSelector) that));
72    }
73  
74    private boolean eqFields(DeletionSelector that) {
75      return Objects.equals(this.mediaPackageId, that.mediaPackageId)
76              && Objects.equals(this.organizationId, that.organizationId)
77              && Objects.equals(this.version, that.version);
78    }
79  
80    @Override
81    public int hashCode() {
82      return Objects.hash(mediaPackageId, organizationId, version);
83    }
84  
85    @Override public String toString() {
86      return format("DeletionSelector(org=%s,mp=%s,v=%s)", organizationId, mediaPackageId, version);
87    }
88  }