use of com.enonic.xp.node.NodeIds in project xp by enonic.
the class DuplicateNodeCommandTest method reference_to_child_in_other_parent_within_duplicate_root.
@Test
public void reference_to_child_in_other_parent_within_duplicate_root() throws Exception {
final PropertyTree data = new PropertyTree();
data.addReference("refTo1_2_1", Reference.from("a1_2_1"));
final Node a1 = createNode(NodePath.ROOT, "a1");
createNode(CreateNodeParams.create().setNodeId(NodeId.from("a1_1")).name("a1_1").parent(a1.path()).data(data).build());
final Node a1_2 = createNode(a1.path(), "a1_2");
createNode(a1_2.path(), "a1_2_1");
final Node a1Duplicate = duplicateNode(a1).getNode();
final NodeIds children = findChildren(a1Duplicate).getNodeIds();
assertEquals(2, children.getSize());
assertDuplicatedTree(a1.path(), a1, a1Duplicate);
}
use of com.enonic.xp.node.NodeIds in project xp by enonic.
the class UnpublishContentCommand method recursiveUnpublish.
private void recursiveUnpublish(final NodeId nodeId, boolean includeChildren, final ContentIds.Builder contentsBuilder) {
if (includeChildren) {
final FindNodesByParentResult result = this.nodeService.findByParent(FindNodesByParentParams.create().parentId(nodeId).build());
result.getNodeIds().forEach((id) -> recursiveUnpublish(id, true, contentsBuilder));
}
final NodeIds nodes = this.nodeService.deleteById(nodeId);
if (nodes != null && nodes.isNotEmpty()) {
if (params.getPublishContentListener() != null) {
params.getPublishContentListener().contentPushed(1);
}
contentsBuilder.add(ContentId.from(nodes.first().toString()));
}
}
use of com.enonic.xp.node.NodeIds in project xp by enonic.
the class SetPublishInfoCommand method execute.
public void execute() {
final NodeIds nodeIdsToUpdate = findNodesWithoutPublishFirstAndFrom(nodeIds);
if (nodeIdsToUpdate.getSize() == 0) {
return;
}
final Instant now = Instant.now();
final Instant publishFrom = contentPublishInfo.getFrom() == null ? now : contentPublishInfo.getFrom();
final Instant publishTo = contentPublishInfo.getTo();
for (final NodeId id : nodeIdsToUpdate) {
this.nodeService.update(UpdateNodeParams.create().editor(toBeEdited -> {
PropertySet publishInfo = toBeEdited.data.getSet(ContentPropertyNames.PUBLISH_INFO);
if (publishInfo == null) {
publishInfo = toBeEdited.data.addSet(ContentPropertyNames.PUBLISH_INFO);
}
if (publishInfo.getInstant(ContentPropertyNames.PUBLISH_FIRST) == null) {
final Instant publishFromPropertyValue = publishInfo.getInstant(ContentPropertyNames.PUBLISH_FROM);
if (publishFromPropertyValue == null) {
publishInfo.setInstant(ContentPropertyNames.PUBLISH_FIRST, publishFrom);
} else {
// TODO Special case for Enonic XP 6.7 and 6.8 contents. Remove after 7.0
publishInfo.setInstant(ContentPropertyNames.PUBLISH_FIRST, publishFromPropertyValue);
}
}
if (publishInfo.getInstant(ContentPropertyNames.PUBLISH_FROM) == null) {
publishInfo.setInstant(ContentPropertyNames.PUBLISH_FROM, publishFrom);
if (publishTo == null) {
if (publishInfo.hasProperty(ContentPropertyNames.PUBLISH_TO)) {
publishInfo.removeProperty(ContentPropertyNames.PUBLISH_TO);
}
} else {
publishInfo.setInstant(ContentPropertyNames.PUBLISH_TO, publishTo);
}
}
}).id(id).build());
if (publishContentListener != null) {
publishContentListener.contentPushed(1);
}
}
this.nodeService.refresh(RefreshMode.ALL);
}
use of com.enonic.xp.node.NodeIds in project xp by enonic.
the class ContentNodeHelperTest method toContentIds.
@Test
public void toContentIds() {
final NodeIds nodeIds = NodeIds.from("e1f57280-d672-4cd8-b674-98e26e5b69ae", "45d67001-7f2b-4093-99ae-639be9fdd1f6");
final ContentIds contentIds = ContentNodeHelper.toContentIds(nodeIds);
assertEquals(ContentIds.from("e1f57280-d672-4cd8-b674-98e26e5b69ae", "45d67001-7f2b-4093-99ae-639be9fdd1f6"), contentIds);
}
use of com.enonic.xp.node.NodeIds in project xp by enonic.
the class AbstractDeleteNodeCommand method deleteNodeWithChildren.
NodeBranchEntries deleteNodeWithChildren(final Node node, final Context context, final DeleteNodeListener deleteNodeListener) {
if (node.isRoot() && !allowDeleteRootNode) {
throw new OperationNotPermittedException("Not allowed to delete root-node");
}
doRefresh();
final NodeBranchEntries nodesToBeDeleted = newResolveNodesToDelete(node);
final NodeIds nodeIds = NodeIds.from(nodesToBeDeleted.getKeys());
final boolean allHasPermissions = NodesHasPermissionResolver.create(this).nodeIds(nodeIds).permission(Permission.DELETE).build().execute();
if (!allHasPermissions) {
throw new NodeAccessException(context.getAuthInfo().getUser(), node.path(), Permission.DELETE);
}
for (final List<NodeId> keysBatch : Iterables.partition(nodeIds, BATCH_SIZE)) {
this.nodeStorageService.delete(NodeIds.from(keysBatch), InternalContext.from(context));
if (deleteNodeListener != null) {
deleteNodeListener.nodesDeleted(keysBatch.size());
}
}
doRefresh();
return nodesToBeDeleted;
}
Aggregations