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