Search in sources :

Example 1 with CreateContentTranslatorParams

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));
}
Also used : CreateContentTranslatorParams(com.enonic.xp.content.CreateContentTranslatorParams) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 2 with CreateContentTranslatorParams

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));
}
Also used : CreateContentTranslatorParams(com.enonic.xp.content.CreateContentTranslatorParams) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) WorkflowCheckState(com.enonic.xp.content.WorkflowCheckState) Test(org.junit.jupiter.api.Test)

Example 3 with CreateContentTranslatorParams

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

Aggregations

CreateContentTranslatorParams (com.enonic.xp.content.CreateContentTranslatorParams)3 PropertySet (com.enonic.xp.data.PropertySet)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Test (org.junit.jupiter.api.Test)2 ContentAccessException (com.enonic.xp.content.ContentAccessException)1 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)1 CreateContentParams (com.enonic.xp.content.CreateContentParams)1 WorkflowCheckState (com.enonic.xp.content.WorkflowCheckState)1 WorkflowInfo (com.enonic.xp.content.WorkflowInfo)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 Node (com.enonic.xp.node.Node)1 NodeAccessException (com.enonic.xp.node.NodeAccessException)1 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)1 ContentType (com.enonic.xp.schema.content.ContentType)1 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)1