Search in sources :

Example 1 with ProcessUpdateResult

use of com.enonic.xp.content.processor.ProcessUpdateResult in project xp by enonic.

the class HtmlAreaContentProcessor method processUpdate.

@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
    final CreateAttachments createAttachments = params.getCreateAttachments();
    final ContentEditor editor;
    editor = editable -> {
        final ContentIds.Builder processedIds = ContentIds.create();
        final ContentType contentType = contentTypeService.getByName(GetContentTypeParams.from(editable.source.getType()));
        processContentData(editable.data, contentType, processedIds);
        processExtraData(editable.extraDatas, processedIds);
        processPageData(editable.page, processedIds);
        if (editable instanceof EditableSite) {
            processSiteConfigData(((EditableSite) editable).siteConfigs, processedIds);
        }
        editable.processedReferences = processedIds;
    };
    return new ProcessUpdateResult(createAttachments, editor);
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ContentEditor(com.enonic.xp.content.ContentEditor) ContentType(com.enonic.xp.schema.content.ContentType) EditableSite(com.enonic.xp.content.EditableSite) ContentIds(com.enonic.xp.content.ContentIds) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult)

Example 2 with ProcessUpdateResult

use of com.enonic.xp.content.processor.ProcessUpdateResult in project xp by enonic.

the class UpdateContentCommand method runContentProcessors.

private Content runContentProcessors(final Content originalContent, Content editedContent, final ContentType contentType) {
    for (final ContentProcessor contentProcessor : this.contentProcessors) {
        if (contentProcessor.supports(contentType)) {
            final ProcessUpdateResult result = contentProcessor.processUpdate(ProcessUpdateParams.create().contentType(contentType).mediaInfo(mediaInfo).createAttachments(params.getCreateAttachments()).originalContent(originalContent).editedContent(editedContent).modifier(getCurrentUser()).build());
            editedContent = updateContentWithProcessedData(editedContent, result);
        }
    }
    return editedContent;
}
Also used : ContentProcessor(com.enonic.xp.content.processor.ContentProcessor) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult)

Example 3 with ProcessUpdateResult

use of com.enonic.xp.content.processor.ProcessUpdateResult in project xp by enonic.

the class ImageContentProcessorTest method testProcessUpdate.

@Test
public void testProcessUpdate() throws IOException {
    Mockito.when(contentService.getBinary(Mockito.any(), Mockito.any())).thenReturn(this.loadImage("cat-small.jpg"));
    final ProcessUpdateParams processUpdateParams = ProcessUpdateParams.create().contentType(ContentType.create().name(ContentTypeName.imageMedia()).superType(ContentTypeName.imageMedia()).build()).build();
    final ProcessUpdateResult result = this.imageContentProcessor.processUpdate(processUpdateParams);
    final PropertyTree data = new PropertyTree();
    data.addProperty(ContentPropertyNames.MEDIA, ValueFactory.newString("MyImage.jpg"));
    final EditableContent editableContent = new EditableContent(Media.create().name("myContentName").type(ContentTypeName.imageMedia()).parentPath(ContentPath.ROOT).data(data).addExtraData(new ExtraData(MediaInfo.IMAGE_INFO_METADATA_NAME, new PropertyTree())).attachments(Attachments.from(Attachment.create().mimeType("image/jpg").name("MyImage.jpg").build())).build());
    result.getEditor().edit(editableContent);
    assertNotNull(editableContent.extraDatas.first().getData().getLong("pixelSize", 0));
    assertNotNull(editableContent.extraDatas.first().getData().getLong("imageHeight", 0));
    assertNotNull(editableContent.extraDatas.first().getData().getLong("imageWidth", 0));
    assertNotNull(editableContent.extraDatas.first().getData().getLong("byteSize", 0));
}
Also used : ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) PropertyTree(com.enonic.xp.data.PropertyTree) EditableContent(com.enonic.xp.content.EditableContent) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) ExtraData(com.enonic.xp.content.ExtraData) Test(org.junit.jupiter.api.Test)

Example 4 with ProcessUpdateResult

use of com.enonic.xp.content.processor.ProcessUpdateResult in project xp by enonic.

the class ProjectAccessSiteProcessorTest method testProcessUpdateWithNoRightsAndNoChanges.

@Test
public void testProcessUpdateWithNoRightsAndNoChanges() {
    final Context context = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(TEST_USER).build()).build();
    context.runWith(() -> {
        final ProcessUpdateParams params = createProcessUpdateParams("white", "white");
        final ProcessUpdateResult result = this.projectAccessSiteProcessor.processUpdate(params);
        assertNull(result);
    });
}
Also used : Context(com.enonic.xp.context.Context) ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) Test(org.junit.jupiter.api.Test)

Example 5 with ProcessUpdateResult

use of com.enonic.xp.content.processor.ProcessUpdateResult in project xp by enonic.

the class ProjectAccessSiteProcessorTest method testProcessUpdateWithNoChanges.

@Test
public void testProcessUpdateWithNoChanges() {
    final Context context = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(TEST_USER).principals(RoleKeys.ADMIN).build()).build();
    context.runWith(() -> {
        final ProcessUpdateParams params = createProcessUpdateParams("white", "white");
        final ProcessUpdateResult result = this.projectAccessSiteProcessor.processUpdate(params);
        assertNull(result);
    });
}
Also used : Context(com.enonic.xp.context.Context) ProcessUpdateParams(com.enonic.xp.content.processor.ProcessUpdateParams) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessUpdateResult (com.enonic.xp.content.processor.ProcessUpdateResult)9 ProcessUpdateParams (com.enonic.xp.content.processor.ProcessUpdateParams)7 Test (org.junit.jupiter.api.Test)6 Context (com.enonic.xp.context.Context)4 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)3 EditableContent (com.enonic.xp.content.EditableContent)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 ContentEditor (com.enonic.xp.content.ContentEditor)2 ExtraData (com.enonic.xp.content.ExtraData)2 ContentProcessor (com.enonic.xp.content.processor.ContentProcessor)2 ContentType (com.enonic.xp.schema.content.ContentType)2 XData (com.enonic.xp.schema.xdata.XData)2 Attachment (com.enonic.xp.attachment.Attachment)1 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)1 ContentIds (com.enonic.xp.content.ContentIds)1 ContentService (com.enonic.xp.content.ContentService)1 CreateContentParams (com.enonic.xp.content.CreateContentParams)1 EditableSite (com.enonic.xp.content.EditableSite)1 ExtraDatas (com.enonic.xp.content.ExtraDatas)1 Media (com.enonic.xp.content.Media)1