Java Code Examples for org.apache.jackrabbit.commons.JcrUtils#getChildNodes()

The following examples show how to use org.apache.jackrabbit.commons.JcrUtils#getChildNodes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 6 votes vote down vote up
@Override
public void removeProjectVersion(RepositorySession session, String repoId, String namespace, String projectId, String projectVersion)
        throws MetadataRepositoryException {
    final Session jcrSession = getSession(session);
    try {

        String path = getProjectPath(repoId, namespace, projectId);
        Node root = jcrSession.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);
    }
}
 
Example 2
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 6 votes vote down vote up
private Node findArtifactNode(Session jcrSession, String namespace, String projectId,
                              String projectVersion, String id) throws RepositoryException {

    if (namespace==null || projectId==null||projectVersion==null||id==null) {
        return null;
    }
    Node root = jcrSession.getRootNode();
    Node node = JcrUtils.getOrAddNode(root, "repositories");
    for (Node n : JcrUtils.getChildNodes(node)) {
        String repositoryId = n.getName();
        Node repo = getOrAddRepositoryContentNode(jcrSession, repositoryId);
        Node nsNode = JcrUtils.getNodeIfExists(repo, StringUtils.replaceChars(namespace, '.', '/'));
        if (nsNode!=null) {
            Node projNode = JcrUtils.getNodeIfExists(nsNode, projectId);
            if (projNode !=null ) {
                Node projVersionNode = JcrUtils.getNodeIfExists(projNode, projectVersion);
                if (projVersionNode != null) {
                    return JcrUtils.getNodeIfExists(projVersionNode, id);
                }
            }
        }
    }

    return null;
}
 
Example 3
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
private void recurse(List<String> facets, String prefix, Node node)
        throws RepositoryException {
    for (Node n : JcrUtils.getChildNodes(node)) {
        String name = prefix + "/" + n.getName();
        if (n.hasNodes()) {
            recurse(facets, name, n);
        } else {
            // strip leading / first
            facets.add(name.substring(1));
        }
    }
}
 
Example 4
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
private void retrieveFacetProperties(FacetedMetadata metadata, Node node) throws RepositoryException {
    for (Node n : JcrUtils.getChildNodes(node)) {
        if (n.isNodeType(FACET_NODE_TYPE)) {
            String name = n.getName();
            MetadataFacetFactory factory = metadataService.getFactory(name);
            if (factory == null) {
                log.error("Attempted to load unknown project version metadata facet: {}", name);
            } else {
                MetadataFacet facet = createFacetFromNode(factory, n);
                metadata.addFacet(facet);
            }
        }
    }
}
 
Example 5
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public void removeTimestampedArtifact(RepositorySession session, ArtifactMetadata artifactMetadata, String baseVersion)
        throws MetadataRepositoryException {
    final Session jcrSession = getSession(session);
    String repositoryId = artifactMetadata.getRepositoryId();

    try {
        Node root = jcrSession.getRootNode();
        String path =
                getProjectVersionPath(repositoryId, artifactMetadata.getNamespace(), artifactMetadata.getProject(),
                        baseVersion);

        if (root.hasNode(path)) {
            Node node = root.getNode(path);

            for (Node n : JcrUtils.getChildNodes(node)) {
                if (n.isNodeType(ARTIFACT_NODE_TYPE)) {
                    if (n.hasProperty("version")) {
                        String version = n.getProperty("version").getString();
                        if (StringUtils.equals(version, artifactMetadata.getVersion())) {
                            n.remove();
                        }
                    }

                }
            }
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }


}
 
Example 6
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public void removeArtifact(RepositorySession session, String repositoryId, String namespace, String projectId, String projectVersion,
                           String id)
        throws MetadataRepositoryException {
    final Session jcrSession = getSession(session);
    try {
        Node root = jcrSession.getRootNode();
        String path = getArtifactPath(repositoryId, namespace, projectId, projectVersion, id);
        if (root.hasNode(path)) {
            root.getNode(path).remove();
        }

        // remove version

        path = getProjectPath(repositoryId, namespace, projectId);

        Node nodeAtPath = root.getNode(path);

        for (Node node : JcrUtils.getChildNodes(nodeAtPath)) {
            if (node.isNodeType(PROJECT_VERSION_NODE_TYPE) //
                    && StringUtils.equals(node.getName(), projectVersion)) {
                node.remove();
            }
        }
    } catch (RepositoryException e) {
        throw new MetadataRepositoryException(e.getMessage(), e);
    }
}
 
Example 7
Source File: JcrMetadataRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public void removeFacetFromArtifact(RepositorySession session, String repositoryId, String namespace, String project, String projectVersion,
                                    MetadataFacet metadataFacet)
        throws MetadataRepositoryException {
    final Session jcrSession = getSession(session);
    try {
        Node root = jcrSession.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);
    }
}