Search in sources :

Example 16 with ServoyJSONObject

use of com.servoy.j2db.util.ServoyJSONObject in project servoy-client by Servoy.

the class AbstractPersistFactory method convertArgumentStringToObject.

/**
 * Converter method to convert String in object
 *
 * @param type_id the type
 * @param s the string
 * @return the object
 */
public Object convertArgumentStringToObject(int typeId, String s) throws RepositoryException {
    Object retval = null;
    switch(typeId) {
        case IRepository.DIMENSION:
            retval = PersistHelper.createDimension(s);
            break;
        case IRepository.ELEMENTS:
            retval = Integer.valueOf(getElementIdForUUIDString(s));
            break;
        case IRepository.BLOBS:
        case IRepository.INTEGER:
            retval = Integer.valueOf(Utils.getAsInteger(s));
            break;
        case IRepository.BORDER:
            retval = s;
            break;
        case IRepository.COLOR:
            retval = PersistHelper.createColor(s);
            break;
        case IRepository.POINT:
            retval = PersistHelper.createPoint(s);
            break;
        case IRepository.INSETS:
            retval = PersistHelper.createInsets(s);
            break;
        case IRepository.CSSPOSITION:
            retval = PersistHelper.createCSSPosition(s);
            break;
        case IRepository.STRING:
        case IRepository.STYLES:
        case IRepository.TEMPLATES:
        case IRepository.SERVERS:
        case IRepository.TABLES:
        case IRepository.DATASOURCES:
            retval = s;
            break;
        case IRepository.FONT:
            // PersistHelper.createFont(s); fonts must be created in client
            retval = s;
            break;
        case IRepository.BOOLEAN:
            retval = Boolean.valueOf(Utils.getAsBoolean(s));
            break;
        case IRepository.JSON:
            try {
                retval = new ServoyJSONObject(s, false);
            } catch (JSONException ex) {
                Debug.error(ex);
            }
            break;
        default:
            throw new RepositoryException("type with id=" + typeId + " does not exist");
    }
    retval = Internalize.intern(retval);
    return retval;
}
Also used : ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) JSONException(org.json.JSONException) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject)

Example 17 with ServoyJSONObject

use of com.servoy.j2db.util.ServoyJSONObject in project servoy-client by Servoy.

the class WebCustomType method resetUUID.

@Override
public void resetUUID(UUID uuidParam) {
    super.resetUUID(uuidParam);
    JSONObject fullJSONInFrmFile = WebObjectImpl.getFullJSONInFrmFile(this, false);
    if (fullJSONInFrmFile == null)
        fullJSONInFrmFile = new ServoyJSONObject();
    fullJSONInFrmFile.put(UUID_KEY, getUUID().toString());
    webObjectImpl.setJsonInternal(fullJSONInFrmFile);
}
Also used : ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject)

Example 18 with ServoyJSONObject

use of com.servoy.j2db.util.ServoyJSONObject in project servoy-client by Servoy.

the class JSNGWebComponent method getJSONProperty.

@Override
public Object getJSONProperty(String propertyName) {
    WebComponent webComponent = getBaseComponent(false);
    JSONObject json = webComponent.getFlattenedJson();
    if (json == null)
        return Context.getUndefinedValue();
    Object value;
    WebObjectSpecification spec = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(webComponent.getTypeName());
    if (spec != null) {
        Pair<PropertyDescription, String> propAndName = getPropertyDescriptionAndName(propertyName, spec);
        if (!json.has(propAndName.getRight()) && propAndName.getLeft() != null && propAndName.getLeft().hasDefault()) {
            value = propAndName.getLeft().getDefaultValue();
        } else {
            value = json.opt(propAndName.getRight());
        }
        value = fromDesignToRhinoValue(value, propAndName.getLeft(), application, this, propertyName);
    // JSONArray and JSONObject are automatically wrapped when going to Rhino through ServoyWrapFactory, so no need to treat them specially here
    } else {
        value = json.opt(propertyName);
    }
    // so we need to make sure we always return a JSONObject.
    if (value instanceof ServoyJSONObject) {
        value = new JSONObject((ServoyJSONObject) value, ((ServoyJSONObject) value).keySet().toArray(new String[0]));
    } else if (value instanceof ServoyJSONArray) {
        ServoyJSONArray sArray = (ServoyJSONArray) value;
        JSONArray array = new JSONArray();
        for (int i = 0; i < sArray.length(); i++) {
            array.put(i, sArray.get(i));
        }
        value = sArray;
    }
    return value == null ? Context.getUndefinedValue() : ServoyJSONObject.jsonNullToNull(value);
}
Also used : PropertyDescription(org.sablo.specification.PropertyDescription) WebComponent(com.servoy.j2db.persistence.WebComponent) WebObjectSpecification(org.sablo.specification.WebObjectSpecification) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) ServoyJSONArray(com.servoy.j2db.util.ServoyJSONArray) JSONArray(org.json.JSONArray) ServoyJSONArray(com.servoy.j2db.util.ServoyJSONArray) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject)

Example 19 with ServoyJSONObject

use of com.servoy.j2db.util.ServoyJSONObject in project servoy-client by Servoy.

the class FoundsetTest method fillTestSolution.

@Override
protected void fillTestSolution() throws ServoyException {
    try {
        Form form = solution.createNewForm(validator, null, "test", "mem:test", false, new Dimension(600, 400));
        form.setNavigatorID(-1);
        form.createNewPart(IBaseSMPart.BODY, 5);
        WebComponent bean = form.createNewWebComponent("mycustombean", "my-component");
        bean.setProperty("myfoundset", new ServoyJSONObject("{foundsetSelector:'',dataproviders:{firstname:'test1',lastname:'test2'}}", false));
        bean.setProperty("myfoundsetWithAllow", new ServoyJSONObject("{foundsetSelector:'',dataproviders:{firstname:'test1',lastname:'test2'}}", false));
        WebComponent bean1 = form.createNewWebComponent("mydynamiccustombean", "my-dynamiccomponent");
        bean1.setProperty("myfoundset", new ServoyJSONObject("{foundsetSelector:'test_to_relatedtest', dataproviders:{dp1:'relatedtest1',dp2:'relatedtest2'}}", false));
        bean1.setProperty("myfoundsetWithAllow", new ServoyJSONObject("{foundsetSelector:'test_to_relatedtest', dataproviders:{dp1:'relatedtest1',dp2:'relatedtest2'}}", false));
        WebComponent bean2 = form.createNewWebComponent("mycustomseparatefoundsetbean", "my-component");
        bean2.setProperty("myfoundset", new ServoyJSONObject("{foundsetSelector: \"mem:testseparatefoundset\", loadAllRecords: true, dataproviders:{firstname:'test1',lastname:'test2'}}", false));
    } catch (JSONException e) {
        e.printStackTrace();
        throw new ServoyException();
    }
}
Also used : WebComponent(com.servoy.j2db.persistence.WebComponent) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Form(com.servoy.j2db.persistence.Form) JSONException(org.json.JSONException) Dimension(java.awt.Dimension) ServoyException(com.servoy.j2db.util.ServoyException)

Example 20 with ServoyJSONObject

use of com.servoy.j2db.util.ServoyJSONObject in project servoy-client by Servoy.

the class PersistFieldInstanceTest method testCustomComponentWithFormProperty.

@Test
public void testCustomComponentWithFormProperty() throws RepositoryException, JSONException {
    // TODO this should become a test on form uuid in the inner html/bean xml instead of the form name..
    Form form = solution.getForm("test");
    Assert.assertNotNull(form);
    DataAdapterList dataAdapterList = new DataAdapterList(new TestFormController(form, client));
    Form tabForm = solution.createNewForm(validator, null, "tabform", null, false, new Dimension(600, 400));
    // as client's "inDesigner" == true we will generate an error bean because legacy Bean usage for custom web components with custom object/array types is depreacated and not fully working (in designer at least)
    // so we will check that it generates an error bean (that means no props are set)
    // TODO maybe this can be uncommented after https://support.servoy.com/browse/SVY-9459 is done
    // Bean bean = form.createNewBean("mycustombean", "my-component");
    // bean.setInnerHTML("{atype:{name:'name',form:'tabform'}}");
    List<FormElement> formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    // Assert.assertEquals(1, formElements.size());
    // WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null);
    @SuppressWarnings("unchecked") WebComponent // form.removeChild(bean);
    webComponent = form.createNewWebComponent("mycustombean", "my-component");
    webComponent.setProperty("atype", new ServoyJSONObject("{name:'name',form:'tabform'}", false));
    formElements = FormElementHelper.INSTANCE.getFormElements(form.getAllObjects(), new ServoyDataConverterContext(client));
    Assert.assertEquals(1, formElements.size());
    WebFormComponent wc = ComponentFactory.createComponent(client, dataAdapterList, formElements.get(0), null, form);
    Map<String, Object> type = (Map<String, Object>) wc.getProperty("atype");
    Assert.assertEquals("name", type.get("name"));
    Assert.assertEquals("tabform", type.get("form"));
    Assert.assertEquals(0, wc.getAndClearChanges().content.size());
    TypedData<Map<String, Object>> props = wc.getProperties();
    String json = JSONUtils.writeDataWithConversions(props.content, props.contentType, null);
    JSONAssert.assertEquals("{\"atype\":{\"rt\":\"my-component.mytype\",\"vEr\":2,\"v\":{\"form\":\"tabform\",\"name\":\"name\"}},\"svyMarkupId\":\"sf331d64ddc0c17747371b7740e3e3447\",\"svy_types\":{\"atype\":\"JSON_obj\"}}", json, true);
}
Also used : Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) DataAdapterList(com.servoy.j2db.server.ngclient.DataAdapterList) Dimension(java.awt.Dimension) FormElement(com.servoy.j2db.server.ngclient.FormElement) WebComponent(com.servoy.j2db.persistence.WebComponent) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) ServoyDataConverterContext(com.servoy.j2db.server.ngclient.ServoyDataConverterContext) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)24 JSONObject (org.json.JSONObject)12 JSONException (org.json.JSONException)7 BaseColumnType (com.servoy.base.query.BaseColumnType)6 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 JSONArray (org.json.JSONArray)5 TableNode (com.servoy.j2db.persistence.TableNode)4 WebComponent (com.servoy.j2db.persistence.WebComponent)4 ServoyException (com.servoy.j2db.util.ServoyException)4 ServoyJSONArray (com.servoy.j2db.util.ServoyJSONArray)4 ColumnInfoDef (com.servoy.j2db.util.xmlxport.ColumnInfoDef)4 TableDef (com.servoy.j2db.util.xmlxport.TableDef)4 IOException (java.io.IOException)4 PropertyDescription (org.sablo.specification.PropertyDescription)4 BaseQueryTable (com.servoy.base.query.BaseQueryTable)3 ApplicationException (com.servoy.j2db.ApplicationException)3 Form (com.servoy.j2db.persistence.Form)3 ITable (com.servoy.j2db.persistence.ITable)3