This project has retired. For details please refer to its
Attic page.
AbstractMetadataRepository xref
1 package org.apache.archiva.metadata.repository;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.archiva.metadata.QueryParameter;
23 import org.apache.archiva.metadata.model.ArtifactMetadata;
24 import org.apache.archiva.metadata.model.MetadataFacet;
25 import org.apache.archiva.metadata.model.MetadataFacetFactory;
26 import org.apache.archiva.metadata.model.ProjectMetadata;
27 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
28 import org.apache.archiva.metadata.model.ProjectVersionReference;
29 import org.apache.commons.collections4.ComparatorUtils;
30
31 import java.time.ZonedDateTime;
32 import java.util.*;
33 import java.util.stream.Stream;
34
35 public abstract class AbstractMetadataRepository
36 implements MetadataRepository
37 {
38
39 protected MetadataService metadataService;
40
41 public AbstractMetadataRepository() {
42
43 }
44
45 public AbstractMetadataRepository( MetadataService metadataService )
46 {
47 this.metadataService = metadataService;
48 }
49
50 @Override
51 public void updateProject( RepositorySession session, String repositoryId, ProjectMetadata project )
52 throws MetadataRepositoryException
53 {
54 throw new UnsupportedOperationException();
55 }
56
57 @Override
58 public void updateArtifact( RepositorySession session, String repositoryId, String namespace, String projectId, String projectVersion,
59 ArtifactMetadata artifactMeta )
60 throws MetadataRepositoryException
61 {
62 throw new UnsupportedOperationException();
63 }
64
65 @Override
66 public void updateProjectVersion( RepositorySession session, String repositoryId, String namespace, String projectId,
67 ProjectVersionMetadata versionMetadata )
68 throws MetadataRepositoryException
69 {
70 throw new UnsupportedOperationException();
71 }
72
73 @Override
74 public void updateNamespace( RepositorySession session, String repositoryId, String namespace )
75 throws MetadataRepositoryException
76 {
77 throw new UnsupportedOperationException();
78 }
79
80 @Override
81 public List<String> getMetadataFacets( RepositorySession session, String repositoryId, String facetId )
82 throws MetadataRepositoryException
83 {
84 throw new UnsupportedOperationException();
85 }
86
87 @Override
88 public boolean hasMetadataFacet( RepositorySession session, String repositoryId, String facetId )
89 throws MetadataRepositoryException
90 {
91 return false;
92 }
93
94 @Override
95 public void addMetadataFacet( RepositorySession session, String repositoryId, MetadataFacet metadataFacet )
96 throws MetadataRepositoryException
97 {
98 }
99
100 @Override
101 public void removeMetadataFacets( RepositorySession session, String repositoryId, String facetId )
102 throws MetadataRepositoryException
103 {
104 }
105
106 @Override
107 public void removeMetadataFacet( RepositorySession session, String repositoryId, String facetId, String name )
108 throws MetadataRepositoryException
109 {
110 throw new UnsupportedOperationException();
111 }
112
113 @Override
114 public List<ArtifactMetadata> getArtifactsByDateRange(RepositorySession session, String repositoryId, ZonedDateTime startTime, ZonedDateTime endTime, QueryParameter queryParameter )
115 throws MetadataRepositoryException
116 {
117 throw new UnsupportedOperationException();
118 }
119
120 @Override
121 public List<ArtifactMetadata> getArtifactsByChecksum(RepositorySession session, String repositoryId, String checksum )
122 throws MetadataRepositoryException
123 {
124 throw new UnsupportedOperationException();
125 }
126
127 @Override
128 public List<ArtifactMetadata> getArtifactsByProjectVersionFacet( RepositorySession session, String key, String value, String repositoryId )
129 throws MetadataRepositoryException
130 {
131 throw new UnsupportedOperationException();
132 }
133
134 @Override
135 public List<ArtifactMetadata> getArtifactsByAttribute( RepositorySession session, String key, String value, String repositoryId )
136 throws MetadataRepositoryException
137 {
138 throw new UnsupportedOperationException();
139 }
140
141 @Override
142 public List<ArtifactMetadata> getArtifactsByProjectVersionAttribute( RepositorySession session, String key, String value, String repositoryId )
143 throws MetadataRepositoryException
144 {
145 throw new UnsupportedOperationException();
146 }
147
148 @Override
149 public void removeArtifact( RepositorySession session, String repositoryId, String namespace, String project, String version, String id )
150 throws MetadataRepositoryException
151 {
152 throw new UnsupportedOperationException();
153 }
154
155 @Override
156 public void removeTimestampedArtifact( RepositorySession session, ArtifactMetadata artifactMetadata, String baseVersion )
157 throws MetadataRepositoryException
158 {
159 throw new UnsupportedOperationException();
160 }
161
162 @Override
163 public void removeFacetFromArtifact( RepositorySession session, String repositoryId, String namespace, String project, String version,
164 MetadataFacet metadataFacet )
165 throws MetadataRepositoryException
166 {
167 throw new UnsupportedOperationException();
168 }
169
170 @Override
171 public void removeRepository( RepositorySession session, String repositoryId )
172 throws MetadataRepositoryException
173 {
174 }
175
176 @Override
177 public void removeNamespace( RepositorySession session, String repositoryId, String namespace )
178 throws MetadataRepositoryException
179 {
180 throw new UnsupportedOperationException();
181
182 }
183
184 @Override
185 public List<ArtifactMetadata> getArtifacts( RepositorySession session, String repositoryId )
186 throws MetadataRepositoryException
187 {
188 throw new UnsupportedOperationException();
189 }
190
191 @Override
192 public ProjectMetadata getProject( RepositorySession session, String repoId, String namespace, String projectId )
193 throws MetadataResolutionException
194 {
195 throw new UnsupportedOperationException();
196 }
197
198 @Override
199 public ProjectVersionMetadata getProjectVersion( RepositorySession session, String repoId, String namespace, String projectId,
200 String projectVersion )
201 throws MetadataResolutionException
202 {
203 throw new UnsupportedOperationException();
204 }
205
206 @Override
207 public List<String> getArtifactVersions( RepositorySession session, String repoId, String namespace, String projectId,
208 String projectVersion )
209 throws MetadataResolutionException
210 {
211 throw new UnsupportedOperationException();
212 }
213
214 @Override
215 public List<ProjectVersionReference> getProjectReferences( RepositorySession session, String repoId, String namespace, String projectId,
216 String projectVersion )
217 throws MetadataResolutionException
218 {
219 throw new UnsupportedOperationException();
220 }
221
222 @Override
223 public List<String> getRootNamespaces( RepositorySession session, String repoId )
224 throws MetadataResolutionException
225 {
226 throw new UnsupportedOperationException();
227 }
228
229 @Override
230 public List<String> getChildNamespaces( RepositorySession session, String repoId, String namespace )
231 throws MetadataResolutionException
232 {
233 throw new UnsupportedOperationException();
234 }
235
236 @Override
237 public List<String> getProjects( RepositorySession session, String repoId, String namespace )
238 throws MetadataResolutionException
239 {
240 throw new UnsupportedOperationException();
241 }
242
243 @Override
244 public List<String> getProjectVersions( RepositorySession session, String repoId, String namespace, String projectId )
245 throws MetadataResolutionException
246 {
247 throw new UnsupportedOperationException();
248 }
249
250 @Override
251 public void removeProjectVersion( RepositorySession session, String repoId, String namespace, String projectId, String projectVersion )
252 throws MetadataRepositoryException
253 {
254 throw new UnsupportedOperationException();
255 }
256
257 protected static Comparator<ArtifactMetadata> getArtifactMetadataComparator(final QueryParameter queryParameter, String defaultAttr) {
258 List<Comparator<ArtifactMetadata>> compList = new ArrayList<>();
259 List<String> sortFields = new ArrayList<>();
260 if (queryParameter.getSortFields().size() == 0) {
261 sortFields.add(defaultAttr);
262 } else {
263 sortFields = queryParameter.getSortFields();
264 }
265 for (String attribute : sortFields) {
266 switch (attribute) {
267 case "id":
268 compList.add(Comparator.comparing(ArtifactMetadata::getId));
269 break;
270 case "whenGathered":
271 compList.add(Comparator.comparing(ArtifactMetadata::getWhenGathered));
272 break;
273 case "fileLastModified":
274 compList.add(Comparator.comparing(ArtifactMetadata::getFileLastModified));
275 case "version":
276 compList.add(Comparator.comparing(ArtifactMetadata::getVersion));
277 break;
278 case "projectVersion":
279 compList.add(Comparator.comparing(ArtifactMetadata::getProjectVersion));
280 break;
281 case "project":
282 compList.add(Comparator.comparing(ArtifactMetadata::getProject));
283 break;
284 default:
285
286 }
287 }
288 Comparator<ArtifactMetadata> comp = ComparatorUtils.chainedComparator(compList);
289 if (queryParameter.isAscending()) {
290 return comp;
291 } else {
292 return comp.reversed();
293 }
294 }
295
296 @Override
297 public List<ArtifactMetadata> getArtifacts( RepositorySession session, String repoId, String namespace, String projectId,
298 String projectVersion )
299 throws MetadataResolutionException
300 {
301 throw new UnsupportedOperationException();
302 }
303
304 @Override
305 public void removeProject( RepositorySession session, String repositoryId, String namespace, String projectId )
306 throws MetadataRepositoryException
307 {
308 throw new UnsupportedOperationException();
309 }
310
311
312 @Override
313 public void close()
314 throws MetadataRepositoryException
315 {
316 }
317
318 @Override
319 public List<ArtifactMetadata> searchArtifacts( RepositorySession session, String repositoryId, String text, boolean exact )
320 throws MetadataRepositoryException
321 {
322 throw new UnsupportedOperationException();
323 }
324
325 @Override
326 public List<ArtifactMetadata> searchArtifacts( RepositorySession session, String repositoryId, String key, String text, boolean exact )
327 throws MetadataRepositoryException
328 {
329 throw new UnsupportedOperationException();
330 }
331
332 @Override
333 public <T extends MetadataFacet> Stream<T> getMetadataFacetStream( RepositorySession session, String repositoryId, Class<T> facetClazz ) throws MetadataRepositoryException
334 {
335 return getMetadataFacetStream( session, repositoryId, facetClazz, new QueryParameter());
336 }
337
338 @Override
339 public Stream<ArtifactMetadata> getArtifactByDateRangeStream( RepositorySession session, String repositoryId, ZonedDateTime startTime, ZonedDateTime endTime ) throws MetadataRepositoryException
340 {
341 return getArtifactByDateRangeStream( session, repositoryId, startTime, endTime, new QueryParameter());
342 }
343
344 @Override
345 public MetadataFacet getMetadataFacet( RepositorySession session, String repositoryId, String facetId, String name )
346 throws MetadataRepositoryException
347 {
348 return getMetadataFacet( session, repositoryId, getFactoryClassForId( facetId ), name );
349 }
350
351 @Override
352 public <T extends MetadataFacet> Stream<T> getMetadataFacetStream(RepositorySession session, String repositoryId, Class<T> facetClazz, QueryParameter queryParameter) throws MetadataRepositoryException
353 {
354 throw new UnsupportedOperationException();
355 }
356
357 @Override
358 public <T extends MetadataFacet> T getMetadataFacet( RepositorySession session, String repositoryId, Class<T> clazz, String name ) throws MetadataRepositoryException
359 {
360 throw new UnsupportedOperationException();
361 }
362
363
364
365 @Override
366 public Stream<ArtifactMetadata> getArtifactByDateRangeStream( RepositorySession session, String repositoryId, ZonedDateTime startTime, ZonedDateTime endTime, QueryParameter queryParameter) throws MetadataRepositoryException
367 {
368 throw new UnsupportedOperationException();
369 }
370
371
372 protected <T extends MetadataFacet> MetadataFacetFactory getFacetFactory(Class<T> facetClazz) {
373 return metadataService.getFactory( facetClazz );
374 }
375
376 protected MetadataFacetFactory getFacetFactory(String facetId) {
377 return metadataService.getFactory( facetId );
378 }
379
380 protected Set<String> getSupportedFacets() {
381 return metadataService.getSupportedFacets( );
382 }
383
384 protected Class<? extends MetadataFacet> getFactoryClassForId( String facetId ) {
385 return metadataService.getFactoryClassForId( facetId );
386 }
387
388
389
390 @Override
391 public List<ArtifactMetadata> getArtifactsByDateRange(RepositorySession session, String repoId, ZonedDateTime startTime, ZonedDateTime endTime)
392 throws MetadataRepositoryException {
393 return getArtifactsByDateRange(session, repoId, startTime, endTime, new QueryParameter( ));
394 }
395
396 @Override
397 public Stream<ArtifactMetadata> getArtifactStream( final RepositorySession session, final String repositoryId ) throws MetadataResolutionException
398 {
399 return getArtifactStream( session, repositoryId, new QueryParameter( ) );
400 }
401
402 @Override
403 public Stream<ArtifactMetadata> getArtifactStream( final RepositorySession session, final String repoId,
404 final String namespace, final String projectId,
405 final String projectVersion) throws MetadataResolutionException
406 {
407 return getArtifactStream( session,repoId,namespace, projectId, projectVersion, new QueryParameter( ));
408 }
409
410 @Override
411 public Stream<ArtifactMetadata> getArtifactStream( final RepositorySession session, final String repositoryId, QueryParameter queryParameter ) throws MetadataResolutionException
412 {
413 throw new UnsupportedOperationException( );
414 }
415
416 @Override
417 public Stream<ArtifactMetadata> getArtifactStream( final RepositorySession session, final String repoId,
418 final String namespace, final String projectId,
419 final String projectVersion, final QueryParameter queryParameter ) throws MetadataResolutionException
420 {
421 throw new UnsupportedOperationException( );
422 }
423
424 }