Search in sources :

Example 1 with PushNodeEntries

use of com.enonic.xp.node.PushNodeEntries in project xp by enonic.

the class NodeEventsTest method testPushed.

@Test
public void testPushed() {
    final Node pushed1 = createNode("pushed1", NodePath.create("/mynode1/pushed1").build(), "id1");
    final Node pushed2 = createNode("pushed2", NodePath.create("/mynode1/pushed2").build(), "id2");
    final Node pushed3 = createNode("pushed3Renamed", NodePath.create("/mynode1/pushed3").build(), "id3");
    final NodeBranchEntry nodeBranchEntry = NodeBranchEntry.create().nodeId(pushed1.id()).nodePath(pushed1.path()).nodeState(NodeState.DEFAULT).nodeVersionId(pushed1.getNodeVersionId()).build();
    final NodeBranchEntry nodeBranchEntry2 = NodeBranchEntry.create().nodeId(pushed2.id()).nodePath(pushed2.path()).nodeState(NodeState.DEFAULT).nodeVersionId(pushed2.getNodeVersionId()).build();
    final NodeBranchEntry nodeBranchEntry3 = NodeBranchEntry.create().nodeId(pushed3.id()).nodePath(pushed3.path()).nodeState(NodeState.DEFAULT).nodeVersionId(pushed3.getNodeVersionId()).build();
    final PushNodeEntries pushNodeEntries = PushNodeEntries.create().targetRepo(ContentConstants.CONTENT_REPO_ID).targetBranch(ContentConstants.BRANCH_MASTER).add(PushNodeEntry.create().nodeBranchEntry(nodeBranchEntry).build()).add(PushNodeEntry.create().nodeBranchEntry(nodeBranchEntry2).build()).add(PushNodeEntry.create().nodeBranchEntry(nodeBranchEntry3).currentTargetPath(NodePath.create("/mynode1/pushed3/pushed3").build()).build()).build();
    Event event = NodeEvents.pushed(pushNodeEntries);
    assertNotNull(event);
    assertTrue(event.isDistributed());
    assertTrue(event.hasValue("nodes"));
    assertEquals(NodeEvents.NODE_PUSHED_EVENT, event.getType());
    assertEquals("[{id=id1, path=/mynode1/pushed1/pushed1, branch=master, repo=com.enonic.cms.default}" + ", {id=id2, path=/mynode1/pushed2/pushed2, branch=master, repo=com.enonic.cms.default}" + ", {id=id3, path=/mynode1/pushed3/pushed3Renamed, branch=master, repo=com.enonic.cms.default, currentTargetPath=/mynode1/pushed3/pushed3}]", event.getValue("nodes").get().toString());
}
Also used : Node(com.enonic.xp.node.Node) Event(com.enonic.xp.event.Event) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) PushNodeEntries(com.enonic.xp.node.PushNodeEntries) Test(org.junit.jupiter.api.Test)

Example 2 with PushNodeEntries

use of com.enonic.xp.node.PushNodeEntries in project xp by enonic.

the class NodeEventListenerTest method node_pushed_event.

@Test
public void node_pushed_event() throws Exception {
    final NodeId nodeId = NodeId.from("node1");
    final NodePath nodePath = NodePath.create(NodePath.ROOT, "nodeName").build();
    final NodePath previousNodePath = NodePath.create(NodePath.ROOT, "previousName").build();
    final NodeBranchEntry nodeBranchEntry = NodeBranchEntry.create().nodeId(nodeId).nodePath(nodePath).nodeState(NodeState.DEFAULT).build();
    final PushNodeEntry pushNodeEntry = PushNodeEntry.create().nodeBranchEntry(nodeBranchEntry).currentTargetPath(previousNodePath).build();
    final PushNodeEntries pushNodeEntries = PushNodeEntries.create().targetRepo(ContentConstants.CONTENT_REPO_ID).targetBranch(ContentConstants.BRANCH_MASTER).add(pushNodeEntry).build();
    final Event localEvent = NodeEvents.pushed(pushNodeEntries);
    nodeEventListener.onEvent(Event.create(localEvent).localOrigin(false).build());
    Mockito.verify(nodeStorageService, Mockito.times(1)).handleNodePushed(Mockito.eq(nodeId), Mockito.eq(nodePath), Mockito.eq(previousNodePath), Mockito.isA(InternalContext.class));
}
Also used : InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeId(com.enonic.xp.node.NodeId) Event(com.enonic.xp.event.Event) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) PushNodeEntries(com.enonic.xp.node.PushNodeEntries) NodePath(com.enonic.xp.node.NodePath) PushNodeEntry(com.enonic.xp.node.PushNodeEntry) Test(org.junit.jupiter.api.Test)

Example 3 with PushNodeEntries

use of com.enonic.xp.node.PushNodeEntries in project xp by enonic.

the class PushNodesCommand method pushNodes.

private InternalPushNodesResult.Builder pushNodes(final Context context, final NodeBranchEntries nodeBranchEntries, final NodeComparisons comparisons) {
    final PushNodeEntries.Builder publishBuilder = PushNodeEntries.create().targetBranch(this.target).targetRepo(context.getRepositoryId());
    final InternalPushNodesResult.Builder builder = InternalPushNodesResult.create();
    final ArrayList<NodeBranchEntry> list = new ArrayList<>(nodeBranchEntries.getSet());
    list.sort(Comparator.comparing(NodeBranchEntry::getNodePath));
    for (final NodeBranchEntry branchEntry : list) {
        final NodeComparison comparison = comparisons.get(branchEntry.getNodeId());
        final NodeBranchEntry nodeBranchEntry = nodeBranchEntries.get(comparison.getNodeId());
        final boolean hasPublishPermission = NodesHasPermissionResolver.create(this).nodeIds(NodeIds.from(nodeBranchEntry.getNodeId())).permission(Permission.PUBLISH).build().execute();
        if (!hasPublishPermission) {
            builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.ACCESS_DENIED);
            nodePushed(1);
            continue;
        }
        if (comparison.getCompareStatus() == CompareStatus.EQUAL) {
            builder.addSuccess(nodeBranchEntry);
            nodePushed(1);
            continue;
        }
        if ((CompareStatus.NEW == comparison.getCompareStatus() || CompareStatus.MOVED == comparison.getCompareStatus()) && targetAlreadyExists(nodeBranchEntry.getNodePath(), comparisons, context)) {
            builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.ALREADY_EXIST);
            nodePushed(1);
            continue;
        }
        if (!targetParentExists(nodeBranchEntry.getNodePath(), builder, context)) {
            builder.addFailed(nodeBranchEntry, PushNodesResult.Reason.PARENT_NOT_FOUND);
            nodePushed(1);
            continue;
        }
        publishBuilder.add(PushNodeEntry.create().nodeBranchEntry(nodeBranchEntry).currentTargetPath(comparison.getTargetPath()).build());
        builder.addSuccess(nodeBranchEntry);
        if (comparison.getCompareStatus() == CompareStatus.MOVED) {
            updateTargetChildrenMetaData(nodeBranchEntry, builder);
        }
    }
    final PushNodeEntries pushNodeEntries = publishBuilder.build();
    builder.setPushNodeEntries(pushNodeEntries);
    final InternalContext pushContext = InternalContext.create(context).skipConstraints(true).build();
    this.nodeStorageService.push(pushNodeEntries, pushListener, pushContext);
    return builder;
}
Also used : NodeComparison(com.enonic.xp.node.NodeComparison) InternalContext(com.enonic.xp.repo.impl.InternalContext) ArrayList(java.util.ArrayList) NodeBranchEntry(com.enonic.xp.node.NodeBranchEntry) PushNodeEntries(com.enonic.xp.node.PushNodeEntries)

Aggregations

NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)3 PushNodeEntries (com.enonic.xp.node.PushNodeEntries)3 Event (com.enonic.xp.event.Event)2 InternalContext (com.enonic.xp.repo.impl.InternalContext)2 Test (org.junit.jupiter.api.Test)2 Node (com.enonic.xp.node.Node)1 NodeComparison (com.enonic.xp.node.NodeComparison)1 NodeId (com.enonic.xp.node.NodeId)1 NodePath (com.enonic.xp.node.NodePath)1 PushNodeEntry (com.enonic.xp.node.PushNodeEntry)1 ArrayList (java.util.ArrayList)1