Search in sources :

Example 1 with Input

use of com.enonic.xp.form.Input in project xp by enonic.

the class JsonToPropertyTreeTranslator method mapValue.

private void mapValue(final PropertySet parent, final String key, final JsonNode value) {
    final Property parentProperty = parent.getProperty();
    final Input input = getInput(parentProperty, key);
    if (input == null) {
        if (this.strictMode) {
            throw new IllegalArgumentException("No mapping defined for property " + key + " with value " + resolveStringValue(value));
        }
        parent.addProperty(key, resolveCoreValue(value));
    } else {
        final InputType type = this.inputTypeResolver.resolve(input.getInputType());
        final Value mappedPropertyValue = type.createValue(resolveCoreValue(value), input.getInputTypeConfig());
        parent.addProperty(key, mappedPropertyValue);
    }
}
Also used : Input(com.enonic.xp.form.Input) InputType(com.enonic.xp.inputtype.InputType) Value(com.enonic.xp.data.Value) Property(com.enonic.xp.data.Property)

Example 2 with Input

use of com.enonic.xp.form.Input in project xp by enonic.

the class DateTypeTest method testCreateDefaultValue_invalid.

@Test
public void testCreateDefaultValue_invalid() {
    final Input input = getDefaultInputBuilder(InputTypeName.DATE, "2014-18-16").build();
    assertThrows(IllegalArgumentException.class, () -> this.type.createDefaultValue(input));
}
Also used : Input(com.enonic.xp.form.Input) Test(org.junit.jupiter.api.Test)

Example 3 with Input

use of com.enonic.xp.form.Input in project xp by enonic.

the class DateTypeTest method testRelativeDefaultValue.

@Test
public void testRelativeDefaultValue() {
    final Input input = getDefaultInputBuilder(InputTypeName.DATE, "+1year -5months -36d").build();
    final Value value = this.type.createDefaultValue(input);
    assertNotNull(value);
    assertSame(ValueTypes.LOCAL_DATE, value.getType());
    assertEquals(value.getObject(), LocalDate.now().plusYears(1).plusMonths(-5).plusDays(-36));
}
Also used : Input(com.enonic.xp.form.Input) Value(com.enonic.xp.data.Value) Test(org.junit.jupiter.api.Test)

Example 4 with Input

use of com.enonic.xp.form.Input in project xp by enonic.

the class GeoPointTypeTest method testCreateDefaultValue.

@Test
public void testCreateDefaultValue() {
    final Input input = getDefaultInputBuilder(InputTypeName.GEO_POINT, "41.387588,2.169994").build();
    final Value value = this.type.createDefaultValue(input);
    assertNotNull(value);
    assertEquals("41.387588,2.169994", value.toString());
}
Also used : Input(com.enonic.xp.form.Input) Value(com.enonic.xp.data.Value) Test(org.junit.jupiter.api.Test)

Example 5 with Input

use of com.enonic.xp.form.Input in project xp by enonic.

the class GeoPointTypeTest method testCreateDefaultValue_invalid.

@Test
public void testCreateDefaultValue_invalid() {
    final Input input = getDefaultInputBuilder(InputTypeName.GEO_POINT, "41.387588;2.169994").build();
    assertThrows(IllegalArgumentException.class, () -> this.type.createDefaultValue(input));
}
Also used : Input(com.enonic.xp.form.Input) Test(org.junit.jupiter.api.Test)

Aggregations

Input (com.enonic.xp.form.Input)62 Test (org.junit.jupiter.api.Test)47 Value (com.enonic.xp.data.Value)24 Form (com.enonic.xp.form.Form)15 PropertyTree (com.enonic.xp.data.PropertyTree)11 FormItem (com.enonic.xp.form.FormItem)9 FormItemSet (com.enonic.xp.form.FormItemSet)9 FormDefaultValuesProcessor (com.enonic.xp.form.FormDefaultValuesProcessor)7 ContentType (com.enonic.xp.schema.content.ContentType)7 FormOptionSet (com.enonic.xp.form.FormOptionSet)5 FieldSet (com.enonic.xp.form.FieldSet)4 FormOptionSetOption (com.enonic.xp.form.FormOptionSetOption)4 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)4 Property (com.enonic.xp.data.Property)3 Occurrences (com.enonic.xp.form.Occurrences)3 Content (com.enonic.xp.content.Content)2 ExtraData (com.enonic.xp.content.ExtraData)2 ValidationErrors (com.enonic.xp.content.ValidationErrors)2 PropertyPath (com.enonic.xp.data.PropertyPath)2 PropertySet (com.enonic.xp.data.PropertySet)2