Search in sources :

Example 46 with PropertyTree

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());
    }
}
Also used : ScriptValueTranslatorResult(com.enonic.xp.lib.value.ScriptValueTranslatorResult) PropertyTree(com.enonic.xp.data.PropertyTree) ScriptValueTranslator(com.enonic.xp.lib.value.ScriptValueTranslator)

Example 47 with PropertyTree

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);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) AuditLog(com.enonic.xp.audit.AuditLog)

Example 48 with PropertyTree

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());
}
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 49 with PropertyTree

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));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) EditableNode(com.enonic.xp.node.EditableNode) EditableNode(com.enonic.xp.node.EditableNode) Test(org.junit.jupiter.api.Test)

Example 50 with PropertyTree

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");
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyTree (com.enonic.xp.data.PropertyTree)660 Test (org.junit.jupiter.api.Test)405 PropertySet (com.enonic.xp.data.PropertySet)150 Content (com.enonic.xp.content.Content)126 Node (com.enonic.xp.node.Node)112 CreateContentParams (com.enonic.xp.content.CreateContentParams)64 Form (com.enonic.xp.form.Form)37 Page (com.enonic.xp.page.Page)32 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)31 DescriptorKey (com.enonic.xp.page.DescriptorKey)30 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)30 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)28 PrincipalKey (com.enonic.xp.security.PrincipalKey)28 BinaryReference (com.enonic.xp.util.BinaryReference)28 Property (com.enonic.xp.data.Property)26 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)24 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)23 ByteSource (com.google.common.io.ByteSource)22 ExtraData (com.enonic.xp.content.ExtraData)21 Instant (java.time.Instant)21