use of com.enonic.xp.content.CreateContentTranslatorParams in project xp by enonic.
the class ContentDataSerializerTest method create_propertyTree_populated_with_attachment_properties.
@Test
public void create_propertyTree_populated_with_attachment_properties() {
final ContentDataSerializer contentDataSerializer = createContentDataSerializer();
final String binaryName = "myName";
final String binaryLabel = "myLabel";
final String binaryMimeType = "myMimeType";
final byte[] binaryData = "my binary".getBytes();
final CreateContentTranslatorParams params = CreateContentTranslatorParams.create().parent(ContentPath.ROOT).name("myContentName").contentData(new PropertyTree()).displayName("myDisplayName").type(ContentTypeName.codeMedia()).creator(PrincipalKey.ofAnonymous()).childOrder(ChildOrder.defaultOrder()).createAttachments(CreateAttachments.from(CreateAttachment.create().byteSource(ByteSource.wrap(binaryData)).label(binaryLabel).mimeType(binaryMimeType).name(binaryName).build())).build();
final PropertyTree data = contentDataSerializer.toCreateNodeData(params);
final PropertySet attachmentData = data.getSet(ContentPropertyNames.ATTACHMENT);
assertNotNull(attachmentData);
assertEquals(binaryName, attachmentData.getString(ContentPropertyNames.ATTACHMENT_NAME));
assertEquals(binaryLabel, attachmentData.getString(ContentPropertyNames.ATTACHMENT_LABEL));
assertEquals(binaryMimeType, attachmentData.getString(ContentPropertyNames.ATTACHMENT_MIMETYPE));
assertEquals(binaryData.length + "", attachmentData.getString(ContentPropertyNames.ATTACHMENT_SIZE));
assertEquals(binaryName, attachmentData.getString(ContentPropertyNames.ATTACHMENT_BINARY_REF));
}
use of com.enonic.xp.content.CreateContentTranslatorParams in project xp by enonic.
the class ContentDataSerializerTest method create_propertyTree_populated_with_workflowInfo.
@Test
public void create_propertyTree_populated_with_workflowInfo() {
final String check1Name = "myCheck1";
final WorkflowCheckState check1State = WorkflowCheckState.APPROVED;
final String check2Name = "myCheck2";
final WorkflowCheckState check2State = WorkflowCheckState.PENDING;
final WorkflowInfo workflowInfo = WorkflowInfo.create().state(WorkflowState.PENDING_APPROVAL).checks(Map.of(check1Name, check1State, check2Name, check2State)).build();
final ContentDataSerializer contentDataSerializer = createContentDataSerializer();
final CreateContentTranslatorParams params = CreateContentTranslatorParams.create().parent(ContentPath.ROOT).name("myContentName").contentData(new PropertyTree()).displayName("myDisplayName").type(ContentTypeName.codeMedia()).creator(PrincipalKey.ofAnonymous()).childOrder(ChildOrder.defaultOrder()).workflowInfo(workflowInfo).build();
final PropertyTree data = contentDataSerializer.toCreateNodeData(params);
final PropertySet workflowData = data.getSet(ContentPropertyNames.WORKFLOW_INFO);
assertEquals(workflowInfo.getState().toString(), workflowData.getString(ContentPropertyNames.WORKFLOW_INFO_STATE));
final PropertySet workflowChecks = workflowData.getPropertySet(ContentPropertyNames.WORKFLOW_INFO_CHECKS);
assertEquals(check1State.toString(), workflowChecks.getString(check1Name));
assertEquals(check2State.toString(), workflowChecks.getString(check2Name));
}
use of com.enonic.xp.content.CreateContentTranslatorParams 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);
}
}
Aggregations