Search in sources :

Example 1 with CommandContext

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

the class ResourceChangeCommandFactory method removeFileCommand.

private Command<?> removeFileCommand(Repository repository, IResource resource) throws CoreException, IOException {
    if (resource.isTeamPrivateMember(IResource.CHECK_ANCESTORS)) {
        Activator.getDefault().getPluginLogger().trace("Skipping team-private resource {0}", resource);
        return null;
    }
    if (ignoredFileNames.contains(resource.getName())) {
        return null;
    }
    IFolder syncDirectory = ProjectUtil.getSyncDirectory(resource.getProject());
    Filter filter = ProjectUtil.loadFilter(syncDirectory.getProject());
    FilterResult filterResult = getFilterResult(resource, null, filter);
    if (filterResult == FilterResult.DENY || filterResult == FilterResult.PREREQUISITE) {
        return null;
    }
    String resourceLocation = getRepositoryPathForDeletedResource(resource, ProjectUtil.getSyncDirectoryFile(resource.getProject()));
    // verify whether a resource being deleted does not signal that the content structure
    // was rearranged under a covering parent aggregate
    IPath serializationFilePath = Path.fromOSString(serializationManager.getSerializationFilePath(resourceLocation, SerializationKind.FOLDER));
    ResourceProxy coveringParentData = findSerializationDataFromCoveringParent(resource, syncDirectory, resourceLocation, serializationFilePath);
    if (coveringParentData != null) {
        Activator.getDefault().getPluginLogger().trace("Found covering resource data ( repository path = {0} ) for resource at {1},  skipping deletion and performing an update instead", coveringParentData.getPath(), resource.getFullPath());
        FileInfo info = createFileInfo(resource);
        return repository.newAddOrUpdateNodeCommand(new CommandContext(filter), info, coveringParentData);
    }
    return repository.newDeleteNodeCommand(serializationManager.getRepositoryPath(resourceLocation));
}
Also used : IPath(org.eclipse.core.runtime.IPath) FileInfo(org.apache.sling.ide.transport.FileInfo) CommandContext(org.apache.sling.ide.transport.CommandContext) Filter(org.apache.sling.ide.filter.Filter) FilterResult(org.apache.sling.ide.filter.FilterResult) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with CommandContext

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

the class AddOrUpdateNodeCommandTest method nodeNotPresentButOutsideOfFilterIsNotRemoved.

@Test
public void nodeNotPresentButOutsideOfFilterIsNotRemoved() throws Exception {
    final CommandContext context = new CommandContext(new Filter() {

        @Override
        public FilterResult filter(String repositoryPath) {
            if (repositoryPath.equals("/content/not-included-child")) {
                return FilterResult.DENY;
            }
            return FilterResult.ALLOW;
        }
    });
    doWithTransientRepository(new CallableWithSession() {

        @Override
        public Void call() throws Exception {
            Node content = session().getRootNode().addNode("content", "nt:unstructured");
            content.addNode("included-child");
            content.addNode("not-included-child");
            session().save();
            ResourceProxy resource = newResource("/content", "nt:unstructured");
            resource.addChild(newResource("/content/included-child", "nt:unstructured"));
            AddOrUpdateNodeCommand cmd = new AddOrUpdateNodeCommand(repo(), credentials(), context, null, resource, logger);
            cmd.execute().get();
            session().refresh(false);
            content = session().getRootNode().getNode("content");
            content.getNode("included-child");
            content.getNode("not-included-child");
            return null;
        }
    });
}
Also used : CommandContext(org.apache.sling.ide.transport.CommandContext) Filter(org.apache.sling.ide.filter.Filter) Node(javax.jcr.Node) FilterResult(org.apache.sling.ide.filter.FilterResult) NodeTypeExistsException(javax.jcr.nodetype.NodeTypeExistsException) InvalidNodeTypeDefinitionException(javax.jcr.nodetype.InvalidNodeTypeDefinitionException) RepositoryException(javax.jcr.RepositoryException) ParseException(org.apache.jackrabbit.commons.cnd.ParseException) IOException(java.io.IOException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) Test(org.junit.Test)

Example 3 with CommandContext

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

the class ResourceChangeCommandFactory method addFileCommand.

private Command<?> addFileCommand(Repository repository, IResource resource) throws CoreException, IOException {
    ResourceAndInfo rai = buildResourceAndInfo(resource, repository);
    if (rai == null) {
        return null;
    }
    CommandContext context = new CommandContext(ProjectUtil.loadFilter(resource.getProject()));
    if (rai.isOnlyWhenMissing()) {
        return repository.newAddOrUpdateNodeCommand(context, rai.getInfo(), rai.getResource(), Repository.CommandExecutionFlag.CREATE_ONLY_WHEN_MISSING);
    }
    return repository.newAddOrUpdateNodeCommand(context, rai.getInfo(), rai.getResource());
}
Also used : CommandContext(org.apache.sling.ide.transport.CommandContext)

Aggregations

CommandContext (org.apache.sling.ide.transport.CommandContext)3 Filter (org.apache.sling.ide.filter.Filter)2 FilterResult (org.apache.sling.ide.filter.FilterResult)2 ResourceProxy (org.apache.sling.ide.transport.ResourceProxy)2 IOException (java.io.IOException)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)1 InvalidNodeTypeDefinitionException (javax.jcr.nodetype.InvalidNodeTypeDefinitionException)1 NodeTypeExistsException (javax.jcr.nodetype.NodeTypeExistsException)1 ParseException (org.apache.jackrabbit.commons.cnd.ParseException)1 FileInfo (org.apache.sling.ide.transport.FileInfo)1 IFolder (org.eclipse.core.resources.IFolder)1 IPath (org.eclipse.core.runtime.IPath)1 Test (org.junit.Test)1