use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class CreateContentCommandTest method mockNodeServiceCreate.
private Node mockNodeServiceCreate(final InvocationOnMock invocation) throws Throwable {
CreateNodeParams params = (CreateNodeParams) invocation.getArguments()[0];
final AccessControlList permissions = AccessControlList.create().add(AccessControlEntry.create().allowAll().principal(PrincipalKey.ofAnonymous()).build()).build();
return Node.create().id(params.getNodeId() != null ? params.getNodeId() : new NodeId()).parentPath(params.getParent()).name(NodeName.from(params.getName())).data(params.getData()).indexConfigDocument(params.getIndexConfigDocument()).childOrder(params.getChildOrder() != null ? params.getChildOrder() : ChildOrder.defaultOrder()).permissions(permissions).inheritPermissions(params.inheritPermissions()).nodeType(params.getNodeType() != null ? params.getNodeType() : NodeType.DEFAULT_NODE_COLLECTION).timestamp(Instant.now()).build();
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class DuplicateNodeCommand method storeChildNodes.
private void storeChildNodes(final Node originalParent, final Node newParent, final NodeReferenceUpdatesHolder.Builder builder) {
final FindNodesByParentResult findNodesByParentResult = doFindNodesByParent(FindNodesByParentParams.create().parentPath(originalParent.path()).from(0).size(NodeSearchService.GET_ALL_SIZE_FLAG).build());
final Nodes children = GetNodesByIdsCommand.create(this).ids(findNodesByParentResult.getNodeIds()).build().execute();
for (final Node node : children) {
final CreateNodeParams.Builder paramsBuilder = CreateNodeParams.from(node).parent(newParent.path());
decideInsertStrategy(originalParent, node, paramsBuilder);
attachBinaries(node, paramsBuilder);
final CreateNodeParams originalParams = paramsBuilder.build();
final CreateNodeParams processedParams = executeProcessors(originalParams);
final Node newChildNode = CreateNodeCommand.create(this).params(processedParams).binaryService(this.binaryService).build().execute();
builder.add(node.id(), newChildNode.id());
result.addChild(newChildNode);
nodeDuplicated(1);
storeChildNodes(node, newChildNode, builder);
}
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class NodeServiceImplTest method create.
@Test
public void create() throws Exception {
final ChildOrder childOrder = ChildOrder.create().add(FieldOrderExpr.create(NodeIndexPath.TIMESTAMP, OrderExpr.Direction.DESC)).add(FieldOrderExpr.create(NodeIndexPath.NAME, OrderExpr.Direction.ASC)).build();
final AccessControlList aclList = AccessControlList.create().add(AccessControlEntry.create().principal(PrincipalKey.from("user:myidprovider:rmy")).allow(Permission.READ).build()).build();
final CreateNodeParams params = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(aclList).childOrder(childOrder).build();
final Node node = this.nodeService.create(params);
refresh();
assertTrue(node.getPermissions() != null);
assertEquals(aclList, node.getPermissions());
assertEquals(childOrder, node.getChildOrder());
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class GetNodeByIdCommandTest method get_by_id.
@Test
public void get_by_id() throws Exception {
final CreateNodeParams createNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
final Node createdNode = createNode(createNodeParams);
final Node fetchedNode = GetNodeByIdCommand.create().indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).id(createdNode.id()).build().execute();
assertEquals(createdNode, fetchedNode);
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class UpdateNodeCommandTest method unreferred_binary_attachment_ignored.
@Test
public void unreferred_binary_attachment_ignored() throws Exception {
final PropertyTree data = new PropertyTree();
final BinaryReference binaryRef = BinaryReference.from("my-car.jpg");
data.setBinaryReference("my-image", binaryRef);
final CreateNodeParams params = CreateNodeParams.create().parent(NodePath.ROOT).name("my-node").data(data).attachBinary(binaryRef, ByteSource.wrap("my-car-image-source".getBytes())).build();
final Node node = createNode(params);
final UpdateNodeParams updateNodeParams = UpdateNodeParams.create().editor(toBeEdited -> {
final PropertyTree nodeData = toBeEdited.data;
nodeData.addString("newValue", "hepp");
}).attachBinary(BinaryReference.from("unreferred binary"), ByteSource.wrap("nothing to see here".getBytes())).id(node.id()).build();
final Node updatedNode = updateNode(updateNodeParams);
assertEquals(1, updatedNode.getAttachedBinaries().getSize());
}
Aggregations