1 package org.apache.archiva.metadata.repository;
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.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;
31 import java.time.ZonedDateTime;
33 import java.util.stream.Stream;
35 public abstract class AbstractMetadataRepository
36 implements MetadataRepository
39 protected MetadataService metadataService;
41 public AbstractMetadataRepository() {
45 public AbstractMetadataRepository( MetadataService metadataService )
47 this.metadataService = metadataService;
51 public void updateProject( RepositorySession session, String repositoryId, ProjectMetadata project )
52 throws MetadataRepositoryException
54 throw new UnsupportedOperationException();
58 public void updateArtifact( RepositorySession session, String repositoryId, String namespace, String projectId, String projectVersion,
59 ArtifactMetadata artifactMeta )
60 throws MetadataRepositoryException
62 throw new UnsupportedOperationException();
66 public void updateProjectVersion( RepositorySession session, String repositoryId, String namespace, String projectId,
67 ProjectVersionMetadata versionMetadata )
68 throws MetadataRepositoryException
70 throw new UnsupportedOperationException();
74 public void updateNamespace( RepositorySession session, String repositoryId, String namespace )
75 throws MetadataRepositoryException
77 throw new UnsupportedOperationException();
81 public List<String> getMetadataFacets( RepositorySession session, String repositoryId, String facetId )
82 throws MetadataRepositoryException
84 throw new UnsupportedOperationException();
88 public boolean hasMetadataFacet( RepositorySession session, String repositoryId, String facetId )
89 throws MetadataRepositoryException
95 public void addMetadataFacet( RepositorySession session, String repositoryId, MetadataFacet metadataFacet )
96 throws MetadataRepositoryException
101 public void removeMetadataFacets( RepositorySession session, String repositoryId, String facetId )
102 throws MetadataRepositoryException
107 public void removeMetadataFacet( RepositorySession session, String repositoryId, String facetId, String name )
108 throws MetadataRepositoryException
110 throw new UnsupportedOperationException();
114 public List<ArtifactMetadata> getArtifactsByDateRange(RepositorySession session, String repositoryId, ZonedDateTime startTime, ZonedDateTime endTime, QueryParameter queryParameter )
115 throws MetadataRepositoryException
117 throw new UnsupportedOperationException();
121 public List<ArtifactMetadata> getArtifactsByChecksum(RepositorySession session, String repositoryId, String checksum )
122 throws MetadataRepositoryException
124 throw new UnsupportedOperationException();
128 public List<ArtifactMetadata> getArtifactsByProjectVersionFacet( RepositorySession session, String key, String value, String repositoryId )
129 throws MetadataRepositoryException
131 throw new UnsupportedOperationException();
135 public List<ArtifactMetadata> getArtifactsByAttribute( RepositorySession session, String key, String value, String repositoryId )
136 throws MetadataRepositoryException
138 throw new UnsupportedOperationException();
142 public List<ArtifactMetadata> getArtifactsByProjectVersionAttribute( RepositorySession session, String key, String value, String repositoryId )
143 throws MetadataRepositoryException
145 throw new UnsupportedOperationException();
149 public void removeArtifact( RepositorySession session, String repositoryId, String namespace, String project, String version, String id )
150 throws MetadataRepositoryException
152 throw new UnsupportedOperationException();
156 public void removeTimestampedArtifact( RepositorySession session, ArtifactMetadata artifactMetadata, String baseVersion )
157 throws MetadataRepositoryException
159 throw new UnsupportedOperationException();
163 public void removeFacetFromArtifact( RepositorySession session, String repositoryId, String namespace, String project, String version,
164 MetadataFacet metadataFacet )
165 throws MetadataRepositoryException
167 throw new UnsupportedOperationException();
171 public void removeRepository( RepositorySession session, String repositoryId )
172 throws MetadataRepositoryException
177 public void removeNamespace( RepositorySession session, String repositoryId, String namespace )
178 throws MetadataRepositoryException
180 throw new UnsupportedOperationException();
185 public List<ArtifactMetadata> getArtifacts( RepositorySession session, String repositoryId )
186 throws MetadataRepositoryException
188 throw new UnsupportedOperationException();
192 public ProjectMetadata getProject( RepositorySession session, String repoId, String namespace, String projectId )
193 throws MetadataResolutionException
195 throw new UnsupportedOperationException();
199 public ProjectVersionMetadata getProjectVersion( RepositorySession session, String repoId, String namespace, String projectId,
200 String projectVersion )
201 throws MetadataResolutionException
203 throw new UnsupportedOperationException();
207 public Collection<String> getArtifactVersions( RepositorySession session, String repoId, String namespace, String projectId,
208 String projectVersion )
209 throws MetadataResolutionException
211 throw new UnsupportedOperationException();
215 public Collection<ProjectVersionReference> getProjectReferences( RepositorySession session, String repoId, String namespace, String projectId,
216 String projectVersion )
217 throws MetadataResolutionException
219 throw new UnsupportedOperationException();
223 public Collection<String> getRootNamespaces( RepositorySession session, String repoId )
224 throws MetadataResolutionException
226 throw new UnsupportedOperationException();
230 public Collection<String> getChildNamespaces( RepositorySession session, String repoId, String namespace )
231 throws MetadataResolutionException
233 throw new UnsupportedOperationException();
237 public Collection<String> getProjects( RepositorySession session, String repoId, String namespace )
238 throws MetadataResolutionException
240 throw new UnsupportedOperationException();
244 public Collection<String> getProjectVersions( RepositorySession session, String repoId, String namespace, String projectId )
245 throws MetadataResolutionException
247 throw new UnsupportedOperationException();
251 public void removeProjectVersion( RepositorySession session, String repoId, String namespace, String projectId, String projectVersion )
252 throws MetadataRepositoryException
254 throw new UnsupportedOperationException();
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);
263 sortFields = queryParameter.getSortFields();
265 for (String attribute : sortFields) {
268 compList.add(Comparator.comparing(ArtifactMetadata::getId));
271 compList.add(Comparator.comparing(ArtifactMetadata::getWhenGathered));
273 case "fileLastModified":
274 compList.add(Comparator.comparing(ArtifactMetadata::getFileLastModified));
276 compList.add(Comparator.comparing(ArtifactMetadata::getVersion));
278 case "projectVersion":
279 compList.add(Comparator.comparing(ArtifactMetadata::getProjectVersion));
282 compList.add(Comparator.comparing(ArtifactMetadata::getProject));
288 Comparator<ArtifactMetadata> comp = ComparatorUtils.chainedComparator(compList);
289 if (queryParameter.isAscending()) {
292 return comp.reversed();
297 public Collection<ArtifactMetadata> getArtifacts( RepositorySession session, String repoId, String namespace, String projectId,
298 String projectVersion )
299 throws MetadataResolutionException
301 throw new UnsupportedOperationException();
305 public void removeProject( RepositorySession session, String repositoryId, String namespace, String projectId )
306 throws MetadataRepositoryException
308 throw new UnsupportedOperationException();
314 throws MetadataRepositoryException
319 public List<ArtifactMetadata> searchArtifacts( RepositorySession session, String repositoryId, String text, boolean exact )
320 throws MetadataRepositoryException
322 throw new UnsupportedOperationException();
326 public List<ArtifactMetadata> searchArtifacts( RepositorySession session, String repositoryId, String key, String text, boolean exact )
327 throws MetadataRepositoryException
329 throw new UnsupportedOperationException();
333 public <T extends MetadataFacet> Stream<T> getMetadataFacetStream( RepositorySession session, String repositoryId, Class<T> facetClazz ) throws MetadataRepositoryException
335 return getMetadataFacetStream( session, repositoryId, facetClazz, new QueryParameter());
339 public Stream<ArtifactMetadata> getArtifactByDateRangeStream( RepositorySession session, String repositoryId, ZonedDateTime startTime, ZonedDateTime endTime ) throws MetadataRepositoryException
341 return getArtifactByDateRangeStream( session, repositoryId, startTime, endTime, new QueryParameter());
345 public MetadataFacet getMetadataFacet( RepositorySession session, String repositoryId, String facetId, String name )
346 throws MetadataRepositoryException
348 return getMetadataFacet( session, repositoryId, getFactoryClassForId( facetId ), name );
352 public <T extends MetadataFacet> Stream<T> getMetadataFacetStream(RepositorySession session, String repositoryId, Class<T> facetClazz, QueryParameter queryParameter) throws MetadataRepositoryException
354 throw new UnsupportedOperationException();
358 public <T extends MetadataFacet> T getMetadataFacet( RepositorySession session, String repositoryId, Class<T> clazz, String name ) throws MetadataRepositoryException
360 throw new UnsupportedOperationException();
366 public Stream<ArtifactMetadata> getArtifactByDateRangeStream( RepositorySession session, String repositoryId, ZonedDateTime startTime, ZonedDateTime endTime, QueryParameter queryParameter) throws MetadataRepositoryException
368 throw new UnsupportedOperationException();
372 protected <T extends MetadataFacet> MetadataFacetFactory getFacetFactory(Class<T> facetClazz) {
373 return metadataService.getFactory( facetClazz );
376 protected MetadataFacetFactory getFacetFactory(String facetId) {
377 return metadataService.getFactory( facetId );
380 protected Set<String> getSupportedFacets() {
381 return metadataService.getSupportedFacets( );
384 protected Class<? extends MetadataFacet> getFactoryClassForId( String facetId ) {
385 return metadataService.getFactoryClassForId( facetId );
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( ));
397 public Stream<ArtifactMetadata> getArtifactStream( final RepositorySession session, final String repositoryId ) throws MetadataResolutionException
399 return getArtifactStream( session, repositoryId, new QueryParameter( ) );
403 public Stream<ArtifactMetadata> getArtifactStream( final RepositorySession session, final String repoId,
404 final String namespace, final String projectId,
405 final String projectVersion) throws MetadataResolutionException
407 return getArtifactStream( session,repoId,namespace, projectId, projectVersion, new QueryParameter( ));
411 public Stream<ArtifactMetadata> getArtifactStream( final RepositorySession session, final String repositoryId, QueryParameter queryParameter ) throws MetadataResolutionException
413 throw new UnsupportedOperationException( );
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
421 throw new UnsupportedOperationException( );