This project has retired. For details please refer to its Attic page.
ArtifactMetadataModel xref
View Javadoc
1   package org.apache.archiva.metadata.repository.cassandra.model;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
23  
24  import java.io.Serializable;
25  import java.util.Date;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames.*;
30  
31  /**
32   * Cassandra storage model for {@link org.apache.archiva.metadata.model.ArtifactMetadata}
33   *
34   * @author Olivier Lamy
35   * @since 2.0.0
36   */
37  public class ArtifactMetadataModel
38      implements Serializable
39  {
40  
41      public final static String[] COLUMNS = new String[] { ID.toString(), REPOSITORY_NAME.toString(),
42          NAMESPACE_ID.toString(), PROJECT.toString(), PROJECT_VERSION.toString(), VERSION.toString(),
43          FILE_LAST_MODIFIED.toString(), SIZE.toString(), MD5.toString(), SHA1.toString(), WHEN_GATHERED.toString() };
44  
45      private String id;
46  
47      private String repositoryId;
48  
49      private String namespace;
50  
51      private String project;
52  
53      private String projectVersion;
54  
55      private String version;
56  
57      private long fileLastModified;
58  
59      private long size;
60  
61      private String md5;
62  
63      private String sha1;
64  
65      private long whenGathered;
66  
67      private Map<String, String> checksums = new HashMap<>();
68  
69      public ArtifactMetadataModel()
70      {
71          // no op
72      }
73  
74      public ArtifactMetadataModel( String id, String repositoryId, String namespace, String project,
75                                    String projectVersion, String version, Date fileLastModified, long size, String md5,
76                                    String sha1, Date whenGathered )
77      {
78          this.id = id;
79          this.repositoryId = repositoryId;
80          this.namespace = namespace;
81          this.project = project;
82          this.projectVersion = projectVersion;
83          this.version = version;
84          this.fileLastModified = ( fileLastModified != null ? fileLastModified.getTime() : 0 );
85          this.size = size;
86          this.md5 = md5;
87          this.sha1 = sha1;
88          this.whenGathered = whenGathered != null ? whenGathered.getTime() : new Date().getTime();
89      }
90  
91  
92      public String getId()
93      {
94          return id;
95      }
96  
97      public void setId( String id )
98      {
99          this.id = id;
100     }
101 
102     public String getRepositoryId()
103     {
104         return repositoryId;
105     }
106 
107     public void setRepositoryId( String repositoryId )
108     {
109         this.repositoryId = repositoryId;
110     }
111 
112     public String getNamespace()
113     {
114         return namespace;
115     }
116 
117     public void setNamespace( String namespace )
118     {
119         this.namespace = namespace;
120     }
121 
122     public String getProject()
123     {
124         return project;
125     }
126 
127     public void setProject( String project )
128     {
129         this.project = project;
130     }
131 
132     public String getProjectVersion()
133     {
134         return projectVersion;
135     }
136 
137     public void setProjectVersion( String projectVersion )
138     {
139         this.projectVersion = projectVersion;
140     }
141 
142     public String getVersion()
143     {
144         return version;
145     }
146 
147     public void setVersion( String version )
148     {
149         this.version = version;
150     }
151 
152     public long getFileLastModified()
153     {
154         return fileLastModified;
155     }
156 
157     public void setFileLastModified( long fileLastModified )
158     {
159         this.fileLastModified = fileLastModified;
160     }
161 
162     public long getSize()
163     {
164         return size;
165     }
166 
167     public void setSize( long size )
168     {
169         this.size = size;
170     }
171 
172     public String getMd5()
173     {
174         return md5;
175     }
176 
177     public void setMd5( String md5 )
178     {
179         this.md5 = md5;
180     }
181 
182     public String getSha1()
183     {
184         return sha1;
185     }
186 
187     public void setSha1( String sha1 )
188     {
189         this.sha1 = sha1;
190     }
191 
192     public Date getWhenGathered()
193     {
194         return new Date( whenGathered );
195     }
196 
197     public void setWhenGathered( long whenGathered )
198     {
199         this.whenGathered = whenGathered;
200     }
201 
202     public void setChecksum(String type, String value) {
203         this.checksums.put(type, value);
204     }
205 
206     public String getChecksum(String type) {
207         return this.checksums.get(type);
208     }
209 
210     public void setChecksums(Map<String,String> checksums) {
211         this.checksums = checksums;
212     }
213 
214     public Map<String,String> getChecksums() {
215         return this.checksums;
216     }
217 
218 
219     @Override
220     public String toString()
221     {
222         final StringBuilder sb = new StringBuilder( "ArtifactMetadataModel{" );
223         sb.append( ", id='" ).append( id ).append( '\'' );
224         sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' );
225         sb.append( ", namespace='" ).append( namespace ).append( '\'' );
226         sb.append( ", project='" ).append( project ).append( '\'' );
227         sb.append( ", projectVersion='" ).append( projectVersion ).append( '\'' );
228         sb.append( ", version='" ).append( version ).append( '\'' );
229         sb.append( ", fileLastModified=" ).append( fileLastModified );
230         sb.append( ", size=" ).append( size );
231         sb.append( ", md5='" ).append( md5 ).append( '\'' );
232         sb.append( ", sha1='" ).append( sha1 ).append( '\'' );
233         sb.append( ", whenGathered=" ).append( whenGathered );
234         sb.append( '}' );
235         return sb.toString();
236     }
237 
238     public static class KeyBuilder
239     {
240 
241         private String project;
242 
243         private String id;
244 
245         private String namespaceId;
246 
247         private String repositoryId;
248 
249         private String projectVersion;
250 
251         public KeyBuilder()
252         {
253 
254         }
255 
256         public KeyBuilder withId( String id )
257         {
258             this.id = id;
259             return this;
260         }
261 
262 
263         public KeyBuilder withNamespace( Namespace namespace )
264         {
265             this.namespaceId = namespace.getName();
266             this.repositoryId = namespace.getRepository().getName();
267             return this;
268         }
269 
270         public KeyBuilder withNamespace( String namespaceId )
271         {
272             this.namespaceId = namespaceId;
273             return this;
274         }
275 
276         public KeyBuilder withProject( String project )
277         {
278             this.project = project;
279             return this;
280         }
281 
282         public KeyBuilder withProjectVersion( String projectVersion )
283         {
284             this.projectVersion = projectVersion;
285             return this;
286         }
287 
288         public KeyBuilder withRepositoryId( String repositoryId )
289         {
290             this.repositoryId = repositoryId;
291             return this;
292         }
293 
294         public String build()
295         {
296             //repositoryId + namespaceId + project + projectVersion + id
297             // FIXME add some controls
298 
299             String str =
300                 CassandraUtils.generateKey( this.repositoryId, this.namespaceId, this.project, this.projectVersion,
301                                             this.id );
302 
303             //return Long.toString( str.hashCode() );
304             return str;
305         }
306     }
307 
308 }