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 ContentAuditLogSupportImplTest method testUpdateContent.
@Test
public void testUpdateContent() throws Exception {
final PropertyTree propertyTree = new PropertyTree();
propertyTree.addString("test-data", "test-data");
final User user = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "testUser")).displayName("Test User").modifiedTime(Instant.now()).email("test-user@enonic.com").login("test-user").build();
final UpdateContentParams params = new UpdateContentParams().requireValid(true).contentId(ContentId.from("contentId")).clearAttachments(true).modifier(user.getKey()).editor(edit -> edit.displayName = "New Display Name");
final Content content = Content.create().id(ContentId.from("contentId")).type(ContentTypeName.site()).name("contentName").displayName("displayName").parentPath(ContentPath.ROOT).build();
final AuthenticationInfo authInfo = AuthenticationInfo.create().user(user).principals(RoleKeys.ADMIN_LOGIN).build();
final Context context = ContextBuilder.create().branch(ContentConstants.BRANCH_DRAFT).repositoryId(RepositoryId.from("test-repository")).authInfo(authInfo).build();
// test
context.runWith(() -> support.update(params, content));
executor.shutdown();
executor.awaitTermination(1, TimeUnit.MINUTES);
// verify and assert
final ArgumentCaptor<LogAuditLogParams> argumentCaptor = ArgumentCaptor.forClass(LogAuditLogParams.class);
Mockito.verify(auditLogService, Mockito.times(1)).log(argumentCaptor.capture());
Assertions.assertEquals(user.getKey(), argumentCaptor.getValue().getUser());
final String modifier = argumentCaptor.getValue().getData().getSet("params").getString("modifier");
Assertions.assertEquals(user.getKey().toString(), modifier);
}
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 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 ContentServiceImplTest_create method create_with_root_language.
@Test
public void create_with_root_language() throws Exception {
final Content root = this.contentService.getByPath(ContentPath.ROOT);
contentService.update(new UpdateContentParams().contentId(root.getId()).modifier(ContextAccessor.current().getAuthInfo().getUser().getKey()).editor(edit -> edit.language = Locale.ENGLISH));
final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
final Content content = this.contentService.create(createContentParams);
final Content storedContent = this.contentService.getById(content.getId());
assertEquals(Locale.ENGLISH, storedContent.getLanguage());
}
Aggregations