use of com.enonic.xp.node.NodeBranchEntry in project xp by enonic.
the class ProjectServiceImplTest method create_in_non_master_node.
@Test
void create_in_non_master_node() {
IndexServiceInternal indexServiceInternalMock = mock(IndexServiceInternal.class);
when(indexServiceInternalMock.waitForYellowStatus()).thenReturn(true);
indexService.setIndexServiceInternal(indexServiceInternalMock);
final RepositoryId projectRepoId = RepositoryId.from("com.enonic.cms.test-project");
final Project project = adminContext().callWith(() -> doCreateProject(ProjectName.from(projectRepoId), null, true, null));
assertNotNull(project);
assertEquals("test-project", project.getName().toString());
final NodeBranchEntry nodeBranchEntry = this.branchService.get(Node.ROOT_UUID, InternalContext.create(adminContext()).repositoryId(projectRepoId).build());
assertNotNull(nodeBranchEntry);
adminContext().runWith(() -> {
final Repository pro = repositoryService.get(projectRepoId);
assertNotNull(pro);
});
}
use of com.enonic.xp.node.NodeBranchEntry in project xp by enonic.
the class GetActiveNodeVersionsCommand method execute.
public GetActiveNodeVersionsResult execute() {
final GetActiveNodeVersionsResult.Builder builder = GetActiveNodeVersionsResult.create();
for (final Branch branch : branches) {
final Context context = ContextAccessor.current();
final NodeBranchEntry nodeBranchEntry = this.nodeStorageService.getBranchNodeVersion(this.nodeId, InternalContext.create(context).branch(branch).build());
if (nodeBranchEntry != null) {
builder.add(branch, this.nodeStorageService.getVersion(nodeBranchEntry.getNodeId(), nodeBranchEntry.getVersionId(), InternalContext.from(context)));
}
}
return builder.build();
}
use of com.enonic.xp.node.NodeBranchEntry 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;
}
use of com.enonic.xp.node.NodeBranchEntry in project xp by enonic.
the class PushNodesCommand method updateTargetChildrenMetaData.
private void updateTargetChildrenMetaData(final NodeBranchEntry nodeBranchEntry, PushNodesResult.Builder resultBuilder) {
final Context context = ContextAccessor.current();
final Context targetContext = ContextBuilder.create().authInfo(context.getAuthInfo()).branch(this.target).repositoryId(context.getRepositoryId()).build();
final FindNodesByParentResult result = FindNodesByParentCommand.create(this).params(FindNodesByParentParams.create().parentPath(nodeBranchEntry.getNodePath()).childOrder(ChildOrder.from(NodeIndexPath.PATH + " asc")).build()).build().execute();
final NodeBranchEntries childEntries = this.nodeStorageService.getBranchNodeVersions(result.getNodeIds(), false, InternalContext.from(ContextAccessor.current()));
for (final NodeBranchEntry child : childEntries) {
final NodeBranchEntry targetNodeEntry = this.nodeStorageService.getBranchNodeVersion(child.getNodeId(), InternalContext.from(targetContext));
if (targetNodeEntry != null) {
final Node childNode = GetNodeByIdCommand.create(this).id(child.getNodeId()).build().execute();
this.nodeStorageService.move(StoreMovedNodeParams.create().nodeVersionId(child.getVersionId()).node(childNode).build(), InternalContext.from(targetContext));
resultBuilder.addSuccess(child);
updateTargetChildrenMetaData(child, resultBuilder);
}
}
}
use of com.enonic.xp.node.NodeBranchEntry in project xp by enonic.
the class MoveNodeCommand method doMoveNode.
private Node doMoveNode(final NodePath newParentPath, final NodeName newNodeName, final NodeId id) {
final Node persistedNode = doGetById(id);
final SearchResult result = this.nodeSearchService.query(NodeQuery.create().parent(persistedNode.path()).from(0).size(NodeSearchService.GET_ALL_SIZE_FLAG).build(), SingleRepoSearchSource.from(ContextAccessor.current()));
final NodeBranchEntries nodeBranchEntries = this.nodeStorageService.getBranchNodeVersions(NodeIds.from(result.getIds()), false, InternalContext.from(ContextAccessor.current()));
final Node.Builder nodeToMoveBuilder = Node.create(persistedNode).name(newNodeName).data(processor.process(persistedNode.data())).parentPath(newParentPath).indexConfigDocument(persistedNode.getIndexConfigDocument()).timestamp(Instant.now(CLOCK));
final Node movedNode;
final boolean isTheOriginalMovedNode = persistedNode.id().equals(this.nodeId);
if (isTheOriginalMovedNode) {
final boolean isRenaming = newParentPath.equals(persistedNode.parentPath());
if (!isRenaming) {
updateStoredNodeProperties(newParentPath, nodeToMoveBuilder);
}
}
movedNode = doStore(nodeToMoveBuilder.build());
this.result.addMovedNode(MoveNodeResult.MovedNode.create().previousPath(persistedNode.path()).node(movedNode).build());
nodeMoved(1);
for (final NodeBranchEntry nodeBranchEntry : nodeBranchEntries) {
doMoveNode(nodeToMoveBuilder.build().path(), getNodeName(nodeBranchEntry), nodeBranchEntry.getNodeId());
}
return movedNode;
}
Aggregations