use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class ModifyProfileHandler method updateUser.
private void updateUser(final EditableUser target, final ScriptValue value) {
if (value == null) {
if (scope != null) {
target.profile.removeProperty(scope);
}
return;
}
final ScriptValueTranslatorResult scriptValueTranslatorResult = new ScriptValueTranslator(false).create(value);
final PropertyTree propertyTree = scriptValueTranslatorResult.getPropertyTree();
if (this.scope == null) {
target.profile = propertyTree;
} else {
target.profile.setSet(scope, propertyTree.getRoot());
}
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class CreateAuditLogHandlerTest method mockCreateLog.
public void mockCreateLog() {
PropertyTree data = new PropertyTree();
data.setString("custom", "string");
data.addDouble("somevalue", 2.5);
AuditLog mocklog1 = auditLogBuilder(LogAuditLogParams.create().type("testlog").build()).source("testbundle").build();
AuditLog mocklog2 = auditLogBuilder(LogAuditLogParams.create().type("testlog").source("testbundle").user(PrincipalKey.ofAnonymous()).objectUris(AuditLogUris.from("some:resource:uri")).data(data).build()).build();
Mockito.when(this.auditLogService.log(Mockito.any(LogAuditLogParams.class))).thenReturn(mocklog1).thenReturn(mocklog2);
}
use of com.enonic.xp.data.PropertyTree 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.data.PropertyTree in project xp by enonic.
the class ModifyNodeHandlerTest method keep_original_value_types_when_not_touched.
@Test
public void keep_original_value_types_when_not_touched() {
final PropertyTree data = new PropertyTree();
data.setString("myString", "originalValue");
data.setString("untouchedString", "originalValue");
data.setBoolean("untouchedBoolean", true);
data.setDouble("untouchedDouble", 2.0);
data.setLong("untouchedLong", 2L);
data.setLink("untouchedLink", Link.from("myLink"));
data.setInstant("untouchedInstant", Instant.parse("2017-01-02T10:00:00Z"));
data.setBinaryReference("untouchedBinaryRef", BinaryReference.from("abcd"));
data.setGeoPoint("untouchedGeoPoint", GeoPoint.from("30,-30"));
data.setLocalDate("untouchedLocalDate", LocalDate.parse("2017-03-24"));
data.setReference("untouchedReference", Reference.from("myReference"));
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-keep-types.js");
Mockito.verify(this.nodeService).update(updateCaptor.capture());
assertEquals(updateCaptor.getValue().getId(), NodeId.from("abc"));
final EditableNode editedNode = getEditedNode(node);
assertEquals("modifiedValue", editedNode.data.getString("myString"));
// Validate that properties not changed keeps original type
assertTrue(editedNode.data.getProperty("untouchedString").getType().equals(ValueTypes.STRING));
assertTrue(editedNode.data.getProperty("untouchedBoolean").getType().equals(ValueTypes.BOOLEAN));
assertTrue(editedNode.data.getProperty("untouchedDouble").getType().equals(ValueTypes.DOUBLE));
assertTrue(editedNode.data.getProperty("untouchedLong").getType().equals(ValueTypes.LONG));
assertTrue(editedNode.data.getProperty("untouchedLink").getType().equals(ValueTypes.LINK));
assertTrue(editedNode.data.getProperty("untouchedInstant").getType().equals(ValueTypes.DATE_TIME));
assertTrue(editedNode.data.getProperty("untouchedGeoPoint").getType().equals(ValueTypes.GEO_POINT));
assertTrue(editedNode.data.getProperty("untouchedLocalDate").getType().equals(ValueTypes.LOCAL_DATE));
assertTrue(editedNode.data.getProperty("untouchedReference").getType().equals(ValueTypes.REFERENCE));
assertTrue(editedNode.data.getProperty("untouchedBinaryRef").getType().equals(ValueTypes.BINARY_REFERENCE));
}
use of com.enonic.xp.data.PropertyTree in project xp by enonic.
the class CreateNodeHandlerTest method example_3.
@Test
public void example_3() {
final PropertyTree data = new PropertyTree();
data.setString("displayName", "Child node inheriting permissions");
final Node node = Node.create().name("myName").parentPath(NodePath.create("/parent").build()).id(NodeId.from("b186d24f-ac38-42ca-a6db-1c1bda6c6c26")).data(data).inheritPermissions(true).permissions(AccessControlList.create().add(AccessControlEntry.create().allowAll().principal(RoleKeys.ADMIN).build()).add(AccessControlEntry.create().allow(Permission.READ).principal(RoleKeys.EVERYONE).build()).add(AccessControlEntry.create().allow(Permission.READ, Permission.MODIFY, Permission.CREATE, Permission.DELETE).principal(PrincipalKey.ofUser(IdProviderKey.system(), "user1")).build()).build()).build();
mockCreateNode(node);
Mockito.when(this.repositoryService.get(RepositoryId.from("com.enonic.cms.default"))).thenReturn(Repository.create().id(RepositoryId.from("com.enonic.cms.default")).branches(Branches.from(ContentConstants.BRANCH_DRAFT, ContentConstants.BRANCH_MASTER)).build());
runScript("/lib/xp/examples/node/create-3.js");
}
Aggregations