Search in sources :

Example 16 with CreateContentParams

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

the class ContentServiceImplTest_duplicate method data_removed_on_duplicate.

@Test
public void data_removed_on_duplicate() throws Exception {
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("rootContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).permissions(AccessControlList.create().build()).build();
    final Content content = this.contentService.create(createContentParams);
    this.nodeService.update(UpdateNodeParams.create().id(NodeId.from(content.getId())).editor(toBeEdited -> {
        toBeEdited.data.addSet(ContentPropertyNames.PUBLISH_INFO, new PropertySet());
        toBeEdited.data.addString(ContentPropertyNames.ORIGIN_PROJECT, "some-project");
        toBeEdited.data.addStrings(ContentPropertyNames.INHERIT, ContentInheritType.CONTENT.name(), ContentInheritType.NAME.name());
    }).build());
    final Content duplicateContent = doDuplicateContent(content);
    assertNull(duplicateContent.getPublishInfo());
    assertNull(duplicateContent.getOriginProject());
    assertTrue(duplicateContent.getInherit().isEmpty());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Test(org.junit.jupiter.api.Test)

Example 17 with CreateContentParams

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

the class ContentServiceImplTest_duplicate method some_metadata_reset_on_duplicate.

@Test
public void some_metadata_reset_on_duplicate() throws Exception {
    final User otherUser = User.create().key(PrincipalKey.ofUser(IdProviderKey.system(), "fisk")).login("fisk").build();
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("rootContent").parent(ContentPath.ROOT).type(ContentTypeName.folder()).permissions(AccessControlList.create().add(AccessControlEntry.create().principal(otherUser.getKey()).allowAll().build()).build()).build();
    final Content rootContent = this.contentService.create(createContentParams);
    final Context duplicateContext = ContextBuilder.from(ContextAccessor.current()).authInfo(AuthenticationInfo.create().user(otherUser).principals(RoleKeys.CONTENT_MANAGER_ADMIN).build()).build();
    final Content duplicateContent = duplicateContext.callWith(() -> doDuplicateContent(rootContent));
    assertTrue(rootContent.getModifiedTime().isBefore(duplicateContent.getModifiedTime()));
    assertTrue(rootContent.getCreatedTime().isBefore(duplicateContent.getCreatedTime()));
    assertEquals(otherUser.getKey(), duplicateContent.getModifier());
    assertEquals(otherUser.getKey(), duplicateContent.getOwner());
    assertEquals(otherUser.getKey(), duplicateContent.getCreator());
}
Also used : Context(com.enonic.xp.context.Context) User(com.enonic.xp.security.User) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 18 with CreateContentParams

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

the class AbstractContentSynchronizerTest method createContent.

protected Content createContent(final ContentPath parent, final String name) {
    final PropertyTree data = new PropertyTree();
    data.addStrings("stringField", "stringValue");
    final CreateContentParams createParent = CreateContentParams.create().contentData(data).name(name).displayName(name).parent(parent).type(ContentTypeName.folder()).build();
    return this.contentService.create(createParent);
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree)

Example 19 with CreateContentParams

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

the class ContentServiceImplTest_create method create_content_unnamed.

@Test
public void create_content_unnamed() throws Exception {
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content content = this.contentService.create(createContentParams);
    final Content storedContent = this.contentService.getById(content.getId());
    assertNotNull(storedContent.getName());
    assertTrue(storedContent.getName().isUnnamed());
    assertTrue(storedContent.getName().hasUniqueness());
    assertNotNull(storedContent.getCreatedTime());
    assertNotNull(storedContent.getCreator());
    assertNotNull(storedContent.getModifiedTime());
    assertNotNull(storedContent.getModifier());
    assertNotNull(storedContent.getChildOrder());
    assertEquals(ContentConstants.DEFAULT_CHILD_ORDER, storedContent.getChildOrder());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 20 with CreateContentParams

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

the class ContentServiceImplTest_create method create_with_attachments.

@Test
public void create_with_attachments() throws Exception {
    final String name = "cat-small.jpg";
    final ByteSource image = loadImage(name);
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").parent(ContentPath.ROOT).type(ContentTypeName.imageMedia()).createAttachments(createAttachment("cat", "image/jpeg", image)).build();
    final Content content = this.contentService.create(createContentParams);
    final Content storedContent = this.contentService.getById(content.getId());
    final Attachments attachments = storedContent.getAttachments();
    assertEquals(1, attachments.getSize());
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) ByteSource(com.google.common.io.ByteSource) Attachments(com.enonic.xp.attachment.Attachments) Test(org.junit.jupiter.api.Test)

Aggregations

CreateContentParams (com.enonic.xp.content.CreateContentParams)81 Test (org.junit.jupiter.api.Test)66 PropertyTree (com.enonic.xp.data.PropertyTree)63 Content (com.enonic.xp.content.Content)52 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)25 PropertySet (com.enonic.xp.data.PropertySet)14 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)11 ContentType (com.enonic.xp.schema.content.ContentType)10 LogAuditLogParams (com.enonic.xp.audit.LogAuditLogParams)9 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)9 PublishContentResult (com.enonic.xp.content.PublishContentResult)7 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)7 CreateAttachments (com.enonic.xp.attachment.CreateAttachments)6 ExtraData (com.enonic.xp.content.ExtraData)6 ProcessCreateParams (com.enonic.xp.content.processor.ProcessCreateParams)6 Attachments (com.enonic.xp.attachment.Attachments)5 Node (com.enonic.xp.node.Node)5 ByteSource (com.google.common.io.ByteSource)5 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)4 ExtraDatas (com.enonic.xp.content.ExtraDatas)4