Search in sources :

Example 6 with IndexConfigDocument

use of com.enonic.xp.index.IndexConfigDocument in project xp by enonic.

the class CreateNodeParamsFactory method produce.

public CreateNodeParams produce() {
    final PropertyTree contentAsData = contentDataSerializer.toCreateNodeData(params);
    final PropertySet extraDataSet = contentAsData.getPropertySet(PropertyPath.from(ContentPropertyNames.EXTRA_DATA));
    final String language = contentAsData.getString(PropertyPath.from(ContentPropertyNames.LANGUAGE));
    final SiteConfigs siteConfigs = new SiteConfigsDataSerializer().fromProperties(contentAsData.getPropertySet(PropertyPath.from(ContentPropertyNames.DATA))).build();
    final Page page = contentAsData.hasProperty(COMPONENTS) ? contentDataSerializer.fromPageData(contentAsData.getRoot()) : null;
    final ExtraDatas extraData = extraDataSet != null ? contentDataSerializer.fromExtraData(extraDataSet) : null;
    final ContentIndexConfigFactory.Builder indexConfigFactoryBuilder = ContentIndexConfigFactory.create().contentTypeName(params.getType()).siteConfigs(siteConfigs).siteService(siteService).xDataService(xDataService).contentTypeService(contentTypeService);
    if (page != null) {
        indexConfigFactoryBuilder.page(page).pageDescriptorService(pageDescriptorService).partDescriptorService(partDescriptorService).layoutDescriptorService(layoutDescriptorService);
    }
    if (extraData != null) {
        indexConfigFactoryBuilder.extraDatas(extraData);
    }
    if (!nullToEmpty(language).isBlank()) {
        indexConfigFactoryBuilder.language(language);
    }
    final IndexConfigDocument indexConfigDocument = indexConfigFactoryBuilder.build().produce();
    final CreateNodeParams.Builder builder = CreateNodeParams.create().name(resolveNodeName(params.getName())).parent(ContentNodeHelper.translateContentParentToNodeParentPath(params.getParent())).data(contentAsData).indexConfigDocument(indexConfigDocument).permissions(params.getPermissions()).inheritPermissions(params.isInheritPermissions()).childOrder(params.getChildOrder()).nodeType(ContentConstants.CONTENT_NODE_COLLECTION);
    for (final CreateAttachment attachment : params.getCreateAttachments()) {
        builder.attachBinary(attachment.getBinaryReference(), attachment.getByteSource());
    }
    return builder.build();
}
Also used : SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) Page(com.enonic.xp.page.Page) SiteConfigs(com.enonic.xp.site.SiteConfigs) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) CreateAttachment(com.enonic.xp.attachment.CreateAttachment) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) ExtraDatas(com.enonic.xp.content.ExtraDatas) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument) ContentIndexConfigFactory(com.enonic.xp.core.impl.content.index.ContentIndexConfigFactory)

Example 7 with IndexConfigDocument

use of com.enonic.xp.index.IndexConfigDocument in project xp by enonic.

the class IndexConfigFactoryTest method default_with_alias.

@Test
public void default_with_alias() throws Exception {
    IndexConfigDocument minimal = create("{\n" + " \"default\": \"minimal\"" + " }");
    assertEquals(IndexConfig.MINIMAL, minimal.getConfigForPath(PropertyPath.from("my.random.path")));
    IndexConfigDocument byType = create("{\n" + " \"default\": \"byType\"" + " }");
    assertEquals(IndexConfig.BY_TYPE, byType.getConfigForPath(PropertyPath.from("my.random.path")));
}
Also used : PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument) Test(org.junit.jupiter.api.Test)

Example 8 with IndexConfigDocument

use of com.enonic.xp.index.IndexConfigDocument in project xp by enonic.

the class IndexConfigFactoryTest method empty.

@Test
public void empty() throws Exception {
    IndexConfigDocument config = create("{}");
    assertEquals(IndexConfig.BY_TYPE, config.getConfigForPath(PropertyPath.from("my.random.path")));
}
Also used : PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument) Test(org.junit.jupiter.api.Test)

Aggregations

IndexConfigDocument (com.enonic.xp.index.IndexConfigDocument)8 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)6 Test (org.junit.jupiter.api.Test)5 PropertySet (com.enonic.xp.data.PropertySet)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 CreateAttachment (com.enonic.xp.attachment.CreateAttachment)1 ExtraDatas (com.enonic.xp.content.ExtraDatas)1 ContentIndexConfigFactory (com.enonic.xp.core.impl.content.index.ContentIndexConfigFactory)1 IndexConfig (com.enonic.xp.index.IndexConfig)1 PathIndexConfig (com.enonic.xp.index.PathIndexConfig)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 EditableNode (com.enonic.xp.node.EditableNode)1 Node (com.enonic.xp.node.Node)1 Page (com.enonic.xp.page.Page)1 IndexDocument (com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument)1 JsonMapGenerator (com.enonic.xp.script.serializer.JsonMapGenerator)1 AccessControlList (com.enonic.xp.security.acl.AccessControlList)1 SiteConfigs (com.enonic.xp.site.SiteConfigs)1 SiteConfigsDataSerializer (com.enonic.xp.site.SiteConfigsDataSerializer)1 GeoPoint (com.enonic.xp.util.GeoPoint)1