Search in sources :

Example 41 with CreateNodeParams

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

the class CreateIssueCommand method doExecute.

private Issue doExecute() {
    validateBlockingChecks();
    final long index = countTotalIssues() + 1;
    final IssueName issueName = IssueNameFactory.create(index);
    final CreateNodeParams createNodeParams = CreateNodeParamsFactory.create(this.params, this.getCurrentUser(), index, issueName);
    final Node createdNode;
    try {
        createdNode = nodeService.create(createNodeParams);
    } catch (NodeAlreadyExistAtPathException e) {
        throw new IssueAlreadyExistsException(IssueName.from(createNodeParams.getName()));
    }
    nodeService.refresh(RefreshMode.SEARCH);
    return IssueNodeTranslator.fromNode(createdNode);
}
Also used : IssueAlreadyExistsException(com.enonic.xp.issue.IssueAlreadyExistsException) IssueName(com.enonic.xp.issue.IssueName) Node(com.enonic.xp.node.Node) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 42 with CreateNodeParams

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

the class CreateNodeParamsFactory method doCreate.

private CreateNodeParams doCreate(final PropertyTree properties, BinaryAttachments createAttachments) {
    final String name = properties.getString(NODE_NAME);
    final String parentPath = properties.getString(PARENT_PATH);
    final Long manualOrderValue = properties.getLong(MANUAL_ORDER_VALUE);
    final String childOrder = properties.getString(CHILD_ORDER);
    final String nodeType = properties.getString(NODE_TYPE);
    final Iterable<PropertySet> permissions = properties.getSets(PERMISSIONS);
    final Boolean inheritPermissions = properties.getBoolean(INHERITS_PERMISSIONS);
    final PropertySet indexConfig = properties.getSet(INDEX_CONFIG);
    final CreateNodeParams.Builder builder = CreateNodeParams.create();
    setName(name, builder);
    setUserData(properties, builder);
    builder.parent(isNullOrEmpty(parentPath) ? NodePath.ROOT : NodePath.create(parentPath).build()).manualOrderValue(manualOrderValue).childOrder(ChildOrder.from(childOrder)).nodeType(isNullOrEmpty(nodeType) ? NodeType.DEFAULT_NODE_COLLECTION : NodeType.from(nodeType)).indexConfigDocument(new IndexConfigFactory(indexConfig).create()).setBinaryAttachments(createAttachments);
    if (inheritPermissions != null && inheritPermissions) {
        builder.inheritPermissions(true);
    } else {
        builder.permissions(new PermissionsFactory(permissions).create());
    }
    return builder.build();
}
Also used : PropertySet(com.enonic.xp.data.PropertySet) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 43 with CreateNodeParams

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

the class CreateNodeHandler method execute.

@Override
public Object execute() {
    final ScriptValueTranslatorResult params = getParams(this.params);
    final CreateNodeParams createNodeParams = new CreateNodeParamsFactory().create(params);
    final Node node = this.nodeService.create(createNodeParams);
    return new NodeMapper(node);
}
Also used : ScriptValueTranslatorResult(com.enonic.xp.lib.value.ScriptValueTranslatorResult) Node(com.enonic.xp.node.Node) NodeMapper(com.enonic.xp.lib.node.mapper.NodeMapper) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 44 with CreateNodeParams

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

the class CreateNodeParamsFactoryTest method nodeName.

@Test
public void nodeName() throws Exception {
    final CreateNodeParams createNodeParams = createWithStringProperty(NODE_NAME, "myNode");
    assertEquals("myNode", createNodeParams.getName());
}
Also used : CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Example 45 with CreateNodeParams

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

the class CreateNodeParamsFactoryTest method nodeType.

@Test
public void nodeType() throws Exception {
    final CreateNodeParams createNodeParams = createWithStringProperty(NODE_TYPE, "myNodeType");
    assertEquals(NodeType.from("myNodeType"), createNodeParams.getNodeType());
}
Also used : CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

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