1 package org.apache.archiva.repository.content.base;
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 org.apache.archiva.repository.content.BaseArtifactTypes;
23 import org.apache.archiva.repository.content.BaseDataItemTypes;
24 import org.apache.archiva.repository.content.ContentItem;
25 import org.apache.archiva.repository.content.DataItem;
26 import org.apache.archiva.repository.content.DataItemType;
27 import org.apache.archiva.repository.content.base.builder.DataItemOptBuilder;
28 import org.apache.archiva.repository.content.base.builder.DataItemWithIdBuilder;
29 import org.apache.archiva.repository.storage.StorageAsset;
30 import org.apache.commons.lang3.StringUtils;
33 * Base implementation of artifact.
35 * You have to use the builder method {@link #withAsset(StorageAsset)} to create a instance.
36 * The build() method can be called after the required attributes are set.
38 * Artifacts are equal if the following coordinates match:
44 * <li>artifactVersion</li>
47 * <li>artifactType</li>
50 * @author Martin Stockhammer <martin_s@apache.org>
52 public class ArchivaDataItem extends ArchivaContentItem implements DataItem
55 private ContentItem parent;
56 private String contentType;
57 private DataItemType dataItemType;
59 private ArchivaDataItem( )
65 public String getId( )
71 public ContentItem getParent( )
77 public String getContentType( )
83 public DataItemType getDataType( )
90 * Returns the builder for creating a new artifact instance. You have to fill the
91 * required attributes before the build() method is available.
93 * @param asset the storage asset representing the artifact
94 * @return a builder for creating new artifact instance
96 public static DataItemWithIdBuilder withAsset( StorageAsset asset )
98 return new Builder( ).withAsset( asset );
103 public boolean equals( Object o )
105 if ( this == o ) return true;
106 if ( o == null || getClass( ) != o.getClass( ) ) return false;
107 if ( !super.equals( o ) ) return false;
109 ArchivaDataItem that = (ArchivaDataItem) o;
111 if ( !id.equals( that.id ) ) return false;
112 if ( !parent.equals( that.parent ) ) return false;
113 return dataItemType.equals(that.dataItemType );
117 public int hashCode( )
119 int result = super.hashCode( );
120 result = 31 * result + id.hashCode( );
121 result = 31 * result + parent.hashCode( );
122 result = 31 * result + dataItemType.hashCode( );
127 public String toString( )
129 final StringBuilder sb = new StringBuilder( "ArchivaArtifact{" );
130 sb.append( "id='" ).append( id ).append( '\'' );
131 sb.append( ", parent=" ).append( parent );
132 sb.append( ", contentType='" ).append( contentType ).append( '\'' );
133 sb.append( ", artifactType=" ).append( dataItemType );
135 return sb.toString( );
138 public static String defaultString( String value )
148 private static class Builder
149 extends ContentItemBuilder<ArchivaDataItem, DataItemOptBuilder, DataItemWithIdBuilder >
150 implements DataItemOptBuilder,DataItemWithIdBuilder
155 super( new ArchivaDataItem( ) );
159 protected DataItemOptBuilder getOptBuilder( )
165 protected DataItemWithIdBuilder getNextBuilder( )
171 public DataItemOptBuilder withParent( ContentItem parent )
173 if ( parent == null )
175 throw new IllegalArgumentException( "version may not be null" );
177 item.parent = parent;
178 super.setRepository( parent.getRepository( ) );
183 public DataItemOptBuilder withId( String id )
185 if ( StringUtils.isEmpty( id ) )
187 throw new IllegalArgumentException( "Artifact id may not be null or empty" );
195 public DataItemOptBuilder withContentType( String contentType )
197 item.contentType = contentType;
202 public DataItemOptBuilder withDataType( DataItemType type )
204 item.dataItemType = type;
209 public ArchivaDataItem build( )
212 if ( item.contentType == null )
214 item.contentType = "";
216 if (item.dataItemType ==null) {
217 item.dataItemType = BaseDataItemTypes.UNKNOWN;