Search in sources :

Example 1 with UpdateContentParams

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

the class AddAttachmentHandler method execute.

public void execute() {
    UpdateContentParams updateContent = new UpdateContentParams();
    if (!this.key.startsWith("/")) {
        updateContent.contentId(ContentId.from(this.key));
    } else {
        final Content contentByPath = this.contentService.getByPath(ContentPath.from(key));
        updateContent.contentId(contentByPath.getId());
    }
    final CreateAttachment createAttachment = CreateAttachment.create().name(this.name).label(this.label).mimeType(this.mimeType).byteSource(getData()).build();
    updateContent.createAttachments(CreateAttachments.from(createAttachment));
    contentService.update(updateContent);
}
Also used : CreateAttachment(com.enonic.xp.attachment.CreateAttachment) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content)

Example 2 with UpdateContentParams

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

the class ModifyContentHandlerTest method modifyNotMappedXDataFieldNameNotStricted.

@Test
public void modifyNotMappedXDataFieldNameNotStricted() throws Exception {
    final Content content = TestDataFixtures.newSmallContent();
    when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    when(this.contentService.update(Mockito.isA(UpdateContentParams.class))).thenAnswer(invocationOnMock -> invokeUpdate((UpdateContentParams) invocationOnMock.getArguments()[0], TestDataFixtures.newSmallContent()));
    mockXData();
    runFunction("/test/ModifyContentHandlerTest.js", "modifyNotMappedXDataFieldName_notStricted");
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) Test(org.junit.jupiter.api.Test)

Example 3 with UpdateContentParams

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

the class ModifyContentHandler method doExecute.

@Override
protected Object doExecute() {
    final Content existingContent = getExistingContent(this.key);
    if (existingContent == null) {
        return null;
    }
    final UpdateContentParams params = new UpdateContentParams();
    params.contentId(existingContent.getId());
    params.editor(newContentEditor(existingContent));
    params.requireValid(this.requireValid);
    final Content result = this.contentService.update(params);
    return result != null ? new ContentMapper(result) : null;
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) ContentMapper(com.enonic.xp.lib.content.mapper.ContentMapper)

Example 4 with UpdateContentParams

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

the class ModifyContentHandlerTest method testExample.

@Test
public void testExample() {
    GetContentTypeParams getContentType = GetContentTypeParams.from(ContentTypeName.unstructured());
    when(this.contentTypeService.getByName(getContentType)).thenReturn(ContentType.create().name(ContentTypeName.unstructured()).setBuiltIn().build());
    final Content content = TestDataFixtures.newExampleContent();
    when(this.contentService.getByPath(Mockito.any())).thenReturn(content);
    when(this.contentService.update(Mockito.isA(UpdateContentParams.class))).thenAnswer(invocationOnMock -> invokeUpdate((UpdateContentParams) invocationOnMock.getArguments()[0], content));
    mockXData();
    runScript("/lib/xp/examples/content/modify.js");
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) Test(org.junit.jupiter.api.Test)

Example 5 with UpdateContentParams

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

the class ModifyContentHandlerTest method modifyByPath.

@Test
public void modifyByPath() throws Exception {
    final Content content = TestDataFixtures.newSmallContent();
    when(this.contentService.getByPath(content.getPath())).thenReturn(content);
    when(this.contentService.update(Mockito.isA(UpdateContentParams.class))).thenAnswer(invocationOnMock -> invokeUpdate((UpdateContentParams) invocationOnMock.getArguments()[0], TestDataFixtures.newSmallContent()));
    mockXData();
    runFunction("/test/ModifyContentHandlerTest.js", "modifyByPath");
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) EditableContent(com.enonic.xp.content.EditableContent) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateContentParams (com.enonic.xp.content.UpdateContentParams)49 Content (com.enonic.xp.content.Content)43 Test (org.junit.jupiter.api.Test)35 PropertyTree (com.enonic.xp.data.PropertyTree)27 CreateContentParams (com.enonic.xp.content.CreateContentParams)14 ContentPath (com.enonic.xp.content.ContentPath)9 EditableContent (com.enonic.xp.content.EditableContent)9 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)9 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)9 ContentId (com.enonic.xp.content.ContentId)8 ContentInheritType (com.enonic.xp.content.ContentInheritType)7 WorkflowInfo (com.enonic.xp.content.WorkflowInfo)7 ByteSource (com.google.common.io.ByteSource)7 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)7 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)7 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)6 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)6 DeleteContentParams (com.enonic.xp.content.DeleteContentParams)6 ResetContentInheritParams (com.enonic.xp.content.ResetContentInheritParams)6 SetContentChildOrderParams (com.enonic.xp.content.SetContentChildOrderParams)6