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 static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames.*;
23  
24  import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
25  
26  import java.io.Serializable;
27  import java.util.Date;
28  
29  /**
30   * Cassandra storage model for {@link org.apache.archiva.metadata.model.ArtifactMetadata}
31   *
32   * @author Olivier Lamy
33   * @since 2.0.0
34   */
35  public class ArtifactMetadataModel
36      implements Serializable
37  {
38  
39      public final static String[] COLUMNS = new String[] { ID.toString(), REPOSITORY_NAME.toString(),
40          NAMESPACE_ID.toString(), PROJECT.toString(), PROJECT_VERSION.toString(), VERSION.toString(),
41          FILE_LAST_MODIFIED.toString(), SIZE.toString(), MD5.toString(), SHA1.toString(), WHEN_GATHERED.toString() };
42  
43      private String id;
44  
45      private String repositoryId;
46  
47      private String namespace;
48  
49      private String project;
50  
51      private String projectVersion;
52  
53      private String version;
54  
55      private long fileLastModified;
56  
57      private long size;
58  
59      private String md5;
60  
61      private String sha1;
62  
63      private long whenGathered;
64  
65      public ArtifactMetadataModel()
66      {
67          // no op
68      }
69  
70      public ArtifactMetadataModel( String id, String repositoryId, String namespace, String project,
71                                    String projectVersion, String version, Date fileLastModified, long size, String md5,
72                                    String sha1, Date whenGathered )
73      {
74          this.id = id;
75          this.repositoryId = repositoryId;
76          this.namespace = namespace;
77          this.project = project;
78          this.projectVersion = projectVersion;
79          this.version = version;
80          this.fileLastModified = ( fileLastModified != null ? fileLastModified.getTime() : 0 );
81          this.size = size;
82          this.md5 = md5;
83          this.sha1 = sha1;
84          this.whenGathered = whenGathered != null ? whenGathered.getTime() : new Date().getTime();
85      }
86  
87  
88      public String getId()
89      {
90          return id;
91      }
92  
93      public void setId( String id )
94      {
95          this.id = id;
96      }
97  
98      public String getRepositoryId()
99      {
100         return repositoryId;
101     }
102 
103     public void setRepositoryId( String repositoryId )
104     {
105         this.repositoryId = repositoryId;
106     }
107 
108     public String getNamespace()
109     {
110         return namespace;
111     }
112 
113     public void setNamespace( String namespace )
114     {
115         this.namespace = namespace;
116     }
117 
118     public String getProject()
119     {
120         return project;
121     }
122 
123     public void setProject( String project )
124     {
125         this.project = project;
126     }
127 
128     public String getProjectVersion()
129     {
130         return projectVersion;
131     }
132 
133     public void setProjectVersion( String projectVersion )
134     {
135         this.projectVersion = projectVersion;
136     }
137 
138     public String getVersion()
139     {
140         return version;
141     }
142 
143     public void setVersion( String version )
144     {
145         this.version = version;
146     }
147 
148     public long getFileLastModified()
149     {
150         return fileLastModified;
151     }
152 
153     public void setFileLastModified( long fileLastModified )
154     {
155         this.fileLastModified = fileLastModified;
156     }
157 
158     public long getSize()
159     {
160         return size;
161     }
162 
163     public void setSize( long size )
164     {
165         this.size = size;
166     }
167 
168     public String getMd5()
169     {
170         return md5;
171     }
172 
173     public void setMd5( String md5 )
174     {
175         this.md5 = md5;
176     }
177 
178     public String getSha1()
179     {
180         return sha1;
181     }
182 
183     public void setSha1( String sha1 )
184     {
185         this.sha1 = sha1;
186     }
187 
188     public Date getWhenGathered()
189     {
190         return new Date( whenGathered );
191     }
192 
193     public void setWhenGathered( long whenGathered )
194     {
195         this.whenGathered = whenGathered;
196     }
197 
198 
199     @Override
200     public String toString()
201     {
202         final StringBuilder sb = new StringBuilder( "ArtifactMetadataModel{" );
203         sb.append( ", id='" ).append( id ).append( '\'' );
204         sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' );
205         sb.append( ", namespace='" ).append( namespace ).append( '\'' );
206         sb.append( ", project='" ).append( project ).append( '\'' );
207         sb.append( ", projectVersion='" ).append( projectVersion ).append( '\'' );
208         sb.append( ", version='" ).append( version ).append( '\'' );
209         sb.append( ", fileLastModified=" ).append( fileLastModified );
210         sb.append( ", size=" ).append( size );
211         sb.append( ", md5='" ).append( md5 ).append( '\'' );
212         sb.append( ", sha1='" ).append( sha1 ).append( '\'' );
213         sb.append( ", whenGathered=" ).append( whenGathered );
214         sb.append( '}' );
215         return sb.toString();
216     }
217 
218     public static class KeyBuilder
219     {
220 
221         private String project;
222 
223         private String id;
224 
225         private String namespaceId;
226 
227         private String repositoryId;
228 
229         private String projectVersion;
230 
231         public KeyBuilder()
232         {
233 
234         }
235 
236         public KeyBuilder withId( String id )
237         {
238             this.id = id;
239             return this;
240         }
241 
242 
243         public KeyBuilder withNamespace( Namespace namespace )
244         {
245             this.namespaceId = namespace.getName();
246             this.repositoryId = namespace.getRepository().getName();
247             return this;
248         }
249 
250         public KeyBuilder withNamespace( String namespaceId )
251         {
252             this.namespaceId = namespaceId;
253             return this;
254         }
255 
256         public KeyBuilder withProject( String project )
257         {
258             this.project = project;
259             return this;
260         }
261 
262         public KeyBuilder withProjectVersion( String projectVersion )
263         {
264             this.projectVersion = projectVersion;
265             return this;
266         }
267 
268         public KeyBuilder withRepositoryId( String repositoryId )
269         {
270             this.repositoryId = repositoryId;
271             return this;
272         }
273 
274         public String build()
275         {
276             //repositoryId + namespaceId + project + projectVersion + id
277             // FIXME add some controls
278 
279             String str =
280                 CassandraUtils.generateKey( this.repositoryId, this.namespaceId, this.project, this.projectVersion,
281                                             this.id );
282 
283             //return Long.toString( str.hashCode() );
284             return str;
285         }
286     }
287 
288 }