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);
}
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));
}
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();
}
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);
}
}
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);
}
Aggregations