Search in sources :

Example 26 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class CreateContentCommandTest method nameGeneratedFromDisplayName.

@Test
public void nameGeneratedFromDisplayName() {
    final CreateContentParams params = createContentParams().build();
    final CreateContentCommand command = createContentCommand(params);
    final ContentType contentType = ContentType.create().superType(ContentTypeName.documentMedia()).name(ContentTypeName.dataMedia()).build();
    Mockito.when(contentTypeService.getByName(Mockito.isA(GetContentTypeParams.class))).thenReturn(contentType);
    mockContentRootNode();
    // exercise
    final Content createdContent = command.execute();
    assertEquals(ContentName.from("displayname"), createdContent.getName());
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) CreateContentParams(com.enonic.xp.content.CreateContentParams) Content(com.enonic.xp.content.Content) Test(org.junit.jupiter.api.Test)

Example 27 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class HtmlAreaContentProcessor method processUpdate.

@Override
public ProcessUpdateResult processUpdate(final ProcessUpdateParams params) {
    final CreateAttachments createAttachments = params.getCreateAttachments();
    final ContentEditor editor;
    editor = editable -> {
        final ContentIds.Builder processedIds = ContentIds.create();
        final ContentType contentType = contentTypeService.getByName(GetContentTypeParams.from(editable.source.getType()));
        processContentData(editable.data, contentType, processedIds);
        processExtraData(editable.extraDatas, processedIds);
        processPageData(editable.page, processedIds);
        if (editable instanceof EditableSite) {
            processSiteConfigData(((EditableSite) editable).siteConfigs, processedIds);
        }
        editable.processedReferences = processedIds;
    };
    return new ProcessUpdateResult(createAttachments, editor);
}
Also used : CreateAttachments(com.enonic.xp.attachment.CreateAttachments) ContentEditor(com.enonic.xp.content.ContentEditor) ContentType(com.enonic.xp.schema.content.ContentType) EditableSite(com.enonic.xp.content.EditableSite) ContentIds(com.enonic.xp.content.ContentIds) ProcessUpdateResult(com.enonic.xp.content.processor.ProcessUpdateResult)

Example 28 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class CreateContentCommand method doExecute.

private Content doExecute() {
    final ContentType contentType = contentTypeService.getByName(new GetContentTypeParams().contentTypeName(params.getType()));
    validateContentType(contentType);
    formDefaultValuesProcessor.setDefaultValues(contentType.getForm(), params.getData());
    // TODO apply default values to xData
    CreateContentParams processedParams = runContentProcessors(this.params, contentType);
    validateBlockingChecks(processedParams);
    final CreateContentTranslatorParams createContentTranslatorParams = createContentTranslatorParams(processedParams);
    final CreateNodeParams createNodeParams = CreateNodeParamsFactory.create(createContentTranslatorParams).contentTypeService(this.contentTypeService).pageDescriptorService(this.pageDescriptorService).xDataService(this.xDataService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).siteService(this.siteService).build().produce();
    try {
        final Node createdNode = nodeService.create(createNodeParams);
        if (params.isRefresh()) {
            nodeService.refresh(RefreshMode.SEARCH);
        }
        return translator.fromNode(createdNode, false);
    } catch (NodeAlreadyExistAtPathException e) {
        throw new ContentAlreadyExistsException(ContentPath.from(createContentTranslatorParams.getParent(), createContentTranslatorParams.getName().toString()), e.getRepositoryId(), e.getBranch());
    } catch (NodeAccessException e) {
        throw new ContentAccessException(e);
    }
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) NodeAccessException(com.enonic.xp.node.NodeAccessException) ContentType(com.enonic.xp.schema.content.ContentType) CreateContentTranslatorParams(com.enonic.xp.content.CreateContentTranslatorParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Node(com.enonic.xp.node.Node) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) ContentAccessException(com.enonic.xp.content.ContentAccessException)

Example 29 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class MoveContentCommandTest method move_fragment_to_the_same_site.

@Test
public void move_fragment_to_the_same_site() throws Exception {
    final PropertyTree existingContentData = new PropertyTree();
    existingContentData.addString("myData", "aaa");
    final Site parentSite = createSite(existingContentData, ContentPath.ROOT);
    final Content existingContent = createContent(existingContentData, parentSite.getPath(), ContentTypeName.fragment());
    final Content existingFolder = createContent(existingContentData, parentSite.getPath(), ContentTypeName.folder());
    MoveContentParams params = MoveContentParams.create().contentId(existingContent.getId()).parentContentPath(existingFolder.getPath()).build();
    final MoveContentCommand command = MoveContentCommand.create(params).contentTypeService(this.contentTypeService).nodeService(this.nodeService).translator(this.translator).eventPublisher(this.eventPublisher).build();
    final Node mockNode = Node.create().parentPath(NodePath.ROOT).build();
    Mockito.when(nodeService.getById(NodeId.from(existingContent.getId()))).thenReturn(mockNode);
    Mockito.when(nodeService.move(Mockito.any(MoveNodeParams.class))).thenReturn(mockNode);
    Mockito.when(translator.fromNode(mockNode, true)).thenReturn(existingContent);
    Mockito.when(translator.fromNode(mockNode, false)).thenReturn(existingContent);
    final Node mockFolderNode = Node.create().parentPath(NodePath.ROOT).build();
    Mockito.when(nodeService.getByPath(ContentNodeHelper.translateContentPathToNodePath(existingFolder.getPath()))).thenReturn(mockFolderNode);
    Mockito.when(translator.fromNode(mockFolderNode, true)).thenReturn(existingFolder);
    Mockito.when(translator.fromNode(mockFolderNode, false)).thenReturn(existingFolder);
    final ContentType contentType = ContentType.create().name("folder").displayName("folder").setBuiltIn().setFinal(false).setAbstract(false).build();
    Mockito.when(contentTypeService.getByName(new GetContentTypeParams().contentTypeName(existingFolder.getType()))).thenReturn(contentType);
    // exercise
    command.execute();
    Mockito.verify(nodeService, Mockito.times(1)).move(Mockito.any(MoveNodeParams.class));
}
Also used : Site(com.enonic.xp.site.Site) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) MoveContentParams(com.enonic.xp.content.MoveContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 30 with ContentType

use of com.enonic.xp.schema.content.ContentType in project xp by enonic.

the class ProjectAccessSiteProcessorTest method testSupports.

@Test
public void testSupports() {
    ContentType contentType = ContentType.create().superType(ContentTypeName.structured()).name(ContentTypeName.site()).build();
    assertTrue(projectAccessSiteProcessor.supports(contentType));
    contentType = ContentType.create().superType(ContentTypeName.structured()).name(ContentTypeName.media()).build();
    assertFalse(projectAccessSiteProcessor.supports(contentType));
}
Also used : ContentType(com.enonic.xp.schema.content.ContentType) Test(org.junit.jupiter.api.Test)

Aggregations

ContentType (com.enonic.xp.schema.content.ContentType)56 Test (org.junit.jupiter.api.Test)35 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)28 Content (com.enonic.xp.content.Content)12 CreateContentParams (com.enonic.xp.content.CreateContentParams)10 ValidationErrors (com.enonic.xp.content.ValidationErrors)9 Form (com.enonic.xp.form.Form)8 PropertyTree (com.enonic.xp.data.PropertyTree)7 Input (com.enonic.xp.form.Input)7 FormItem (com.enonic.xp.form.FormItem)6 FieldSet (com.enonic.xp.form.FieldSet)5 FormItemSet (com.enonic.xp.form.FormItemSet)5 ContentTypes (com.enonic.xp.schema.content.ContentTypes)5 AbstractSchemaTest (com.enonic.xp.core.impl.schema.AbstractSchemaTest)4 EditableSite (com.enonic.xp.content.EditableSite)3 PropertySet (com.enonic.xp.data.PropertySet)3 FormOptionSet (com.enonic.xp.form.FormOptionSet)3 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)3 XData (com.enonic.xp.schema.xdata.XData)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2