Search in sources :

Example 16 with MetadataRepositoryException

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

the class RepositoryProblemEventListener method addArtifactProblem.

@Override
public void addArtifactProblem(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion, RepositoryStorageMetadataException exception) {
    RepositoryProblemFacet problem = new RepositoryProblemFacet();
    problem.setMessage(exception.getMessage());
    problem.setProject(projectId);
    problem.setNamespace(namespace);
    problem.setRepositoryId(repoId);
    problem.setVersion(projectVersion);
    problem.setProblem(exception.getId());
    try {
        session.getRepository().addMetadataFacet(repoId, problem);
        session.markDirty();
    } catch (MetadataRepositoryException e) {
        log.warn("Unable to add repository problem facets for the version being removed: {}", e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryProblemFacet(org.apache.archiva.metadata.model.facets.RepositoryProblemFacet)

Example 17 with MetadataRepositoryException

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

the class CassandraMetadataRepository method removeNamespace.

@Override
public void removeNamespace(String repositoryId, String namespaceId) throws MetadataRepositoryException {
    try {
        String key = // 
        new Namespace.KeyBuilder().withNamespace(// 
        namespaceId).withRepositoryId(// 
        repositoryId).build();
        // 
        HFactory.createMutator(cassandraArchivaManager.getKeyspace(), new StringSerializer()).addDeletion(key, // 
        cassandraArchivaManager.getNamespaceFamilyName()).execute();
        QueryResult<OrderedRows<String, String, String>> result = // 
        HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
        ss).setColumnFamily(// 
        cassandraArchivaManager.getProjectFamilyName()).setColumnNames(// 
        REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
        repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
        namespaceId).execute();
        for (Row<String, String, String> row : result.get()) {
            this.projectTemplate.deleteRow(row.getKey());
        }
        result = // 
        HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
        ss).setColumnFamily(// 
        cassandraArchivaManager.getProjectVersionMetadataFamilyName()).setColumnNames(// 
        REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
        repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
        namespaceId).execute();
        for (Row<String, String, String> row : result.get()) {
            this.projectVersionMetadataTemplate.deleteRow(row.getKey());
            removeMailingList(row.getKey());
        }
        result = // 
        HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
        ss).setColumnFamily(// 
        cassandraArchivaManager.getArtifactMetadataFamilyName()).setColumnNames(// 
        REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
        repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
        namespaceId).execute();
        for (Row<String, String, String> row : result.get()) {
            this.artifactMetadataTemplate.deleteRow(row.getKey());
        }
        result = // 
        HFactory.createRangeSlicesQuery(keyspace, ss, ss, // 
        ss).setColumnFamily(// 
        cassandraArchivaManager.getMetadataFacetFamilyName()).setColumnNames(// 
        REPOSITORY_NAME.toString()).addEqualsExpression(REPOSITORY_NAME.toString(), // 
        repositoryId).addEqualsExpression(NAMESPACE_ID.toString(), // 
        namespaceId).execute();
        for (Row<String, String, String> row : result.get()) {
            this.metadataFacetTemplate.deleteRow(row.getKey());
        }
    } catch (HInvalidRequestException e) {
        logger.error(e.getMessage(), e);
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) HInvalidRequestException(me.prettyprint.hector.api.exceptions.HInvalidRequestException) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows) StringSerializer(me.prettyprint.cassandra.serializers.StringSerializer) Namespace(org.apache.archiva.metadata.repository.cassandra.model.Namespace)

Example 18 with MetadataRepositoryException

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

the class JcrMetadataRepository method getArtifacts.

@Override
public List<ArtifactMetadata> getArtifacts(String repositoryId) throws MetadataRepositoryException {
    List<ArtifactMetadata> artifacts;
    String q = getArtifactQuery(repositoryId);
    try {
        Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
        QueryResult result = query.execute();
        artifacts = new ArrayList<>();
        for (Node n : JcrUtils.getNodes(result)) {
            if (n.isNodeType(ARTIFACT_NODE_TYPE)) {
                artifacts.add(getArtifactFromNode(repositoryId, 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) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 19 with MetadataRepositoryException

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

the class JcrMetadataRepository method removeRepository.

@Override
public void removeRepository(String repositoryId) throws MetadataRepositoryException {
    try {
        Node root = getJcrSession().getRootNode();
        String path = getRepositoryPath(repositoryId);
        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)

Example 20 with MetadataRepositoryException

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

the class JcrMetadataRepository method runJcrQuery.

private List<ArtifactMetadata> runJcrQuery(String repositoryId, String q, Map<String, String> bindings) throws MetadataRepositoryException {
    List<ArtifactMetadata> artifacts;
    if (repositoryId != null) {
        q += " AND ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath(repositoryId) + "')";
    }
    log.info("Running JCR Query: {}", q);
    try {
        Query query = getJcrSession().getWorkspace().getQueryManager().createQuery(q, Query.JCR_SQL2);
        ValueFactory valueFactory = getJcrSession().getValueFactory();
        for (Entry<String, String> entry : bindings.entrySet()) {
            query.bindValue(entry.getKey(), valueFactory.createValue(entry.getValue()));
        }
        long start = Calendar.getInstance().getTimeInMillis();
        QueryResult result = query.execute();
        long end = Calendar.getInstance().getTimeInMillis();
        log.info("JCR Query ran in {} milliseconds: {}", end - start, q);
        artifacts = new ArrayList<>();
        RowIterator rows = result.getRows();
        while (rows.hasNext()) {
            Row row = rows.nextRow();
            Node node = row.getNode("artifact");
            artifacts.add(getArtifactFromNode(repositoryId, node));
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
    log.info("Artifacts found {}", artifacts.size());
    for (ArtifactMetadata meta : artifacts) {
        log.info("Artifact: " + meta.getVersion() + " " + meta.getFacetList());
    }
    return artifacts;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Query(javax.jcr.query.Query) Node(javax.jcr.Node) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) ValueFactory(javax.jcr.ValueFactory) QueryResult(javax.jcr.query.QueryResult) RowIterator(javax.jcr.query.RowIterator) Row(javax.jcr.query.Row) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

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