Search in sources :

Example 11 with IWebFormController

use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.

the class FoundsetTest method foundsetViewportChangeData.

@Test
public // change rows in/near viewport
void foundsetViewportChangeData() throws // change rows in/near viewport
JSONException, // change rows in/near viewport
ServoyException {
    IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
    Assert.assertNotNull(form);
    WebFormComponent wc = form.getFormUI().getWebComponent("mycustombean");
    FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) wc.getRawPropertyValue("myfoundset");
    // right now the viewport change monitor will NOT ignore updates because the value is directly sent to the client (through the updateController code)
    FoundsetTypeViewport viewPort = rawPropertyValue.getViewPort();
    viewPort.setBounds(1, 1);
    viewPort.changeMonitor.clearChanges();
    rawPropertyValue.getFoundset().getRecord(0).startEditing();
    rawPropertyValue.getFoundset().getRecord(0).setValue("test1", "not test1 any more");
    rawPropertyValue.getFoundset().getRecord(0).stopEditing();
    Assert.assertEquals(0, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
    rawPropertyValue.getFoundset().getRecord(1).startEditing();
    rawPropertyValue.getFoundset().getRecord(1).setValue("test2", "not test2 any more");
    rawPropertyValue.getFoundset().getRecord(1).stopEditing();
    Assert.assertEquals(1, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
    // now simulate a send to client
    rawPropertyValue.toJSON(new JSONStringer(), new DataConversion(), new BrowserConverterContext(wc, PushToServerEnum.allow));
    rawPropertyValue.getFoundset().getRecord(0).startEditing();
    rawPropertyValue.getFoundset().getRecord(0).setValue("test1", "not test1 any more nor not test1 any more");
    rawPropertyValue.getFoundset().getRecord(0).stopEditing();
    Assert.assertEquals(0, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
    rawPropertyValue.getFoundset().getRecord(1).startEditing();
    rawPropertyValue.getFoundset().getRecord(1).setValue("test2", "not test2 any more nor not test2 any more");
    rawPropertyValue.getFoundset().getRecord(1).stopEditing();
    Assert.assertEquals(1, viewPort.changeMonitor.viewPortDataChangeMonitor.getViewPortChanges().length);
}
Also used : DataConversion(org.sablo.websocket.utils.DataConversion) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) BrowserConverterContext(org.sablo.specification.property.BrowserConverterContext) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) JSONStringer(org.json.JSONStringer) Test(org.junit.Test)

Example 12 with IWebFormController

use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.

the class FoundsetTest method foundsetReadByDataprovidersPushToServerReject.

@Test
public void foundsetReadByDataprovidersPushToServerReject() throws JSONException {
    IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
    Assert.assertNotNull(form);
    String full = NGUtils.formComponentPropertiesToString(form.getFormUI(), FullValueToJSONConverter.INSTANCE);
    JSONObject object = new JSONObject(full);
    JSONObject bean = object.getJSONObject("mycustombean");
    JSONObject foundset = bean.getJSONObject("myfoundset");
    Assert.assertEquals(18, foundset.getInt("serverSize"));
    JSONObject viewPort = foundset.getJSONObject("viewPort");
    Assert.assertEquals(0, viewPort.getInt("startIndex"));
    // 15 is default preferredViewPortSize
    Assert.assertEquals(15, viewPort.getInt("size"));
    Assert.assertEquals(15, viewPort.getJSONArray("rows").length());
    // fake incomming request for view port change.
    endpoint.incoming("{\"methodname\":\"dataPush\",\"args\":{\"beanname\":\"mycustombean\",\"formname\":\"test\",\"changes\":{\"myfoundset\":[{\"newViewPort\":{\"startIndex\":0,\"size\":18}, \"id\": 4321}]}},\"service\":\"formService\"}", true);
    String changes = NGUtils.formChangesToString(((Container) form.getFormUI()), FullValueToJSONConverter.INSTANCE);
    object = new JSONObject(changes).getJSONObject("changes");
    bean = object.getJSONObject("mycustombean");
    foundset = bean.getJSONObject("myfoundset");
    Assert.assertEquals(18, foundset.getInt("serverSize"));
    viewPort = foundset.getJSONObject("viewPort");
    Assert.assertEquals(0, viewPort.getInt("startIndex"));
    Assert.assertEquals(18, viewPort.getInt("size"));
    JSONArray rows = viewPort.getJSONArray("rows");
    Assert.assertEquals(18, rows.length());
    JSONArray handledClientReqIds = foundset.getJSONArray("handledClientReqIds");
    Assert.assertEquals(1, handledClientReqIds.length());
    Assert.assertEquals(4321, handledClientReqIds.getJSONObject(0).getInt("id"));
    Assert.assertTrue(handledClientReqIds.getJSONObject(0).getBoolean("value"));
    JSONObject row0 = rows.getJSONObject(0);
    Assert.assertEquals("value1", row0.getString("firstname"));
    Assert.assertEquals("value2", row0.getString("lastname"));
    JSONObject row1 = rows.getJSONObject(1);
    Assert.assertEquals("value3", row1.getString("firstname"));
    Assert.assertEquals("value4", row1.getString("lastname"));
    // fake an update
    endpoint.incoming("{\"methodname\":\"dataPush\",\"args\":{\"beanname\":\"mycustombean\",\"formname\":\"test\",\"changes\":{\"myfoundset\":[{\"viewportDataChanged\":{\"_svyRowId\":\"" + row1.getString("_svyRowId") + "\",\"value\":\"value5\",\"dp\":\"lastname\"}}]}},\"service\":\"formService\"}", true);
    // not value 5 cause pushToServer is rejected!
    Assert.assertEquals("value4", form.getFormModel().getRecord(1).getValue("test2"));
}
Also used : Container(org.sablo.Container) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) JSONArray(org.json.JSONArray) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Test(org.junit.Test)

Example 13 with IWebFormController

use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.

the class FoundsetTest method setPreferredViewport.

@Test
public // change selected index in main foundset and related foundset should change
void setPreferredViewport() throws // change selected index in main foundset and related foundset should change
JSONException {
    IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
    Assert.assertNotNull(form);
    WebFormComponent wc1 = form.getFormUI().getWebComponent("mycustombean");
    WebFormComponent wc2 = form.getFormUI().getWebComponent("mydynamiccustombean");
    FoundsetTypeSabloValue customBeanFoundSet = (FoundsetTypeSabloValue) wc1.getRawPropertyValue("myfoundset");
    FoundsetTypeSabloValue dynamicBeanRelatedFoundset = (FoundsetTypeSabloValue) wc2.getRawPropertyValue("myfoundset");
    BrowserConverterContext allowBrowserConverterContext2 = new BrowserConverterContext(wc1, PushToServerEnum.allow);
    dynamicBeanRelatedFoundset.getViewPort().setPreferredViewportSize(8);
    // selection is now 0, so set to 1 and then back again
    customBeanFoundSet.getFoundset().setSelectedIndex(1);
    customBeanFoundSet.getFoundset().setSelectedIndex(0);
    Assert.assertEquals(8, dynamicBeanRelatedFoundset.getViewPort().getSize());
    Assert.assertEquals(0, dynamicBeanRelatedFoundset.getViewPort().getStartIndex());
    StringWriter stringWriter = new StringWriter();
    JSONWriter jsonWriter = new JSONWriter(stringWriter);
    dynamicBeanRelatedFoundset.toJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext2);
    Assert.assertEquals("{\"serverSize\":12,\"foundsetId\":3,\"sortColumns\":\"\",\"selectedRowIndexes\":[0],\"multiSelect\":false,\"hasMoreRows\":false,\"viewPort\":{\"startIndex\":0,\"size\":8,\"rows\":[{\"_svyRowId\":\"1.1;_0\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.2;_1\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.3;_2\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.5;_3\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.6;_4\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.7;_5\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.9;_6\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"2.10;_7\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"}]}}", stringWriter.toString());
    stringWriter = new StringWriter();
    jsonWriter = new JSONWriter(stringWriter);
    // selection is now 0, so set to 1 and then back again
    customBeanFoundSet.getFoundset().setSelectedIndex(1);
    dynamicBeanRelatedFoundset.changesToJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext2);
    Assert.assertEquals("{\"upd_serverSize\":4,\"upd_foundsetId\":4,\"upd_selectedRowIndexes\":[0],\"upd_viewPort\":{\"startIndex\":0,\"size\":4,\"rows\":[{\"_svyRowId\":\"1.4;_0\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"},{\"_svyRowId\":\"1.8;_1\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"},{\"_svyRowId\":\"2.12;_2\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"},{\"_svyRowId\":\"2.16;_3\",\"dp1\":\"relatedvalue241\",\"dp2\":\"relatedvalue242\"}]}}", stringWriter.toString());
    stringWriter = new StringWriter();
    jsonWriter = new JSONWriter(stringWriter);
    customBeanFoundSet.getFoundset().setSelectedIndex(0);
    dynamicBeanRelatedFoundset.changesToJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext2);
    Assert.assertEquals("{\"upd_serverSize\":12,\"upd_foundsetId\":3,\"upd_selectedRowIndexes\":[0],\"upd_viewPort\":{\"startIndex\":0,\"size\":8,\"rows\":[{\"_svyRowId\":\"1.1;_0\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.2;_1\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.3;_2\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.5;_3\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"1.6;_4\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"},{\"_svyRowId\":\"1.7;_5\",\"dp1\":\"relatedvalue131\",\"dp2\":\"relatedvalue132\"},{\"_svyRowId\":\"1.9;_6\",\"dp1\":\"relatedvalue111\",\"dp2\":\"relatedvalue112\"},{\"_svyRowId\":\"2.10;_7\",\"dp1\":\"relatedvalue121\",\"dp2\":\"relatedvalue122\"}]}}", stringWriter.toString());
}
Also used : JSONWriter(org.json.JSONWriter) DataConversion(org.sablo.websocket.utils.DataConversion) StringWriter(java.io.StringWriter) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) BrowserConverterContext(org.sablo.specification.property.BrowserConverterContext) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Test(org.junit.Test)

Example 14 with IWebFormController

use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.

the class FoundsetTest method foundsetChangeMonitorChangeFlags.

@Test
public void foundsetChangeMonitorChangeFlags() throws ServoyException {
    IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
    Assert.assertNotNull(form);
    FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) form.getFormUI().getWebComponent("mycustombean").getRawPropertyValue("myfoundset");
    IFoundSetInternal foundSet = rawPropertyValue.getFoundset();
    rawPropertyValue.changeMonitor.clearChanges();
    foundSet.newRecord(0, false);
    Assert.assertEquals(FoundsetTypeChangeMonitor.SEND_FOUNDSET_SIZE | FoundsetTypeChangeMonitor.SEND_SELECTED_INDEXES, rawPropertyValue.changeMonitor.changeFlags);
    rawPropertyValue.changeMonitor.clearChanges();
    foundSet.deleteRecord(0);
    Assert.assertEquals(FoundsetTypeChangeMonitor.SEND_FOUNDSET_SIZE | FoundsetTypeChangeMonitor.SEND_SELECTED_INDEXES, rawPropertyValue.changeMonitor.changeFlags);
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Test(org.junit.Test)

Example 15 with IWebFormController

use of com.servoy.j2db.server.ngclient.IWebFormController in project servoy-client by Servoy.

the class FoundsetTest method foundsetViewportAllRecordChangedAndDeleted.

@Test
public // change rows in/near viewport
void foundsetViewportAllRecordChangedAndDeleted() throws // change rows in/near viewport
JSONException, // change rows in/near viewport
ServoyException {
    IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
    Assert.assertNotNull(form);
    WebFormComponent wc = form.getFormUI().getWebComponent("mycustombean");
    FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) wc.getRawPropertyValue("myfoundset");
    BrowserConverterContext allowBrowserConverterContext = new BrowserConverterContext(wc, PushToServerEnum.allow);
    FoundsetTypeViewport viewPort = rawPropertyValue.getViewPort();
    viewPort.setBounds(0, form.getFormModel().getSize());
    StringWriter stringWriter = new StringWriter();
    JSONWriter jsonWriter = new JSONWriter(stringWriter);
    rawPropertyValue.toJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext);
    Assert.assertTrue(new JSONObject("{\"serverSize\":18,\"foundsetId\":2,\"sortColumns\":\"\",\"selectedRowIndexes\":[0],\"multiSelect\":false,\"hasMoreRows\":false,\"viewPort\":{\"startIndex\":0,\"size\":18,\"rows\":[{\"_svyRowId\":\"1.1;_0\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.2;_1\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.3;_2\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.4;_3\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.5;_4\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.6;_5\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.7;_6\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.8;_7\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.9;_8\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.10;_9\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.11;_10\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.12;_11\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.13;_12\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.14;_13\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.15;_14\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.16;_15\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.17;_16\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.18;_17\",\"lastname\":\"value4\",\"firstname\":\"value3\"}]}}").similar(new JSONObject(stringWriter.toString())));
    form.getFormModel().fireFoundSetChanged();
    form.getFormModel().deleteRecord(0);
    stringWriter = new StringWriter();
    jsonWriter = new JSONWriter(stringWriter);
    rawPropertyValue.toJSON(jsonWriter, new DataConversion(), allowBrowserConverterContext);
    Assert.assertTrue(new JSONObject("{\"serverSize\":17,\"foundsetId\":2,\"sortColumns\":\"\",\"selectedRowIndexes\":[0],\"multiSelect\":false,\"hasMoreRows\":false,\"viewPort\":{\"startIndex\":0,\"size\":17,\"rows\":[{\"_svyRowId\":\"1.2;_0\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.3;_1\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.4;_2\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.5;_3\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.6;_4\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.7;_5\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"1.8;_6\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"1.9;_7\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.10;_8\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.11;_9\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.12;_10\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.13;_11\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.14;_12\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.15;_13\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.16;_14\",\"lastname\":\"value4\",\"firstname\":\"value3\"},{\"_svyRowId\":\"2.17;_15\",\"lastname\":\"value2\",\"firstname\":\"value1\"},{\"_svyRowId\":\"2.18;_16\",\"lastname\":\"value4\",\"firstname\":\"value3\"}]}}").similar(new JSONObject(stringWriter.toString())));
}
Also used : JSONWriter(org.json.JSONWriter) DataConversion(org.sablo.websocket.utils.DataConversion) StringWriter(java.io.StringWriter) JSONObject(org.json.JSONObject) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) BrowserConverterContext(org.sablo.specification.property.BrowserConverterContext) IWebFormController(com.servoy.j2db.server.ngclient.IWebFormController) Test(org.junit.Test)

Aggregations

IWebFormController (com.servoy.j2db.server.ngclient.IWebFormController)24 Test (org.junit.Test)21 JSONObject (org.json.JSONObject)12 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)10 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)9 StringWriter (java.io.StringWriter)9 JSONWriter (org.json.JSONWriter)9 BrowserConverterContext (org.sablo.specification.property.BrowserConverterContext)9 DataConversion (org.sablo.websocket.utils.DataConversion)8 JSONArray (org.json.JSONArray)4 Container (org.sablo.Container)4 FormScope (com.servoy.j2db.scripting.FormScope)3 Context (org.mozilla.javascript.Context)3 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)2 Form (com.servoy.j2db.persistence.Form)2 RhinoMapOrArrayWrapper (com.servoy.j2db.server.ngclient.component.RhinoMapOrArrayWrapper)2 ServoyException (com.servoy.j2db.util.ServoyException)2 JSONException (org.json.JSONException)2 WebComponent (org.sablo.WebComponent)2 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)1