Search in sources :

Example 16 with CreateNodeParams

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

the class RenameNodeCommandTest method rename_then_create_with_same_name.

@Test
public void rename_then_create_with_same_name() throws Exception {
    final CreateNodeParams createNodeNamedMyNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
    final Node createdNode = createNode(createNodeNamedMyNodeParams);
    RenameNodeCommand.create().params(RenameNodeParams.create().nodeId(createdNode.id()).nodeName(NodeName.from("my-node-edited")).build()).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
    createNode(createNodeNamedMyNodeParams);
}
Also used : Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Example 17 with CreateNodeParams

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

the class NodeVersionServiceImplTest method getVersions.

@Test
public void getVersions() throws Exception {
    final CreateNodeParams createNodeParams = CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).build();
    final PropertyTree data = new PropertyTree();
    data.addString("myName", "myValue");
    final CreateNodeParams createNodeParams2 = CreateNodeParams.create().name("my-node2").parent(NodePath.ROOT).data(data).build();
    final Node createdNode = createNode(createNodeParams);
    final Node createdNode2 = createNode(createNodeParams2);
    final NodeVersions nodeVersions = nodeDao.get(NodeVersionKeys.from(getNodeVersionKey(createdNode), getNodeVersionKey(createdNode2)), createInternalContext());
    assertEquals(2, nodeVersions.getSize());
    assertEquals(createdNode.id(), nodeVersions.get(0).getId());
    assertEquals(createdNode.data(), nodeVersions.get(0).getData());
    assertEquals(createdNode2.id(), nodeVersions.get(1).getId());
    assertEquals(createdNode2.data(), nodeVersions.get(1).getData());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) NodeVersions(com.enonic.xp.node.NodeVersions) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 18 with CreateNodeParams

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

the class AbstractNodeTest method createNode.

protected Node createNode(final CreateNodeParams createNodeParams, final boolean refresh) {
    final CreateNodeParams.Builder createParamsWithAnalyzer = CreateNodeParams.create(createNodeParams);
    if (createNodeParams.getIndexConfigDocument() == null) {
        createParamsWithAnalyzer.indexConfigDocument(PatternIndexConfigDocument.create().analyzer(ContentConstants.DOCUMENT_INDEX_DEFAULT_ANALYZER).build());
    }
    final Node createdNode = CreateNodeCommand.create().indexServiceInternal(this.indexServiceInternal).binaryService(this.binaryService).storageService(this.storageService).searchService(this.searchService).params(createParamsWithAnalyzer.build()).build().execute();
    if (refresh) {
        refresh();
    }
    return createdNode;
}
Also used : Node(com.enonic.xp.node.Node) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 19 with CreateNodeParams

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

the class PrincipalNodeTranslator method toCreateNodeParams.

public static CreateNodeParams toCreateNodeParams(final Principal principal) {
    Preconditions.checkNotNull(principal);
    final CreateNodeParams.Builder builder = CreateNodeParams.create().name(PrincipalKeyNodeTranslator.toNodeName(principal.getKey()).toString()).parent(principal.getKey().toPath().getParentPath()).setNodeId(NodeId.from(principal.getKey().toString().toLowerCase())).inheritPermissions(true).indexConfigDocument(PrincipalIndexConfigFactory.create());
    final PropertyTree data = new PropertyTree();
    data.setString(PrincipalPropertyNames.DISPLAY_NAME_KEY, principal.getDisplayName());
    data.setString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY, principal.getKey().getType().toString());
    if (!principal.getKey().isRole()) {
        data.setString(PrincipalPropertyNames.ID_PROVIDER_KEY, principal.getKey().getIdProviderKey().toString());
    }
    switch(principal.getKey().getType()) {
        case USER:
            populateUserData(data.getRoot(), (User) principal);
            break;
        case ROLE:
            populateRoleData(data.getRoot(), (Role) principal);
            break;
        case GROUP:
            populateGroupData(data.getRoot(), (Group) principal);
            break;
    }
    builder.data(data);
    return builder.build();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 20 with CreateNodeParams

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

the class SecurityServiceImpl method doCreateUser.

private User doCreateUser(final CreateUserParams createUser) {
    final User user = User.create().key(createUser.getKey()).login(createUser.getLogin()).email(createUser.getEmail()).displayName(createUser.getDisplayName()).modifiedTime(Instant.now(clock)).build();
    final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(user);
    try {
        final Node node = callWithContext(() -> {
            final Node createdNode = nodeService.create(createNodeParams);
            this.nodeService.refresh(RefreshMode.SEARCH);
            return createdNode;
        });
        if (createUser.getPassword() != null) {
            return setPassword(user.getKey(), createUser.getPassword());
        }
        return PrincipalNodeTranslator.userFromNode(node);
    } catch (NodeIdExistsException | NodeAlreadyExistAtPathException e) {
        throw new PrincipalAlreadyExistsException(createUser.getKey());
    }
}
Also used : User(com.enonic.xp.security.User) 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)

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