1 package org.apache.archiva.repository.base;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
20 import org.apache.archiva.repository.EditableRepository;
21 import org.apache.archiva.repository.Repository;
22 import org.apache.archiva.repository.RepositoryHandler;
23 import org.apache.archiva.repository.RepositoryState;
24 import org.apache.archiva.repository.base.group.RepositoryGroupHandler;
25 import org.apache.archiva.repository.validation.CombinedValidator;
26 import org.apache.archiva.repository.validation.RepositoryValidator;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import java.util.Collections;
31 import java.util.List;
32 import java.util.stream.Collectors;
35 * Base abstract class for repository handlers.
36 * @author Martin Stockhammer <martin_s@apache.org>
38 public abstract class AbstractRepositoryHandler<R extends Repository, C> implements RepositoryHandler<R, C>
41 private static final Logger log = LoggerFactory.getLogger( AbstractRepositoryHandler.class );
43 protected List<RepositoryValidator<R>> initValidators( Class<R> clazz, List<RepositoryValidator<? extends Repository>> repositoryGroupValidatorList) {
44 if (repositoryGroupValidatorList!=null && repositoryGroupValidatorList.size()>0) {
45 return repositoryGroupValidatorList.stream( ).filter(
46 v -> v.isFlavour( clazz )
47 ).map( v -> v.narrowTo( clazz ) ).collect( Collectors.toList( ) );
49 return Collections.emptyList( );
53 protected CombinedValidator<R> getCombinedValidatdor(Class<R> clazz, List<RepositoryValidator<? extends Repository>> repositoryGroupValidatorList) {
54 return new CombinedValidator<>( clazz, initValidators( clazz, repositoryGroupValidatorList ) );
57 protected void setLastState(Repository repo, RepositoryState state) {
58 if (repo instanceof EditableRepository ) {
59 if (state.getOrderNumber()>repo.getLastState().getOrderNumber())
61 ( (EditableRepository) repo ).setLastState( state );
64 log.error( "Found a not editable repository instance: {}, {}", repo.getId( ), repo.getClass().getName() );