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