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