1 package org.apache.archiva.metadata.repository.cassandra.model;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.Id;
25 import java.io.Serializable;
26 import java.util.Date;
29 * Cassandra storage model for {@link org.apache.archiva.metadata.model.ArtifactMetadata}
31 * @author Olivier Lamy
34 public class ArtifactMetadataModel
35 implements Serializable
38 // repositoryId + namespaceId + project + projectVersion + id
40 private String artifactMetadataModelId;
45 @Column(name = "repositoryId")
46 private String repositoryId;
48 @Column(name = "namespace")
49 private String namespace;
51 @Column(name = "project")
52 private String project;
54 @Column(name = "projectVersion")
55 private String projectVersion;
57 @Column(name = "version")
58 private String version;
60 @Column(name = "fileLastModified")
61 private long fileLastModified;
63 @Column(name = "size")
69 @Column(name = "sha1")
72 @Column(name = "whenGathered")
73 private long whenGathered;
75 public ArtifactMetadataModel()
80 public ArtifactMetadataModel( String artifactMetadataModelId, String id, String repositoryId, String namespace,
81 String project, String projectVersion, String version, Date fileLastModified,
82 long size, String md5, String sha1, Date whenGathered )
84 this.artifactMetadataModelId = artifactMetadataModelId;
86 this.repositoryId = repositoryId;
87 this.namespace = namespace;
88 this.project = project;
89 this.projectVersion = projectVersion;
90 this.version = version;
91 this.fileLastModified = ( fileLastModified != null ? fileLastModified.getTime() : 0 );
95 this.whenGathered = whenGathered != null ? whenGathered.getTime() : new Date().getTime();
98 public String getArtifactMetadataModelId()
100 return artifactMetadataModelId;
103 public void setArtifactMetadataModelId( String artifactMetadataModelId )
105 this.artifactMetadataModelId = artifactMetadataModelId;
108 public String getId()
113 public void setId( String id )
118 public String getRepositoryId()
123 public void setRepositoryId( String repositoryId )
125 this.repositoryId = repositoryId;
128 public String getNamespace()
133 public void setNamespace( String namespace )
135 this.namespace = namespace;
138 public String getProject()
143 public void setProject( String project )
145 this.project = project;
148 public String getProjectVersion()
150 return projectVersion;
153 public void setProjectVersion( String projectVersion )
155 this.projectVersion = projectVersion;
158 public String getVersion()
163 public void setVersion( String version )
165 this.version = version;
168 public long getFileLastModified()
170 return fileLastModified;
173 public void setFileLastModified( long fileLastModified )
175 this.fileLastModified = fileLastModified;
178 public long getSize()
183 public void setSize( long size )
188 public String getMd5()
193 public void setMd5( String md5 )
198 public String getSha1()
203 public void setSha1( String sha1 )
208 public Date getWhenGathered()
210 return new Date( whenGathered );
213 public void setWhenGathered( long whenGathered )
215 this.whenGathered = whenGathered;
219 public boolean equals( Object o )
225 if ( o == null || getClass() != o.getClass() )
230 ArtifactMetadataModel that = (ArtifactMetadataModel) o;
232 if ( !artifactMetadataModelId.equals( that.artifactMetadataModelId ) )
241 public int hashCode()
243 return artifactMetadataModelId.hashCode();
247 public String toString()
249 final StringBuilder sb = new StringBuilder( "ArtifactMetadataModel{" );
250 sb.append( "artifactMetadataModelId='" ).append( artifactMetadataModelId ).append( '\'' );
251 sb.append( ", id='" ).append( id ).append( '\'' );
252 sb.append( ", repositoryId='" ).append( repositoryId ).append( '\'' );
253 sb.append( ", namespace='" ).append( namespace ).append( '\'' );
254 sb.append( ", project='" ).append( project ).append( '\'' );
255 sb.append( ", projectVersion='" ).append( projectVersion ).append( '\'' );
256 sb.append( ", version='" ).append( version ).append( '\'' );
257 sb.append( ", fileLastModified=" ).append( fileLastModified );
258 sb.append( ", size=" ).append( size );
259 sb.append( ", md5='" ).append( md5 ).append( '\'' );
260 sb.append( ", sha1='" ).append( sha1 ).append( '\'' );
261 sb.append( ", whenGathered=" ).append( whenGathered );
263 return sb.toString();
266 public static class KeyBuilder
269 private String project;
273 private String namespaceId;
275 private String repositoryId;
277 private String projectVersion;
284 public KeyBuilder withId( String id )
291 public KeyBuilder withNamespace( Namespace namespace )
293 this.namespaceId = namespace.getName();
294 this.repositoryId = namespace.getRepository().getId();
298 public KeyBuilder withNamespace( String namespaceId )
300 this.namespaceId = namespaceId;
304 public KeyBuilder withProject( String project )
306 this.project = project;
310 public KeyBuilder withProjectVersion( String projectVersion )
312 this.projectVersion = projectVersion;
316 public KeyBuilder withRepositoryId( String repositoryId )
318 this.repositoryId = repositoryId;
322 public String build()
324 //repositoryId + namespaceId + project + projectVersion + id
325 // FIXME add some controls
326 return this.repositoryId + "-" + this.namespaceId + "-" + this.project + "-" + this.projectVersion + "-"