Example #1
0
void WorkflowModel::setFixedValues(qint32 nodeid, const QString &formValues)
{
    try {
        SPWorkFlowNode node = _workflow->nodeById(nodeid);
        if (!node)
            return;

        IOperationMetaData op = node->operation();

        QStringList inputParameters = formValues.split('|');
        for (int i = 0; i < inputParameters.length(); ++i) {
            QString value = inputParameters[i].trimmed();
            WorkFlowParameter& parm = node->inputRef(i);
            parm.value(value, op->getInputParameters()[i]->type(), WorkFlowParameter::pkFIXED);
        }
    }catch(ErrorObject&){}

}
QStringList WorkflowModel::addOperation(const QString &id)
{
    QStringList* parameterEntrySet = new QStringList();
    bool ok;
    quint64 opid = id.toULongLong(&ok);
    Resource res = mastercatalog()->id2Resource(opid);

    if ( ok && res.isValid()){
        OVertex v = _workflow->addOperation({res});
        IOperationMetaData meta = _workflow->getOperationMetadata(v);
        std::vector<SPOperationParameter> inputs = meta->getInputParameters();
        for (int i = 0 ; i < inputs.size() ; i++) {
            _workflow->assignInputData(v, i);
            ++_inputParameterCount;
            int parameterIndex = _workflow->getWorkflowParameterIndex(v, i);
            parameterEntrySet->push_back(QString::number(parameterIndex) + "|insert");
        }
    }else {
       kernel()->issues()->log(QString(TR("Invalid operation id used in workflow %1")).arg(name()));
    }
    return *parameterEntrySet;
}
/*
    Add all workflow input fields for an operation to the json document. This happens both
    for internal connections and actual input nodes.

    Pre-assigned inputs (fixed values) are taken as is (it is assumed they point to actual existing objects)

    External inputs that are not specified remain empty (this should be avoided, because that
    invalidates the output Json file!).

    Internal inputs get a name (auto-generated) based on the name of the operation
    that provides the input and its corresponding output edge number. The user input folder
    is used to create an actual local file location.

    Every input is also added into a local file list. The list links the WMS layername
    with the local filename. This is necessary to find the correct local file, when the
    Json file is interpreted as a workflow.
 */
QJsonArray WorkflowJSONConnector::createJSONOperationInputList(const SPWorkFlowNode& node) {
    QJsonArray inputs;

    for (int i = 0; i < node->inputCount(); i++) {
        QJsonObject input;

        WorkFlowParameter& wfp = node->inputRef(i);
        input["url"] = QString("");
        input["local"] = QString("");
        input["value"] = QString("");
        input["name"] = wfp.label();
        input["id"] = wfp.order();
        input["description"] = wfp.description();

        input["change"] = false;
        input["show"] = false;
        input["type"] = QString("");
        if (wfp.state() == WorkFlowParameter::pkFIXED)
            input["value"] = wfp.value();

        IOperationMetaData op = node->operation();
        if (op.isValid()) {
            SPOperationParameter parm = op->getInputParameters()[i];
            input["optional"] = parm->isOptional();
            bool isExp = hasType(parm->type(), itSTRING) && wfp.value().contains('@');
            bool isNum = hasType(parm->type(), itNUMBER);
            bool isMap = hasType(parm->type(), itRASTER );    // or should this be itCOVERAGE?
            if (isNum || isMap) input["show"] = true;
            if (isNum) input["type"] = QString("number");
            if (isMap) input["type"] = QString("map");
            if (isExp) input["type"] = QString("expression");
        }
        inputs.append(input);
    }

    return inputs;
}