Search in sources :

Example 11 with MetadataRepositoryException

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

the class JcrMetadataRepository method getMetadataFacets.

@Override
public List<String> getMetadataFacets(String repositoryId, String facetId) throws MetadataRepositoryException {
    List<String> facets = new ArrayList<>();
    try {
        // no need to construct node-by-node here, as we'll find in the next instance, the facet names have / and
        // are paths themselves
        Node node = getJcrSession().getRootNode().getNode(getFacetPath(repositoryId, facetId));
        // TODO: this is a bit awkward. Might be better to review the purpose of this function - why is the list of
        // paths helpful?
        recurse(facets, "", node);
    } catch (PathNotFoundException e) {
    // ignored - the facet doesn't exist, so return the empty list
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
    return facets;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 12 with MetadataRepositoryException

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

the class JcrMetadataRepository method populateStatistics.

@Override
public void populateStatistics(MetadataRepository repository, String repositoryId, RepositoryStatistics repositoryStatistics) throws MetadataRepositoryException {
    if (!(repository instanceof JcrMetadataRepository)) {
        throw new MetadataRepositoryException("The statistics population is only possible for JcrMetdataRepository implementations");
    }
    Session session = (Session) repository.obtainAccess(Session.class);
    try {
        QueryManager queryManager = session.getWorkspace().getQueryManager();
        // TODO: Check, if this is still the case - Switched to Jackrabbit OAK with archiva 3.0
        // Former statement: JCR-SQL2 query will not complete on a large repo in Jackrabbit 2.2.0 - see JCR-2835
        // Using the JCR-SQL2 variants gives
        // "org.apache.lucene.search.BooleanQuery$TooManyClauses: maxClauseCount is set to 1024"
        // String whereClause = "WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content])";
        // Query query = queryManager.createQuery( "SELECT size FROM [archiva:artifact] " + whereClause,
        // Query.JCR_SQL2 );
        String whereClause = "WHERE ISDESCENDANTNODE([/repositories/" + repositoryId + "/content])";
        Query query = queryManager.createQuery("SELECT size FROM [archiva:artifact] " + whereClause, Query.JCR_SQL2);
        QueryResult queryResult = query.execute();
        Map<String, Integer> totalByType = new HashMap<>();
        long totalSize = 0, totalArtifacts = 0;
        for (Row row : JcrUtils.getRows(queryResult)) {
            Node n = row.getNode();
            totalSize += row.getValue("size").getLong();
            String type;
            if (n.hasNode(MavenArtifactFacet.FACET_ID)) {
                Node facetNode = n.getNode(MavenArtifactFacet.FACET_ID);
                type = facetNode.getProperty("type").getString();
            } else {
                type = "Other";
            }
            Integer prev = totalByType.get(type);
            totalByType.put(type, prev != null ? prev + 1 : 1);
            totalArtifacts++;
        }
        repositoryStatistics.setTotalArtifactCount(totalArtifacts);
        repositoryStatistics.setTotalArtifactFileSize(totalSize);
        for (Map.Entry<String, Integer> entry : totalByType.entrySet()) {
            log.info("Setting count for type: {} = {}", entry.getKey(), entry.getValue());
            repositoryStatistics.setTotalCountForType(entry.getKey(), entry.getValue());
        }
        // The query ordering is a trick to ensure that the size is correct, otherwise due to lazy init it will be -1
        // query = queryManager.createQuery( "SELECT * FROM [archiva:project] " + whereClause, Query.JCR_SQL2 );
        query = queryManager.createQuery("SELECT * FROM [archiva:project] " + whereClause + " ORDER BY [jcr:score]", Query.JCR_SQL2);
        repositoryStatistics.setTotalProjectCount(query.execute().getRows().getSize());
        // query = queryManager.createQuery(
        // "SELECT * FROM [archiva:namespace] " + whereClause + " AND namespace IS NOT NULL", Query.JCR_SQL2 );
        query = queryManager.createQuery("SELECT * FROM [archiva:namespace] " + whereClause + " AND namespace IS NOT NULL ORDER BY [jcr:score]", Query.JCR_SQL2);
        repositoryStatistics.setTotalGroupCount(query.execute().getRows().getSize());
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Query(javax.jcr.query.Query) HashMap(java.util.HashMap) Node(javax.jcr.Node) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) QueryResult(javax.jcr.query.QueryResult) QueryManager(javax.jcr.query.QueryManager) Row(javax.jcr.query.Row) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Session(javax.jcr.Session)

Example 13 with MetadataRepositoryException

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

the class JcrMetadataRepository method updateArtifact.

@Override
public void updateArtifact(String repositoryId, String namespace, String projectId, String projectVersion, ArtifactMetadata artifactMeta) throws MetadataRepositoryException {
    updateNamespace(repositoryId, namespace);
    try {
        Node node = getOrAddArtifactNode(repositoryId, namespace, projectId, projectVersion, artifactMeta.getId());
        Calendar cal = Calendar.getInstance();
        cal.setTime(artifactMeta.getFileLastModified());
        node.setProperty(JCR_LAST_MODIFIED, cal);
        cal = Calendar.getInstance();
        cal.setTime(artifactMeta.getWhenGathered());
        node.setProperty("whenGathered", cal);
        node.setProperty("size", artifactMeta.getSize());
        node.setProperty("md5", artifactMeta.getMd5());
        node.setProperty("sha1", artifactMeta.getSha1());
        node.setProperty("version", artifactMeta.getVersion());
        // iterate over available facets to update/add/remove from the artifactMetadata
        for (String facetId : metadataFacetFactories.keySet()) {
            MetadataFacet metadataFacet = artifactMeta.getFacet(facetId);
            if (metadataFacet == null) {
                continue;
            }
            if (node.hasNode(facetId)) {
                node.getNode(facetId).remove();
            }
            if (metadataFacet != null) {
                // recreate, to ensure properties are removed
                Node n = node.addNode(facetId);
                n.addMixin(FACET_NODE_TYPE);
                for (Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet()) {
                    n.setProperty(entry.getKey(), entry.getValue());
                }
            }
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Node(javax.jcr.Node) Calendar(java.util.Calendar) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 14 with MetadataRepositoryException

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

the class JcrMetadataRepository method removeProjectVersion.

@Override
public void removeProjectVersion(String repoId, String namespace, String projectId, String projectVersion) throws MetadataRepositoryException {
    try {
        String path = getProjectPath(repoId, namespace, projectId);
        Node root = getJcrSession().getRootNode();
        Node nodeAtPath = root.getNode(path);
        for (Node node : JcrUtils.getChildNodes(nodeAtPath)) {
            if (node.isNodeType(PROJECT_VERSION_NODE_TYPE) && StringUtils.equals(projectVersion, node.getName())) {
                node.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 15 with MetadataRepositoryException

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

the class JcrMetadataRepository method addMetadataFacet.

@Override
public void addMetadataFacet(String repositoryId, MetadataFacet metadataFacet) throws MetadataRepositoryException {
    try {
        Node repo = getOrAddRepositoryNode(repositoryId);
        Node facets = JcrUtils.getOrAddNode(repo, "facets");
        String id = metadataFacet.getFacetId();
        Node facetNode = JcrUtils.getOrAddNode(facets, id);
        Node node = getOrAddNodeByPath(facetNode, metadataFacet.getName());
        for (Map.Entry<String, String> entry : metadataFacet.toProperties().entrySet()) {
            node.setProperty(entry.getKey(), entry.getValue());
        }
    } 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) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

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