use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class CreateNodeParamsFactoryTest method manual_order_value.
@Test
public void manual_order_value() throws Exception {
final PropertyTree properties = new PropertyTree();
properties.setLong(MANUAL_ORDER_VALUE, 3L);
final CreateNodeParams createNodeParams = new CreateNodeParamsFactory().create(properties, BinaryAttachments.empty());
assertEquals(3L, createNodeParams.getManualOrderValue().longValue());
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class CreateNodeParamsFactoryTest method parent_path.
@Test
public void parent_path() throws Exception {
final CreateNodeParams createNodeParams = createWithStringProperty(PARENT_PATH, "/my/node/path");
assertEquals("/my/node/path", createNodeParams.getParent().toString());
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class ApplicationNodeTransformerTest method binary_reference_added.
@Test
public void binary_reference_added() throws Exception {
final Application app = Mockito.mock(Application.class);
Mockito.when(app.getKey()).thenReturn(ApplicationKey.from("myApp"));
Mockito.when(app.getVersion()).thenReturn(Version.valueOf("1.0.0"));
Mockito.when(app.getMaxSystemVersion()).thenReturn("1.0.0");
Mockito.when(app.getMinSystemVersion()).thenReturn("1.0.0.");
Mockito.when(app.getDisplayName()).thenReturn("displayName");
final ByteSource appSource = ByteSource.wrap(ByteStreams.toByteArray(newBundle("myBundle", true).build()));
final CreateNodeParams createNodeParams = ApplicationNodeTransformer.toCreateNodeParams(app, appSource);
final PropertyTree data = createNodeParams.getData();
final BinaryReference binaryReference = data.getBinaryReference(ApplicationNodeTransformer.APPLICATION_BINARY_REF);
assertNotNull(binaryReference);
final BinaryAttachment binaryAttachment = createNodeParams.getBinaryAttachments().get(binaryReference);
assertEquals(appSource, binaryAttachment.getByteSource());
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class CreateAuditLogCommand method createNode.
private Node createNode() {
NodeId id = new NodeId();
CreateNodeParams createNodeParams = AuditLogSerializer.toCreateNodeParams(params).setNodeId(id).name(id.toString()).parent(NodePath.ROOT).childOrder(AuditLogConstants.AUDIT_LOG_REPO_DEFAULT_CHILD_ORDER).build();
Node node = nodeService.create(createNodeParams);
nodeService.refresh(RefreshMode.ALL);
return node;
}
use of com.enonic.xp.node.CreateNodeParams in project xp by enonic.
the class CreateNodeParamsFactory method produce.
public CreateNodeParams produce() {
final PropertyTree contentAsData = contentDataSerializer.toCreateNodeData(params);
final PropertySet extraDataSet = contentAsData.getPropertySet(PropertyPath.from(ContentPropertyNames.EXTRA_DATA));
final String language = contentAsData.getString(PropertyPath.from(ContentPropertyNames.LANGUAGE));
final SiteConfigs siteConfigs = new SiteConfigsDataSerializer().fromProperties(contentAsData.getPropertySet(PropertyPath.from(ContentPropertyNames.DATA))).build();
final Page page = contentAsData.hasProperty(COMPONENTS) ? contentDataSerializer.fromPageData(contentAsData.getRoot()) : null;
final ExtraDatas extraData = extraDataSet != null ? contentDataSerializer.fromExtraData(extraDataSet) : null;
final ContentIndexConfigFactory.Builder indexConfigFactoryBuilder = ContentIndexConfigFactory.create().contentTypeName(params.getType()).siteConfigs(siteConfigs).siteService(siteService).xDataService(xDataService).contentTypeService(contentTypeService);
if (page != null) {
indexConfigFactoryBuilder.page(page).pageDescriptorService(pageDescriptorService).partDescriptorService(partDescriptorService).layoutDescriptorService(layoutDescriptorService);
}
if (extraData != null) {
indexConfigFactoryBuilder.extraDatas(extraData);
}
if (!nullToEmpty(language).isBlank()) {
indexConfigFactoryBuilder.language(language);
}
final IndexConfigDocument indexConfigDocument = indexConfigFactoryBuilder.build().produce();
final CreateNodeParams.Builder builder = CreateNodeParams.create().name(resolveNodeName(params.getName())).parent(ContentNodeHelper.translateContentParentToNodeParentPath(params.getParent())).data(contentAsData).indexConfigDocument(indexConfigDocument).permissions(params.getPermissions()).inheritPermissions(params.isInheritPermissions()).childOrder(params.getChildOrder()).nodeType(ContentConstants.CONTENT_NODE_COLLECTION);
for (final CreateAttachment attachment : params.getCreateAttachments()) {
builder.attachBinary(attachment.getBinaryReference(), attachment.getByteSource());
}
return builder.build();
}
Aggregations