1 package org.apache.archiva.metadata.repository;
2
3 /*
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
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
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
19 * under the License.
20 */
21
22 import org.apache.archiva.metadata.model.ArtifactMetadata;
23 import org.apache.archiva.metadata.model.MetadataFacet;
24 import org.apache.archiva.metadata.model.ProjectMetadata;
25 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
26 import org.apache.archiva.metadata.model.ProjectVersionReference;
27
28 import java.util.Collection;
29 import java.util.Date;
30 import java.util.List;
31
32 public interface MetadataRepository
33 {
34 /**
35 * Update metadata for a particular project in the metadata repository, or create it if it does not already exist.
36 *
37 * @param repositoryId the repository the project is in
38 * @param project the project metadata to create or update
39 */
40 void updateProject( String repositoryId, ProjectMetadata project )
41 throws MetadataRepositoryException;
42
43 void updateArtifact( String repositoryId, String namespace, String projectId, String projectVersion,
44 ArtifactMetadata artifactMeta )
45 throws MetadataRepositoryException;
46
47 void updateProjectVersion( String repositoryId, String namespace, String projectId,
48 ProjectVersionMetadata versionMetadata )
49 throws MetadataRepositoryException;
50
51 /**
52 * create the namespace in the repository. (if not exist)
53 *
54 * @param repositoryId
55 * @param namespace
56 * @throws MetadataRepositoryException
57 */
58 void updateNamespace( String repositoryId, String namespace )
59 throws MetadataRepositoryException;
60
61 List<String> getMetadataFacets( String repositoryId, String facetId )
62 throws MetadataRepositoryException;
63
64 /**
65 * @param repositoryId
66 * @param facetId
67 * @return true if the repository datas for this facetId
68 * @throws MetadataRepositoryException
69 * @since 1.4-M4
70 */
71 boolean hasMetadataFacet( String repositoryId, String facetId )
72 throws MetadataRepositoryException;
73
74 MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name )
75 throws MetadataRepositoryException;
76
77 void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
78 throws MetadataRepositoryException;
79
80 void removeMetadataFacets( String repositoryId, String facetId )
81 throws MetadataRepositoryException;
82
83 void removeMetadataFacet( String repositoryId, String facetId, String name )
84 throws MetadataRepositoryException;
85
86 /**
87 * if startTime or endTime are <code>null</code> they are not used for search
88 *
89 * @param repositoryId
90 * @param startTime can be <code>null</code>
91 * @param endTime can be <code>null</code>
92 * @return
93 * @throws MetadataRepositoryException
94 */
95 List<ArtifactMetadata> getArtifactsByDateRange( String repositoryId, Date startTime, Date endTime )
96 throws MetadataRepositoryException;
97
98 // TODO: remove from API, just use configuration
99 Collection<String> getRepositories()
100 throws MetadataRepositoryException;
101
102 Collection<ArtifactMetadata> getArtifactsByChecksum( String repositoryId, String checksum )
103 throws MetadataRepositoryException;
104
105 /**
106 * Get artifacts with a project version metadata key that matches the passed value.
107 *
108 * @param key
109 * @param value
110 * @param repositoryId can be null, meaning search in all repositories
111 * @return a list of artifacts
112 * @throws MetadataRepositoryException
113 */
114 List<ArtifactMetadata> getArtifactsByProjectVersionMetadata( String key, String value, String repositoryId )
115 throws MetadataRepositoryException;
116
117 /**
118 * Get artifacts with an artifact metadata key that matches the passed value.
119 *
120 * @param key
121 * @param value
122 * @param repositoryId can be null, meaning search in all repositories
123 * @return a list of artifacts
124 * @throws MetadataRepositoryException
125 */
126 List<ArtifactMetadata> getArtifactsByMetadata( String key, String value, String repositoryId )
127 throws MetadataRepositoryException;
128
129 /**
130 * Get artifacts with a property key that matches the passed value.
131 * Possible keys are 'scm.url', 'org.name', 'url', 'mailingList.0.name', 'license.0.name',...
132 *
133 * @param key
134 * @param value
135 * @param repositoryId can be null, meaning search in all repositories
136 * @return a list of artifacts
137 * @throws MetadataRepositoryException
138 */
139 List<ArtifactMetadata> getArtifactsByProperty( String key, String value, String repositoryId )
140 throws MetadataRepositoryException;
141
142 void removeArtifact( String repositoryId, String namespace, String project, String version, String id )
143 throws MetadataRepositoryException;
144
145 /**
146 * used for deleting timestamped version of SNAPSHOT artifacts
147 *
148 * @param artifactMetadata the artifactMetadata with the timestamped version (2.0-20120618.214135-2)
149 * @param baseVersion the base version of the snapshot (2.0-SNAPSHOT)
150 * @throws MetadataRepositoryException
151 * @since 1.4-M3
152 */
153 void removeArtifact( ArtifactMetadata artifactMetadata, String baseVersion )
154 throws MetadataRepositoryException;
155
156 /**
157 * FIXME need a unit test!!!
158 * Only remove {@link MetadataFacet} for the artifact
159 *
160 * @param repositoryId
161 * @param namespace
162 * @param project
163 * @param version
164 * @param metadataFacet
165 * @throws MetadataRepositoryException
166 * @since 1.4-M3
167 */
168 void removeArtifact( String repositoryId, String namespace, String project, String version,
169 MetadataFacet metadataFacet )
170 throws MetadataRepositoryException;
171
172 /**
173 * Delete a repository's metadata. This includes all associated metadata facets.
174 *
175 * @param repositoryId the repository to delete
176 */
177 void removeRepository( String repositoryId )
178 throws MetadataRepositoryException;
179
180 /**
181 * @param repositoryId
182 * @param namespace (groupId for maven )
183 * @throws MetadataRepositoryException
184 * @since 1.4-M3
185 */
186 void removeNamespace( String repositoryId, String namespace )
187 throws MetadataRepositoryException;
188
189 List<ArtifactMetadata> getArtifacts( String repositoryId )
190 throws MetadataRepositoryException;
191
192 /**
193 * basically just checking it exists not complete data returned
194 *
195 * @param repoId
196 * @param namespace
197 * @param projectId
198 * @return
199 * @throws MetadataResolutionException
200 */
201 ProjectMetadata getProject( String repoId, String namespace, String projectId )
202 throws MetadataResolutionException;
203
204 ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId, String projectVersion )
205 throws MetadataResolutionException;
206
207 Collection<String> getArtifactVersions( String repoId, String namespace, String projectId, String projectVersion )
208 throws MetadataResolutionException;
209
210 /**
211 * Retrieve project references from the metadata repository. Note that this is not built into the content model for
212 * a project version as a reference may be present (due to reverse-lookup of dependencies) before the actual
213 * project is, and we want to avoid adding a stub model to the content repository.
214 *
215 * @param repoId the repository ID to look within
216 * @param namespace the namespace of the project to get references to
217 * @param projectId the identifier of the project to get references to
218 * @param projectVersion the version of the project to get references to
219 * @return a list of project references
220 */
221 Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
222 String projectVersion )
223 throws MetadataResolutionException;
224
225 Collection<String> getRootNamespaces( String repoId )
226 throws MetadataResolutionException;
227
228 /**
229 * @param repoId
230 * @param namespace
231 * @return {@link Collection} of child namespaces of the namespace argument
232 * @throws MetadataResolutionException
233 */
234 Collection<String> getNamespaces( String repoId, String namespace )
235 throws MetadataResolutionException;
236
237 /**
238 * @param repoId
239 * @param namespace
240 * @return
241 * @throws MetadataResolutionException
242 */
243 Collection<String> getProjects( String repoId, String namespace )
244 throws MetadataResolutionException;
245
246 /**
247 * @param repoId
248 * @param namespace
249 * @param projectId
250 * @return
251 * @throws MetadataResolutionException
252 */
253 Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
254 throws MetadataResolutionException;
255
256 /**
257 * @param repoId
258 * @param namespace
259 * @param projectId
260 * @param projectVersion
261 * @throws MetadataRepositoryException
262 * @since 1.4-M4
263 */
264 void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion )
265 throws MetadataRepositoryException;
266
267 /**
268 * @param repoId
269 * @param namespace
270 * @param projectId
271 * @param projectVersion
272 * @return
273 * @throws MetadataResolutionException
274 */
275 Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
276 String projectVersion )
277 throws MetadataResolutionException;
278
279 /**
280 * remove a project
281 *
282 * @param repositoryId
283 * @param namespace
284 * @param projectId
285 * @throws MetadataRepositoryException
286 * @since 1.4-M4
287 */
288 void removeProject( String repositoryId, String namespace, String projectId )
289 throws MetadataRepositoryException;
290
291
292 /**
293 * <b>implementations can throw RuntimeException</b>
294 */
295 void save();
296
297
298 void close()
299 throws MetadataRepositoryException;
300
301 /**
302 * <b>implementations can throw RuntimeException</b>
303 */
304 void revert();
305
306 boolean canObtainAccess( Class<?> aClass );
307
308 <T> T obtainAccess( Class<T> aClass )
309 throws MetadataRepositoryException;
310
311 /**
312 * Full text artifacts search.
313 *
314 * @param text
315 * @param repositoryId can be null to search in all repositories
316 * @param exact running an exact search, the value must exactly match the text.
317 * @return a list of artifacts
318 * @throws MetadataRepositoryException
319 */
320 List<ArtifactMetadata> searchArtifacts( String text, String repositoryId, boolean exact )
321 throws MetadataRepositoryException;
322
323 /**
324 * Full text artifacts search inside the specified key.
325 *
326 * @param key search only inside this key
327 * @param text
328 * @param repositoryId can be null to search in all repositories
329 * @param exact running an exact search, the value must exactly match the text.
330 * @return a list of artifacts
331 * @throws MetadataRepositoryException
332 */
333 List<ArtifactMetadata> searchArtifacts( String key, String text, String repositoryId, boolean exact )
334 throws MetadataRepositoryException;
335
336 }