Search in sources :

Example 1 with CallURL

use of com.centurylink.mdw.common.utilities.form.CallURL in project mdw-designer by CenturyLinkCloud.

the class FormPanel method performGenericAction.

private void performGenericAction(String action) {
    try {
        datadoc.setAttribute(FormDataDocument.ATTR_ACTION, action);
        datadoc.setAttribute(FormDataDocument.ATTR_FORM, formdoc.getId());
        datadoc.setMetaValue(FormDataDocument.META_PRIVILEGES, privileges);
        datadoc.setMetaValue(FormDataDocument.META_USER, dao.getCuid());
        // clear errors
        datadoc.clearErrors();
        String request = datadoc.format();
        String response = dao.engineCall(request);
        // System.out.println("Response: " + response);
        datadoc.load(response);
        List<String> errors = datadoc.getErrors();
        MbengNode node1;
        if (!datadoc.getRootNode().getKind().equals(FormDataDocument.KIND_FORMDATA)) {
            node1 = datadoc.getRootNode().getFirstChild();
            while (node1 != null && errors.size() == 0) {
                if (node1.getKind().contains("StatusMessage")) {
                    errors.add("SUCCESS".equals(node1.getValue()) ? "Unexpected server response." : node1.getValue());
                }
                node1 = node1.getNextSibling();
            }
            if (errors.size() == 0)
                errors.add("Unknown error from engine");
            // change back to form data document
            datadoc.load(request);
        }
        if (errors.size() > 0) {
            show_errors(errors);
        } else {
            String additionalAction = datadoc.getAttribute(FormDataDocument.ATTR_ACTION);
            CallURL callurl = additionalAction == null ? null : new CallURL(additionalAction);
            if (callurl == null) {
                String newFormName = datadoc.getAttribute(FormDataDocument.ATTR_FORM);
                resetData(newFormName, null);
            } else if (callurl.getAction().equals(FormConstants.ACTION_PROMPT)) {
                String message = datadoc.getMetaValue(FormDataDocument.META_PROMPT);
                if (message != null) {
                    show_info(message);
                }
                String newFormName = datadoc.getAttribute(FormDataDocument.ATTR_FORM);
                resetData(newFormName, null);
            } else if (callurl.getAction().equals(FormConstants.ACTION_DIALOG)) {
                String formName = callurl.getParameter(FormConstants.URLARG_FORMNAME);
                if (formName.startsWith(FormConstants.TABLE_ROW_DIALOG_PREFIX)) {
                    String tableId = formName.substring(FormConstants.TABLE_ROW_DIALOG_PREFIX.length());
                    MbengNode tableNode = canvas.getGenerator().getNodeById(tableId);
                    JTablePlus table = (JTablePlus) canvas.getGenerator().getWidget(tableNode);
                    int row = table.getSelectedRow();
                    if (row < 0)
                        throw new Exception("You need to select a row");
                    TableRowDialog dialog = new TableRowDialog(tableNode, table, row);
                    dialog.setVisible(true);
                } else {
                    show_dialog(formName, true);
                }
            } else if (callurl.getAction().equals(FormConstants.ACTION_OK)) {
                String message = datadoc.getMetaValue(FormDataDocument.META_PROMPT);
                if (message != null)
                    show_info(message);
                frame.setVisible(false);
            } else if (callurl.getAction().equals(FormConstants.ACTION_CANCEL)) {
                exit_copy = false;
                frame.setVisible(false);
            } else {
                String newFormName = datadoc.getAttribute(FormDataDocument.ATTR_FORM);
                resetData(newFormName, null);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        show_error(ex.getMessage());
    }
}
Also used : MbengNode(com.qwest.mbeng.MbengNode) CallURL(com.centurylink.mdw.common.utilities.form.CallURL) JTablePlus(com.centurylink.mdw.designer.utils.JTablePlus) MbengException(com.qwest.mbeng.MbengException)

Aggregations

CallURL (com.centurylink.mdw.common.utilities.form.CallURL)1 JTablePlus (com.centurylink.mdw.designer.utils.JTablePlus)1 MbengException (com.qwest.mbeng.MbengException)1 MbengNode (com.qwest.mbeng.MbengNode)1