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.ItemSelector;
23 import org.apache.commons.lang3.StringUtils;
25 import java.util.Collections;
26 import java.util.HashMap;
30 * Item selector for querying artifacts and other content items.
32 public class ArchivaItemSelector implements ItemSelector
35 private String projectId = null;
36 private String version = null;
37 private String artifactVersion = null;
38 private String artifactId = null;
39 private String namespace = "";
40 private String type = null;
41 private String classifier = null;
42 private String extension = null;
43 private Map<String, String> attributes;
44 private boolean searchRelatedArtifacts = false;
45 private boolean searchSubNamespaces = false;
48 private ArchivaItemSelector( )
53 public static Builder builder( )
55 return new Builder( );
58 public static class Builder
60 private final ArchivaItemSelector selector = new ArchivaItemSelector( );
62 public Builder withNamespace( String namespace )
64 selector.namespace = namespace;
69 public Builder withProjectId( String projectId )
71 selector.projectId = projectId;
76 public Builder withVersion( String version )
78 selector.version = version;
83 public Builder withArtifactVersion( String artifactVersion )
85 selector.artifactVersion = artifactVersion;
90 public Builder withArtifactId( String artifactId )
92 selector.artifactId = artifactId;
97 public Builder withType( String type )
104 public Builder withClassifier( String classifier )
106 selector.classifier = classifier;
111 public Builder withAttribute( String key, String value )
113 selector.setAttribute( key, value );
117 public Builder withExtension( String extension )
119 selector.extension = extension;
123 public Builder enableSearchRelatedArtifacts() {
124 selector.searchRelatedArtifacts = true;
128 public Builder enableSearchSubNamespaces() {
129 selector.searchSubNamespaces = true;
133 public ArchivaItemSelector build( )
139 private void setAttribute( String key, String value )
141 if ( this.attributes == null )
143 this.attributes = new HashMap<>( );
145 this.attributes.put( key, value );
149 public String getProjectId( )
155 public String getNamespace( )
161 public String getVersion( )
167 public String getArtifactVersion( )
169 return artifactVersion;
173 public String getArtifactId( )
179 public String getType( )
185 public String getClassifier( )
191 public String getAttribute( String key )
193 if ( this.attributes == null || !this.attributes.containsKey( key ) )
200 return this.attributes.get( key );
205 public String getExtension( )
211 public Map<String, String> getAttributes( )
213 if ( this.attributes == null )
215 return Collections.emptyMap( );
219 return Collections.unmodifiableMap( this.attributes );
224 public boolean searchSubNamespaces( )
226 return searchSubNamespaces;
230 public boolean findRelatedArtifacts( )
232 return searchRelatedArtifacts;
236 public boolean hasAttributes( )
238 return attributes != null && attributes.size( ) > 0;
242 public boolean hasExtension( )
244 return StringUtils.isNotEmpty( extension );