Search in sources :

Example 1 with GeoPoint

use of com.enonic.xp.util.GeoPoint in project xp by enonic.

the class TestDataFixtures method newPropertyTree.

public static PropertyTree newPropertyTree() {
    final PropertyTree tree = new PropertyTree();
    tree.setBoolean("boolean", true);
    tree.addBooleans("boolean", true, false);
    tree.setLong("long", 1L);
    tree.addLongs("longs", 1L, 2L, 3L);
    tree.setDouble("double", 2.2);
    tree.addDoubles("doubles", 1.1, 2.2, 3.3);
    tree.setString("string", "a");
    tree.addStrings("strings", "a", "b", "c");
    tree.setString("stringEmpty", "");
    tree.setString("stringNull", null);
    tree.setString("set.property", "value");
    tree.addXml("xml", "<xml><my-xml hello='world'/></xml>");
    tree.addBinaryReference("binaryReference", BinaryReference.from("abc"));
    tree.addLink("link", Link.from(ContentPath.from("/my/content").toString()));
    tree.addGeoPoint("geoPoint", new GeoPoint(1.1, -1.1));
    tree.addGeoPoints("geoPoints", new GeoPoint(1.1, -1.1), new GeoPoint(2.2, -2.2));
    tree.addInstant("instant", Instant.MAX);
    tree.addLocalDate("localDate", LocalDate.of(2014, 1, 31));
    tree.addLocalDateTime("localDateTime", LocalDateTime.of(2014, 1, 31, 10, 30, 5));
    final PropertySet set1 = tree.addSet("c");
    set1.setBoolean("d", true);
    set1.addStrings("e", "3", "4", "5");
    set1.setLong("f", 2L);
    return tree;
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet)

Example 2 with GeoPoint

use of com.enonic.xp.util.GeoPoint 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 GeoPoint

use of com.enonic.xp.util.GeoPoint in project xp by enonic.

the class TestDataFixtures method newPropertyTree.

public static PropertyTree newPropertyTree() {
    final PropertyTree tree = new PropertyTree();
    tree.setBoolean("boolean", true);
    tree.addBooleans("boolean", true, false);
    tree.setLong("long", 1L);
    tree.addLongs("longs", 1L, 2L, 3L);
    tree.setDouble("double", 2.2);
    tree.addDoubles("doubles", 1.1, 2.2, 3.3);
    tree.setString("string", "a");
    tree.addStrings("strings", "a", "b", "c");
    tree.setString("stringEmpty", "");
    tree.setString("stringNull", null);
    tree.setString("set.property", "value");
    tree.addXml("xml", "<xml><my-xml hello='world'/></xml>");
    tree.addBinaryReference("binaryReference", BinaryReference.from("abc"));
    tree.addLink("link", Link.from(ContentPath.from("/my/content").toString()));
    tree.addGeoPoint("geoPoint", new GeoPoint(1.1, -1.1));
    tree.addGeoPoints("geoPoints", new GeoPoint(1.1, -1.1), new GeoPoint(2.2, -2.2));
    tree.addInstant("instant", Instant.MAX);
    tree.addLocalDate("localDate", LocalDate.of(2014, 1, 31));
    tree.addLocalDateTime("localDateTime", LocalDateTime.of(2014, 1, 31, 10, 30, 5));
    final PropertySet set1 = tree.addSet("c");
    set1.setBoolean("d", true);
    set1.addStrings("e", "3", "4", "5");
    set1.setLong("f", 2L);
    return tree;
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet)

Example 4 with GeoPoint

use of com.enonic.xp.util.GeoPoint in project xp by enonic.

the class ScriptValueTranslator method handleValue.

private void handleValue(final PropertySet parent, final String name, final Object value) {
    if (value instanceof Instant) {
        parent.addInstant(name, (Instant) value);
    } else if (value instanceof GeoPoint) {
        parent.addGeoPoint(name, (GeoPoint) value);
    } else if (value instanceof Double) {
        parent.addDouble(name, (Double) value);
    } else if (value instanceof Float) {
        parent.addDouble(name, ((Float) value).doubleValue());
    } else if (value instanceof Integer) {
        parent.addLong(name, ((Integer) value).longValue());
    } else if (value instanceof Byte) {
        parent.addLong(name, ((Byte) value).longValue());
    } else if (value instanceof Long) {
        parent.addLong(name, ((Long) value));
    } else if (value instanceof Number) {
        parent.addDouble(name, ((Number) value).doubleValue());
    } else if (value instanceof Boolean) {
        parent.addBoolean(name, (Boolean) value);
    } else if (value instanceof LocalDateTime) {
        parent.addLocalDateTime(name, (LocalDateTime) value);
    } else if (value instanceof LocalDate) {
        parent.addLocalDate(name, (LocalDate) value);
    } else if (value instanceof LocalTime) {
        parent.addLocalTime(name, (LocalTime) value);
    } else if (value instanceof Date) {
        parent.addInstant(name, ((Date) value).toInstant());
    } else if (value instanceof Reference) {
        parent.addReference(name, (Reference) value);
    } else if (value instanceof BinaryReference) {
        parent.addBinaryReference(name, (BinaryReference) value);
    } else if (value instanceof Link) {
        parent.addLink(name, (Link) value);
    } else if (value instanceof BinaryAttachment) {
        final BinaryAttachment binaryAttachment = (BinaryAttachment) value;
        parent.addBinaryReference(name, binaryAttachment.getReference());
        if (includeBinaryAttachments) {
            this.binaryAttachmentsBuilder.add(new BinaryAttachment(binaryAttachment.getReference(), binaryAttachment.getByteSource()));
        }
    } else {
        parent.addString(name, value.toString());
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) BinaryReference(com.enonic.xp.util.BinaryReference) Reference(com.enonic.xp.util.Reference) Instant(java.time.Instant) BinaryReference(com.enonic.xp.util.BinaryReference) LocalDate(java.time.LocalDate) BinaryAttachment(com.enonic.xp.node.BinaryAttachment) Date(java.util.Date) LocalDate(java.time.LocalDate) GeoPoint(com.enonic.xp.util.GeoPoint) Link(com.enonic.xp.util.Link)

Example 5 with GeoPoint

use of com.enonic.xp.util.GeoPoint in project xp by enonic.

the class PropertyTreeTest method setGeoPoint.

@Test
public void setGeoPoint() {
    PropertyTree tree = new PropertyTree();
    GeoPoint geoPoint1 = GeoPoint.from("60,60");
    tree.setGeoPoint("geo1", geoPoint1);
    assertEquals(1, tree.getTotalSize());
    assertEquals(geoPoint1, tree.getGeoPoint("geo1"));
    GeoPoint geo2 = GeoPoint.from("90,90");
    tree.setGeoPoint(PropertyPath.from("geo2"), geo2);
    assertEquals(2, tree.getTotalSize());
    assertEquals(geo2, tree.getGeoPoint(PropertyPath.from("geo2")));
    GeoPoint geo3 = GeoPoint.from("-20,-35");
    tree.setGeoPoint("geo3", 0, geo3);
    assertEquals(3, tree.getTotalSize());
    assertEquals(geo3, tree.getGeoPoint("geo3", 0));
    assertEquals(geo3, tree.getGeoPoints("geo3").iterator().next());
}
Also used : GeoPoint(com.enonic.xp.util.GeoPoint) Test(org.junit.jupiter.api.Test) AbstractEqualsTest(com.enonic.xp.support.AbstractEqualsTest)

Aggregations

GeoPoint (com.enonic.xp.util.GeoPoint)15 PropertyTree (com.enonic.xp.data.PropertyTree)8 Test (org.junit.jupiter.api.Test)7 PropertySet (com.enonic.xp.data.PropertySet)5 ExtraData (com.enonic.xp.content.ExtraData)2 EditableNode (com.enonic.xp.node.EditableNode)2 Node (com.enonic.xp.node.Node)2 DistanceRange (com.enonic.xp.query.aggregation.DistanceRange)2 XData (com.enonic.xp.schema.xdata.XData)2 JsonMapGenerator (com.enonic.xp.script.serializer.JsonMapGenerator)2 MapGenerator (com.enonic.xp.script.serializer.MapGenerator)2 ArrayList (java.util.ArrayList)2 Collections.emptyList (java.util.Collections.emptyList)2 Collections.emptyMap (java.util.Collections.emptyMap)2 List (java.util.List)2 Map (java.util.Map)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)1 ProcessCreateParams (com.enonic.xp.content.processor.ProcessCreateParams)1 ProcessCreateResult (com.enonic.xp.content.processor.ProcessCreateResult)1 Value (com.enonic.xp.data.Value)1