Search in sources :

Example 1 with PropertyDescription

use of org.sablo.specification.PropertyDescription in project servoy-client by Servoy.

the class FormElement method propertiesForTemplateJSON.

public TypedData<Map<String, Object>> propertiesForTemplateJSON() {
    Map<String, Object> properties = new HashMap<>();
    WebObjectSpecification componentSpec = getWebComponentSpec();
    Map<String, PropertyDescription> propDescription = componentSpec.getProperties();
    for (PropertyDescription pd : propDescription.values()) {
        Object val = getRawPropertyValue(pd.getName());
        properties.put(pd.getName(), val);
    }
    if (persistImpl == null || !persistImpl.isForm()) {
        Dimension dim = getDesignSize();
        if (dim != null)
            properties.put(StaticContentSpecLoader.PROPERTY_SIZE.getPropertyName(), dim);
        Integer anchor = (Integer) getPropertyValue(StaticContentSpecLoader.PROPERTY_ANCHORS.getPropertyName());
        if (anchor != null) {
            properties.put(StaticContentSpecLoader.PROPERTY_ANCHORS.getPropertyName(), anchor);
        }
    }
    Object offsetY = getPropertyValue("offsetY");
    if (offsetY != null)
        properties.put("offsetY", offsetY);
    Object partHeight = getPropertyValue("partHeight");
    if (partHeight != null)
        properties.put("partHeight", partHeight);
    Object formview = getPropertyValue("formview");
    if (formview != null)
        properties.put("formview", formview);
    // get types for conversion
    PropertyDescriptionBuilder propertyTypes = AggregatedPropertyType.newAggregatedPropertyBuilder();
    for (Entry<String, Object> p : properties.entrySet()) {
        PropertyDescription t = getWebComponentSpec().getProperty(p.getKey());
        if (t != null)
            propertyTypes.withProperty(p.getKey(), t);
    }
    PropertyDescription pd = propertyTypes.build();
    return new TypedData<>(properties, pd.hasChildProperties() ? pd : null);
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) TypedData(org.sablo.websocket.TypedData) HashMap(java.util.HashMap) PropertyDescriptionBuilder(org.sablo.specification.PropertyDescriptionBuilder) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Dimension(java.awt.Dimension)

Example 2 with PropertyDescription

use of org.sablo.specification.PropertyDescription in project servoy-client by Servoy.

the class WebComponentSpecTest method testFormatTypeAsString.

@Test
public void testFormatTypeAsString() throws JSONException {
    String property = "{name:'test',definition:'/test.js', model: {mydataprovider:'dataprovider',myformat:{for:'mydataprovider' , type:'format'}}}";
    WebObjectSpecification spec = WebObjectSpecification.parseSpec(property, "sample", null, null);
    Assert.assertEquals(2, spec.getProperties().size());
    PropertyDescription pd = spec.getProperties().get("myformat");
    Assert.assertNotNull(pd);
    Assert.assertTrue(pd.getType() == TypesRegistry.getType("format"));
    Assert.assertFalse(pd.getType() instanceof CustomJSONArrayType<?, ?>);
    Assert.assertEquals("mydataprovider", ((String[]) pd.getConfig())[0]);
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) Test(org.junit.Test)

Example 3 with PropertyDescription

use of org.sablo.specification.PropertyDescription in project servoy-client by Servoy.

the class WebComponentSpecTest method testFormatTypeAsArray.

@Test
public void testFormatTypeAsArray() throws JSONException {
    String property = "{name:'test',definition:'/test.js', model: {mydataprovider:'dataprovider',myformat:{for:['mydataprovider'] , type:'format'}}}";
    WebObjectSpecification spec = WebObjectSpecification.parseSpec(property, "sample", null, null);
    Assert.assertEquals(2, spec.getProperties().size());
    PropertyDescription pd = spec.getProperties().get("myformat");
    Assert.assertNotNull(pd);
    Assert.assertTrue(pd.getType() == TypesRegistry.getType("format"));
    Assert.assertFalse(pd.getType() instanceof CustomJSONArrayType<?, ?>);
    Assert.assertEquals("mydataprovider", ((String[]) pd.getConfig())[0]);
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) Test(org.junit.Test)

Example 4 with PropertyDescription

use of org.sablo.specification.PropertyDescription in project servoy-client by Servoy.

the class WebComponentSpecTest method testOwnTypeProperyTypeRefernceInOtherOwnType.

@Test
public void testOwnTypeProperyTypeRefernceInOtherOwnType() throws JSONException {
    String property = "{name:'test',definition:'/test.js', model: {myproperty:'mytype'}, types: {mytype:{model:{typeproperty:'mytype2'}},mytype2:{model:{typeproperty:'string'}}}}";
    WebObjectSpecification spec = WebObjectSpecification.parseSpec(property, "sample", null, null);
    Assert.assertEquals(1, spec.getProperties().size());
    PropertyDescription pd = spec.getProperties().get("myproperty");
    Assert.assertNotNull(pd);
    Assert.assertNotNull(((ICustomType) pd.getType()).getCustomJSONTypeDefinition());
    Object config = pd.getConfig();
    Assert.assertNull(config);
    Assert.assertFalse(pd.getType() instanceof CustomJSONArrayType<?, ?>);
    PropertyDescription wct = ((ICustomType) pd.getType()).getCustomJSONTypeDefinition();
    Assert.assertEquals("test.mytype", wct.getName());
    Assert.assertEquals(1, wct.getProperties().size());
    PropertyDescription pd2 = wct.getProperties().get("typeproperty");
    Assert.assertNotNull(pd2);
    Assert.assertNotNull(((ICustomType) pd2.getType()).getCustomJSONTypeDefinition());
    Assert.assertFalse(pd2.getType() instanceof CustomJSONArrayType<?, ?>);
    config = pd2.getConfig();
    Assert.assertNull(config);
    PropertyDescription wct2 = ((ICustomType) pd2.getType()).getCustomJSONTypeDefinition();
    Assert.assertEquals("test.mytype2", wct2.getName());
    Assert.assertEquals(1, wct2.getProperties().size());
    PropertyDescription pd3 = wct2.getProperty("typeproperty");
    Assert.assertNotNull(pd3);
    Assert.assertTrue(pd3.getType() == ServoyStringPropertyType.INSTANCE);
    Assert.assertFalse(pd3.getType() instanceof CustomJSONArrayType<?, ?>);
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) ICustomType(org.sablo.specification.property.ICustomType) Test(org.junit.Test)

Example 5 with PropertyDescription

use of org.sablo.specification.PropertyDescription in project servoy-client by Servoy.

the class WebComponentSpecTest method testArrayStringProperyType.

@Test
public void testArrayStringProperyType() throws JSONException {
    String property = "{name:'test',definition:'/test.js', model: {myproperty:'string[]'}}";
    WebObjectSpecification spec = WebObjectSpecification.parseSpec(property, "sample", null, null);
    Assert.assertEquals(1, spec.getProperties().size());
    PropertyDescription pd = spec.getProperties().get("myproperty");
    Assert.assertNotNull(pd);
    Assert.assertTrue(pd.getType() instanceof CustomJSONArrayType<?, ?>);
    Assert.assertTrue(((CustomJSONArrayType) pd.getType()).getCustomJSONTypeDefinition().getType() == ServoyStringPropertyType.INSTANCE);
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) Test(org.junit.Test)

Aggregations

PropertyDescription (org.sablo.specification.PropertyDescription)113 JSONObject (org.json.JSONObject)53 WebObjectSpecification (org.sablo.specification.WebObjectSpecification)35 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)34 ArrayList (java.util.ArrayList)28 HashMap (java.util.HashMap)23 ScriptableObject (org.mozilla.javascript.ScriptableObject)23 Test (org.junit.Test)19 Map (java.util.Map)15 Form (com.servoy.j2db.persistence.Form)14 JSONArray (org.json.JSONArray)14 JSONException (org.json.JSONException)13 IFormElement (com.servoy.j2db.persistence.IFormElement)11 IPersist (com.servoy.j2db.persistence.IPersist)10 List (java.util.List)10 WebComponent (com.servoy.j2db.persistence.WebComponent)9 ServoyJSONArray (com.servoy.j2db.util.ServoyJSONArray)8 PropertyDescriptionBuilder (org.sablo.specification.PropertyDescriptionBuilder)8 Scriptable (org.mozilla.javascript.Scriptable)7 WebComponent (org.sablo.WebComponent)7