Search in sources :

Example 61 with CreateContentParams

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

the class CreateContentCommandTest method createPageTemplateInRoot_fails.

@Test
public void createPageTemplateInRoot_fails() {
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenAnswer(a -> BuiltinContentTypesAccessor.getContentType(((GetContentTypeParams) a.getArgument(0)).getContentTypeName()));
    mockContentRootNode();
    final CreateContentParams params = CreateContentParams.create().type(ContentTypeName.templateFolder()).name("folder").parent(ContentPath.ROOT).contentData(new PropertyTree()).displayName("displayName").build();
    CreateContentCommand command = createContentCommand(params);
    assertThrows(IllegalArgumentException.class, command::execute);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 62 with CreateContentParams

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

the class CreateContentCommandTest method badParentContentPath.

@Test
public void badParentContentPath() {
    PropertyTree existingContentData = new PropertyTree();
    existingContentData.addString("myData", "aaa");
    CreateContentParams params = CreateContentParams.create().name("name").type(ContentTypeName.site()).parent(ContentPath.from("/myPath/myContent")).contentData(existingContentData).displayName("displayName").build();
    CreateContentCommand command = createContentCommand(params);
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(ContentType.create().superType(ContentTypeName.documentMedia()).name(ContentTypeName.dataMedia()).build());
    assertThrows(IllegalStateException.class, command::execute);
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) PropertyTree(com.enonic.xp.data.PropertyTree) Test(org.junit.jupiter.api.Test)

Example 63 with CreateContentParams

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

the class CreateFragmentCommand method execute.

public Content execute() {
    final String displayName = generateDisplayName(params.getComponent());
    final String name = generateUniqueContentName(params.getParent(), "fragment-" + displayName);
    final CreateContentParams createContent = CreateContentParams.create().parent(params.getParent()).displayName(displayName).name(name).type(ContentTypeName.fragment()).contentData(new PropertyTree()).workflowInfo(params.getWorkflowInfo()).build();
    final Content content = contentService.create(createContent);
    final Page page = Page.create().config(this.params.getConfig()).fragment(this.params.getComponent()).build();
    final UpdateContentParams params = new UpdateContentParams().contentId(content.getId()).modifier(getCurrentUser().getKey()).editor(edit -> edit.page = page);
    return this.contentService.update(params);
}
Also used : UpdateContentParams(com.enonic.xp.content.UpdateContentParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Page(com.enonic.xp.page.Page)

Example 64 with CreateContentParams

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

the class ParentContentSynchronizerTest method testCreatedWithSetOriginProject.

@Test
public void testCreatedWithSetOriginProject() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.setString(ContentPropertyNames.ORIGIN_PROJECT, "first");
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(data).displayName("This is my content").createAttachments(CreateAttachments.create().add(CreateAttachment.create().byteSource(ByteSource.wrap("bytes".getBytes())).label("attachment").name("attachmentName").mimeType("image/png").build()).build()).parent(ContentPath.ROOT).type(ContentTypeName.folder()).build();
    final Content sourceContent = sourceContext.callWith(() -> this.contentService.create(createContentParams));
    final Content targetContent = syncCreated(sourceContent.getId());
    compareSynched(sourceContent, targetContent);
    assertEquals("source_project", targetContent.getOriginProject().toString());
}
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 65 with CreateContentParams

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

the class ContentServiceImplTest_undoPendingDelete method createTestContent.

private Content createTestContent(final String name, final ContentPath parentPath) {
    final CreateContentParams createContentParams = CreateContentParams.create().contentData(new PropertyTree()).displayName("This is my content").name(name).parent(ContentPath.ROOT).type(ContentTypeName.folder()).parent(parentPath == null ? ContentPath.ROOT : parentPath).build();
    final Content content = this.contentService.create(createContentParams);
    this.contentService.publish(PushContentParams.create().contentIds(ContentIds.from(content.getId())).target(WS_OTHER).includeDependencies(false).build());
    this.nodeService.setNodeState(SetNodeStateParams.create().nodeId(NodeId.from(content.getId())).recursive(true).nodeState(NodeState.PENDING_DELETE).build());
    return content;
}
Also used : CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree)

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