1 package org.apache.archiva.repository;
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.configuration.Configuration;
21 import org.apache.archiva.repository.validation.CheckedResult;
22 import org.apache.archiva.repository.validation.RepositoryChecker;
23 import org.apache.archiva.repository.validation.RepositoryValidator;
24 import org.apache.archiva.repository.validation.ValidationError;
25 import org.apache.archiva.repository.validation.ValidationResponse;
27 import java.util.Collection;
28 import java.util.List;
32 * This is the generic interface that handles different repository flavours, currently for
33 * ManagedRepository, RemoteRepository and RepositoryGroup
35 * Lifecycle/states of a repository:
37 * <li>Instance created: This state is reached by the newInstance-methods. The instance is created, filled with the
38 * corresponding attribute data and references are updated. References are object references to other repositories, if they exist.
39 * The instance is not registered on the registry (stored) and configuration is not updated.</li>
40 * <li>Instance registered: Instances added/updated by the put()-methods are created and registered on the registry.
41 * If all goes well, the configuration is updated.</li>
42 * <li>Instance initialized: </li>
46 * @author Martin Stockhammer <martin_s@apache.org>
48 public interface RepositoryHandler<R extends Repository, C>
52 * Initializes the current state from the configuration
54 void initializeFromConfig( );
57 * Initializes the repository. E.g. starts scheduling and activate additional processes.
58 * @param repository the repository to initialize
60 void initialize( R repository );
63 * Creates new instances from the archiva configuration. The instances are not registered in the registry.
65 * @return A map of (repository id, Repository) pairs
67 Map<String, R> newInstancesFromConfig( );
70 * Creates a new instance without registering and without updating the archiva configuration
72 * @param type the repository type
73 * @param id the repository identifier
74 * @return the repository instance
75 * @throws RepositoryException if the creation failed
77 R newInstance( RepositoryType type, String id ) throws RepositoryException;
80 * Creates a new instance and updates the given configuration object.
82 * @param repositoryConfiguration the configuration instance
83 * @return a newly created instance
84 * @throws RepositoryException if the creation failed
86 R newInstance( C repositoryConfiguration ) throws RepositoryException;
89 * Adds the given repository to the registry or replaces a already existing repository in the registry.
90 * If an error occurred during the update, it will revert to the old repository status.
92 * @param repository the repository
93 * @return the created or updated repository instance
94 * @throws RepositoryException if the update or creation failed
96 R put( R repository ) throws RepositoryException;
99 * Adds the repository to the registry, based on the given configuration.
100 * If there is a repository registered with the given id, it is updated.
101 * The archiva configuration is updated. The status is not defined, if an error occurs during update. The
102 * The repository instance is registered and initialized if no error occurs
104 * @param repositoryConfiguration the repository configuration
105 * @return the updated or created repository instance
106 * @throws RepositoryException if the update or creation failed
108 R put( C repositoryConfiguration ) throws RepositoryException;
111 * Adds a repository from the given repository configuration. The changes are stored in
112 * the configuration object. The archiva registry is not updated.
113 * The returned repository instance is a clone of the registered repository instance. It is not registered
114 * and not initialized. References are not updated.
116 * @param repositoryConfiguration the repository configuration
117 * @param configuration the configuration instance
118 * @return the repository instance that was created or updated
119 * @throws RepositoryException if the update or creation failed
121 R put( C repositoryConfiguration, Configuration configuration ) throws RepositoryException;
124 * Adds or updates a repository from the given configuration data. The resulting repository is
125 * checked by the repository checker and the result is returned.
126 * If the checker returns a valid result, the registry is updated and configuration is saved.
128 * @param repositoryConfiguration the repository configuration
129 * @param checker the checker that validates the repository data
130 * @return the repository and the check result
131 * @throws RepositoryException if the creation or update failed
133 <D> CheckedResult<R, D>
134 putWithCheck( C repositoryConfiguration, RepositoryChecker<R, D> checker ) throws RepositoryException;
137 * Removes the given repository from the registry and updates references and saves the new configuration.
139 * @param id The repository identifier
140 * @throws RepositoryException if the repository could not be removed
142 void remove( final String id ) throws RepositoryException;
145 * Removes the given repository from the registry and updates only the given configuration instance.
146 * The archiva registry is not updated
148 * @param id the repository identifier
149 * @param configuration the configuration to update
150 * @throws RepositoryException if the repository could not be removed
152 void remove( String id, Configuration configuration ) throws RepositoryException;
155 * Returns the repository with the given identifier or <code>null</code>, if it is not registered.
157 * @param id the repository id
158 * @return if the retrieval failed
163 * Clones a given repository without registering.
165 * @param repo the repository that should be cloned
166 * @return a newly created instance with the same repository data
168 R clone( R repo ) throws RepositoryException;
171 * Updates the references and stores updates in the given <code>configuration</code> instance.
172 * The references that are updated depend on the concrete repository subclass <code>R</code>.
173 * This method may register/unregister repositories depending on the implementation. That means there is no simple
174 * way to roll back, if an error occurs.
176 * @param repo the repository for which references are updated
177 * @param repositoryConfiguration the repository configuration
179 void updateReferences( R repo, C repositoryConfiguration ) throws RepositoryException;
182 * Returns all registered repositories.
184 * @return the list of repositories
186 Collection<R> getAll( );
189 * Returns a validator that can be used to validate repository data
191 * @return a validator instance
193 RepositoryValidator<R> getValidator( );
196 * Validates the set attributes of the given repository instance and returns the validation result.
197 * The repository registry uses all available validators and applies their validateRepository method to the given
198 * repository. Validation results will be merged per field.
200 * @param repository the repository to validate against
201 * @return the result of the validation.
203 CheckedResult<R,Map<String, List<ValidationError>>> validateRepository( R repository );
206 * Validates the set attributes of the given repository instance for a repository update and returns the validation result.
207 * The repository registry uses all available validators and applies their validateRepositoryForUpdate method to the given
208 * repository. Validation results will be merged per field.
210 * @param repository the repository to validate against
211 * @return the result of the validation.
213 CheckedResult<R,Map<String, List<ValidationError>>> validateRepositoryForUpdate( R repository );
217 * Returns <code>true</code>, if the repository is registered with the given id, otherwise <code>false</code>
219 * @param id the repository identifier
220 * @return <code>true</code>, if it is registered, otherwise <code>false</code>
222 boolean has( String id );