Search in sources :

Example 1 with FormAndTableDataProviderLookup

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

the class NGUtils method getDataProviderPropertyDescription.

public static PropertyDescription getDataProviderPropertyDescription(String dataProviderName, IApplication app, Form form, ITable table, boolean parseHTMLIfString, boolean useLocalDateTime) {
    FormAndTableDataProviderLookup dpLookup = new FormAndTableDataProviderLookup(app.getFlattenedSolution(), form, table);
    IDataProvider dp = null;
    try {
        dp = dpLookup.getDataProvider(dataProviderName);
    } catch (RepositoryException e) {
        Debug.error(e);
    }
    if (dp != null) {
        int dpType;
        if (dp instanceof IColumn || dp instanceof ColumnWrapper) {
            IColumn column = (dp instanceof IColumn) ? (IColumn) dp : ((ColumnWrapper) dp).getColumn();
            ColumnInfo ci = column.getColumnInfo();
            if (ci != null && ci.hasFlag(IBaseColumn.UUID_COLUMN)) {
                return UUID_DATAPROVIDER_CACHED_PD;
            }
            dpType = app.getFoundSetManager().getConvertedTypeForColumn(column, true);
        } else
            dpType = dp.getDataProviderType();
        return getDataProviderPropertyDescription(dpType, parseHTMLIfString, useLocalDateTime);
    }
    return null;
}
Also used : IColumn(com.servoy.j2db.persistence.IColumn) FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IDataProvider(com.servoy.j2db.persistence.IDataProvider)

Example 2 with FormAndTableDataProviderLookup

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

the class DataAdapterList method getStringValue.

public String getStringValue(String name) {
    String stringValue = TagResolver.formatObject(getValueObject(record, name), getApplication());
    ITable table = record != null ? record.getParentFoundSet().getTable() : null;
    FormAndTableDataProviderLookup dataproviderLookup = formController != null ? new FormAndTableDataProviderLookup(formController.getApplication().getFlattenedSolution(), formController.getForm(), table != null ? table : formController.getTable()) : null;
    return processValue(stringValue, name, dataproviderLookup);
}
Also used : FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) ITable(com.servoy.j2db.persistence.ITable)

Example 3 with FormAndTableDataProviderLookup

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

the class DataproviderTypeSabloValue method getValueForToJSON.

protected Object getValueForToJSON(Object uiValue, IBrowserConverterContext dataConverterContext) throws JSONException {
    Object jsonValueRepresentation;
    boolean valuelistDisplayValue = false;
    int valuelistDisplayType = 0;
    if (shouldResolveFromValuelistWithName != null) {
        ValueListTypeSabloValue valuelistSabloValue = (ValueListTypeSabloValue) FoundsetLinkedTypeSabloValue.unwrapIfNeeded(webObjectContext.getProperty(shouldResolveFromValuelistWithName));
        if (valuelistSabloValue != null && valuelistSabloValue.getValueList() != null) {
            valuelistDisplayValue = true;
            valuelistDisplayType = valuelistSabloValue.getValueList().getValueList().getDisplayValueType();
            if (valuelistSabloValue.getValueList().realValueIndexOf(uiValue) != -1) {
                try {
                    // TODO don't we have to apply the UI converter's toObject here as well in the unlikely case of a valuelist + UI converter? and also
                    // when searching we should then use the fromObject(uiValue) rather then uiValue directly I think
                    uiValue = valuelistSabloValue.getValueList().getElementAt(valuelistSabloValue.getValueList().realValueIndexOf(uiValue));
                } catch (Exception ex) {
                    Debug.error(ex);
                }
            } else if (valuelistSabloValue.getValueList() instanceof DBValueList) {
                try {
                    LookupValueList lookup = new LookupValueList(valuelistSabloValue.getValueList().getValueList(), dataAdapterList.getApplication(), ComponentFactory.getFallbackValueList(dataAdapterList.getApplication(), null, Types.OTHER, null, valuelistSabloValue.getValueList().getValueList()), null, dataAdapterList.getRecord());
                    if (lookup.realValueIndexOf(uiValue) != -1) {
                        // TODO don't we have to apply the UI converter's toObject here as well in the unlikely case of a valuelist + UI converter? and also
                        // when searching we should then use the fromObject(uiValue) rather then uiValue directly I think
                        uiValue = lookup.getElementAt(lookup.realValueIndexOf(uiValue));
                    }
                    lookup.deregister();
                } catch (Exception ex) {
                    Debug.error(ex);
                }
            }
        }
    }
    if (findMode) {
        // in UI show only strings in find mode (just like SC/WC do); if they are something else like real dates/numbers which could happen
        // from scripting, then show string representation
        jsonValueRepresentation = uiValue instanceof String ? uiValue : (uiValue != null ? String.valueOf(uiValue) : "");
    } else if (typeOfDP != null && !valuelistDisplayValue) {
        Object value = uiValue;
        // merged this change from SC, DisplaysAdapter
        if (value == null && com.servoy.j2db.dataprocessing.DataAdapterList.isCountOrAvgOrSumAggregateDataProvider(dataProviderID, new FormAndTableDataProviderLookup(servoyDataConverterContext.getApplication().getFlattenedSolution(), servoyDataConverterContext.getForm().getForm(), dataAdapterList.getRecord() != null ? dataAdapterList.getRecord().getParentFoundSet().getTable() : null)))
            value = Integer.valueOf(0);
        // that 'true' is a workaround for allowing directly a value instead of object or array
        EmbeddableJSONWriter ejw = new EmbeddableJSONWriter(true);
        DataConversion jsonDataConversion = new DataConversion();
        FullValueToJSONConverter.INSTANCE.toJSONValue(ejw, null, value, typeOfDP, jsonDataConversion, dataConverterContext);
        if (jsonDataConversion.getConversions().size() == 0)
            jsonDataConversion = null;
        String str = ejw.toJSONString();
        if (str == null || str.trim().length() == 0) {
            Debug.error("A dataprovider that is not able to send itself to client... (" + typeOfDP + ", " + uiValue + ")");
            str = "null";
        }
        jsonValueRepresentation = new JSONStringWithConversions(str, jsonDataConversion);
    } else if (valuelistDisplayValue && (valuelistDisplayType == IColumnTypes.DATETIME || valuelistDisplayType == IColumnTypes.INTEGER || valuelistDisplayType == IColumnTypes.NUMBER || valuelistDisplayType == IColumnTypes.MEDIA) && !(uiValue instanceof String)) {
        // that 'true' is a workaround for allowing directly a value instead of object or array
        EmbeddableJSONWriter ejw = new EmbeddableJSONWriter(true);
        DataConversion jsonDataConversion = new DataConversion();
        if (valuelistDisplayType == IColumnTypes.DATETIME) {
            NGDatePropertyType.NG_INSTANCE.toJSON(ejw, null, (Date) uiValue, null, jsonDataConversion, dataConverterContext);
        } else if (valuelistDisplayType == IColumnTypes.INTEGER) {
            IntPropertyType.INSTANCE.toJSON(ejw, null, (Integer) uiValue, null, jsonDataConversion, dataConverterContext);
        } else if (valuelistDisplayType == IColumnTypes.NUMBER) {
            DoublePropertyType.INSTANCE.toJSON(ejw, null, (Number) uiValue, null, jsonDataConversion, dataConverterContext);
        } else if (valuelistDisplayType == IColumnTypes.MEDIA) {
            MediaDataproviderPropertyType.INSTANCE.toJSON(ejw, null, uiValue, null, jsonDataConversion, dataConverterContext);
        }
        if (jsonDataConversion.getConversions().size() == 0)
            jsonDataConversion = null;
        String str = ejw.toJSONString();
        if (str == null || str.trim().length() == 0) {
            Debug.error("A dataprovider with resolveValuelist that is not able to send itself to client... (" + valuelistDisplayType + ", " + uiValue + ")");
            str = "null";
        }
        jsonValueRepresentation = new JSONStringWithConversions(str, jsonDataConversion);
    } else {
        jsonValueRepresentation = uiValue;
    }
    return jsonValueRepresentation;
}
Also used : DBValueList(com.servoy.j2db.dataprocessing.DBValueList) JSONException(org.json.JSONException) ParseException(java.text.ParseException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IJSONStringWithConversions(org.sablo.websocket.utils.JSONUtils.IJSONStringWithConversions) JSONStringWithConversions(org.sablo.websocket.utils.JSONUtils.JSONStringWithConversions) DataConversion(org.sablo.websocket.utils.DataConversion) EmbeddableJSONWriter(org.sablo.websocket.utils.JSONUtils.EmbeddableJSONWriter) FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) LookupValueList(com.servoy.j2db.dataprocessing.LookupValueList)

Example 4 with FormAndTableDataProviderLookup

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

the class DataproviderTypeSabloValue method dataProviderOrRecordChanged.

@Override
public void dataProviderOrRecordChanged(final IRecordInternal record, final String dataProvider, final boolean isFormDP, final boolean isGlobalDP, boolean fireChangeEvent) {
    // TODO can type or fieldFormat change, for example in scripting the format is reset (but type shouldn't really change)
    IDataProviderLookup dpLookup = new FormAndTableDataProviderLookup(servoyDataConverterContext.getApplication().getFlattenedSolution(), servoyDataConverterContext.getForm().getForm(), record != null ? record.getParentFoundSet().getTable() : null);
    Collection<PropertyDescription> properties = webObjectContext.getProperties(TypesRegistry.getType(FormatPropertyType.TYPE_NAME));
    FormatTypeSabloValue formatSabloValue = null;
    for (PropertyDescription formatPd : properties) {
        // see whether format if "for" this property (dataprovider)
        Object formatConfig = formatPd.getConfig();
        if (formatConfig instanceof String[] && Arrays.asList((String[]) formatConfig).indexOf(dpPD.getName()) != -1) {
            INGApplication application = servoyDataConverterContext.getApplication();
            formatSabloValue = (FormatTypeSabloValue) webObjectContext.getProperty(formatPd.getName());
            if (formatSabloValue != null) {
                if (formatSabloValue.getFormatDesignValue() != null) {
                    fieldFormat = ComponentFormat.getComponentFormat(formatSabloValue.getFormatDesignValue(), dataProviderID, dpLookup, application);
                }
                break;
            }
        }
    }
    if (fieldFormat != null) {
        typeOfDP = NGUtils.getDataProviderPropertyDescription(fieldFormat.uiType, getDataProviderConfig().hasParseHtml(), fieldFormat.parsedFormat.useLocalDateTime());
        if (record instanceof FindState) {
            ((FindState) record).setFormat(dataProviderID, fieldFormat.parsedFormat);
        }
    } else {
        // see type of dataprovider; this is done only once - first time we get a new record
        typeOfDP = NGUtils.getDataProviderPropertyDescription(dataProviderID, servoyDataConverterContext.getApplication(), servoyDataConverterContext.getForm().getForm(), record != null ? record.getParentFoundSet().getTable() : null, getDataProviderConfig().hasParseHtml(), formatSabloValue != null ? formatSabloValue.getComponentFormat().parsedFormat.useLocalDateTime() : false);
    }
    if (dpPD.hasTag(TAG_TYPE_NAME)) {
        IPropertyType<?> specType = TypesRegistry.getType((String) dpPD.getTag(TAG_TYPE_NAME));
        if (specType != null && (typeOfDP == null || !specType.getClass().isAssignableFrom(typeOfDP.getClass()))) {
            typeOfDP = new PropertyDescriptionBuilder().withName("Spec type hint").withType(specType).build();
        }
    }
    String dpID = dataProviderID;
    IDataProvider dp = null;
    if (dpLookup != null) {
        try {
            dp = dpLookup.getDataProvider(dataProviderID);
            if (dp != null) {
                dpID = dp.getDataProviderID();
            }
        } catch (RepositoryException e) {
            Debug.error(e);
        }
    }
    if (globalRelationName != null) {
        try {
            IFoundSetInternal newRelatedFoundset = servoyDataConverterContext.getApplication().getFoundSetManager().getGlobalRelatedFoundSet(globalRelationName);
            if (newRelatedFoundset != globalRelatedFoundset) {
                if (globalRelatedFoundsetListener == null) {
                    globalRelatedFoundsetListener = new IFoundSetEventListener() {

                        @Override
                        public void foundSetChanged(FoundSetEvent e) {
                            if (e.getType() == FoundSetEvent.CONTENTS_CHANGED) {
                                dataProviderOrRecordChanged(DataproviderTypeSabloValue.this.dataAdapterList.getRecord(), null, false, false, true);
                            }
                        }
                    };
                } else if (globalRelatedFoundset != null) {
                    globalRelatedFoundset.removeFoundSetEventListener(globalRelatedFoundsetListener);
                }
                globalRelatedFoundset = newRelatedFoundset;
                globalRelatedFoundset.addFoundSetEventListener(globalRelatedFoundsetListener);
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    if (relatedFoundsetSelectionListener != null) {
        try {
            ArrayList<IFoundSetInternal> newRelatedFoundsets = getRelatedFoundsets(record, relationName);
            boolean equals = testByReference(newRelatedFoundsets, this.relatedFoundsets);
            if (!equals) {
                IDataProvider column = dp;
                if (column instanceof ColumnWrapper) {
                    column = ((ColumnWrapper) column).getColumn();
                }
                boolean isAggregate = (column instanceof IColumn) ? ((IColumn) column).isAggregate() : false;
                if (isAggregate && relatedFoundsets.size() > 0) {
                    relatedFoundsets.get(relatedFoundsets.size() - 1).removeAggregateModificationListener(relatedRecordModificationListener);
                }
                for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
                    ((ISwingFoundSet) relatedFoundset).getSelectionModel().removeListSelectionListener(relatedFoundsetSelectionListener);
                }
                relatedFoundsets = newRelatedFoundsets;
                for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
                    ((ISwingFoundSet) relatedFoundset).getSelectionModel().addListSelectionListener(relatedFoundsetSelectionListener);
                }
                if (isAggregate && relatedFoundsets.size() > 0) {
                    relatedFoundsets.get(relatedFoundsets.size() - 1).addAggregateModificationListener(relatedRecordModificationListener);
                }
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    if (relatedRecordModificationListener != null) {
        try {
            ArrayList<IRecordInternal> newRelatedRecords = getRelatedRecords(record, relationName);
            boolean equals = testByReference(newRelatedRecords, this.relatedRecords);
            if (!equals) {
                for (IRecordInternal relatedRecord : relatedRecords) {
                    relatedRecord.removeModificationListener(relatedRecordModificationListener);
                }
                relatedRecords = newRelatedRecords;
                for (IRecordInternal relatedRecord : relatedRecords) {
                    relatedRecord.addModificationListener(relatedRecordModificationListener);
                }
            }
        } catch (Exception ex) {
            Debug.error(ex);
        }
    }
    Object v = com.servoy.j2db.dataprocessing.DataAdapterList.getValueObject(record, servoyDataConverterContext.getForm().getFormScope(), dpID);
    if (v == Scriptable.NOT_FOUND)
        v = null;
    if (fieldFormat != null && !findMode) {
        // if it has an UI converter, transform it from the record/scope value into the UI value
        v = ComponentFormat.applyUIConverterToObject(v, dataProviderID, servoyDataConverterContext.getApplication().getFoundSetManager(), fieldFormat);
    }
    v = replaceTagsIfNeeded(v);
    boolean changed = ((v != uiValue) && (v == null || !v.equals(uiValue)));
    uiValue = v;
    if (changed) {
        jsonValue = null;
    }
    if (// if it is a foundset related DAL then always call valuechanged (the value can be of a previous row)
    fireChangeEvent && (changed || dataAdapterList instanceof FoundsetDataAdapterList)) {
        changeMonitor.valueChanged();
    }
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) PropertyDescriptionBuilder(org.sablo.specification.PropertyDescriptionBuilder) IDataProvider(com.servoy.j2db.persistence.IDataProvider) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) FindState(com.servoy.j2db.dataprocessing.FindState) FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) FoundsetDataAdapterList(com.servoy.j2db.server.ngclient.property.FoundsetDataAdapterList) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ColumnWrapper(com.servoy.j2db.persistence.ColumnWrapper) RepositoryException(com.servoy.j2db.persistence.RepositoryException) FoundSetEvent(com.servoy.j2db.dataprocessing.FoundSetEvent) JSONException(org.json.JSONException) ParseException(java.text.ParseException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) PropertyDescription(org.sablo.specification.PropertyDescription) IColumn(com.servoy.j2db.persistence.IColumn) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup) IFoundSetEventListener(com.servoy.j2db.dataprocessing.IFoundSetEventListener)

Example 5 with FormAndTableDataProviderLookup

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

the class FormatTypeSabloValue method getSabloValue.

protected ComponentFormat getSabloValue(String formatValue, String dataproviderId, Object valuelistId, String foundsetId, IWebObjectContext webObjectCntxt) {
    INGApplication application = ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getApplication();
    IDataProviderLookup dataProviderLookup = null;
    // IMPORTANT: here we use the for: configs in .spec file
    // 
    // if you have for: [valuelist, dataprovider] then 2 things can happen:
    // - valuelist if it has both real and display values - forces the type; it is either TEXT (custom vl., global method vl.) or the 'display' column type in case it's a DB valuelist
    // - valuelist if not real/display but only one kind of values: here it is required in docs in the spec file that the valuelist property also defines "for": dataprovider if format
    // defines both "for" valuelist and dataprovider => valuelist doesn't force the type and then the dataprovider will decide the type
    // 
    // if you have just for: dataprovider the the dataprovider property determines the type
    // if you have just for: valuelist (TODO) - this is currently not properly supported - as here we should get the type always from the VL (for both display and real values) - as we don't have a dataprovider to fall back on
    isValuelistFormatSet = false;
    if (valuelistId != null) {
        // if we have a "for" valuelist, see if this valuelist forces the format type due to display values (when they are separate from real values)
        // otherwise it will do nothing and loop/fallback to the other if clause below which checks the "for" dataprovider
        ValueList valuelistPersist = ValueListTypeSabloValue.getValuelistPersist(valuelistId, application);
        if (valuelistPersist != null) {
            IDataProvider dataProvider = null;
            ITable table;
            try {
                if (valuelistPersist.getRelationName() != null) {
                    Relation[] relations = application.getFlattenedSolution().getRelationSequence(valuelistPersist.getRelationName());
                    table = application.getFlattenedSolution().getTable(relations[relations.length - 1].getForeignDataSource());
                } else {
                    table = application.getFlattenedSolution().getTable(valuelistPersist.getDataSource());
                }
                if (table != null) {
                    // if the format is for a table valuelist - the type to be used is the one of the dp chosen as 'display' in the valuelist
                    String dp = null;
                    // if show == real then we can use show anyway cause there is only one value for both real and display; if show != real we care about show
                    int showDataProviders = valuelistPersist.getShowDataProviders();
                    if ((showDataProviders & 1) != 0) {
                        dp = valuelistPersist.getDataProviderID1();
                    }
                    if ((showDataProviders & 2) != 0) {
                        // display value is a concat of multiple columns, so a string; not even sure if format property makes sense, but it is for a String then
                        if (dp != null)
                            return ComponentFormat.getComponentFormat(formatValue, IColumnTypes.TEXT, application);
                        dp = valuelistPersist.getDataProviderID2();
                    }
                    if ((showDataProviders & 4) != 0) {
                        // display value is a concat of multiple columns, so a string; not even sure if format property makes sense, but it is for a String then
                        if (dp != null)
                            return ComponentFormat.getComponentFormat(formatValue, IColumnTypes.TEXT, application);
                        dp = valuelistPersist.getDataProviderID3();
                    }
                    if (dp != null) {
                        dataProvider = application.getFlattenedSolution().getDataProviderForTable(table, dp);
                    }
                    isValuelistFormatSet = true;
                    return ComponentFormat.getComponentFormat(formatValue, dataProvider, application, true);
                } else if (valuelistPersist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
                    IValueList realValuelist = null;
                    ValueListTypeSabloValue valuelistSabloValue = (ValueListTypeSabloValue) FoundsetLinkedTypeSabloValue.unwrapIfNeeded(webObjectContext.getProperty(propertyDependencies.valueListPropertyName));
                    if (valuelistSabloValue != null) {
                        // take it from property, may not be the shared instance in case setvaluelistitems on component was used
                        realValuelist = valuelistSabloValue.getValueList();
                    }
                    if (realValuelist == null) {
                        realValuelist = com.servoy.j2db.component.ComponentFactory.getRealValueList(application, valuelistPersist, true, Types.OTHER, ComponentFormat.getComponentFormat(formatValue, dataproviderId, null, application, true).parsedFormat, null, true);
                    }
                    if (realValuelist.hasRealValues()) {
                        // if custom vl has both real and display values, the display values are TEXT (format is for those)
                        // of if it has displayValueType set, use that
                        isValuelistFormatSet = true;
                        int realValueDisplayType = realValuelist.getValueList().getDisplayValueType();
                        return ComponentFormat.getComponentFormat(formatValue, realValueDisplayType != 0 ? realValueDisplayType : IColumnTypes.TEXT, application);
                    }
                } else if (valuelistPersist.getValueListType() == IValueListConstants.GLOBAL_METHOD_VALUES) {
                    PropertyDescription vlPD = webObjectCntxt.getPropertyDescription(propertyDependencies.valueListPropertyName);
                    Object vlPDConfig = null;
                    if (vlPD != null) {
                        vlPDConfig = vlPD.getConfig();
                        if (vlPDConfig instanceof FoundsetLinkedConfig)
                            vlPDConfig = ((FoundsetLinkedConfig) vlPDConfig).getWrappedConfig();
                    }
                    boolean lazyLoad = valuelistPersist.getLazyLoading() && vlPDConfig instanceof ValueListConfig && ((ValueListConfig) vlPDConfig).getLazyLoading();
                    if (!lazyLoad) {
                        IValueList realValuelist = com.servoy.j2db.component.ComponentFactory.getRealValueList(application, valuelistPersist, true, Types.OTHER, null, null, true);
                        if (realValuelist instanceof GlobalMethodValueList) {
                            ((GlobalMethodValueList) realValuelist).fill(null, "", null);
                            if (realValuelist.hasRealValues() || realValuelist.getSize() == 0 || (realValuelist.getSize() == 1 && valuelistPersist.getAddEmptyValue() == IValueListConstants.EMPTY_VALUE_ALWAYS)) {
                                // if global method vl has both real and display values, the display values are TEXT (format is for those)
                                // of if it has displayValueType set, use that
                                isValuelistFormatSet = true;
                                int realValueDisplayType = realValuelist.getValueList().getDisplayValueType();
                                return ComponentFormat.getComponentFormat(formatValue, realValueDisplayType != 0 ? realValueDisplayType : IColumnTypes.TEXT, application);
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
    // here - we want to fall back to the dataprovider if available in for: [ ..., dataprovider] if valuelist didn't force a certain display type on the format
    }
    if (dataproviderId != null && foundsetId != null) {
        ITable table = null;
        Form form = ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
        // always assume now that the the properties has the foundset property name.
        FoundsetTypeSabloValue runtimeValOfFoundset = (FoundsetTypeSabloValue) webObjectCntxt.getUnderlyingWebObject().getProperty(this.propertyDependencies.foundsetPropertyName);
        if (runtimeValOfFoundset != null && runtimeValOfFoundset.getFoundset() != null && runtimeValOfFoundset.getFoundset().getDataSource().equals(foundsetId)) {
            table = runtimeValOfFoundset.getFoundset().getTable();
        }
        if (table == null)
            table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(foundsetId, application, form);
        if (table != null) {
            dataProviderLookup = new FormAndTableDataProviderLookup(application.getFlattenedSolution(), form, table);
        }
    // else it will be searched for in form's context and table as below
    }
    if (dataProviderLookup == null) {
        WebObjectSpecification spec = ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getParent().getSpecification();
        if (spec != null) {
            Collection<PropertyDescription> formComponentProperties = spec.getProperties(FormComponentPropertyType.INSTANCE);
            if (formComponentProperties != null) {
                for (PropertyDescription property : formComponentProperties) {
                    if (property.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig) property.getConfig()).forFoundset != null) {
                        FoundsetTypeSabloValue runtimeValOfFoundset = (FoundsetTypeSabloValue) ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getParent().getProperty(((ComponentTypeConfig) property.getConfig()).forFoundset);
                        ITable table = null;
                        Form form = ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
                        if (runtimeValOfFoundset.getFoundset() != null)
                            table = runtimeValOfFoundset.getFoundset().getTable();
                        if (table == null)
                            table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(runtimeValOfFoundset.getFoundsetSelector(), application, form);
                        if (table != null) {
                            dataProviderLookup = new FormAndTableDataProviderLookup(application.getFlattenedSolution(), form, table);
                        }
                        break;
                    }
                }
            }
        }
    }
    if (dataProviderLookup == null && application != null)
        dataProviderLookup = application.getFlattenedSolution().getDataproviderLookup(application.getFoundSetManager(), ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm());
    ComponentFormat format = ComponentFormat.getComponentFormat(formatValue, dataproviderId, dataProviderLookup, application, true);
    return format;
}
Also used : WebObjectSpecification(org.sablo.specification.WebObjectSpecification) ValueList(com.servoy.j2db.persistence.ValueList) GlobalMethodValueList(com.servoy.j2db.dataprocessing.GlobalMethodValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) FoundsetLinkedConfig(com.servoy.j2db.server.ngclient.property.FoundsetLinkedConfig) GlobalMethodValueList(com.servoy.j2db.dataprocessing.GlobalMethodValueList) IDataProvider(com.servoy.j2db.persistence.IDataProvider) Relation(com.servoy.j2db.persistence.Relation) INGApplication(com.servoy.j2db.server.ngclient.INGApplication) IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) FormAndTableDataProviderLookup(com.servoy.j2db.FormAndTableDataProviderLookup) ITable(com.servoy.j2db.persistence.ITable) ComponentTypeConfig(com.servoy.j2db.server.ngclient.property.ComponentTypeConfig) IValueList(com.servoy.j2db.dataprocessing.IValueList) ComponentFormat(com.servoy.j2db.component.ComponentFormat) ValueListConfig(com.servoy.j2db.server.ngclient.property.ValueListConfig) PropertyDescription(org.sablo.specification.PropertyDescription) FoundsetTypeSabloValue(com.servoy.j2db.server.ngclient.property.FoundsetTypeSabloValue) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup)

Aggregations

FormAndTableDataProviderLookup (com.servoy.j2db.FormAndTableDataProviderLookup)5 IDataProvider (com.servoy.j2db.persistence.IDataProvider)3 RepositoryException (com.servoy.j2db.persistence.RepositoryException)3 ColumnWrapper (com.servoy.j2db.persistence.ColumnWrapper)2 IColumn (com.servoy.j2db.persistence.IColumn)2 IDataProviderLookup (com.servoy.j2db.persistence.IDataProviderLookup)2 ITable (com.servoy.j2db.persistence.ITable)2 INGApplication (com.servoy.j2db.server.ngclient.INGApplication)2 ParseException (java.text.ParseException)2 JSONException (org.json.JSONException)2 PropertyDescription (org.sablo.specification.PropertyDescription)2 ComponentFormat (com.servoy.j2db.component.ComponentFormat)1 DBValueList (com.servoy.j2db.dataprocessing.DBValueList)1 FindState (com.servoy.j2db.dataprocessing.FindState)1 FoundSetEvent (com.servoy.j2db.dataprocessing.FoundSetEvent)1 GlobalMethodValueList (com.servoy.j2db.dataprocessing.GlobalMethodValueList)1 IFoundSetEventListener (com.servoy.j2db.dataprocessing.IFoundSetEventListener)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)1 IValueList (com.servoy.j2db.dataprocessing.IValueList)1