Search in sources :

Example 21 with ResourceProxy

use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.

the class ContentXmlHandlerTest method parseFullCoverageXmlFile.

@Test
public void parseFullCoverageXmlFile() throws ParserConfigurationException, SAXException, IOException {
    ResourceProxy root = parseContentXmlFile("full-coverage.xml", "/apps/full-coverage");
    assertThat("full-coverage path", root.getPath(), is("/apps/full-coverage"));
    assertThat("full-coverage properties.size", root.getProperties().size(), is(3));
    assertThat("full-coverage properties[jcr:title]", root.getProperties(), hasEntry("jcr:title", (Object) "Full coverage parent"));
    assertThat("full-coverage children.size", root.getChildren().size(), is(2));
    ResourceProxy parent1 = root.getChildren().get(0);
    assertThat("parent-1 path", parent1.getPath(), is("/apps/full-coverage/parent-1"));
    assertThat("parent-1 properties[jcr:title]", parent1.getProperties(), hasEntry("jcr:title", (Object) "Parent 1"));
    assertThat("parent-1 children.size", parent1.getChildren().size(), is(2));
    ResourceProxy child11 = parent1.getChildren().get(0);
    assertThat("child-1-1 path", child11.getPath(), is("/apps/full-coverage/parent-1/child-1-1"));
    assertThat("child-1-1 properties[jcr:title]", child11.getProperties(), hasEntry("jcr:title", (Object) "Child 1-1"));
}
Also used : ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) Test(org.junit.Test)

Example 22 with ResourceProxy

use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.

the class ContentXmlHandlerTest method parseContentXmlWithEscapedNames.

@Test
public void parseContentXmlWithEscapedNames() throws ParserConfigurationException, SAXException, IOException {
    ResourceProxy root = parseContentXmlFile("full-coverage-escaped-names.xml", "/");
    assertThat("node contains /50-50", root.getChildren(), hasChildPath("/50-50"));
}
Also used : ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) Test(org.junit.Test)

Example 23 with ResourceProxy

use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.

the class AddOrUpdateNodeCommand method processDeletedNodes.

private void processDeletedNodes(Node node, ResourceProxy resource2) throws RepositoryException {
    // TODO - we probably don't support SNS here ( and in other places as well )
    List<ResourceProxy> resourceChildren = resource2.getChildren();
    if (resourceChildren.size() == 0) {
        getLogger().trace("Resource at {0} has no children, skipping deleted nodes processing", resource2.getPath());
        return;
    }
    Map<String, ResourceProxy> resourceChildrenPaths = new HashMap<>(resourceChildren.size());
    for (ResourceProxy child : resourceChildren) {
        resourceChildrenPaths.put(child.getPath(), child);
    }
    for (NodeIterator it = node.getNodes(); it.hasNext(); ) {
        Node child = it.nextNode();
        if (resourceChildrenPaths.containsKey(child.getPath())) {
            // don't have enough information
            if (resource2.covers(child.getPath())) {
                processDeletedNodes(child, resourceChildrenPaths.get(child.getPath()));
            }
            continue;
        }
        if (context.filter() != null && context.filter().filter(child.getPath()) == FilterResult.DENY) {
            getLogger().trace("Not deleting node at {0} since it is not included in the filter", child.getPath());
            continue;
        }
        getLogger().trace("Deleting node {0} as it is no longer present in the local checkout", child.getPath());
        child.remove();
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) HashMap(java.util.HashMap) Node(javax.jcr.Node) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy)

Example 24 with ResourceProxy

use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.

the class ResourceChangeCommandFactoryTest method commandForSlingOrderedFolder_children.

@Test
public void commandForSlingOrderedFolder_children() throws CoreException {
    // create a sling:OrderedFolder at /content/test-root
    project.createOrUpdateFile(Path.fromPortableString("jcr_root/content/test-root/.content.xml"), getClass().getResourceAsStream("sling-ordered-folder-with-children.xml"));
    // create the child folder listed in the .content.xml file
    contentProject.getFolder("jcr_root/content/test-root/folder").create(true, true, new NullProgressMonitor());
    SpyCommand<?> command = (SpyCommand<?>) factory.newCommandForAddedOrUpdated(spyRepo, contentProject.findMember("jcr_root/content/test-root"));
    List<ResourceProxy> children = command.getResourceProxy().getChildren();
    assertThat("command.resource.children.size", children.size(), equalTo(2));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SpyCommand(org.apache.sling.ide.test.impl.helpers.SpyCommand) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) Test(org.junit.Test)

Example 25 with ResourceProxy

use of org.apache.sling.ide.transport.ResourceProxy in project sling by apache.

the class ImportRepositoryContentAction method crawlChildrenAndImport.

/**
     * Crawls the repository and recursively imports founds resources
     * @param path the current path to import from
     * @param tracer
     * @throws JSONException
     * @throws RepositoryException
     * @throws CoreException
     * @throws IOException
     */
// TODO: This probably should be pushed into the service layer
private void crawlChildrenAndImport(String path) throws RepositoryException, CoreException, IOException, SerializationException {
    logger.trace("crawlChildrenAndImport({0},  {1}, {2}, {3}", repository, path, project, projectRelativePath);
    ResourceProxy resource = executeCommand(repository.newListChildrenNodeCommand(path));
    SerializationData serializationData = builder.buildSerializationData(contentSyncRoot, resource);
    logger.trace("For resource at path {0} got serialization data {1}", resource.getPath(), serializationData);
    final List<ResourceProxy> resourceChildren = new LinkedList<>(resource.getChildren());
    if (serializationData != null) {
        IPath serializationFolderPath = contentSyncRootDir.getProjectRelativePath().append(serializationData.getFolderPath());
        switch(serializationData.getSerializationKind()) {
            case FILE:
                {
                    byte[] contents = executeCommand(repository.newGetNodeCommand(path));
                    createFile(project, getPathForPlainFileNode(resource, serializationFolderPath), contents);
                    if (serializationData.hasContents()) {
                        createFolder(project, serializationFolderPath);
                        createFile(project, serializationFolderPath.append(serializationData.getFileName()), serializationData.getContents());
                        // special processing for nt:resource nodes
                        for (Iterator<ResourceProxy> it = resourceChildren.iterator(); it.hasNext(); ) {
                            ResourceProxy child = it.next();
                            if (Repository.NT_RESOURCE.equals(child.getProperties().get(Repository.JCR_PRIMARY_TYPE))) {
                                ResourceProxy reloadedChildResource = executeCommand(repository.newListChildrenNodeCommand(child.getPath()));
                                logger.trace("Skipping direct handling of {0} node at {1} ; will additionally handle {2} direct children", Repository.NT_RESOURCE, child.getPath(), reloadedChildResource.getChildren().size());
                                if (reloadedChildResource.getChildren().size() != 0) {
                                    String pathName = Text.getName(reloadedChildResource.getPath());
                                    pathName = serializationManager.getOsPath(pathName);
                                    createFolder(project, serializationFolderPath.append(pathName));
                                    // 2. recursively handle all resources
                                    for (ResourceProxy grandChild : reloadedChildResource.getChildren()) {
                                        crawlChildrenAndImport(grandChild.getPath());
                                    }
                                }
                                it.remove();
                                break;
                            }
                        }
                    }
                    break;
                }
            case FOLDER:
            case METADATA_PARTIAL:
                {
                    IFolder folder = createFolder(project, serializationFolderPath);
                    parseIgnoreFiles(folder, path);
                    if (serializationData.hasContents()) {
                        createFile(project, serializationFolderPath.append(serializationData.getFileName()), serializationData.getContents());
                    }
                    break;
                }
            case METADATA_FULL:
                {
                    if (serializationData.hasContents()) {
                        createFile(project, serializationFolderPath.append(serializationData.getFileName()), serializationData.getContents());
                    }
                    break;
                }
        }
        logger.trace("Resource at {0} has children: {1}", resource.getPath(), resourceChildren);
        if (serializationData.getSerializationKind() == SerializationKind.METADATA_FULL) {
            return;
        }
    } else {
        logger.trace("No serialization data found for {0}", resource.getPath());
    }
    ProgressUtils.advance(monitor, 1);
    for (ResourceProxy child : resourceChildren) {
        if (ignoredResources.isIgnored(child.getPath())) {
            continue;
        }
        if (filter != null) {
            FilterResult filterResult = filter.filter(child.getPath());
            if (filterResult == FilterResult.DENY) {
                continue;
            }
        }
        crawlChildrenAndImport(child.getPath());
    }
}
Also used : SerializationData(org.apache.sling.ide.serialization.SerializationData) IPath(org.eclipse.core.runtime.IPath) Iterator(java.util.Iterator) FilterResult(org.apache.sling.ide.filter.FilterResult) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) LinkedList(java.util.LinkedList) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ResourceProxy (org.apache.sling.ide.transport.ResourceProxy)42 Test (org.junit.Test)14 Node (javax.jcr.Node)8 NodeIterator (javax.jcr.NodeIterator)5 IPath (org.eclipse.core.runtime.IPath)5 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 FilterResult (org.apache.sling.ide.filter.FilterResult)4 IFile (org.eclipse.core.resources.IFile)4 IFolder (org.eclipse.core.resources.IFolder)4 Filter (org.apache.sling.ide.filter.Filter)3 RepositoryException (org.apache.sling.ide.transport.RepositoryException)3 JsonReader (com.google.gson.stream.JsonReader)2 JsonToken (com.google.gson.stream.JsonToken)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2