001package org.apache.archiva.metadata.repository; 002 003/* 004* Licensed to the Apache Software Foundation (ASF) under one 005* or more contributor license agreements. See the NOTICE file 006* distributed with this work for additional information 007* regarding copyright ownership. The ASF licenses this file 008* to you under the Apache License, Version 2.0 (the 009* "License"); you may not use this file except in compliance 010* with the License. You may obtain a copy of the License at 011* 012* http://www.apache.org/licenses/LICENSE-2.0 013* 014* Unless required by applicable law or agreed to in writing, 015* software distributed under the License is distributed on an 016* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017* KIND, either express or implied. See the License for the 018* specific language governing permissions and limitations 019* under the License. 020*/ 021 022import org.apache.archiva.metadata.QueryParameter; 023import org.apache.archiva.metadata.model.ArtifactMetadata; 024import org.apache.archiva.metadata.model.MetadataFacet; 025import org.apache.archiva.metadata.model.MetadataFacetFactory; 026import org.apache.archiva.metadata.model.ProjectMetadata; 027import org.apache.archiva.metadata.model.ProjectVersionMetadata; 028import org.apache.archiva.metadata.model.ProjectVersionReference; 029import org.apache.commons.collections4.ComparatorUtils; 030 031import java.time.ZonedDateTime; 032import java.util.*; 033import java.util.stream.Stream; 034 035public abstract class AbstractMetadataRepository 036 implements MetadataRepository 037{ 038 039 protected MetadataService metadataService; 040 041 public AbstractMetadataRepository() { 042 043 } 044 045 public AbstractMetadataRepository( MetadataService metadataService ) 046 { 047 this.metadataService = metadataService; 048 } 049 050 @Override 051 public void updateProject( RepositorySession session, String repositoryId, ProjectMetadata project ) 052 throws MetadataRepositoryException 053 { 054 throw new UnsupportedOperationException(); 055 } 056 057 @Override 058 public void updateArtifact( RepositorySession session, String repositoryId, String namespace, String projectId, String projectVersion, 059 ArtifactMetadata artifactMeta ) 060 throws MetadataRepositoryException 061 { 062 throw new UnsupportedOperationException(); 063 } 064 065 @Override 066 public void updateProjectVersion( RepositorySession session, String repositoryId, String namespace, String projectId, 067 ProjectVersionMetadata versionMetadata ) 068 throws MetadataRepositoryException 069 { 070 throw new UnsupportedOperationException(); 071 } 072 073 @Override 074 public void updateNamespace( RepositorySession session, String repositoryId, String namespace ) 075 throws MetadataRepositoryException 076 { 077 throw new UnsupportedOperationException(); 078 } 079 080 @Override 081 public List<String> getMetadataFacets( RepositorySession session, String repositoryId, String facetId ) 082 throws MetadataRepositoryException 083 { 084 throw new UnsupportedOperationException(); 085 } 086 087 @Override 088 public boolean hasMetadataFacet( RepositorySession session, String repositoryId, String facetId ) 089 throws MetadataRepositoryException 090 { 091 return false; 092 } 093 094 @Override 095 public void addMetadataFacet( RepositorySession session, String repositoryId, MetadataFacet metadataFacet ) 096 throws MetadataRepositoryException 097 { 098 } 099 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}