Search in sources :

Example 56 with MetadataRepositoryException

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

the class JcrMetadataRepository method removeProject.

@Override
public void removeProject(String repositoryId, String namespace, String projectId) throws MetadataRepositoryException {
    try {
        Node root = getJcrSession().getRootNode();
        String namespacePath = getNamespacePath(repositoryId, namespace);
        if (root.hasNode(namespacePath)) {
            Iterator<Node> nodeIterator = JcrUtils.getChildNodes(root.getNode(namespacePath)).iterator();
            while (nodeIterator.hasNext()) {
                Node node = nodeIterator.next();
                if (node.isNodeType(PROJECT_NODE_TYPE) && projectId.equals(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 57 with MetadataRepositoryException

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

the class JcrMetadataRepository method updateNamespace.

@Override
public void updateNamespace(String repositoryId, String namespace) throws MetadataRepositoryException {
    try {
        Node node = getOrAddNamespaceNode(repositoryId, namespace);
        node.setProperty("namespace", namespace);
    } 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 58 with MetadataRepositoryException

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

the class JcrMetadataRepository method getRepositories.

@Override
public Collection<String> getRepositories() throws MetadataRepositoryException {
    List<String> repositories;
    try {
        Node root = getJcrSession().getRootNode();
        if (root.hasNode("repositories")) {
            Node node = root.getNode("repositories");
            repositories = new ArrayList<>();
            NodeIterator i = node.getNodes();
            while (i.hasNext()) {
                Node n = i.nextNode();
                repositories.add(n.getName());
            }
        } else {
            repositories = Collections.emptyList();
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
    return repositories;
}
Also used : NodeIterator(javax.jcr.NodeIterator) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Node(javax.jcr.Node) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException)

Example 59 with MetadataRepositoryException

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

the class JcrMetadataRepository method updateProjectVersion.

@Override
public void updateProjectVersion(String repositoryId, String namespace, String projectId, ProjectVersionMetadata versionMetadata) throws MetadataRepositoryException {
    updateProject(repositoryId, namespace, projectId);
    try {
        Node versionNode = getOrAddProjectVersionNode(repositoryId, namespace, projectId, versionMetadata.getId());
        versionNode.setProperty("name", versionMetadata.getName());
        versionNode.setProperty("description", versionMetadata.getDescription());
        versionNode.setProperty("url", versionMetadata.getUrl());
        versionNode.setProperty("incomplete", versionMetadata.isIncomplete());
        // FIXME: decide how to treat these in the content repo
        if (versionMetadata.getScm() != null) {
            versionNode.setProperty("scm.connection", versionMetadata.getScm().getConnection());
            versionNode.setProperty("scm.developerConnection", versionMetadata.getScm().getDeveloperConnection());
            versionNode.setProperty("scm.url", versionMetadata.getScm().getUrl());
        }
        if (versionMetadata.getCiManagement() != null) {
            versionNode.setProperty("ci.system", versionMetadata.getCiManagement().getSystem());
            versionNode.setProperty("ci.url", versionMetadata.getCiManagement().getUrl());
        }
        if (versionMetadata.getIssueManagement() != null) {
            versionNode.setProperty("issue.system", versionMetadata.getIssueManagement().getSystem());
            versionNode.setProperty("issue.url", versionMetadata.getIssueManagement().getUrl());
        }
        if (versionMetadata.getOrganization() != null) {
            versionNode.setProperty("org.name", versionMetadata.getOrganization().getName());
            versionNode.setProperty("org.url", versionMetadata.getOrganization().getUrl());
        }
        int i = 0;
        for (License license : versionMetadata.getLicenses()) {
            versionNode.setProperty("license." + i + ".name", license.getName());
            versionNode.setProperty("license." + i + ".url", license.getUrl());
            i++;
        }
        i = 0;
        for (MailingList mailingList : versionMetadata.getMailingLists()) {
            versionNode.setProperty("mailingList." + i + ".archive", mailingList.getMainArchiveUrl());
            versionNode.setProperty("mailingList." + i + ".name", mailingList.getName());
            versionNode.setProperty("mailingList." + i + ".post", mailingList.getPostAddress());
            versionNode.setProperty("mailingList." + i + ".unsubscribe", mailingList.getUnsubscribeAddress());
            versionNode.setProperty("mailingList." + i + ".subscribe", mailingList.getSubscribeAddress());
            versionNode.setProperty("mailingList." + i + ".otherArchives", join(mailingList.getOtherArchives()));
            i++;
        }
        if (!versionMetadata.getDependencies().isEmpty()) {
            Node dependenciesNode = JcrUtils.getOrAddNode(versionNode, "dependencies");
            for (Dependency dependency : versionMetadata.getDependencies()) {
                // Note that we deliberately don't alter the namespace path - not enough dependencies for
                // number of nodes at a given depth to be an issue. Similarly, we don't add subnodes for each
                // component of the ID as that creates extra depth and causes a great cost in space and memory
                // FIXME: change group ID to namespace
                // FIXME: change to artifact's ID - this is constructed by the Maven 2 format for now.
                // This won't support types where the extension doesn't match the type.
                // (see also Maven2RepositoryStorage#readProjectVersionMetadata construction of POM)
                String id = dependency.getGroupId() + ";" + dependency.getArtifactId() + "-" + dependency.getVersion();
                if (dependency.getClassifier() != null) {
                    id += "-" + dependency.getClassifier();
                }
                id += "." + dependency.getType();
                Node n = JcrUtils.getOrAddNode(dependenciesNode, id);
                n.addMixin(DEPENDENCY_NODE_TYPE);
                // FIXME: remove temp code just to make it keep working
                n.setProperty("groupId", dependency.getGroupId());
                n.setProperty("artifactId", dependency.getArtifactId());
                n.setProperty("version", dependency.getVersion());
                n.setProperty("type", dependency.getType());
                n.setProperty("classifier", dependency.getClassifier());
                n.setProperty("scope", dependency.getScope());
                n.setProperty("systemPath", dependency.getSystemPath());
                n.setProperty("optional", dependency.isOptional());
            // node has no native content at this time, just facets
            // no need to list a type as it's implied by the path. Parents are Maven specific.
            // FIXME: add scope, systemPath, type, version, classifier & maven2 specific IDs as a facet
            // (should also have been added to the Dependency)
            // TODO: add a property that is a weak reference to the originating artifact, creating it if
            // necessary (without adding the archiva:artifact mixin so that it doesn't get listed as an
            // artifact, which gives a different meaning to "incomplete" which is a known local project
            // that doesn't have metadata yet but has artifacts). (Though we may want to give it the
            // artifact mixin and another property to identify all non-local artifacts for the closure
            // reports)
            }
        }
        for (MetadataFacet facet : versionMetadata.getFacetList()) {
            // recreate, to ensure properties are removed
            if (versionNode.hasNode(facet.getFacetId())) {
                versionNode.getNode(facet.getFacetId()).remove();
            }
            Node n = versionNode.addNode(facet.getFacetId());
            n.addMixin(FACET_NODE_TYPE);
            for (Map.Entry<String, String> entry : facet.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) License(org.apache.archiva.metadata.model.License) MailingList(org.apache.archiva.metadata.model.MailingList) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) Dependency(org.apache.archiva.metadata.model.Dependency) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 60 with MetadataRepositoryException

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

the class JcrMetadataRepository method removeArtifact.

@Override
public void removeArtifact(String repositoryId, String namespace, String project, String projectVersion, MetadataFacet metadataFacet) throws MetadataRepositoryException {
    try {
        Node root = getJcrSession().getRootNode();
        String path = getProjectVersionPath(repositoryId, namespace, project, projectVersion);
        if (root.hasNode(path)) {
            Node node = root.getNode(path);
            for (Node n : JcrUtils.getChildNodes(node)) {
                if (n.isNodeType(ARTIFACT_NODE_TYPE)) {
                    ArtifactMetadata artifactMetadata = getArtifactFromNode(repositoryId, n);
                    log.debug("artifactMetadata: {}", artifactMetadata);
                    MetadataFacet metadataFacetToRemove = artifactMetadata.getFacet(metadataFacet.getFacetId());
                    if (metadataFacetToRemove != null && metadataFacet.equals(metadataFacetToRemove)) {
                        n.remove();
                    }
                }
            }
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Node(javax.jcr.Node) MetadataFacet(org.apache.archiva.metadata.model.MetadataFacet) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryException(javax.jcr.RepositoryException) 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