Search in sources :

Example 1 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 2 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class TestDataFixtures method getTestUserWithProfile.

public static User getTestUserWithProfile() {
    final PropertySet data = new PropertySet();
    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 PropertyTree profile = new PropertyTree();
    profile.setSet("myApp", data);
    return User.create().key(PrincipalKey.ofUser(IdProviderKey.from("enonic"), "user1")).displayName("User 1").modifiedTime(Instant.now(clock)).email("user1@enonic.com").login("user1").profile(profile).build();
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet)

Example 3 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class BaseContentHandler method createPropertyTree.

PropertyTree createPropertyTree(final Map<String, Object> value, final ContentTypeName contentTypeName) {
    if (value == null) {
        return null;
    }
    if (value.containsKey(ContentPropertyNames.SITECONFIG)) {
        Map<String, Object> newValue = new LinkedHashMap<>(value);
        newValue.remove(ContentPropertyNames.SITECONFIG);
        final PropertyTree result = this.translateToPropertyTree(newValue, contentTypeName);
        final List<PropertySet> siteConfigs = createSiteConfigSets(value.get(ContentPropertyNames.SITECONFIG), contentTypeName);
        if (siteConfigs != null) {
            siteConfigs.forEach(propertySet -> {
                final PropertySet newSet = propertySet.copy(result);
                result.addSet(ContentPropertyNames.SITECONFIG, newSet);
            });
        }
        return result;
    }
    return this.translateToPropertyTree(value, contentTypeName);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class JsonToPropertyTreeTranslatorTest method boolean_value.

@Test
public void boolean_value() throws Exception {
    final JsonNode node = loadJson("allInputTypes");
    final PropertyTree data = JsonToPropertyTreeTranslator.translate(node);
    final Property property = data.getProperty("checkbox");
    assertTrue(property.getValue().isBoolean());
    assertEquals(true, property.getBoolean());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) JsonNode(com.fasterxml.jackson.databind.JsonNode) Property(com.enonic.xp.data.Property) Test(org.junit.jupiter.api.Test)

Example 5 with PropertyTree

use of com.enonic.xp.data.PropertyTree in project xp by enonic.

the class JsonToPropertyTreeTranslatorTest method all_input_types.

@Test
public void all_input_types() throws Exception {
    final JsonNode node = loadJson("allInputTypes");
    final PropertyTree data = JsonToPropertyTreeTranslator.translate(node);
    final Property media = data.getProperty("media");
    assertNotNull(media);
    assertEquals(ValueTypes.PROPERTY_SET.getName(), media.getType().getName());
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) JsonNode(com.fasterxml.jackson.databind.JsonNode) Property(com.enonic.xp.data.Property) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyTree (com.enonic.xp.data.PropertyTree)639 Test (org.junit.jupiter.api.Test)404 PropertySet (com.enonic.xp.data.PropertySet)134 Content (com.enonic.xp.content.Content)125 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