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