use of com.enonic.xp.node.NodePath in project xp by enonic.
the class ParentContentSynchronizer method sync.
@Override
public void sync(final ContentSyncParams params) {
final Map<NodePath, Context> sourceContexts = initContexts(params.getSourceProject());
final Map<NodePath, Context> targetContexts = initContexts(params.getTargetProject());
if (params.getContentIds().isEmpty()) {
sourceContexts.forEach((root, context) -> this.doSyncWithChildren(context.callWith(() -> List.of(ContentToSync.create().sourceContent(contentService.getByPath(ContentPath.ROOT)).sourceContext(context).targetContext(targetContexts.get(root)).build()))));
return;
}
final ImmutableList.Builder<ContentToSync> contentsToSync = ImmutableList.builder();
params.getContentIds().forEach(contentId -> {
final Context actualSourceContext = getActualContext(contentId, sourceContexts.values());
Context actualTargetContext = getActualContext(contentId, targetContexts.values());
if (actualSourceContext != null) {
final Content sourceContent = actualSourceContext.callWith(() -> contentService.getById(contentId));
Content targetContent = null;
if (actualTargetContext == null) {
actualTargetContext = targetContexts.get((NodePath) actualSourceContext.getAttribute(CONTENT_ROOT_PATH_ATTRIBUTE));
} else {
targetContent = actualTargetContext.callWith(() -> contentService.getById(contentId));
}
contentsToSync.add(ContentToSync.create().sourceContent(sourceContent).targetContent(targetContent).sourceContext(actualSourceContext).targetContext(actualTargetContext).build());
if (params.isIncludeChildren()) {
this.doSyncWithChildren(contentsToSync.build());
} else {
this.doSync(contentsToSync.build());
}
} else if (actualTargetContext != null) {
actualTargetContext.runWith(() -> this.sync(ContentEventsSyncParams.create().addContentIds(params.getContentIds()).sourceProject(params.getSourceProject()).targetProject(params.getTargetProject()).syncEventType(ContentSyncEventType.DELETED).build()));
}
});
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class UndoPendingDeleteContentCommand method ensureValidParent.
private void ensureValidParent(final NodeComparison nodeComparison) {
final NodePath parentPath = nodeComparison.getSourcePath().getParentPath();
if (ContentNodeHelper.translateNodePathToContentPath(parentPath).isRoot()) {
return;
}
final Node parentNode = this.nodeService.getByPath(parentPath);
if (parentNode == null) {
throw new IllegalArgumentException("Parent with path [" + parentPath + "] does not exists");
}
final NodeComparison parentState = this.nodeService.compare(parentNode.id(), this.params.getTarget());
if (CompareStatus.PENDING_DELETE == parentState.getCompareStatus()) {
removePendingDeleteState(parentState);
}
ensureValidParent(parentState);
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class CreateContentCommandTest method createContent_unknown_parent_content_type.
@Test
public void createContent_unknown_parent_content_type() {
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenAnswer(a -> BuiltinContentTypesAccessor.getContentType(((GetContentTypeParams) a.getArgument(0)).getContentTypeName()));
final NodePath sitePath = initContent(ContentTypeName.site(), "site", ContentConstants.CONTENT_ROOT_PATH);
final NodePath parentPath = initContent(ContentTypeName.from("unknown:unknown"), "parent", sitePath);
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.dataMedia()).name("media").parent(ContentPath.from("/site/parent")).contentData(new PropertyTree()).displayName("displayName").build();
CreateContentCommand command = createContentCommand(params);
final Content content = command.execute();
assertNotNull(content);
}
use of com.enonic.xp.node.NodePath in project xp by enonic.
the class CreateContentCommandTest method createContentInValidPageTemplate.
@Test
public void createContentInValidPageTemplate() {
Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenAnswer(a -> BuiltinContentTypesAccessor.getContentType(((GetContentTypeParams) a.getArgument(0)).getContentTypeName()));
final NodePath sitePath = initContent(ContentTypeName.site(), "site", ContentConstants.CONTENT_ROOT_PATH);
final NodePath templatePath = initContent(ContentTypeName.pageTemplate(), "template", sitePath);
final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.dataMedia()).name("media").parent(ContentPath.from("/site/template")).contentData(new PropertyTree()).displayName("displayName").build();
CreateContentCommand command = createContentCommand(params);
final Content content = command.execute();
assertNotNull(content);
assertEquals(ContentPath.from("/site/template"), content.getParentPath());
}
Aggregations