Search in sources :

Example 66 with CreateContentParams

use of com.enonic.xp.content.CreateContentParams in project xp by enonic.

the class ContentServiceImplTest_update method update_content_image.

@Test
public void update_content_image() throws Exception {
    final ByteSource image = loadImage("cat-small.jpg");
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.imageMedia()).createAttachments(createAttachment("cat", "image/jpg", image)).build();
    final Content content = this.contentService.create(createContentParams);
    final UpdateContentParams updateContentParams = new UpdateContentParams();
    updateContentParams.contentId(content.getId()).editor(edit -> {
        edit.displayName = "new display name";
    }).clearAttachments(true).createAttachments(createAttachment("darth", "image/jpg", loadImage("darth-small.jpg")));
    this.contentService.update(updateContentParams);
    final Content storedContent = this.contentService.getById(content.getId());
    final Attachments attachments = storedContent.getAttachments();
    assertEquals(1, attachments.getSize());
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ByteSource(com.google.common.io.ByteSource) CreateAttachments(com.enonic.xp.attachment.CreateAttachments) Attachments(com.enonic.xp.attachment.Attachments) Test(org.junit.jupiter.api.Test)

Example 67 with CreateContentParams

use of com.enonic.xp.content.CreateContentParams in project xp by enonic.

the class ContentServiceImplTest_update method audit_data.

@Test
public void audit_data() {
    final ArgumentCaptor<LogAuditLogParams> captor = ArgumentCaptor.forClass(LogAuditLogParams.class);
    final PropertyTree data = new PropertyTree();
    data.setString("testString", "value");
    data.setString("testString2", "value");
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(data).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final UpdateContentParams updateContentParams = new UpdateContentParams();
    updateContentParams.contentId(content.getId()).editor(edit -> {
        final PropertyTree editData = edit.data;
        editData.setString("testString", "value-updated");
    });
    this.contentService.update(updateContentParams);
    Mockito.verify(auditLogService, Mockito.timeout(5000).atLeast(16)).log(captor.capture());
    final PropertySet logResultSet = captor.getAllValues().stream().filter(log -> log.getType().equals("system.content.update")).findFirst().get().getData().getSet("result");
    assertEquals(content.getId().toString(), logResultSet.getString("id"));
    assertEquals(content.getPath().toString(), logResultSet.getString("path"));
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 68 with CreateContentParams

use of com.enonic.xp.content.CreateContentParams in project xp by enonic.

the class CreateContentHandler method doExecute.

@Override
protected Object doExecute() {
    if (nullToEmpty(this.name).isBlank() && !nullToEmpty(this.displayName).isBlank() && !nullToEmpty(this.parentPath).isBlank()) {
        this.name = generateUniqueContentName(ContentPath.from(this.parentPath), this.displayName);
    }
    if (nullToEmpty(this.displayName).isBlank() && !nullToEmpty(this.name).isBlank()) {
        this.displayName = this.name;
    }
    final CreateContentParams params = createParams();
    final Content result = this.contentService.create(params);
    return new ContentMapper(result);
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) ContentMapper(com.enonic.xp.lib.content.mapper.ContentMapper)

Example 69 with CreateContentParams

use of com.enonic.xp.content.CreateContentParams in project xp by enonic.

the class HtmlAreaContentProcessor method processCreate.

@Override
public ProcessCreateResult processCreate(final ProcessCreateParams params) {
    final CreateContentParams createContentParams = params.getCreateContentParams();
    final ContentIds.Builder processedIds = ContentIds.create();
    final ContentType contentType = contentTypeService.getByName(GetContentTypeParams.from(createContentParams.getType()));
    processContentData(createContentParams.getData(), contentType, processedIds);
    processExtraData(createContentParams.getExtraDatas(), processedIds);
    return new ProcessCreateResult(CreateContentParams.create(createContentParams).addProcessedIds(processedIds.build()).build());
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) CreateContentParams(com.enonic.xp.content.CreateContentParams) ContentIds(com.enonic.xp.content.ContentIds) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult)

Example 70 with CreateContentParams

use of com.enonic.xp.content.CreateContentParams in project xp by enonic.

the class HtmlAreaContentProcessorTest method create.

@Test
public void create() throws IOException {
    final PropertyTree data = new PropertyTree();
    data.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans01.jpg\" data-src=\"image://image-id1\"/>"));
    final XDataName xDataName = XDataName.from("xDataName");
    final XData xData = XData.create().name(xDataName).addFormItem(Input.create().name("htmlData").label("htmlData").inputType(InputTypeName.HTML_AREA).build()).build();
    final PropertyTree extraData = new PropertyTree();
    extraData.addProperty("htmlData", ValueFactory.newString("<img alt=\"Dictyophorus_spumans02.jpg\" data-src=\"image://image-id2\"/>"));
    Mockito.when(xDataService.getByNames(XDataNames.from(xDataName))).thenReturn(XDatas.from(xData));
    final ProcessCreateParams processCreateParams = Mockito.mock(ProcessCreateParams.class);
    final CreateContentParams createContentParams = CreateContentParams.create().parent(ContentPath.ROOT).contentData(data).extraDatas(ExtraDatas.create().add(new ExtraData(XDataName.from("xDataName"), extraData)).build()).type(contentTypeName).build();
    contentType = ContentType.create(contentType).xData(XDataNames.from(XDataName.from("xDataName"))).build();
    Mockito.when(contentTypeService.getByName(GetContentTypeParams.from(contentTypeName))).thenReturn(contentType);
    Mockito.when(processCreateParams.getCreateContentParams()).thenReturn(createContentParams);
    final ProcessCreateResult result = htmlAreaContentProcessor.processCreate(processCreateParams);
    assertEquals(2, result.getCreateContentParams().getProcessedIds().getSize());
    assertTrue(result.getCreateContentParams().getProcessedIds().contains(ContentId.from("image-id1")));
    assertTrue(result.getCreateContentParams().getProcessedIds().contains(ContentId.from("image-id2")));
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) ProcessCreateResult(com.enonic.xp.content.processor.ProcessCreateResult) XData(com.enonic.xp.schema.xdata.XData) ExtraData(com.enonic.xp.content.ExtraData) XDataName(com.enonic.xp.schema.xdata.XDataName) ProcessCreateParams(com.enonic.xp.content.processor.ProcessCreateParams) Test(org.junit.jupiter.api.Test)

Aggregations

CreateContentParams (com.enonic.xp.content.CreateContentParams)81 Test (org.junit.jupiter.api.Test)66 PropertyTree (com.enonic.xp.data.PropertyTree)63 Content (com.enonic.xp.content.Content)52 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)25 PropertySet (com.enonic.xp.data.PropertySet)14 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)11 ContentType (com.enonic.xp.schema.content.ContentType)10 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)9 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)9 PublishContentResult (com.enonic.xp.content.PublishContentResult)7 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)7 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)6 ExtraData (com.enonic.xp.content.ExtraData)6 ProcessCreateParams (com.enonic.xp.content.processor.ProcessCreateParams)6 Attachments (com.enonic.xp.attachment.Attachments)5 Node (com.enonic.xp.node.Node)5 ByteSource (com.google.common.io.ByteSource)5 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)4 ExtraDatas (com.enonic.xp.content.ExtraDatas)4