001    package org.apache.archiva.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    
022    import org.apache.archiva.admin.model.beans.ManagedRepository;
023    import org.apache.archiva.model.ArchivaArtifact;
024    import org.apache.archiva.model.ArtifactReference;
025    import org.apache.archiva.model.ProjectReference;
026    import org.apache.archiva.model.VersionedReference;
027    import org.apache.archiva.repository.layout.LayoutException;
028    
029    import java.io.File;
030    import java.util.Set;
031    
032    /**
033     * ManagedRepositoryContent interface for interacting with a managed repository in an abstract way,
034     * without the need for processing based on filesystem paths, or working with the database.
035     */
036    public interface ManagedRepositoryContent
037    {
038        /**
039         * Delete from the managed repository all files / directories associated with the
040         * provided version reference.
041         *
042         * @param reference the version reference to delete.
043         * @throws ContentNotFoundException
044         */
045        void deleteVersion( VersionedReference reference )
046            throws ContentNotFoundException;
047    
048        /**
049         * delete a specified artifact from the repository
050         *
051         * @param artifactReference
052         * @throws ContentNotFoundException
053         */
054        void deleteArtifact( ArtifactReference artifactReference )
055            throws ContentNotFoundException;
056    
057        /**
058         * @param groupId
059         * @throws ContentNotFoundException
060         * @since 1.4-M3
061         */
062        void deleteGroupId( String groupId )
063            throws ContentNotFoundException;
064    
065        /**
066         *
067         * @param namespace groupId for maven
068         * @param projectId artifactId for maven
069         * @throws ContentNotFoundException
070         */
071        void deleteProject( String namespace, String projectId )
072            throws RepositoryException;
073    
074        /**
075         * <p>
076         * Convenience method to get the repository id.
077         * </p>
078         * <p/>
079         * <p>
080         * Equivalent to calling <code>.getRepository().getId()</code>
081         * </p>
082         *
083         * @return the repository id.
084         */
085        String getId();
086    
087        /**
088         * <p>
089         * Gather up the list of related artifacts to the ArtifactReference provided.
090         * This typically inclues the pom files, and those things with
091         * classifiers (such as doc, source code, test libs, etc...)
092         * </p>
093         * <p/>
094         * <p>
095         * <strong>NOTE:</strong> Some layouts (such as maven 1 "legacy") are not compatible with this query.
096         * </p>
097         *
098         * @param reference the reference to work off of.
099         * @return the set of ArtifactReferences for related artifacts.
100         * @throws ContentNotFoundException if the initial artifact reference does not exist within the repository.
101         * @throws LayoutException
102         */
103        Set<ArtifactReference> getRelatedArtifacts( ArtifactReference reference )
104            throws ContentNotFoundException;
105    
106        /**
107         * <p>
108         * Convenience method to get the repository (on disk) root directory.
109         * </p>
110         * <p/>
111         * <p>
112         * Equivalent to calling <code>.getRepository().getLocation()</code>
113         * </p>
114         *
115         * @return the repository (on disk) root directory.
116         */
117        String getRepoRoot();
118    
119        /**
120         * Get the repository configuration associated with this
121         * repository content.
122         *
123         * @return the repository that is associated with this repository content.
124         */
125        ManagedRepository getRepository();
126    
127        /**
128         * Given a specific {@link ProjectReference}, return the list of available versions for
129         * that project reference.
130         *
131         * @param reference the project reference to work off of.
132         * @return the list of versions found for that project reference.
133         * @throws ContentNotFoundException if the project reference does nto exist within the repository.
134         * @throws LayoutException
135         */
136        Set<String> getVersions( ProjectReference reference )
137            throws ContentNotFoundException, LayoutException;
138    
139        /**
140         * <p>
141         * Given a specific {@link VersionedReference}, return the list of available versions for that
142         * versioned reference.
143         * </p>
144         * <p/>
145         * <p>
146         * <strong>NOTE:</strong> This is really only useful when working with SNAPSHOTs.
147         * </p>
148         *
149         * @param reference the versioned reference to work off of.
150         * @return the set of versions found.
151         * @throws ContentNotFoundException if the versioned reference does not exist within the repository.
152         * @throws LayoutException
153         */
154        Set<String> getVersions( VersionedReference reference )
155            throws ContentNotFoundException;
156    
157        /**
158         * Determines if the artifact referenced exists in the repository.
159         *
160         * @param reference the artifact reference to check for.
161         * @return true if the artifact referenced exists.
162         */
163        boolean hasContent( ArtifactReference reference );
164    
165        /**
166         * Determines if the project referenced exists in the repository.
167         *
168         * @param reference the project reference to check for.
169         * @return true it the project referenced exists.
170         */
171        boolean hasContent( ProjectReference reference );
172    
173        /**
174         * Determines if the version reference exists in the repository.
175         *
176         * @param reference the version reference to check for.
177         * @return true if the version referenced exists.
178         */
179        boolean hasContent( VersionedReference reference );
180    
181        /**
182         * Set the repository configuration to associate with this
183         * repository content.
184         *
185         * @param repo the repository to associate with this repository content.
186         */
187        void setRepository( ManagedRepository repo );
188    
189        /**
190         * Given a repository relative path to a filename, return the {@link VersionedReference} object suitable for the path.
191         *
192         * @param path the path relative to the repository base dir for the artifact.
193         * @return the {@link ArtifactReference} representing the path.  (or null if path cannot be converted to
194         *         a {@link ArtifactReference})
195         * @throws LayoutException if there was a problem converting the path to an artifact.
196         */
197        ArtifactReference toArtifactReference( String path )
198            throws LayoutException;
199    
200        /**
201         * Given an {@link ArtifactReference}, return the file reference to the artifact.
202         *
203         * @param reference the artifact reference to use.
204         * @return the relative path to the artifact.
205         */
206        File toFile( ArtifactReference reference );
207    
208        /**
209         * Given an {@link ArchivaArtifact}, return the file reference to the artifact.
210         *
211         * @param reference the archiva artifact to use.
212         * @return the relative path to the artifact.
213         */
214        File toFile( ArchivaArtifact reference );
215    
216        /**
217         * Given a {@link ProjectReference}, return the path to the metadata for
218         * the project.
219         *
220         * @param reference the reference to use.
221         * @return the path to the metadata file, or null if no metadata is appropriate.
222         */
223        String toMetadataPath( ProjectReference reference );
224    
225        /**
226         * Given a {@link VersionedReference}, return the path to the metadata for
227         * the specific version of the project.
228         *
229         * @param reference the reference to use.
230         * @return the path to the metadata file, or null if no metadata is appropriate.
231         */
232        String toMetadataPath( VersionedReference reference );
233    
234        /**
235         * Given an {@link ArtifactReference}, return the relative path to the artifact.
236         *
237         * @param reference the artifact reference to use.
238         * @return the relative path to the artifact.
239         */
240        String toPath( ArtifactReference reference );
241    
242        /**
243         * Given an {@link ArchivaArtifact}, return the relative path to the artifact.
244         *
245         * @param reference the archiva artifact to use.
246         * @return the relative path to the artifact.
247         */
248        String toPath( ArchivaArtifact reference );
249    }