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