Package org.joget.apps.form.model

Examples of org.joget.apps.form.model.FormRowSet


     */
    protected FormRowSet getRows(FormData formData) {
        if (cachedRowSet == null) {
            String id = getPropertyString(FormUtil.PROPERTY_ID);
            String param = FormUtil.getElementParameterName(this);
            FormRowSet rowSet = new FormRowSet();
            rowSet.setMultiRow(true);

            // get headers
            Map<String, String> headerMap = getHeaderMap(formData);

            // read from 'value' property
            String json = getPropertyString(FormUtil.PROPERTY_VALUE);
            try {
                rowSet = parseFormRowSetFromJson(json);
            } catch (Exception ex) {
                LogUtil.error(Grid.class.getName(), ex, "Error parsing grid JSON");
            }

            // read from request if available.
            boolean continueLoop = true;
            int i = 0;
            while (continueLoop) {
                FormRow row = new FormRow();
                for (String header : headerMap.keySet()) {
                    String paramName = param + "_" + header + "_" + i;
                    String paramValue = formData.getRequestParameter(paramName);
                    if (paramValue != null) {
                        row.setProperty(header, paramValue);
                    }
                }
                i++;
                if (!row.isEmpty()) {
                    if (i == 0) {
                        // reset rowset
                        rowSet = new FormRowSet();
                    }
                    rowSet.add(row);
                } else {
                    // no more rows, stop looping
                    continueLoop = false;
                }
            }

            if (!FormUtil.isFormSubmitted(this, formData)) {
                // load from binder if available
                FormRowSet binderRowSet = formData.getLoadBinderData(this);
                if (binderRowSet != null) {
                    if (!binderRowSet.isMultiRow()) {
                        // parse from String
                        if (!binderRowSet.isEmpty()) {
                            FormRow row = binderRowSet.get(0);
                            String jsonValue = row.getProperty(id);
                            try {
                                rowSet = parseFormRowSetFromJson(jsonValue);
                            } catch (Exception ex) {
                                LogUtil.error(Grid.class.getName(), ex, "Error parsing grid JSON");
View Full Code Here


     * @param json
     * @return
     * @throws JSONException
     */
    protected FormRowSet parseFormRowSetFromJson(String json) throws JSONException {
        FormRowSet rowSet = new FormRowSet();
        rowSet.setMultiRow(false);

        if (json != null && json.trim().length() > 0) {
            // loop thru each row in json array
            JSONArray jsonArray = new JSONArray(json);
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonRow = (JSONObject) jsonArray.get(i);

                // create row and populate fields
                FormRow row = new FormRow();
                JSONArray fields = jsonRow.names();
                if (fields != null && fields.length() > 0) {
                    for (int k = 0; k < fields.length(); k++) {
                        String fieldName = fields.getString(k);
                        String value = jsonRow.getString(fieldName);
                        row.setProperty(fieldName, value);
                    }
                }
                rowSet.add(row);
            }
        }
        return rowSet;
    }
View Full Code Here

                        return q.list();
                    }
                });

        FormRowSet rowSet = new FormRowSet();
        rowSet.addAll(result);
        return rowSet;
    }
View Full Code Here

            }
        }
        Document document = (Document)formRowDocument.cloneNode(true);

        // set entity name for form
        FormRowSet rowSet = (FormRowSet) metaData[2];
        pc.setEntityName(entityName);

        // set column names
        Collection<String> formFields = null;
        if (rowSet != null) {
View Full Code Here

    protected String retrieveFormRowId(FormData formResult) {
        String formRowId = null;
        Collection<FormStoreBinder> binders = formResult.getStoreBinders();
        for (FormStoreBinder binder : binders) {
            if (binder instanceof FormStoreBinder) {
                FormRowSet rowSet = formResult.getStoreBinderData(binder);
                if (!rowSet.isEmpty()) {
                    FormRow row = rowSet.get(0);
                    formRowId = row.getProperty("FORM_ID"); // TODO: use constant for form ID field
                }
                break;
            }
        }
View Full Code Here

     * @param primaryKeyValue
     * @return null if the form is not available, empty FormRowSet if the form is available but record is not found.
     */
    @Override
    public FormRowSet loadFormData(String appId, String version, String formDefId, String primaryKeyValue) {
        FormRowSet results = null;
        Form form = viewDataForm(appId, version, formDefId, null, null, null, null, null, null);
        if (form != null) {
            results = loadFormData(form, primaryKeyValue);
        }
        return results;
View Full Code Here

     * @param primaryKeyValue
     * @param transactional Determines whether the DAO method to call i.e. transactional or non-transactional
     * @return null if the form is not available, empty FormRowSet if the form is available but record is not found.
     */
    protected FormRowSet internalLoadFormData(Form form, String primaryKeyValue, boolean transactional) {
        FormRowSet results = null;
        if (form != null) {
            results = new FormRowSet();
            results.setMultiRow(false);
            if (primaryKeyValue != null && primaryKeyValue.trim().length() > 0) {
                FormRow row = (transactional) ? formDataDao.load(form, primaryKeyValue) : formDataDao.loadWithoutTransaction(form, primaryKeyValue);
                if (row != null) {
                    results.add(row);
                }
                LogUtil.debug(getClass().getName(), "  -- Loaded form data row [" + primaryKeyValue + "] for form [" + form.getProperty(FormUtil.PROPERTY_ID) + "] from table [" + form.getProperty(FormUtil.PROPERTY_TABLE_NAME) + "]");
            }
        }
        return results;
View Full Code Here

     * @param primaryKeyValue
     * @return
     */
    @Override
    public FormRowSet storeFormData(String appId, String version, String formDefId, FormRowSet rows, String primaryKeyValue) {
        FormRowSet results = null;
        Form form = viewDataForm(appId, version, formDefId, null, null, null, null, null, null);
        if (form != null) {
            results = storeFormData(form, rows, primaryKeyValue);
        }
        return results;
View Full Code Here

     * @param primaryKeyValue For single-row data. If null, a UUID will be generated. For multi-row data, this value is not used.
     * @return
     */
    @Override
    public FormRowSet storeFormData(Form form, FormRowSet rows, String primaryKeyValue) {
        FormRowSet results = null;
        if (form != null && rows != null && !rows.isEmpty()) {

            // determine rows to store
            results = new FormRowSet();
            if (!rows.isMultiRow()) {
                results.add(rows.get(0));
            } else {
                primaryKeyValue = null;
                results.addAll(rows);
            }

            // iterate through rows
            for (int i = 0; i < results.size(); i++) {
                FormRow row = results.get(i);
                String rowPrimaryKeyValue = row.getId();

                // set id
                if (rowPrimaryKeyValue == null || rowPrimaryKeyValue.trim().length() == 0) {
                    rowPrimaryKeyValue = primaryKeyValue;
                }
                if (rowPrimaryKeyValue == null || rowPrimaryKeyValue.trim().length() == 0) {
                    // no primary key value specified, generate new primary key value
                    rowPrimaryKeyValue = UuidGenerator.getInstance().getUuid();
                }
                row.setId(rowPrimaryKeyValue);
                if (!rows.isMultiRow() && (primaryKeyValue == null || primaryKeyValue.trim().isEmpty())) {
                    primaryKeyValue = rowPrimaryKeyValue;
                }

                // set meta data
                Date currentDate = new Date();
                row.setDateModified(currentDate);
                Date dateCreated = null;
                FormRowSet loadedRow = loadFormDataWithoutTransaction(form, rowPrimaryKeyValue);
                if (loadedRow != null && loadedRow.iterator().hasNext()) {
                    dateCreated = loadedRow.iterator().next().getDateCreated();
                }
                if (dateCreated == null) {
                    dateCreated = currentDate;
                }
                row.setDateCreated(dateCreated);
View Full Code Here

    }

    @Override
    public FormRowSet formatData(FormData formData) {
        // get form rowset
        FormRowSet rowSet = getRows(formData);
        rowSet.setMultiRow(true);

        // TODO: set foreign key?

        return rowSet;
    }
View Full Code Here

TOP

Related Classes of org.joget.apps.form.model.FormRowSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.