Search in sources :

Example 6 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class FileMetadataRepository method getMetadataFacets.

@Override
public List<String> getMetadataFacets(String repoId, String facetId) throws MetadataRepositoryException {
    try {
        Path directory = getMetadataDirectory(repoId, facetId);
        if (!(Files.exists(directory) && Files.isDirectory(directory))) {
            return Collections.emptyList();
        }
        List<String> facets;
        final String searchFile = METADATA_KEY + ".properties";
        try (Stream<Path> fs = Files.walk(directory, FileVisitOption.FOLLOW_LINKS)) {
            facets = fs.filter(Files::isDirectory).filter(path -> Files.exists(path.resolve(searchFile))).map(path -> directory.relativize(path).toString()).collect(Collectors.toList());
        }
        return facets;
    } catch (IOException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MailingList(org.apache.archiva.metadata.model.MailingList) NoSuchFileException(java.nio.file.NoSuchFileException) Arrays(java.util.Arrays) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) StringTokenizer(java.util.StringTokenizer) Map(java.util.Map) ProjectMetadata(org.apache.archiva.metadata.model.ProjectMetadata) Organization(org.apache.archiva.metadata.model.Organization) Scm(org.apache.archiva.metadata.model.Scm) Path(java.nio.file.Path) LinkedHashSet(java.util.LinkedHashSet) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) OutputStream(java.io.OutputStream) ProjectVersionReference(org.apache.archiva.metadata.model.ProjectVersionReference) Logger(org.slf4j.Logger) Properties(java.util.Properties) Files(java.nio.file.Files) Collection(java.util.Collection) Set(java.util.Set) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) CiManagement(org.apache.archiva.metadata.model.CiManagement) IOException(java.io.IOException) IssueManagement(org.apache.archiva.metadata.model.IssueManagement) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) List(java.util.List) Stream(java.util.stream.Stream) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) License(org.apache.archiva.metadata.model.License) Dependency(org.apache.archiva.metadata.model.Dependency) MetadataFacetFactory(org.apache.archiva.metadata.model.MetadataFacetFactory) Comparator(java.util.Comparator) Collections(java.util.Collections) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) InputStream(java.io.InputStream) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException) Files(java.nio.file.Files)

Example 7 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class FileMetadataRepository method removeMetadataFacets.

@Override
public void removeMetadataFacets(String repositoryId, String facetId) throws MetadataRepositoryException {
    try {
        Path dir = getMetadataDirectory(repositoryId, facetId);
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(dir);
    } catch (IOException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : Path(java.nio.file.Path) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) IOException(java.io.IOException)

Example 8 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class FileMetadataRepository method getArtifactsByDateRange.

@Override
public List<ArtifactMetadata> getArtifactsByDateRange(String repoId, Date startTime, Date endTime) throws MetadataRepositoryException {
    try {
        // TODO: this is quite slow - if we are to persist with this repository implementation we should build an index
        // of this information (eg. in Lucene, as before)
        List<ArtifactMetadata> artifacts = new ArrayList<>();
        for (String ns : getRootNamespaces(repoId)) {
            getArtifactsByDateRange(artifacts, repoId, ns, startTime, endTime);
        }
        artifacts.sort(new ArtifactComparator());
        return artifacts;
    } catch (MetadataResolutionException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) ArrayList(java.util.ArrayList) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException)

Example 9 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class JcrMetadataRepository method getArtifactsByDateRange.

@Override
public List<ArtifactMetadata> getArtifactsByDateRange(String repoId, Date startTime, Date endTime) throws MetadataRepositoryException {
    List<ArtifactMetadata> artifacts;
    String q = getArtifactQuery(repoId);
    if (startTime != null) {
        q += " AND [whenGathered] >= $start";
    }
    if (endTime != null) {
        q += " AND [whenGathered] <= $end";
    }
    try {
        Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
        ValueFactory valueFactory = getJcrSession().getValueFactory();
        if (startTime != null) {
            query.bindValue("start", valueFactory.createValue(createCalendar(startTime)));
        }
        if (endTime != null) {
            query.bindValue("end", valueFactory.createValue(createCalendar(endTime)));
        }
        QueryResult result = query.execute();
        artifacts = new ArrayList<>();
        for (Node n : JcrUtils.getNodes(result)) {
            artifacts.add(getArtifactFromNode(repoId, n));
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
    return artifacts;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) QueryResult(javax.jcr.query.QueryResult) Query(javax.jcr.query.Query) Node(javax.jcr.Node) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) ValueFactory(javax.jcr.ValueFactory) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 10 with MetadataRepositoryException

use of org.apache.archiva.metadata.repository.MetadataRepositoryException in project archiva by apache.

the class JcrMetadataRepository method removeMetadataFacets.

@Override
public void removeMetadataFacets(String repositoryId, String facetId) throws MetadataRepositoryException {
    try {
        Node root = getJcrSession().getRootNode();
        String path = getFacetPath(repositoryId, facetId);
        if (root.hasNode(path)) {
            root.getNode(path).remove();
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Node(javax.jcr.Node) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Aggregations

MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)65 MetadataRepository (org.apache.archiva.metadata.repository.MetadataRepository)24 RepositoryException (javax.jcr.RepositoryException)22 Node (javax.jcr.Node)21 RepositorySession (org.apache.archiva.metadata.repository.RepositorySession)19 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)18 Path (java.nio.file.Path)15 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)13 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)10 HashMap (java.util.HashMap)8 RepositoryException (org.apache.archiva.repository.RepositoryException)8 Map (java.util.Map)6 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)6 MetadataFacet (org.apache.archiva.metadata.model.MetadataFacet)6 MetadataResolutionException (org.apache.archiva.metadata.repository.MetadataResolutionException)6 Date (java.util.Date)5 Query (javax.jcr.query.Query)5 QueryResult (javax.jcr.query.QueryResult)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5