Search in sources :

Example 21 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 22 with UpdateContentParams

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);
}
Also used : Context(com.enonic.xp.context.Context) User(com.enonic.xp.security.User) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Test(org.junit.jupiter.api.Test)

Example 23 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 24 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 25 with UpdateContentParams

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());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContentConstants(com.enonic.xp.content.ContentConstants) WorkflowInfo(com.enonic.xp.content.WorkflowInfo) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) WorkflowState(com.enonic.xp.content.WorkflowState) ArgumentCaptor(org.mockito.ArgumentCaptor) ContextAccessor(com.enonic.xp.context.ContextAccessor) Locale(java.util.Locale) WorkflowCheckState(com.enonic.xp.content.WorkflowCheckState) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) LogAuditLogParams(com.enonic.xp.audit.LogAuditLogParams) PropertyTree(com.enonic.xp.data.PropertyTree) CreateSiteParams(com.enonic.xp.site.CreateSiteParams) ContentPath(com.enonic.xp.content.ContentPath) PropertySet(com.enonic.xp.data.PropertySet) Content(com.enonic.xp.content.Content) ContentPublishInfo(com.enonic.xp.content.ContentPublishInfo) Instant(java.time.Instant) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) SiteConfigs(com.enonic.xp.site.SiteConfigs) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Attachments(com.enonic.xp.attachment.Attachments) UpdateContentParams(com.enonic.xp.content.UpdateContentParams) Content(com.enonic.xp.content.Content) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) 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