Search in sources :

Example 16 with Property

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

the class PageDataSerializerTest method page_deserialize_custom_order_of_components.

@Test
public void page_deserialize_custom_order_of_components() {
    final Page page = createPage();
    final PropertyTree pageAsData = new PropertyTree();
    pageDataSerializer.toData(page, pageAsData.getRoot());
    final List<PropertySet> componentsAsData = pageAsData.getRoot().getProperties(COMPONENTS).stream().filter(Property::hasNotNullValue).map(item -> item.getSet()).collect(Collectors.toList());
    final List<PropertySet> customOrdercomponentsAsData = new ArrayList<>();
    customOrdercomponentsAsData.add(componentsAsData.get(7));
    customOrdercomponentsAsData.add(componentsAsData.get(11));
    customOrdercomponentsAsData.add(componentsAsData.get(4));
    customOrdercomponentsAsData.add(componentsAsData.get(3));
    customOrdercomponentsAsData.add(componentsAsData.get(1));
    customOrdercomponentsAsData.add(componentsAsData.get(10));
    customOrdercomponentsAsData.add(componentsAsData.get(5));
    customOrdercomponentsAsData.add(componentsAsData.get(6));
    customOrdercomponentsAsData.add(componentsAsData.get(8));
    customOrdercomponentsAsData.add(componentsAsData.get(2));
    customOrdercomponentsAsData.add(componentsAsData.get(0));
    customOrdercomponentsAsData.add(componentsAsData.get(9));
    final PropertySet root = new PropertySet();
    customOrdercomponentsAsData.forEach(componentData -> root.addSet(COMPONENTS, componentData));
    final Page parsedPage = pageDataSerializer.fromData(root);
    assertEquals(page, parsedPage);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) PageDescriptor(com.enonic.xp.page.PageDescriptor) RegionDescriptors(com.enonic.xp.region.RegionDescriptors) Page(com.enonic.xp.page.Page) ArrayList(java.util.ArrayList) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Region(com.enonic.xp.region.Region) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) ImageComponent(com.enonic.xp.region.ImageComponent) PageRegions(com.enonic.xp.page.PageRegions) RegionDescriptor(com.enonic.xp.region.RegionDescriptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) TextComponent(com.enonic.xp.region.TextComponent) Property(com.enonic.xp.data.Property) PropertySet(com.enonic.xp.data.PropertySet) PageTemplateKey(com.enonic.xp.page.PageTemplateKey) Collectors(java.util.stream.Collectors) COMPONENTS(com.enonic.xp.core.impl.content.serializer.ComponentDataSerializer.COMPONENTS) Test(org.junit.jupiter.api.Test) Form(com.enonic.xp.form.Form) Mockito(org.mockito.Mockito) List(java.util.List) LayoutComponent(com.enonic.xp.region.LayoutComponent) DescriptorKey(com.enonic.xp.page.DescriptorKey) LayoutRegions(com.enonic.xp.region.LayoutRegions) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest) PartComponent(com.enonic.xp.region.PartComponent) PropertyTree(com.enonic.xp.data.PropertyTree) ArrayList(java.util.ArrayList) PropertySet(com.enonic.xp.data.PropertySet) Page(com.enonic.xp.page.Page) Property(com.enonic.xp.data.Property) Test(org.junit.jupiter.api.Test) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)

Example 17 with Property

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

the class NodeImporter method processBinaryAttachments.

private BinaryAttachments processBinaryAttachments(final VirtualFile nodeFile, final Node newNode) {
    final PropertyTree data = newNode.data();
    final ImmutableList<Property> binaryReferences = data.getProperties(ValueTypes.BINARY_REFERENCE);
    if (binaryReferences.isEmpty()) {
        return BinaryAttachments.empty();
    }
    final BinaryAttachments.Builder builder = BinaryAttachments.create();
    for (final Property binaryReference : binaryReferences) {
        addBinary(nodeFile, builder, binaryReference);
    }
    return builder.build();
}
Also used : BinaryAttachments(com.enonic.xp.node.BinaryAttachments) PropertyTree(com.enonic.xp.data.PropertyTree) Property(com.enonic.xp.data.Property)

Example 18 with Property

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

the class NodeStoreDocumentFactory method addNodeDataProperties.

private void addNodeDataProperties(final IndexItems.Builder builder) {
    PropertyVisitor visitor = new PropertyVisitor() {

        @Override
        public void visit(final Property property) {
            if (!isNullOrEmpty(property.getString())) {
                final IndexConfig configForData = node.getIndexConfigDocument().getConfigForPath(property.getPath());
                if (configForData == null) {
                    throw new RuntimeException("Missing index configuration for data " + property.getPath());
                }
                builder.add(property, node.getIndexConfigDocument());
                addReferenceAggregation(property);
            }
        }

        private void addReferenceAggregation(final Property property) {
            if (property.getType().equals(ValueTypes.REFERENCE)) {
                builder.add(NodeIndexPath.REFERENCE, property.getValue(), createDefaultDocument(IndexConfig.MINIMAL));
            }
        }
    };
    visitor.traverse(this.node.data());
}
Also used : IndexConfig(com.enonic.xp.index.IndexConfig) Property(com.enonic.xp.data.Property) PropertyVisitor(com.enonic.xp.data.PropertyVisitor)

Example 19 with Property

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

the class DslExpressionBuilder method build.

public static QueryBuilder build(final DslExpr dslExpr) {
    final PropertyTree expression = dslExpr.getExpression();
    final List<Property> properties = (List<Property>) expression.getRoot().getProperties();
    if (properties.size() == 0) {
        throw new IllegalArgumentException("Query is empty");
    } else if (properties.size() > 1) {
        throw new IllegalArgumentException("Query allows only single root expression, but actual size is: " + expression.getTotalSize());
    }
    return DslQueryParser.parseQuery(properties.get(0));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) List(java.util.List) Property(com.enonic.xp.data.Property)

Example 20 with Property

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

the class DuplicateNodeCommandTest method assertDuplicatedTree.

private void assertDuplicatedTree(final NodePath duplicatedTreeRootPath, final Node originalNode, final Node duplicatedNode) {
    final ImmutableList<Property> originalReferences = originalNode.data().getProperties(ValueTypes.REFERENCE);
    final ImmutableList<Property> duplicateReferences = duplicatedNode.data().getProperties(ValueTypes.REFERENCE);
    assertReferenceIntegrity(duplicatedTreeRootPath, originalReferences, duplicateReferences);
    final Nodes originalChildren = getNodes(findChildren(originalNode).getNodeIds());
    final Nodes duplicatedChildren = getNodes(findChildren(duplicatedNode).getNodeIds());
    assertEquals(originalChildren.getSize(), duplicatedChildren.getSize());
    originalChildren.forEach((originalChild) -> {
        final Node duplicatedChild = getNodeByName(duplicatedChildren, originalChild.name());
        assertDuplicatedTree(duplicatedTreeRootPath, originalChild, duplicatedChild);
    });
}
Also used : Node(com.enonic.xp.node.Node) Property(com.enonic.xp.data.Property) Nodes(com.enonic.xp.node.Nodes)

Aggregations

Property (com.enonic.xp.data.Property)44 PropertyTree (com.enonic.xp.data.PropertyTree)27 Test (org.junit.jupiter.api.Test)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)12 PropertySet (com.enonic.xp.data.PropertySet)11 InputTypeProperty (com.enonic.xp.inputtype.InputTypeProperty)10 Value (com.enonic.xp.data.Value)4 ValueType (com.enonic.xp.data.ValueType)4 ValueTypes (com.enonic.xp.data.ValueTypes)3 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)3 Input (com.enonic.xp.form.Input)3 Node (com.enonic.xp.node.Node)3 List (java.util.List)3 PropertyPath (com.enonic.xp.data.PropertyPath)2 PropertyVisitor (com.enonic.xp.data.PropertyVisitor)2 Form (com.enonic.xp.form.Form)2 InputType (com.enonic.xp.inputtype.InputType)2 AttachedBinary (com.enonic.xp.node.AttachedBinary)2 PageDescriptor (com.enonic.xp.page.PageDescriptor)2 RepositoryId (com.enonic.xp.repository.RepositoryId)2