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;
}
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);
}
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);
}
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();
}
}
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);
}
Aggregations