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));
}
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;
}
});
}
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());
}
Aggregations