001    package org.apache.archiva.metadata.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    
022    import javax.xml.bind.annotation.XmlRootElement;
023    import java.util.Date;
024    
025    /**
026     * Metadata stored in the content repository for a particular artifact. Information that is shared between different
027     * artifacts of a given project version can be found in the
028     * {@link org.apache.archiva.metadata.model.ProjectVersionMetadata} class. The metadata is faceted to store information
029     * about particular types of artifacts, for example Maven 2.x artifact specific information.
030     * For more information, see the
031     * <a href="{@docRoot}/../metadata-content-model.html" target="_top">Metadata Content Model</a>.
032     */
033    @XmlRootElement ( name = "artifactMetadata" )
034    public class ArtifactMetadata
035        extends FacetedMetadata
036    {
037        /**
038         * The artifact ID uniquely identifies an artifact within a given namespace, project and project version. For
039         * example, <tt>archiva-1.4-20100201.345612-2.jar</tt>
040         */
041        private String id;
042    
043        /**
044         * The repository that the artifact is stored in within the content repository.
045         */
046        private String repositoryId;
047    
048        /**
049         * The namespace of the project within the repository.
050         *
051         * @see org.apache.archiva.metadata.model.ProjectMetadata#namespace
052         */
053        private String namespace;
054    
055        /**
056         * The identifier of the project within the repository and namespace.
057         *
058         * @see org.apache.archiva.metadata.model.ProjectMetadata#id
059         */
060        private String project;
061    
062        /**
063         * The version of the project. This may be more generalised than @{link #version}.
064         *
065         * @see org.apache.archiva.metadata.model.ProjectVersionMetadata#id
066         */
067        private String projectVersion;
068    
069        /**
070         * The artifact version, if different from the project version. Note that the metadata does not do any calculation
071         * of this based on the project version - the calling code must be sure to set and check it appropriately if
072         * <tt>null</tt>.
073         */
074        private String version;
075    
076        /**
077         * The last modified date of the artifact file, if known.
078         */
079        private Date fileLastModified;
080    
081        /**
082         * The file size of the artifact, if known.
083         */
084        private long size;
085    
086        /**
087         * The MD5 checksum of the artifact, if calculated.
088         */
089        private String md5;
090    
091        /**
092         * The SHA-1 checksum of the artifact, if calculated.
093         */
094        private String sha1;
095    
096        /**
097         * When the artifact was found in the repository storage and added to the metadata content repository.
098         */
099        private Date whenGathered;
100    
101        public String getId()
102        {
103            return id;
104        }
105    
106        public void setId( String id )
107        {
108            this.id = id;
109        }
110    
111        public long getSize()
112        {
113            return size;
114        }
115    
116        public void setSize( long size )
117        {
118            this.size = size;
119        }
120    
121        public String getVersion()
122        {
123            return version;
124        }
125    
126        public void setVersion( String version )
127        {
128            this.version = version;
129        }
130    
131        public String getProjectVersion()
132        {
133            return projectVersion;
134        }
135    
136        public void setProjectVersion( String projectVersion )
137        {
138            this.projectVersion = projectVersion;
139        }
140    
141        public void setFileLastModified( long fileLastModified )
142        {
143            this.fileLastModified = new Date( fileLastModified );
144        }
145    
146        public void setWhenGathered( Date whenGathered )
147        {
148            this.whenGathered = whenGathered;
149        }
150    
151        public void setMd5( String md5 )
152        {
153            this.md5 = md5;
154        }
155    
156        public void setSha1( String sha1 )
157        {
158            this.sha1 = sha1;
159        }
160    
161        public Date getWhenGathered()
162        {
163            return whenGathered;
164        }
165    
166        public String getMd5()
167        {
168            return md5;
169        }
170    
171        public String getSha1()
172        {
173            return sha1;
174        }
175    
176        public Date getFileLastModified()
177        {
178    
179            return fileLastModified;
180        }
181    
182        public String getNamespace()
183        {
184            return namespace;
185        }
186    
187        public void setNamespace( String namespace )
188        {
189            this.namespace = namespace;
190        }
191    
192        public void setProject( String project )
193        {
194            this.project = project;
195        }
196    
197        public String getProject()
198        {
199            return project;
200        }
201    
202        public String getRepositoryId()
203        {
204            return repositoryId;
205        }
206    
207        public void setRepositoryId( String repositoryId )
208        {
209            this.repositoryId = repositoryId;
210        }
211    
212        @Override
213        public boolean equals( Object o )
214        {
215            if ( this == o )
216            {
217                return true;
218            }
219            if ( o == null || getClass() != o.getClass() )
220            {
221                return false;
222            }
223    
224            ArtifactMetadata that = (ArtifactMetadata) o;
225    
226            if ( size != that.size )
227            {
228                return false;
229            }
230            if ( fileLastModified != null
231                ? !fileLastModified.equals( that.fileLastModified )
232                : that.fileLastModified != null )
233            {
234                return false;
235            }
236            if ( !id.equals( that.id ) )
237            {
238                return false;
239            }
240            if ( md5 != null ? !md5.equals( that.md5 ) : that.md5 != null )
241            {
242                return false;
243            }
244            if ( namespace != null ? !namespace.equals( that.namespace ) : that.namespace != null )
245            {
246                return false;
247            }
248            if ( project != null ? !project.equals( that.project ) : that.project != null )
249            {
250                return false;
251            }
252            if ( projectVersion != null ? !projectVersion.equals( that.projectVersion ) : that.projectVersion != null )
253            {
254                return false;
255            }
256            if ( !repositoryId.equals( that.repositoryId ) )
257            {
258                return false;
259            }
260            if ( sha1 != null ? !sha1.equals( that.sha1 ) : that.sha1 != null )
261            {
262                return false;
263            }
264            if ( version != null ? !version.equals( that.version ) : that.version != null )
265            {
266                return false;
267            }
268            if ( whenGathered != null ? !whenGathered.equals( that.whenGathered ) : that.whenGathered != null )
269            {
270                return false;
271            }
272    
273            return true;
274        }
275    
276        @Override
277        public int hashCode()
278        {
279            int result = id != null ? id.hashCode() : 0;
280            result = 31 * result + ( repositoryId != null ? repositoryId.hashCode() : 0 );
281            result = 31 * result + ( namespace != null ? namespace.hashCode() : 0 );
282            result = 31 * result + ( project != null ? project.hashCode() : 0 );
283            result = 31 * result + ( projectVersion != null ? projectVersion.hashCode() : 0 );
284            result = 31 * result + ( version != null ? version.hashCode() : 0 );
285            result = 31 * result + ( fileLastModified != null ? fileLastModified.hashCode() : 0 );
286            result = 31 * result + (int) ( size ^ ( size >>> 32 ) );
287            result = 31 * result + ( md5 != null ? md5.hashCode() : 0 );
288            result = 31 * result + ( sha1 != null ? sha1.hashCode() : 0 );
289            result = 31 * result + ( whenGathered != null ? whenGathered.hashCode() : 0 );
290            return result;
291        }
292    
293        @Override
294        public String toString()
295        {
296            return "ArtifactMetadata{" + "id='" + id + '\'' + ", size=" + size + ", version='" + version + '\'' +
297                ", fileLastModified=" + fileLastModified + ", whenGathered=" + whenGathered + ", md5='" + md5 + '\'' +
298                ", sha1='" + sha1 + '\'' + ", namespace='" + namespace + '\'' + ", project='" + project + '\'' +
299                ", projectVersion='" + projectVersion + '\'' + ", repositoryId='" + repositoryId + '\'' + '}';
300        }
301    }