Search in sources :

Example 1 with UnknownParamException

use of org.apache.hop.core.parameters.UnknownParamException in project hop by apache.

the class WorkflowMeta method getXml.

/**
 * Gets the XML representation of this workflow.
 *
 * @return the XML representation of this workflow
 * @throws HopException if any errors occur during generation of the XML
 * @see IXml#getXml(IVariables)
 * @param variables
 */
@Override
public String getXml(IVariables variables) throws HopException {
    StringBuilder xml = new StringBuilder(500);
    xml.append(XmlHandler.getLicenseHeader(variables));
    xml.append(XmlHandler.openTag(XML_TAG)).append(Const.CR);
    xml.append("  ").append(// lossy if name is sync'ed with filename
    XmlHandler.addTagValue("name", getName()));
    xml.append("  ").append(XmlHandler.addTagValue("name_sync_with_filename", nameSynchronizedWithFilename));
    xml.append("  ").append(XmlHandler.addTagValue("description", description));
    xml.append("  ").append(XmlHandler.addTagValue("extended_description", extendedDescription));
    xml.append("  ").append(XmlHandler.addTagValue("workflow_version", workflowVersion));
    if (workflowStatus >= 0) {
        xml.append("  ").append(XmlHandler.addTagValue("workflow_status", workflowStatus));
    }
    xml.append("  ").append(XmlHandler.addTagValue("created_user", createdUser));
    xml.append("  ").append(XmlHandler.addTagValue("created_date", XmlHandler.date2string(createdDate)));
    xml.append("  ").append(XmlHandler.addTagValue("modified_user", modifiedUser));
    xml.append("  ").append(XmlHandler.addTagValue("modified_date", XmlHandler.date2string(modifiedDate)));
    xml.append("    ").append(XmlHandler.openTag(XML_TAG_PARAMETERS)).append(Const.CR);
    String[] parameters = listParameters();
    for (int idx = 0; idx < parameters.length; idx++) {
        xml.append("      ").append(XmlHandler.openTag("parameter")).append(Const.CR);
        xml.append("        ").append(XmlHandler.addTagValue("name", parameters[idx]));
        try {
            xml.append("        ").append(XmlHandler.addTagValue("default_value", getParameterDefault(parameters[idx])));
            xml.append("        ").append(XmlHandler.addTagValue("description", getParameterDescription(parameters[idx])));
        } catch (UnknownParamException e) {
        // skip the default value and/or description. This exception should never happen because we
        // use listParameters()
        // above.
        }
        xml.append("      ").append(XmlHandler.closeTag("parameter")).append(Const.CR);
    }
    xml.append("    ").append(XmlHandler.closeTag(XML_TAG_PARAMETERS)).append(Const.CR);
    xml.append("  ").append(XmlHandler.openTag("actions")).append(Const.CR);
    for (int i = 0; i < nrActions(); i++) {
        ActionMeta jge = getAction(i);
        xml.append(jge.getXml());
    }
    xml.append("  ").append(XmlHandler.closeTag("actions")).append(Const.CR);
    xml.append("  ").append(XmlHandler.openTag("hops")).append(Const.CR);
    for (WorkflowHopMeta hi : workflowHops) {
        // Look at all the hops
        xml.append(hi.getXml());
    }
    xml.append("  ").append(XmlHandler.closeTag("hops")).append(Const.CR);
    xml.append("  ").append(XmlHandler.openTag("notepads")).append(Const.CR);
    for (int i = 0; i < nrNotes(); i++) {
        NotePadMeta ni = getNote(i);
        xml.append(ni.getXml());
    }
    xml.append("  ").append(XmlHandler.closeTag("notepads")).append(Const.CR);
    // Also store the attribute groups
    // 
    xml.append(AttributesUtil.getAttributesXml(attributesMap));
    xml.append(XmlHandler.closeTag(XML_TAG)).append(Const.CR);
    return XmlFormatter.format(xml.toString());
}
Also used : ActionMeta(org.apache.hop.workflow.action.ActionMeta) UnknownParamException(org.apache.hop.core.parameters.UnknownParamException) Point(org.apache.hop.core.gui.Point) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint)

Example 2 with UnknownParamException

use of org.apache.hop.core.parameters.UnknownParamException in project hop by apache.

the class WorkflowExecutor method passParametersToWorkflow.

private void passParametersToWorkflow() throws HopException {
    // Set parameters, when fields are used take the first row in the set.
    // 
    WorkflowExecutorParameters parameters = meta.getParameters();
    for (int i = 0; i < parameters.getVariable().length; i++) {
        String variableName = parameters.getVariable()[i];
        String variableInput = parameters.getInput()[i];
        String fieldName = parameters.getField()[i];
        String variableValue = null;
        if (StringUtils.isNotEmpty(variableName)) {
            // 
            if (StringUtils.isNotEmpty(fieldName)) {
                int idx = getInputRowMeta().indexOfValue(fieldName);
                if (idx < 0) {
                    throw new HopException(BaseMessages.getString(PKG, "WorkflowExecutor.Exception.UnableToFindField", fieldName));
                }
                variableValue = data.groupBuffer.get(0).getString(idx, "");
            } else {
                // 
                if (StringUtils.isNotEmpty(variableInput)) {
                    variableValue = this.resolve(variableInput);
                }
            }
            try {
                data.executorWorkflow.setParameterValue(variableName, Const.NVL(variableValue, ""));
            } catch (UnknownParamException e) {
                data.executorWorkflow.setVariable(variableName, Const.NVL(variableValue, ""));
            }
        }
    }
    data.executorWorkflow.activateParameters(data.executorWorkflow);
}
Also used : HopException(org.apache.hop.core.exception.HopException) UnknownParamException(org.apache.hop.core.parameters.UnknownParamException) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint)

Example 3 with UnknownParamException

use of org.apache.hop.core.parameters.UnknownParamException in project hop by apache.

the class Repeat method updateParameters.

private void updateParameters(INamedParameters subParams, IVariables subVars, INamedParameters... params) {
    // Inherit
    for (INamedParameters param : params) {
        if (param != null) {
        }
    }
    // Any parameters to initialize from the workflow action?
    // 
    String[] parameterNames = subParams.listParameters();
    for (ParameterDetails parameter : parameters) {
        if (Const.indexOfString(parameter.getName(), parameterNames) >= 0) {
            // Set this parameter
            // 
            String value = resolve(parameter.getField());
            try {
                subParams.setParameterValue(parameter.getName(), value);
            } catch (UnknownParamException e) {
            // Ignore
            }
        }
    }
    // 
    if (keepingValues && subVars != null) {
        for (String parameterName : subParams.listParameters()) {
            try {
                String value = subVars.getVariable(parameterName);
                subParams.setParameterValue(parameterName, value);
            } catch (UnknownParamException e) {
            // Ignore
            }
        }
    }
// subParams.activateParameters(); TODO
}
Also used : INamedParameters(org.apache.hop.core.parameters.INamedParameters) UnknownParamException(org.apache.hop.core.parameters.UnknownParamException)

Example 4 with UnknownParamException

use of org.apache.hop.core.parameters.UnknownParamException in project hop by apache.

the class PipelineDialog method getData.

/**
 * Copy information from the meta-data input to the dialog fields.
 */
public void getData() {
    wPipelineName.setText(Const.NVL(pipelineMeta.getName(), ""));
    wNameFilenameSync.setSelection(pipelineMeta.isNameSynchronizedWithFilename());
    wPipelineFilename.setText(Const.NVL(pipelineMeta.getFilename(), ""));
    updateNameFilenameSync(null);
    wPipelineDescription.setText(Const.NVL(pipelineMeta.getDescription(), ""));
    wExtendedDescription.setText(Const.NVL(pipelineMeta.getExtendedDescription(), ""));
    wPipelineVersion.setText(Const.NVL(pipelineMeta.getPipelineVersion(), ""));
    wPipelineStatus.select(pipelineMeta.getPipelineStatus() - 1);
    if (pipelineMeta.getCreatedUser() != null) {
        wCreateUser.setText(pipelineMeta.getCreatedUser());
    }
    if (pipelineMeta.getCreatedDate() != null) {
        wCreateDate.setText(pipelineMeta.getCreatedDate().toString());
    }
    if (pipelineMeta.getModifiedUser() != null) {
        wModUser.setText(pipelineMeta.getModifiedUser());
    }
    if (pipelineMeta.getModifiedDate() != null) {
        wModDate.setText(pipelineMeta.getModifiedDate().toString());
    }
    // The named parameters
    String[] parameters = pipelineMeta.listParameters();
    for (int idx = 0; idx < parameters.length; idx++) {
        TableItem item = wParamFields.table.getItem(idx);
        String defValue;
        try {
            defValue = pipelineMeta.getParameterDefault(parameters[idx]);
        } catch (UnknownParamException e) {
            defValue = "";
        }
        String description;
        try {
            description = pipelineMeta.getParameterDescription(parameters[idx]);
        } catch (UnknownParamException e) {
            description = "";
        }
        item.setText(1, parameters[idx]);
        item.setText(2, Const.NVL(defValue, ""));
        item.setText(3, Const.NVL(description, ""));
    }
    wParamFields.setRowNums();
    wParamFields.optWidth(true);
    // Performance monitoring tab:
    // 
    wEnableTransformPerfMonitor.setSelection(pipelineMeta.isCapturingTransformPerformanceSnapShots());
    wTransformPerfInterval.setText(Long.toString(pipelineMeta.getTransformPerformanceCapturingDelay()));
    wTransformPerfMaxSize.setText(Const.NVL(pipelineMeta.getTransformPerformanceCapturingSizeLimit(), ""));
    wPipelineName.selectAll();
    wPipelineName.setFocus();
    for (IPipelineDialogPlugin extraTab : extraTabs) {
        try {
            extraTab.getData(pipelineMeta);
        } catch (Exception e) {
            new ErrorDialog(shell, "Error", "Error adding extra plugin tab", e);
        }
    }
}
Also used : UnknownParamException(org.apache.hop.core.parameters.UnknownParamException) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) UnknownParamException(org.apache.hop.core.parameters.UnknownParamException) HopException(org.apache.hop.core.exception.HopException) DuplicateParamException(org.apache.hop.core.parameters.DuplicateParamException)

Example 5 with UnknownParamException

use of org.apache.hop.core.parameters.UnknownParamException in project hop by apache.

the class AsyncRunServlet method doGet.

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) {
    if (isJettyMode() && !request.getContextPath().startsWith(CONTEXT_PATH)) {
        return;
    }
    if (log.isDebug()) {
        logDebug(BaseMessages.getString(PKG, "AsyncRunServlet.Log.AsyncRunRequested"));
    }
    IVariables variables = pipelineMap.getHopServerConfig().getVariables();
    MultiMetadataProvider metadataProvider = new MultiMetadataProvider(Encr.getEncoder(), new ArrayList<>(), variables);
    metadataProvider.getProviders().add(HopMetadataUtil.getStandardHopMetadataProvider(variables));
    String metadataFolder = pipelineMap.getHopServerConfig().getMetadataFolder();
    if (StringUtils.isNotEmpty(metadataFolder)) {
        // Get the metadata from the specified metadata folder...
        // 
        metadataProvider.getProviders().add(new JsonMetadataProvider(Encr.getEncoder(), metadataFolder, variables));
    }
    String webServiceName = request.getParameter("service");
    if (StringUtils.isEmpty(webServiceName)) {
        log.logError("Please specify a service parameter pointing to the name of the asynchronous webservice object");
    }
    try {
        IHopMetadataSerializer<AsyncWebService> serializer = metadataProvider.getSerializer(AsyncWebService.class);
        AsyncWebService webService = serializer.load(webServiceName);
        if (webService == null) {
            throw new HopException("Unable to find asynchronous web service '" + webServiceName + "'.  You can set option metadata_folder in the Hop server XML configuration");
        }
        if (!webService.isEnabled()) {
            throw new HopException("Asynchronous Web service '" + webServiceName + "' is disabled.");
        }
        String filename = variables.resolve(webService.getFilename());
        // We give back the ID of the executing workflow...
        // 
        response.setContentType("application/json");
        response.setCharacterEncoding(Const.XML_ENCODING);
        String serverObjectId = UUID.randomUUID().toString();
        SimpleLoggingObject servletLoggingObject = new SimpleLoggingObject(CONTEXT_PATH, LoggingObjectType.HOP_SERVER, null);
        servletLoggingObject.setContainerObjectId(serverObjectId);
        // Load and start the workflow
        // Output the ID to the response output stream...
        // 
        WorkflowMeta workflowMeta = new WorkflowMeta(variables, filename, metadataProvider);
        LocalWorkflowEngine workflow = new LocalWorkflowEngine(workflowMeta, servletLoggingObject);
        workflow.setContainerId(serverObjectId);
        workflow.setMetadataProvider(metadataProvider);
        workflow.setLogLevel(LogLevel.BASIC);
        workflow.initializeFrom(variables);
        workflow.setVariable("SERVER_OBJECT_ID", serverObjectId);
        // See if we need to pass a variable with the content in it...
        // 
        // Read the content posted?
        // 
        String contentVariable = variables.resolve(webService.getBodyContentVariable());
        String content = "";
        if (StringUtils.isNotEmpty(contentVariable)) {
            try (InputStream in = request.getInputStream()) {
                try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                    byte[] buffer = new byte[1024];
                    int length;
                    while ((length = in.read(buffer)) != -1) {
                        outputStream.write(buffer, 0, length);
                    }
                    outputStream.flush();
                    // Now we have the content...
                    // 
                    content = new String(outputStream.toByteArray(), StandardCharsets.UTF_8);
                }
            }
            workflow.setVariable(contentVariable, Const.NVL(content, ""));
        }
        // Set all the other parameters as variables/parameters...
        // 
        String[] pipelineParameters = workflowMeta.listParameters();
        workflow.copyParametersFromDefinitions(workflowMeta);
        for (String requestParameter : request.getParameterMap().keySet()) {
            if ("service".equals(requestParameter)) {
                continue;
            }
            String requestParameterValue = request.getParameter(requestParameter);
            if (Const.indexOfString(requestParameter, pipelineParameters) < 0) {
                workflow.setVariable(requestParameter, Const.NVL(requestParameterValue, ""));
            } else {
                try {
                    workflow.setParameterValue(requestParameter, Const.NVL(requestParameterValue, ""));
                } catch (UnknownParamException e) {
                    log.logError("Error running asynchronous web service", e);
                }
            }
        }
        workflow.activateParameters(workflow);
        // Add the workflow to the status map, so we can retrieve statuses later on
        // 
        WorkflowExecutionConfiguration workflowExecutionConfiguration = new WorkflowExecutionConfiguration();
        WorkflowConfiguration workflowConfiguration = new WorkflowConfiguration(workflowMeta, workflowExecutionConfiguration, new SerializableMetadataProvider(metadataProvider));
        // We use the service name to store the workflow under!
        // That way we don't have to look up the name of the workflow when retrieving the status.
        // 
        getWorkflowMap().addWorkflow(webServiceName, serverObjectId, workflow, workflowConfiguration);
        // Allocate the workflow in the background...
        // 
        new Thread(workflow::startExecution).start();
        try (OutputStream outputStream = response.getOutputStream()) {
            // Report the ID in a JSON block
            // 
            JSONObject json = new JSONObject();
            json.put("name", workflowMeta.getName());
            json.put("id", serverObjectId);
            String jsonString = json.toJSONString();
            outputStream.write(jsonString.getBytes(StandardCharsets.UTF_8));
            outputStream.write("\n".getBytes(StandardCharsets.UTF_8));
            outputStream.flush();
        } catch (IOException e) {
            log.logError("Error running asynchronous web service", e);
        }
        response.setStatus(HttpServletResponse.SC_OK);
    } catch (IOException | HopException e) {
        log.logError("Error running asynchronous web service", e);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) LocalWorkflowEngine(org.apache.hop.workflow.engines.local.LocalWorkflowEngine) JsonMetadataProvider(org.apache.hop.metadata.serializer.json.JsonMetadataProvider) WorkflowExecutionConfiguration(org.apache.hop.workflow.WorkflowExecutionConfiguration) MultiMetadataProvider(org.apache.hop.metadata.serializer.multi.MultiMetadataProvider) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) WorkflowConfiguration(org.apache.hop.workflow.WorkflowConfiguration) IVariables(org.apache.hop.core.variables.IVariables) HopException(org.apache.hop.core.exception.HopException) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SimpleLoggingObject(org.apache.hop.core.logging.SimpleLoggingObject) SerializableMetadataProvider(org.apache.hop.core.metadata.SerializableMetadataProvider) JSONObject(org.json.simple.JSONObject) UnknownParamException(org.apache.hop.core.parameters.UnknownParamException)

Aggregations

UnknownParamException (org.apache.hop.core.parameters.UnknownParamException)5 HopException (org.apache.hop.core.exception.HopException)3 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Point (org.apache.hop.core.gui.Point)1 SimpleLoggingObject (org.apache.hop.core.logging.SimpleLoggingObject)1 SerializableMetadataProvider (org.apache.hop.core.metadata.SerializableMetadataProvider)1 DuplicateParamException (org.apache.hop.core.parameters.DuplicateParamException)1 INamedParameters (org.apache.hop.core.parameters.INamedParameters)1 IVariables (org.apache.hop.core.variables.IVariables)1 JsonMetadataProvider (org.apache.hop.metadata.serializer.json.JsonMetadataProvider)1 MultiMetadataProvider (org.apache.hop.metadata.serializer.multi.MultiMetadataProvider)1 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)1 WorkflowConfiguration (org.apache.hop.workflow.WorkflowConfiguration)1 WorkflowExecutionConfiguration (org.apache.hop.workflow.WorkflowExecutionConfiguration)1 WorkflowMeta (org.apache.hop.workflow.WorkflowMeta)1 ActionMeta (org.apache.hop.workflow.action.ActionMeta)1