Search in sources :

Example 1 with IndexConfigDocument

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

the class IndexConfigDocMapperTest method all.

@Test
public void all() throws Exception {
    final IndexConfigDocument doc = PatternIndexConfigDocument.create().defaultConfig(IndexConfig.BY_TYPE).add("path", IndexConfig.PATH).add("none", IndexConfig.NONE).add("minimal", IndexConfig.MINIMAL).add("full", IndexConfig.FULLTEXT).add("byType", IndexConfig.BY_TYPE).add("property1", IndexConfig.BY_TYPE).add("property1.*", IndexConfig.BY_TYPE).add("property1.x", IndexConfig.BY_TYPE).add("property1.property2", IndexConfig.BY_TYPE).add("property1.*.property3", IndexConfig.create(IndexConfig.BY_TYPE).addLanguage("en").build()).build();
    final JsonMapGenerator jsonGenerator = new JsonMapGenerator();
    new IndexConfigDocMapper(doc).serialize(jsonGenerator);
    assertJson("index_config_full.json", jsonGenerator);
}
Also used : JsonMapGenerator(com.enonic.xp.script.serializer.JsonMapGenerator) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument) Test(org.junit.jupiter.api.Test)

Example 2 with IndexConfigDocument

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

the class ModifyNodeHandlerTest method testExample.

@Test
public void testExample() {
    final PropertyTree data = new PropertyTree();
    data.setString("notChanged", "originalValue");
    data.setString("myString", "originalValue");
    data.setString("toBeRemoved", "removeThis");
    final PropertySet mySet = data.addSet("mySet");
    mySet.setGeoPoint("myGeoPoint", new GeoPoint(30, -30));
    final Node node = Node.create().id(NodeId.from("abc")).parentPath(NodePath.ROOT).data(data).name("myNode").build();
    mockGetNode(node);
    mockUpdateNode(node);
    runScript("/lib/xp/examples/node/modify.js");
    Mockito.verify(this.nodeService).update(updateCaptor.capture());
    assertEquals(updateCaptor.getValue().getId(), NodeId.from("abc"));
    final EditableNode editedNode = getEditedNode(node);
    assertEquals("modified", editedNode.data.getString("myString"));
    assertEquals("originalValue", editedNode.data.getString("notChanged"));
    assertEquals(new GeoPoint(0, 0), editedNode.data.getGeoPoint("mySet.myGeoPoint"));
    final Iterable<String> myArray = editedNode.data.getStrings("myArray");
    assertNotNull(myArray);
    final ArrayList<String> myArrayValues = Lists.newArrayList(myArray);
    assertEquals(3, myArrayValues.size());
    assertTrue(myArrayValues.containsAll(List.of("modified1", "modified2", "modified3")));
    final AccessControlList permissions = editedNode.permissions;
    assertTrue(permissions.getEntry(PrincipalKey.from("role:newRole")).isAllowed(Permission.MODIFY));
    assertTrue(permissions.getEntry(PrincipalKey.from("user:system:newUser")).isAllowed(Permission.CREATE));
    final IndexConfigDocument indexConfigDocument = editedNode.indexConfigDocument;
    assertFalse(indexConfigDocument.getConfigForPath(PropertyPath.from("displayName")).isEnabled());
    assertTrue(indexConfigDocument.getConfigForPath(PropertyPath.from("whatever")).isFulltext());
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) GeoPoint(com.enonic.xp.util.GeoPoint) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) PropertySet(com.enonic.xp.data.PropertySet) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument) EditableNode(com.enonic.xp.node.EditableNode) Test(org.junit.jupiter.api.Test)

Example 3 with IndexConfigDocument

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

the class IndexConfigFactoryTest method default_full.

@Test
public void default_full() throws Exception {
    IndexConfigDocument config = create(" {" + "\"default\": {\n" + "                \"decideByType\": true,\n" + "                \"enabled\": true,\n" + "                \"nGram\": false,\n" + "                \"fulltext\": false,\n" + "                \"includeInAllText\": false,\n" + "                \"path\": true,\n" + "                \"indexValueProcessors\": [],\n" + "                \"languages\": []\n" + "            }" + "}");
    assertTrue(config instanceof PatternIndexConfigDocument);
    final PatternIndexConfigDocument patternIndexConfigDocument = (PatternIndexConfigDocument) config;
    final IndexConfig defaultConfig = patternIndexConfigDocument.getDefaultConfig();
    assertEquals(true, defaultConfig.isDecideByType());
    assertEquals(true, defaultConfig.isEnabled());
    assertEquals(false, defaultConfig.isnGram());
    assertEquals(false, defaultConfig.isFulltext());
    assertEquals(false, defaultConfig.isIncludeInAllText());
    assertEquals(true, defaultConfig.isPath());
}
Also used : IndexConfig(com.enonic.xp.index.IndexConfig) PathIndexConfig(com.enonic.xp.index.PathIndexConfig) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) Test(org.junit.jupiter.api.Test)

Example 4 with IndexConfigDocument

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

the class IndexConfigFactoryTest method createFullConfig.

private PatternIndexConfigDocument createFullConfig() {
    final IndexConfigDocument indexConfigDoc = create("{\n" + "            \"configs\": [\n" + "                {\n" + "                    \"path\": \"displayName\",\n" + "                    \"config\": \"fulltext\"" + "                },\n" + "                {\n" + "                    \"path\": \"myHtmlField\",\n" + "                    \"config\": {\n" + "                        \"decideByType\": false,\n" + "                        \"enabled\": true,\n" + "                        \"nGram\": false,\n" + "                        \"fulltext\": false,\n" + "                        \"includeInAllText\": true,\n" + "                        \"indexValueProcessors\": [\n" + "                            \"htmlStripper\"\n" + "                        ],\n" + "                        \"languages\": [\n" + "                            \"en\",\"no\"\n" + "                        ]\n" + "                    }\n" + "                },\n" + "                {\n" + "                    \"path\": \"type\",\n" + "                    \"config\": {\n" + "                        \"decideByType\": false,\n" + "                        \"enabled\": false,\n" + "                        \"nGram\": false,\n" + "                        \"fulltext\": false,\n" + "                        \"includeInAllText\": false,\n" + "                        \"path\": false,\n" + "                        \"indexValueProcessors\": []\n" + "                    }\n" + "                }\n" + "            ]\n" + "        }");
    assertTrue(indexConfigDoc instanceof PatternIndexConfigDocument);
    return (PatternIndexConfigDocument) indexConfigDoc;
}
Also used : PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument)

Example 5 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)

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