Search in sources :

Example 76 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class FlattenedPageIndexUpgraderTest method test.

private void test(final String dataFile, final String oldIndexDocumentFile, final String newIndexDocumentFile) throws Exception {
    final JsonNode pageComponents = loadJson(dataFile);
    final PropertyTree data = new JsonToPropertyTreeTranslator().translate(pageComponents);
    final List<PropertySet> components = Lists.newArrayList(data.getSets("components"));
    if (components.size() == 0) {
        throw new RuntimeException("page components is empty");
    }
    final String descriptorKeyStr = data.getString(PropertyPath.from("components.page.descriptor"));
    if (descriptorKeyStr == null) {
        throw new RuntimeException("page descriptorKey is null");
    }
    final DescriptorKey descriptorKey = DescriptorKey.from(descriptorKeyStr);
    final PatternIndexConfigDocument oldDocument = getIndexConfigDocument(oldIndexDocumentFile);
    final PatternIndexConfigDocument newDocument = new FlattenedPageIndexUpgrader(descriptorKey, components).upgrade(oldDocument);
    assertEquals(getIndexConfigDocument(newIndexDocumentFile), newDocument);
}
Also used : JsonToPropertyTreeTranslator(com.enonic.xp.json.JsonToPropertyTreeTranslator) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) DescriptorKey(com.enonic.xp.page.DescriptorKey) JsonNode(com.fasterxml.jackson.databind.JsonNode) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) FlattenedPageIndexUpgrader(com.enonic.xp.repo.impl.dump.upgrade.flattenedpage.FlattenedPageIndexUpgrader)

Example 77 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class HtmlAreaNodeDataUpgraderTest method testUpgrade.

@Test
public void testUpgrade() throws IOException {
    final PropertyTree data = new PropertyTree();
    data.setString("data.htmlarea", readTestResource("htmlarea-source.xml"));
    final NodeVersion nodeVersion = NodeVersion.create().nodeType(ContentConstants.CONTENT_NODE_COLLECTION).data(data).build();
    final PatternIndexConfigDocument indexConfigDocument = createIndexConfigDocument();
    final DumpUpgradeStepResult.Builder result = DumpUpgradeStepResult.create();
    final boolean upgraded = htmlAreaNodeDataUpgrader.upgrade(nodeVersion, indexConfigDocument, result);
    assertTrue(upgraded);
    final PropertyTree upgradedData = nodeVersion.getData();
    final Collection<Reference> upgradedProcessedReferences = (Collection<Reference>) upgradedData.getReferences("processedReferences");
    assertEquals(5, upgradedProcessedReferences.size());
    final List<Reference> expectedReferences = Arrays.stream(new String[] { "e1f57280-d672-4cd8-b674-98e26e5b69ae", "be1ca151-cf61-4a54-9ea4-c8d01ce83e0e", "81b1e3cd-575f-4565-a618-3c85d56224f6", "43d54e23-d8ce-4058-befb-777abe1a0d9f", "32169e70-49e1-444c-a6ac-d38f22438134" }).map(Reference::from).collect(Collectors.toList());
    assertTrue(expectedReferences.containsAll(upgradedProcessedReferences));
    assertEquals(readTestResource("htmlarea-expected.xml"), upgradedData.getString("data.htmlarea"));
}
Also used : NodeVersion(com.enonic.xp.node.NodeVersion) DumpUpgradeStepResult(com.enonic.xp.dump.DumpUpgradeStepResult) Reference(com.enonic.xp.util.Reference) PropertyTree(com.enonic.xp.data.PropertyTree) Collection(java.util.Collection) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) Test(org.junit.jupiter.api.Test)

Example 78 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class SortBuilderFactoryTest method createDsl.

@Test
public void createDsl() {
    final PropertyTree geoExpression = new PropertyTree();
    geoExpression.addString("type", "geoDistance");
    geoExpression.addString("field", "myGeoPoint");
    geoExpression.addString("unit", "ft");
    geoExpression.addString("direction", "ASC");
    final PropertySet location1 = geoExpression.addSet("location");
    location1.addDouble("lat", 2.2);
    location1.addDouble("lon", 3.3);
    final PropertyTree geoExpressionWithoutOptional = new PropertyTree();
    geoExpressionWithoutOptional.addString("type", "geoDistance");
    geoExpressionWithoutOptional.addString("field", "myGeoPoint");
    final PropertySet location2 = geoExpressionWithoutOptional.addSet("location");
    location2.addDouble("lat", 2D);
    location2.addDouble("lon", 3D);
    final PropertyTree fieldExpressionWithDirection = new PropertyTree();
    fieldExpressionWithDirection.addString("field", "myField");
    fieldExpressionWithDirection.addString("direction", "DESC");
    final PropertyTree fieldExpressionWithoutDirection = new PropertyTree();
    fieldExpressionWithoutDirection.addString("field", "_name");
    final DslOrderExpr geoOrderExpr = DslOrderExpr.from(geoExpression);
    final DslOrderExpr geoOrderWithoutOptionalExpr = DslOrderExpr.from(geoExpressionWithoutOptional);
    final DslOrderExpr fieldWithDirectionOrderExpr = DslOrderExpr.from(fieldExpressionWithDirection);
    final DslOrderExpr fieldWithoutDirectionOrderExpr = DslOrderExpr.from(fieldExpressionWithoutDirection);
    final List<SortBuilder> sortBuilders = new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(List.of(geoOrderExpr, geoOrderWithoutOptionalExpr, fieldWithDirectionOrderExpr, fieldWithoutDirectionOrderExpr));
    assertEquals(4, sortBuilders.size());
    assertTrue(sortBuilders.get(0) instanceof GeoDistanceSortBuilder);
    assertTrue(sortBuilders.get(1) instanceof GeoDistanceSortBuilder);
    assertTrue(sortBuilders.get(2) instanceof FieldSortBuilder);
    assertTrue(sortBuilders.get(3) instanceof FieldSortBuilder);
}
Also used : FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) SortBuilder(org.elasticsearch.search.sort.SortBuilder) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) DslOrderExpr(com.enonic.xp.query.expr.DslOrderExpr) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) GeoDistanceSortBuilder(org.elasticsearch.search.sort.GeoDistanceSortBuilder) Test(org.junit.jupiter.api.Test)

Example 79 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class SortBuilderFactoryTest method createDslInvalidFunction.

@Test
public void createDslInvalidFunction() {
    final PropertyTree geoExpression = new PropertyTree();
    geoExpression.addString("type", "unknownFunction");
    geoExpression.addString("field", "myGeoPoint");
    final DslOrderExpr unknownOrderExpr = DslOrderExpr.from(geoExpression);
    assertThrows(IllegalArgumentException.class, () -> new SortQueryBuilderFactory(new SearchQueryFieldNameResolver()).create(List.of(unknownOrderExpr)));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) DslOrderExpr(com.enonic.xp.query.expr.DslOrderExpr) SearchQueryFieldNameResolver(com.enonic.xp.repo.impl.elasticsearch.query.translator.resolver.SearchQueryFieldNameResolver) Test(org.junit.jupiter.api.Test)

Example 80 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class NodeStoreDocumentFactoryTest method references.

@Test
public void references() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addReference("myRef", new Reference(NodeId.from("otherNode")));
    final Node node = Node.create().id(NodeId.from("myNodeId")).parentPath(NodePath.ROOT).name("myNode").data(data).build();
    final Collection<IndexDocument> indexDocuments = NodeStoreDocumentFactory.createBuilder().node(node).branch(Branch.from("myBranch")).repositoryId(RepositoryId.from("my-repo")).build().create();
    assertEquals(1, indexDocuments.size());
    final IndexDocument indexDocument = indexDocuments.iterator().next();
    final IndexItems indexItems = indexDocument.getIndexItems();
    final Collection<IndexValue> referenceValues = indexItems.get(NodeIndexPath.REFERENCE.getPath());
    assertEquals(1, referenceValues.size());
    final IndexValue next = referenceValues.iterator().next();
    assertTrue(next instanceof IndexValueString);
    final IndexValueString referenceValue = (IndexValueString) next;
    assertEquals("otherNode", referenceValue.getValue());
}
Also used : IndexDocument(com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument) Reference(com.enonic.xp.util.Reference) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) IndexValueString(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValueString) IndexItems(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItems) IndexValue(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValue) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyTree (com.enonic.xp.data.PropertyTree)660 Test (org.junit.jupiter.api.Test)405 PropertySet (com.enonic.xp.data.PropertySet)150 Content (com.enonic.xp.content.Content)126 Node (com.enonic.xp.node.Node)112 CreateContentParams (com.enonic.xp.content.CreateContentParams)64 Form (com.enonic.xp.form.Form)37 Page (com.enonic.xp.page.Page)32 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)31 DescriptorKey (com.enonic.xp.page.DescriptorKey)30 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)30 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)28 PrincipalKey (com.enonic.xp.security.PrincipalKey)28 BinaryReference (com.enonic.xp.util.BinaryReference)28 Property (com.enonic.xp.data.Property)26 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)24 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)23 ByteSource (com.google.common.io.ByteSource)22 ExtraData (com.enonic.xp.content.ExtraData)21 Instant (java.time.Instant)21