Search in sources :

Example 1 with IPushToServerSpecialType

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

the class FoundsetLinkedTypeSabloValue method browserUpdatesReceived.

public void browserUpdatesReceived(Object newJSONValue, PropertyDescription wrappedPropertyDescription, PropertyDescription pd, IBrowserConverterContext dataConverterContext, ValueReference<Boolean> returnValueAdjustedIncommingValue) {
    PushToServerEnum pushToServer = BrowserConverterContext.getPushToServerValue(dataConverterContext);
    if (!wrappedValueInitialized) {
        Debug.error("Trying to update state for an uninitialized foundset linked property: " + wrappedPropertyDescription + " | " + webObjectContext);
        return;
    }
    if (!(newJSONValue instanceof JSONArray)) {
        // is a data push
        if (wrappedSabloValue instanceof DataproviderTypeSabloValue) {
            ((DataproviderTypeSabloValue) wrappedSabloValue).browserUpdateReceived(newJSONValue, dataConverterContext);
        }
        return;
    }
    if ((wrappedPropertyDescription instanceof IPushToServerSpecialType && ((IPushToServerSpecialType) wrappedPropertyDescription).shouldAlwaysAllowIncommingJSON()) || PushToServerEnum.allow.compareTo(pushToServer) <= 0) {
        try {
            JSONArray updates = (JSONArray) newJSONValue;
            for (int i = 0; i < updates.length(); i++) {
                JSONObject update = (JSONObject) updates.get(i);
                if (update.has(PROPERTY_CHANGE)) {
                    if (viewPortChangeMonitor != null) {
                        Debug.error("Trying to update single state value for a foundset linked record dependent property: " + wrappedPropertyDescription + " | " + webObjectContext);
                        return;
                    }
                    Object object = update.get(PROPERTY_CHANGE);
                    YT newWrappedValue = (YT) JSONUtils.fromJSONUnwrapped(wrappedSabloValue, object, wrappedPropertyDescription, dataConverterContext, returnValueAdjustedIncommingValue);
                    if (newWrappedValue != wrappedSabloValue) {
                        // TODO should we make current method return a completely new instance instead and leave component code do the rest?
                        if (wrappedSabloValue instanceof IDataLinkedPropertyValue)
                            ((IDataLinkedPropertyValue) wrappedSabloValue).detach();
                        setWrappedSabloValue(newWrappedValue);
                        if (wrappedSabloValue instanceof IDataLinkedPropertyValue)
                            ((IDataLinkedPropertyValue) wrappedSabloValue).attachToBaseObject(changeMonitor, wrappedComponentContext);
                    }
                } else if (update.has(ViewportDataChangeMonitor.VIEWPORT_CHANGED)) {
                    if (viewPortChangeMonitor == null) {
                        Debug.error("Trying to update some record value for a foundset linked non-record dependent property: " + wrappedPropertyDescription + " | " + webObjectContext);
                        return;
                    }
                    // property is linked to a foundset and the value of a property that depends on the record changed client side;
                    // in this case update DataAdapterList with the correct record and then set the value on the wrapped property
                    FoundsetTypeSabloValue foundsetPropertyValue = getFoundsetValue();
                    if (foundsetPropertyValue != null && foundsetPropertyValue.getFoundset() != null) {
                        JSONObject change = update.getJSONObject(ViewportDataChangeMonitor.VIEWPORT_CHANGED);
                        String rowIDValue = change.getString(FoundsetTypeSabloValue.ROW_ID_COL_KEY);
                        Object value = change.get(FoundsetTypeSabloValue.VALUE_KEY);
                        updatePropertyValueForRecord(foundsetPropertyValue, rowIDValue, value, wrappedPropertyDescription, dataConverterContext);
                    } else {
                        Debug.error("Component updates received for record linked property, but component is not linked to a foundset: " + update.get(ViewportDataChangeMonitor.VIEWPORT_CHANGED));
                    }
                }
            // as svyApply/data push for DPs does not go through here but through NGFormServiceHandler.executeMethod(String, JSONObject), the
            // "setApplyingDPValueFromClient" will be called from there not here...
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    } else {
        Debug.error("Foundset linked property (" + pd + ") that doesn't define a suitable pushToServer value (allow/shallow/deep) tried to update proxied value(s) serverside. Denying and sending back server value!");
        if (viewPortChangeMonitor != null)
            viewPortChangeMonitor.shouldSendWholeViewport();
        else
            changeMonitor.valueChanged();
    }
}
Also used : JSONObject(org.json.JSONObject) DataproviderTypeSabloValue(com.servoy.j2db.server.ngclient.property.types.DataproviderTypeSabloValue) IPushToServerSpecialType(org.sablo.specification.property.IPushToServerSpecialType) JSONArray(org.json.JSONArray) JSONObject(org.json.JSONObject) PushToServerEnum(org.sablo.specification.WebObjectSpecification.PushToServerEnum) JSONException(org.json.JSONException)

Aggregations

DataproviderTypeSabloValue (com.servoy.j2db.server.ngclient.property.types.DataproviderTypeSabloValue)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 PushToServerEnum (org.sablo.specification.WebObjectSpecification.PushToServerEnum)1 IPushToServerSpecialType (org.sablo.specification.property.IPushToServerSpecialType)1