Search in sources :

Example 21 with CreateNodeParams

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

the class SecurityServiceImpl method createGroup.

@Override
public Group createGroup(final CreateGroupParams createGroup) {
    final Group group = Group.create().key(createGroup.getKey()).displayName(createGroup.getDisplayName()).modifiedTime(Instant.now(clock)).description(createGroup.getDescription()).build();
    final CreateNodeParams createGroupParams = PrincipalNodeTranslator.toCreateNodeParams(group);
    try {
        final Node node = callWithContext(() -> {
            final Node createdNode = this.nodeService.create(createGroupParams);
            this.nodeService.refresh(RefreshMode.SEARCH);
            return createdNode;
        });
        return PrincipalNodeTranslator.groupFromNode(node);
    } catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
        throw new PrincipalAlreadyExistsException(createGroup.getKey());
    }
}
Also used : Group(com.enonic.xp.security.Group) PrincipalAlreadyExistsException(com.enonic.xp.security.PrincipalAlreadyExistsException) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 22 with CreateNodeParams

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

the class SecurityServiceImpl method createRole.

@Override
public Role createRole(final CreateRoleParams createRole) {
    final Role role = Role.create().key(createRole.getKey()).displayName(createRole.getDisplayName()).modifiedTime(Instant.now(clock)).description(createRole.getDescription()).build();
    final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(role);
    try {
        final Node node = callWithContext(() -> {
            final Node createdNode = this.nodeService.create(createNodeParams);
            this.nodeService.refresh(RefreshMode.SEARCH);
            return createdNode;
        });
        return PrincipalNodeTranslator.roleFromNode(node);
    } catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
        throw new PrincipalAlreadyExistsException(createRole.getKey());
    }
}
Also used : Role(com.enonic.xp.security.Role) PrincipalAlreadyExistsException(com.enonic.xp.security.PrincipalAlreadyExistsException) NodeIdExistsException(com.enonic.xp.node.NodeIdExistsException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 23 with CreateNodeParams

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

the class UserNodeTranslatorTest method toCreateNode.

@Test
public void toCreateNode() throws Exception {
    final User user = User.create().displayName("displayname").email("rmy@enonic.com").login("login").authenticationHash("password").key(PrincipalKey.ofUser(IdProviderKey.system(), "rmy")).modifiedTime(Instant.now(clock)).build();
    final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(user);
    assertEquals("rmy", createNodeParams.getName());
    final PropertyTree rootDataSet = createNodeParams.getData();
    assertEquals(IdProviderKey.system().toString(), rootDataSet.getString(PrincipalPropertyNames.ID_PROVIDER_KEY));
    assertEquals(PrincipalType.USER.toString(), rootDataSet.getString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY));
    assertEquals("displayname", rootDataSet.getString(PrincipalPropertyNames.DISPLAY_NAME_KEY));
    assertNotNull(rootDataSet);
    assertEquals(7, rootDataSet.getTotalSize());
}
Also used : User(com.enonic.xp.security.User) PropertyTree(com.enonic.xp.data.PropertyTree) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Example 24 with CreateNodeParams

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

the class ContentImportValidator method ensureValid.

@Override
public CreateNodeParams ensureValid(final CreateNodeParams original) {
    final CreateNodeParams.Builder builder = CreateNodeParams.create(original);
    final PropertyTree updatedData = original.getData();
    validateChildOrder(original, builder);
    builder.data(updatedData);
    return builder.build();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 25 with CreateNodeParams

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

the class DuplicateNodeCommand method execute.

public DuplicateNodeResult execute() {
    final Node existingNode = doGetById(params.getNodeId());
    if (existingNode == null) {
        throw new NodeNotFoundException("Cannot duplicate node with id [" + params.getNodeId() + "]");
    }
    if (existingNode.isRoot()) {
        throw new OperationNotPermittedException("Not allowed to duplicate root-node");
    }
    final CreateNodeParams.Builder createNodeParams = CreateNodeParams.from(existingNode);
    attachBinaries(existingNode, createNodeParams);
    Node duplicatedNode = null;
    String newNodeName = existingNode.name().toString();
    do {
        try {
            newNodeName = DuplicateValueResolver.name(newNodeName);
            final CreateNodeParams processedParams = executeProcessors(createNodeParams.name(newNodeName).build());
            duplicatedNode = CreateNodeCommand.create(this).params(processedParams).binaryService(binaryService).build().execute();
        } catch (NodeAlreadyExistAtPathException e) {
            // try again with other name
            LOG.debug(String.format("[%s] node with [%s] parent already exist.", newNodeName, existingNode.parentPath().toString()), e);
        }
    } while (duplicatedNode == null);
    result.node(duplicatedNode);
    nodeDuplicated(1);
    final NodeReferenceUpdatesHolder.Builder builder = NodeReferenceUpdatesHolder.create().add(existingNode.id(), duplicatedNode.id());
    if (params.getIncludeChildren()) {
        storeChildNodes(existingNode, duplicatedNode, builder);
    }
    final NodeReferenceUpdatesHolder nodesToBeUpdated = builder.build();
    RefreshCommand.create().refreshMode(RefreshMode.SEARCH).indexServiceInternal(this.indexServiceInternal).build().execute();
    updateNodeReferences(duplicatedNode, nodesToBeUpdated);
    updateChildReferences(duplicatedNode, nodesToBeUpdated);
    return result.build();
}
Also used : NodeNotFoundException(com.enonic.xp.node.NodeNotFoundException) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) OperationNotPermittedException(com.enonic.xp.node.OperationNotPermittedException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Aggregations

CreateNodeParams (com.enonic.xp.node.CreateNodeParams)46 Node (com.enonic.xp.node.Node)32 Test (org.junit.jupiter.api.Test)28 PropertyTree (com.enonic.xp.data.PropertyTree)18 BinaryReference (com.enonic.xp.util.BinaryReference)9 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)8 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)7 NodeId (com.enonic.xp.node.NodeId)4 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)4 AccessControlList (com.enonic.xp.security.acl.AccessControlList)4 ByteSource (com.google.common.io.ByteSource)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 NodeBinaryReferenceException (com.enonic.xp.node.NodeBinaryReferenceException)3 NodeIdExistsException (com.enonic.xp.node.NodeIdExistsException)3 NodePath (com.enonic.xp.node.NodePath)3 PrincipalAlreadyExistsException (com.enonic.xp.security.PrincipalAlreadyExistsException)3 ByteStreams (com.google.common.io.ByteStreams)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)3