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 org.opencastproject.assetmanager.api.Version;
24  
25  import java.io.Serializable;
26  import java.util.Objects;
27  
28  import javax.annotation.ParametersAreNonnullByDefault;
29  import javax.annotation.concurrent.Immutable;
30  
31  /**
32   * A vector that uniquely identifies a stored media package asset.
33   */
34  @ParametersAreNonnullByDefault
35  @Immutable
36  public final class StoragePath implements Serializable {
37    private static final long serialVersionUID = -5646543990835098350L;
38  
39    private final String mediaPackageId;
40    private final String mediaPackageElementId;
41    private final String organizationId;
42    private final Version version;
43  
44    public StoragePath(String organizationId, String mediaPackageId, Version version, String mediaPackageElementId) {
45      this.mediaPackageId = mediaPackageId;
46      this.mediaPackageElementId = mediaPackageElementId;
47      this.organizationId = organizationId;
48      this.version = version;
49    }
50  
51    public static StoragePath mk(
52            String organizationId, String mediaPackageId, Version version, String mediaPackageElementId) {
53      return new StoragePath(organizationId, mediaPackageId, version, mediaPackageElementId);
54    }
55  
56    public String getMediaPackageId() {
57      return mediaPackageId;
58    }
59  
60    public String getMediaPackageElementId() {
61      return mediaPackageElementId;
62    }
63  
64    public String getOrganizationId() {
65      return organizationId;
66    }
67  
68    public Version getVersion() {
69      return version;
70    }
71  
72    @Override
73    public boolean equals(Object that) {
74      return (this == that) || (that instanceof StoragePath && eqFields((StoragePath) that));
75    }
76  
77    private boolean eqFields(StoragePath that) {
78      return Objects.equals(this.mediaPackageId, that.mediaPackageId)
79              && Objects.equals(this.mediaPackageElementId, that.mediaPackageElementId)
80              && Objects.equals(this.organizationId, that.organizationId)
81              && Objects.equals(this.version, that.version);
82    }
83  
84    @Override
85    public int hashCode() {
86      return Objects.hash(mediaPackageId, mediaPackageElementId, organizationId, version);
87    }
88  
89    @Override public String toString() {
90      return "StoragePath(orgId=" + organizationId
91              + ", mpId=" + mediaPackageId
92              + ", version=" + version
93              + ", mpeId=" + mediaPackageElementId
94              + ")";
95    }
96  }