Search in sources :

Example 1 with ISelectionMapper

use of org.pentaho.platform.api.engine.ISelectionMapper in project pentaho-platform by pentaho.

the class SecureFilterComponent method executeAction.

@Override
public boolean executeAction() {
    boolean parameterUINeeded = false;
    if (getOutputPreference() == IOutputHandler.OUTPUT_TYPE_PARAMETERS) {
        parameterUINeeded = true;
    }
    boolean stopHere = getInputBooleanValue(StandardSettings.HANDLE_ALL_PROMPTS, true);
    SelEntry entry;
    boolean isOk = true;
    // Set to true if this securefilter
    boolean causingPrompting = false;
    // component actually adds feeback parameters.
    for (Iterator it = selList.iterator(); it.hasNext(); ) {
        entry = (SelEntry) it.next();
        ISelectionMapper selMap = SelectionMapper.create(entry.selectionParam, entry.valueCol, entry.dispCol, entry.title, entry.displayStyle);
        // If we have a value for the input param, verify that it is within the selections
        if ((entry.inputParam.hasValue() || (entry.inputParam.hasDefaultValue() && !feedbackAllowed())) && !parameterUINeeded) {
            // TODO support numeric values here
            Object value = entry.inputParam.getValue();
            if (value instanceof String) {
                if ((selMap != null) && !selMap.hasValue((String) value)) {
                    if (!entry.isOptional || !"".equals(value)) {
                        // $NON-NLS-1$
                        error(Messages.getInstance().getErrorString("SecureFilterComponent.ERROR_0001_INVALID_SELECTION", entry.inputParam.getValue().toString(), // $NON-NLS-1$
                        entry.inputParam.getName()));
                        isOk = false;
                    }
                }
            // else this should be ok, we are just checking for selMap's existance
            } else if (value instanceof Object[]) {
                // test each item
                if (selMap != null) {
                    Object[] values = (Object[]) value;
                    for (Object element : values) {
                        if (!selMap.hasValue(element.toString())) {
                            if (!entry.isOptional || !"".equals(value)) {
                                // $NON-NLS-1$
                                error(Messages.getInstance().getErrorString("SecureFilterComponent.ERROR_0001_INVALID_SELECTION", entry.inputParam.getValue().toString(), // $NON-NLS-1$
                                entry.inputParam.getName()));
                                isOk = false;
                            }
                        }
                    }
                }
            // else this should be ok, we are just checking for selMap's existence
            } else {
                // we cannot validate this
                error(Messages.getInstance().getErrorString("SecureFilterComponent.ERROR_0001_INVALID_SELECTION", entry.inputParam.getValue().toString(), // $NON-NLS-1$
                entry.inputParam.getName()));
                isOk = false;
            }
        } else {
            // Need to prompt
            if (selMap == null) {
                entry.createFeedbackParam = true;
                if (!entry.isOptional) {
                    // trigger feedback below
                    causingPrompting = true;
                }
            } else if (!entry.promptOne && (selMap.selectionCount() == 1)) {
                entry.inputParam.setValue(selMap.getValueAt(0));
            } else if (!feedbackAllowed() && entry.isOptional) {
                isOk = true;
            } else if (!feedbackAllowed()) {
                isOk = false;
            } else {
                entry.createFeedbackParam = true;
                entry.selMap = selMap;
                if (!entry.isOptional) {
                    // trigger feedback below
                    causingPrompting = true;
                }
            }
        }
    }
    if (causingPrompting) {
        // Only make the call to createFeedbackParameter if causingPrompting is true.
        for (Iterator it = selList.iterator(); it.hasNext(); ) {
            entry = (SelEntry) it.next();
            if (entry.createFeedbackParam) {
                if (entry.selMap != null) {
                    createFeedbackParameter(entry.selMap, entry.inputParam.getName(), entry.inputParam.getValue(), entry.isOptional);
                } else {
                    // TODO support help/hints
                    createFeedbackParameter(entry.inputParam.getName(), entry.title, "", entry.inputParam.getValue().toString(), true, // $NON-NLS-1$
                    entry.isOptional);
                }
                entry.inputParam.setPromptStatus(IActionParameter.PROMPT_PENDING);
            }
        }
        promptNeeded();
        if (stopHere) {
            promptNow();
        }
        // we only want to add the hidden fields if this component has caused prompting to occur.
        for (int i = 0; i < hiddenList.size(); i++) {
            entry = (SelEntry) hiddenList.get(i);
            Object value = entry.inputParam.getValue();
            if (value instanceof String) {
                // $NON-NLS-1$
                createFeedbackParameter(entry.inputParam.getName(), entry.inputParam.getName(), "", (String) value, false);
            } else {
                // Support other types of hidden field parameters (like
                // Integer/Decimal/Etc.) by using toString.
                // $NON-NLS-1$
                createFeedbackParameter(entry.inputParam.getName(), entry.inputParam.getName(), "", value.toString(), false);
            }
        }
    }
    return isOk;
}
Also used : ISelectionMapper(org.pentaho.platform.api.engine.ISelectionMapper) Iterator(java.util.Iterator)

Aggregations

Iterator (java.util.Iterator)1 ISelectionMapper (org.pentaho.platform.api.engine.ISelectionMapper)1