Search in sources :

Example 36 with CreateNodeParams

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

the class CreateScheduledJobCommand method doExecute.

private ScheduledJob doExecute() {
    final PropertyTree data = SchedulerSerializer.toCreateNodeData(params);
    final CreateNodeParams createNodeParams = CreateNodeParams.create().setNodeId(new NodeId()).name(params.getName().getValue()).data(data).parent(NodePath.ROOT).build();
    final Node node = nodeService.create(createNodeParams);
    nodeService.refresh(RefreshMode.ALL);
    return SchedulerSerializer.fromNode(node);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) CreateNodeParams(com.enonic.xp.node.CreateNodeParams)

Example 37 with CreateNodeParams

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

the class GroupNodeTranslatorTest method toCreateNode.

@Test
public void toCreateNode() throws Exception {
    final Group group = Group.create().displayName("My Group").key(PrincipalKey.ofGroup(IdProviderKey.system(), "group-a")).modifiedTime(Instant.now(clock)).description("my group a").build();
    final CreateNodeParams createNodeParams = PrincipalNodeTranslator.toCreateNodeParams(group);
    assertEquals("group-a", createNodeParams.getName());
    final PropertyTree rootDataSet = createNodeParams.getData();
    assertNotNull(rootDataSet);
    assertEquals(4, rootDataSet.getTotalSize());
    assertEquals(IdProviderKey.system().toString(), rootDataSet.getString(PrincipalPropertyNames.ID_PROVIDER_KEY));
    assertEquals(PrincipalType.GROUP.toString(), rootDataSet.getString(PrincipalPropertyNames.PRINCIPAL_TYPE_KEY));
    assertEquals("My Group", rootDataSet.getString(PrincipalPropertyNames.DISPLAY_NAME_KEY));
    assertEquals("my group a", rootDataSet.getString(PrincipalPropertyNames.DESCRIPTION_KEY));
}
Also used : Group(com.enonic.xp.security.Group) PropertyTree(com.enonic.xp.data.PropertyTree) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Test(org.junit.jupiter.api.Test)

Example 38 with CreateNodeParams

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

the class AuditLogServiceImplTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    PropertyTree data = new PropertyTree();
    data.setString("a", "b");
    data.setBoolean("c", false);
    auditLogParams = LogAuditLogParams.create().type("testType").source("testSource").objectUris(AuditLogUris.from("a:b:c", "d:e:f")).data(data).build();
    CreateNodeParams createNodeParams = AuditLogSerializer.toCreateNodeParams(auditLogParams).setNodeId(new NodeId()).build();
    Node node = Node.create().id(createNodeParams.getNodeId()).data(createNodeParams.getData()).build();
    nodeService = mock(NodeService.class);
    when(nodeService.create(any(CreateNodeParams.class))).thenReturn(node);
    when(nodeService.getById(any(NodeId.class))).thenReturn(node);
    when(nodeService.getByIds(any(NodeIds.class))).thenReturn(Nodes.from(node));
    when(nodeService.findByQuery(any(NodeQuery.class))).thenReturn(FindNodesByQueryResult.create().addNodeHit(NodeHit.create().nodeId(node.id()).build()).totalHits(1).hits(1).build());
    IndexService indexService = mock(IndexService.class);
    when(indexService.isMaster()).thenReturn(true);
    when(indexService.waitForYellowStatus()).thenReturn(true);
    RepositoryService repositoryService = mock(RepositoryService.class);
    config = mock(AuditLogConfig.class);
    when(config.isEnabled()).thenReturn(true);
    when(config.isOutputLogs()).thenReturn(true);
    auditLogService = new AuditLogServiceImpl(config, indexService, repositoryService, nodeService);
    auditLogService.initialize();
}
Also used : IndexService(com.enonic.xp.index.IndexService) NodeIds(com.enonic.xp.node.NodeIds) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) NodeService(com.enonic.xp.node.NodeService) NodeQuery(com.enonic.xp.node.NodeQuery) NodeId(com.enonic.xp.node.NodeId) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) AuditLogConfig(com.enonic.xp.core.impl.audit.config.AuditLogConfig) RepositoryService(com.enonic.xp.repository.RepositoryService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 39 with CreateNodeParams

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

the class CreateContentCommand method doExecute.

private Content doExecute() {
    final ContentType contentType = contentTypeService.getByName(new GetContentTypeParams().contentTypeName(params.getType()));
    validateContentType(contentType);
    formDefaultValuesProcessor.setDefaultValues(contentType.getForm(), params.getData());
    // TODO apply default values to xData
    CreateContentParams processedParams = runContentProcessors(this.params, contentType);
    validateBlockingChecks(processedParams);
    final CreateContentTranslatorParams createContentTranslatorParams = createContentTranslatorParams(processedParams);
    final CreateNodeParams createNodeParams = CreateNodeParamsFactory.create(createContentTranslatorParams).contentTypeService(this.contentTypeService).pageDescriptorService(this.pageDescriptorService).xDataService(this.xDataService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).siteService(this.siteService).build().produce();
    try {
        final Node createdNode = nodeService.create(createNodeParams);
        if (params.isRefresh()) {
            nodeService.refresh(RefreshMode.SEARCH);
        }
        return translator.fromNode(createdNode, false);
    } catch (NodeAlreadyExistAtPathException e) {
        throw new ContentAlreadyExistsException(ContentPath.from(createContentTranslatorParams.getParent(), createContentTranslatorParams.getName().toString()), e.getRepositoryId(), e.getBranch());
    } catch (NodeAccessException e) {
        throw new ContentAccessException(e);
    }
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) NodeAccessException(com.enonic.xp.node.NodeAccessException) ContentType(com.enonic.xp.schema.content.ContentType) CreateContentTranslatorParams(com.enonic.xp.content.CreateContentTranslatorParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Node(com.enonic.xp.node.Node) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) ContentAccessException(com.enonic.xp.content.ContentAccessException)

Example 40 with CreateNodeParams

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

the class CreateIssueCommentCommand method doExecute.

private IssueComment doExecute() {
    validateBlockingChecks();
    final Node issueNode = nodeService.getById(NodeId.from(params.getIssue()));
    final String commentName = IssueCommentNameFactory.create(params.getCreated());
    final CreateNodeParams createNodeParams = CreateNodeParamsFactory.create(this.params, issueNode.name(), commentName);
    final Node createdNode;
    try {
        createdNode = nodeService.create(createNodeParams);
    } catch (NodeAlreadyExistAtPathException e) {
        throw new IssueAlreadyExistsException(IssueName.from(createNodeParams.getName()));
    }
    nodeService.refresh(RefreshMode.SEARCH);
    return IssueCommentNodeTranslator.fromNode(createdNode);
}
Also used : IssueAlreadyExistsException(com.enonic.xp.issue.IssueAlreadyExistsException) 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