This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.metadata.repository.cassandra.model;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import static org.apache.archiva.metadata.repository.cassandra.model.ColumnNames.*;
023
024import org.apache.archiva.metadata.repository.cassandra.CassandraUtils;
025
026import java.io.Serializable;
027import java.util.Date;
028
029/**
030 * Cassandra storage model for {@link org.apache.archiva.metadata.model.ArtifactMetadata}
031 *
032 * @author Olivier Lamy
033 * @since 2.0.0
034 */
035public class ArtifactMetadataModel
036    implements Serializable
037{
038
039    public final static String[] COLUMNS = new String[] { ID.toString(), REPOSITORY_NAME.toString(),
040        NAMESPACE_ID.toString(), PROJECT.toString(), PROJECT_VERSION.toString(), VERSION.toString(),
041        FILE_LAST_MODIFIED.toString(), SIZE.toString(), MD5.toString(), SHA1.toString(), WHEN_GATHERED.toString() };
042
043    private String id;
044
045    private String repositoryId;
046
047    private String namespace;
048
049    private String project;
050
051    private String projectVersion;
052
053    private String version;
054
055    private long fileLastModified;
056
057    private long size;
058
059    private String md5;
060
061    private String sha1;
062
063    private long whenGathered;
064
065    public ArtifactMetadataModel()
066    {
067        // no op
068    }
069
070    public ArtifactMetadataModel( String id, String repositoryId, String namespace, String project,
071                                  String projectVersion, String version, Date fileLastModified, long size, String md5,
072                                  String sha1, Date whenGathered )
073    {
074        this.id = id;
075        this.repositoryId = repositoryId;
076        this.namespace = namespace;
077        this.project = project;
078        this.projectVersion = projectVersion;
079        this.version = version;
080        this.fileLastModified = ( fileLastModified != null ? fileLastModified.getTime() : 0 );
081        this.size = size;
082        this.md5 = md5;
083        this.sha1 = sha1;
084        this.whenGathered = whenGathered != null ? whenGathered.getTime() : new Date().getTime();
085    }
086
087
088    public String getId()
089    {
090        return id;
091    }
092
093    public void setId( String id )
094    {
095        this.id = id;
096    }
097
098    public String getRepositoryId()
099    {
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}