Search in sources :

Example 21 with UUID

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

the class FormPropertyType method toTemplateJSONValue.

@Override
public JSONWriter toTemplateJSONValue(JSONWriter writer, String key, Object formElementValue, PropertyDescription pd, DataConversion browserConversionMarkers, FormElementContext formElementContext) throws JSONException {
    if (formElementValue == null)
        return writer;
    FlattenedSolution fs = formElementContext.getFlattenedSolution();
    Form form = null;
    if (formElementValue instanceof Integer) {
        form = fs.getForm(((Integer) formElementValue).intValue());
    } else if (formElementValue instanceof String || formElementValue instanceof UUID) {
        form = fs.getForm(formElementValue.toString());
        if (form == null) {
            form = (Form) fs.searchPersist(formElementValue.toString());
        }
    }
    if (form != null) {
        writer.key(key);
        writer.value(form.getName());
        if (CurrentWindow.safeGet() instanceof INGClientWindow) {
            ((INGClientWindow) CurrentWindow.get()).registerAllowedForm(form.getName(), formElementContext.getFormElement());
        }
    }
    return writer;
}
Also used : INGClientWindow(com.servoy.j2db.server.ngclient.INGClientWindow) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) FlattenedSolution(com.servoy.j2db.FlattenedSolution) UUID(com.servoy.j2db.util.UUID)

Example 22 with UUID

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

the class FormElementHelper method getFormComponentCache.

public FormComponentCache getFormComponentCache(INGFormElement formElement, PropertyDescription pd, JSONObject formElementValue, Form form, FlattenedSolution fs) {
    ConcurrentMap<UUID, Map<String, FormComponentCache>> cache = formElement.getDesignId() != null ? formComponentElementsForDesign : formComponentElements;
    Solution solutionCopy = fs.getSolutionCopy(false);
    FlattenedSolution usedFS = getSharedFlattenedSolution(fs);
    if (solutionCopy != null && solutionCopy.getForm(formElement.getForm().getName()) != null) {
        usedFS = fs;
        // if the form is a solution model for we can't use the standard caches.
        cache = solutionCopy.getRuntimeProperty(SOLUTION_MODEL_CACHE);
        if (cache == null) {
            cache = new ConcurrentHashMap<UUID, Map<String, FormComponentCache>>();
            solutionCopy.setRuntimeProperty(SOLUTION_MODEL_CACHE, cache);
        }
    }
    return getFormComponentFromCache(formElement, pd, formElementValue, form, usedFS, cache);
}
Also used : FlattenedSolution(com.servoy.j2db.FlattenedSolution) UUID(com.servoy.j2db.util.UUID) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) WeakHashMap(java.util.WeakHashMap) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 23 with UUID

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

the class JSDatabaseManager method js_convertToDataSet.

/**
 * @clonedesc js_convertToDataSet(IFoundSetInternal)
 *
 * @sampleas js_convertToDataSet(IFoundSetInternal)
 *
 * @param values The values array.
 * @param dataproviderNames The property names array.
 *
 * @return JSDataSet with the data.
 */
public JSDataSet js_convertToDataSet(Object[] values, String[] dataproviderNames) {
    if (values == null) {
        return null;
    }
    // $NON-NLS-1$
    String[] dpnames = { "id" };
    ColumnType[] dptypes = { ColumnType.getInstance(IColumnTypes.INTEGER, Integer.MAX_VALUE, 0) };
    List<Object[]> lst = new ArrayList<Object[]>();
    Object[] array = values;
    if (dataproviderNames != null) {
        dpnames = dataproviderNames;
    }
    Map<String, Method> getters = new HashMap<String, Method>();
    for (Object o : array) {
        if (o instanceof Number || o instanceof String || o instanceof UUID || o instanceof Date) {
            if (o instanceof Double && ((Double) o).doubleValue() == ((Double) o).intValue()) {
                o = new Integer(((Double) o).intValue());
            }
            lst.add(new Object[] { o });
        } else if (o instanceof Scriptable) {
            List<Object> row = new ArrayList<Object>();
            for (String dpname : dpnames) {
                if (((Scriptable) o).has(dpname, (Scriptable) o))
                    row.add(ScriptVariableScope.unwrap(((Scriptable) o).get(dpname, (Scriptable) o)));
            }
            if (dpnames.length != row.size() || dpnames.length == 0) {
                // for backward compatibility
                lst.add(new Object[] { o });
            } else {
                lst.add(row.toArray());
            }
        } else if (o != null) {
            // try reflection
            List<Object> row = new ArrayList<Object>();
            for (String dpname : dpnames) {
                Method m = getMethod(o, dpname, getters);
                if (m != null) {
                    try {
                        row.add(m.invoke(o, (Object[]) null));
                    } catch (Exception e) {
                        Debug.error(e);
                    }
                }
            }
            if (dpnames.length != row.size() || dpnames.length == 0) {
                // for backward compatibility
                lst.add(new Object[] { o });
            } else {
                lst.add(row.toArray());
            }
        }
    }
    return new JSDataSet(application, BufferedDataSetInternal.createBufferedDataSet(dpnames, dptypes, lst, false));
}
Also used : ColumnType(com.servoy.j2db.query.ColumnType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) QueryString(com.servoy.j2db.persistence.QueryString) Method(java.lang.reflect.Method) Scriptable(org.mozilla.javascript.Scriptable) IScriptable(com.servoy.j2db.scripting.IScriptable) Date(java.util.Date) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) SQLException(java.sql.SQLException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) NativeObject(org.mozilla.javascript.NativeObject) List(java.util.List) ArrayList(java.util.ArrayList) UUID(com.servoy.j2db.util.UUID)

Aggregations

UUID (com.servoy.j2db.util.UUID)23 RepositoryException (com.servoy.j2db.persistence.RepositoryException)6 RemoteException (java.rmi.RemoteException)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 JSONObject (org.json.JSONObject)5 IPersist (com.servoy.j2db.persistence.IPersist)4 ServoyException (com.servoy.j2db.util.ServoyException)4 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)4 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)3 Form (com.servoy.j2db.persistence.Form)3 Date (java.util.Date)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ApplicationException (com.servoy.j2db.ApplicationException)2 FlattenedSolution (com.servoy.j2db.FlattenedSolution)2 JSDataSet (com.servoy.j2db.dataprocessing.JSDataSet)2 AbstractBase (com.servoy.j2db.persistence.AbstractBase)2 ChangeHandler (com.servoy.j2db.persistence.ChangeHandler)2 ISupportChilds (com.servoy.j2db.persistence.ISupportChilds)2