Search in sources :

Example 1 with VariableBinding

use of com.centurylink.mdw.plugin.designer.model.VariableBinding in project mdw-designer by CenturyLinkCloud.

the class MappingEditor method getMappedVariableBindings.

private List<VariableBinding> getMappedVariableBindings(Map<String, String> map) {
    List<VariableBinding> bindings = new ArrayList<VariableBinding>();
    for (String variableName : map.keySet()) {
        VariableVO variableVO = getOwningProcess().getVariable(variableName);
        if (variableVO != null)
            bindings.add(new VariableBinding(variableVO, map.get(variableName)));
    }
    Collections.<VariableBinding>sort(bindings);
    return bindings;
}
Also used : ArrayList(java.util.ArrayList) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO) VariableBinding(com.centurylink.mdw.plugin.designer.model.VariableBinding)

Example 2 with VariableBinding

use of com.centurylink.mdw.plugin.designer.model.VariableBinding in project mdw-designer by CenturyLinkCloud.

the class MappingEditor method serializeMapping.

/**
 * Converts a list of variable bindings to a string value to be stored with
 * the activity attribute.
 */
public String serializeMapping(List<VariableBinding> bindings) {
    if (getProject().checkRequiredVersion(6, 0, 4)) {
        if (bindings.isEmpty())
            return "";
        JSONObject json = new JSONObject();
        try {
            for (VariableBinding variableBinding : bindings) {
                json.put(variableBinding.getVariableVO().getVariableName(), variableBinding.getExpression());
            }
        } catch (JSONException ex) {
            throw new StringParseException(ex.getMessage(), ex);
        }
        return json.toString();
    } else {
        StringBuffer sb = new StringBuffer();
        boolean first = true;
        for (VariableBinding variableBinding : bindings) {
            if (first)
                first = false;
            else
                sb.append(getRowDelimiter());
            sb.append(variableBinding.getVariableVO().getVariableName());
            sb.append(getColumnDelimiter());
            sb.append(StringHelper.escapeWithBackslash(variableBinding.getExpression() == null ? "" : variableBinding.getExpression(), ";"));
        }
        return sb.toString();
    }
}
Also used : StringParseException(com.centurylink.mdw.common.utilities.StringHelper.StringParseException) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) VariableBinding(com.centurylink.mdw.plugin.designer.model.VariableBinding)

Example 3 with VariableBinding

use of com.centurylink.mdw.plugin.designer.model.VariableBinding in project mdw-designer by CenturyLinkCloud.

the class SubProcessMappingSection method populateVariableBindingsTable.

private void populateVariableBindingsTable() {
    mappingEditor.disposeWidget();
    mappingEditor.setOwningProcess(subProcess);
    inputOutputVariables = getInputOutputVariables();
    List<ColumnSpec> columnSpecs = createColumnSpecs();
    mappingEditor.setColumnSpecs(columnSpecs);
    mappingEditor.render(composite, false);
    if (subProcess != null) {
        Map<String, String> map = StringHelper.parseMap(activity.getAttribute("variables"));
        // clear inapplicable bindings
        List<String> inapplicableVars = new ArrayList<>();
        for (String varName : map.keySet()) {
            boolean found = false;
            for (VariableVO inputVar : subProcess.getInputOutputVariables()) {
                if (inputVar.getName().equals(varName)) {
                    found = true;
                    break;
                }
            }
            if (!found)
                inapplicableVars.add(varName);
        }
        for (String inapplicableVar : inapplicableVars) map.remove(inapplicableVar);
        if (!inapplicableVars.isEmpty()) {
            String newAttrVal = StringHelper.formatMap(map);
            activity.setAttribute("variables", newAttrVal);
            activity.fireAttributeValueChanged("variables", newAttrVal);
        }
        List<VariableBinding> variableBindings = getVariableBindings(map);
        mappingEditor.setValue(variableBindings);
    }
    composite.layout(true);
}
Also used : ColumnSpec(com.centurylink.mdw.plugin.designer.properties.editor.ColumnSpec) ArrayList(java.util.ArrayList) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO) VariableBinding(com.centurylink.mdw.plugin.designer.model.VariableBinding)

Example 4 with VariableBinding

use of com.centurylink.mdw.plugin.designer.model.VariableBinding in project mdw-designer by CenturyLinkCloud.

the class SubProcessMappingSection method getVariableBindings.

/**
 * Returns a list of variable bindings corresponding to the input, output
 * and input/output variables of the subprocess, with expressions populated
 * based on the activity attribute map.
 */
private List<VariableBinding> getVariableBindings(Map<String, String> map) {
    List<VariableBinding> variableBindings = new ArrayList<>();
    for (VariableVO variableVO : inputOutputVariables.values()) {
        VariableBinding variableBinding = new VariableBinding(variableVO, null);
        if (map.containsKey(variableVO.getVariableName())) {
            variableBinding.setExpression(map.get(variableVO.getVariableName()));
        }
        variableBindings.add(variableBinding);
    }
    return variableBindings;
}
Also used : ArrayList(java.util.ArrayList) VariableVO(com.centurylink.mdw.model.value.variable.VariableVO) VariableBinding(com.centurylink.mdw.plugin.designer.model.VariableBinding)

Aggregations

VariableBinding (com.centurylink.mdw.plugin.designer.model.VariableBinding)4 VariableVO (com.centurylink.mdw.model.value.variable.VariableVO)3 ArrayList (java.util.ArrayList)3 StringParseException (com.centurylink.mdw.common.utilities.StringHelper.StringParseException)1 ColumnSpec (com.centurylink.mdw.plugin.designer.properties.editor.ColumnSpec)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1