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);
}
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());
}
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());
}
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;
}
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();
}
Aggregations