View Javadoc
1   /*
2    * Copyright 2023 Adrian Herscu
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package dev.aherscu.qa.s3.publisher.maven.plugin.config;
18  
19  import java.util.*;
20  
21  public class Metadata {
22  
23      /**
24       * The id of this metadata.
25       */
26      String  id;
27      /**
28       * Cache control directive. The format must be compliant with Cache-Control
29       * HTTP header.
30       */
31      String  cacheControl;
32      String  contentDisposition;
33      /**
34       * Content type value. Should be used for those cases where it is not
35       * possible to guess it from file extension.
36       */
37      String  contentType;
38      /**
39       */
40      String  contentLanguage;
41      /**
42       * Number of seconds to add to time when the file is uploaded to S3 for
43       * setting Expires metadata.
44       */
45      int     secondsToExpire;
46      /**
47       * Content encoding. Only plain and gzip are supported currentlt.
48       */
49      String  contentEncoding;
50      /**
51       */
52      String  websiteRedirectLocation;
53      /**
54       * The S3 permission to apply to uploaded files. Could be any of the
55       * following: AuthenticatedRead, BucketOwnerFullControl, BucketOwnerRead,
56       * LogDeliveryWrite, Private, PublicRead, PublicReadWrite.
57       */
58      String  cannedAcl;
59      /**
60       * Set if this is the default metadata which will be applied to all Binds
61       * which don't specify a metadata id.
62       */
63      boolean def;
64  
65      private static String toLowerCase(final String value) {
66          if (value != null)
67              return value.toLowerCase(Locale.ENGLISH);
68  
69          return null;
70      }
71  
72      @Override
73      public boolean equals(final Object o) {
74          if (o == this)
75              return true;
76          if (!(o instanceof Metadata))
77              return false;
78          final Metadata metadata = (Metadata) o;
79          return Objects.equals(id, metadata.id)
80              && Objects.equals(cacheControl, metadata.cacheControl)
81              && Objects.equals(contentDisposition, metadata.contentDisposition)
82              && Objects.equals(contentType, metadata.contentType)
83              && Objects.equals(contentLanguage, metadata.contentLanguage)
84              && secondsToExpire == metadata.secondsToExpire
85              && Objects.equals(contentEncoding, metadata.contentEncoding)
86              && Objects
87                  .equals(websiteRedirectLocation,
88                      metadata.websiteRedirectLocation)
89              && Objects.equals(cannedAcl, metadata.cannedAcl)
90              && def == metadata.def;
91      }
92  
93      public String getCacheControl() {
94          return toLowerCase(cacheControl);
95      }
96  
97      public String getCannedAcl() {
98          return cannedAcl;
99      }
100 
101     public String getContentDisposition() {
102         return toLowerCase(contentDisposition);
103     }
104 
105     public String getContentEncoding() {
106         return toLowerCase(contentEncoding);
107     }
108 
109     public String getContentLanguage() {
110         return toLowerCase(contentLanguage);
111     }
112 
113     public String getContentType() {
114         return toLowerCase(contentType);
115     }
116 
117     public String getId() {
118         return id;
119     }
120 
121     public int getSecondsToExpire() {
122         return secondsToExpire;
123     }
124 
125     public String getWebsiteRedirectLocation() {
126         return toLowerCase(websiteRedirectLocation);
127     }
128 
129     @Override
130     public int hashCode() {
131         final int prime = 31;
132         int result = 1;
133         result = prime * result + (id == null ? 0 : id.hashCode());
134         return result;
135     }
136 
137     public boolean isDefault() {
138         return def;
139     }
140 
141     @Override
142     public String toString() {
143         return "metadada ["
144             + " id=" + id
145             + " cacheControl=" + cacheControl
146             + " contentDisposition=" + contentDisposition
147             + " contentType=" + contentType
148             + " contentLanguage=" + contentLanguage
149             + " secondsToExpire=" + secondsToExpire
150             + " contentEncoding=" + contentEncoding
151             + " websiteRedirectLocation=" + websiteRedirectLocation
152             + " cannedAcl=" + cannedAcl
153             + " ]";
154     }
155 }