Search in sources :

Example 51 with NodePath

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()));
        }
    });
}
Also used : Context(com.enonic.xp.context.Context) ImmutableList(com.google.common.collect.ImmutableList) Content(com.enonic.xp.content.Content) NodePath(com.enonic.xp.node.NodePath)

Example 52 with NodePath

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);
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath)

Example 53 with NodePath

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);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Example 54 with NodePath

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());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) NodePath(com.enonic.xp.node.NodePath) Test(org.junit.jupiter.api.Test)

Aggregations

NodePath (com.enonic.xp.node.NodePath)54 Node (com.enonic.xp.node.Node)27 Test (org.junit.jupiter.api.Test)20 NodeId (com.enonic.xp.node.NodeId)15 InternalContext (com.enonic.xp.repo.impl.InternalContext)12 Content (com.enonic.xp.content.Content)7 Event (com.enonic.xp.event.Event)7 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)4 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)4 NodeVersionId (com.enonic.xp.node.NodeVersionId)4 ChildOrder (com.enonic.xp.index.ChildOrder)3 NodeIds (com.enonic.xp.node.NodeIds)3 NodeVersionKey (com.enonic.xp.blob.NodeVersionKey)2 ContentId (com.enonic.xp.content.ContentId)2 ContentPath (com.enonic.xp.content.ContentPath)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)2 Context (com.enonic.xp.context.Context)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 MoveNodeParams (com.enonic.xp.node.MoveNodeParams)2 NodeVersion (com.enonic.xp.node.NodeVersion)2