Search in sources :

Example 1 with Parameter

use of org.talend.mdm.repository.ui.dialogs.job.JobOptionsDialog.Parameter in project tmdm-studio-se by Talend.

the class GenerateJobTransformerAction method createTransformer.

/**
 * @param jobVersion
 */
private WSTransformerV2E createTransformer(String jobName, String jobVersion, JobOptionsDialog dialog) {
    // $NON-NLS-1$
    String server = "http://localhost:8180";
    Execution execution = dialog.getExecution();
    Parameter executionParameter = dialog.getParameter();
    // $NON-NLS-1$
    final String TRANSFORMER_PLUGIN = "amalto/local/transformer/plugin/xslt";
    WSTransformerV2E transformer = MdmserverobjectFactory.eINSTANCE.createWSTransformerV2E();
    // $NON-NLS-1$
    String url = "";
    switch(execution) {
        case EMBEDDED:
            // $NON-NLS-1$//$NON-NLS-2$
            url = "ltj://" + jobName + "/" + jobVersion;
            break;
        case WEB_SERVICE:
            url = Messages.bind(Messages.GenerateJobXX_UrlString, server, jobName, jobVersion, jobName);
            break;
    }
    // Generate the job call
    List<WSTransformerProcessStepE> steps = new ArrayList<WSTransformerProcessStepE>();
    WSTransformerVariablesMapping[] input;
    WSTransformerVariablesMapping[] output;
    try {
        List<WSTransformerVariablesMappingE> inItems;
        List<WSTransformerVariablesMappingE> outItems;
        switch(executionParameter) {
            case CONTEXT_VARIABLE:
                String itemstr = // $NON-NLS-1$
                "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"  xmlns:mdm=\"java:com.amalto.core.plugin.base.xslt.MdmExtension\" version=\"1.0\"> <xsl:output method=\"xml\" indent=\"yes\" omit-xml-declaration=\"yes\" /> <xsl:template match=\"/\" priority=\"1\">\n" + // $NON-NLS-1$
                "<exchange> <report>\n <xsl:copy-of select=\"Update\"/> </report>  <item><xsl:copy-of select='mdm:getItemProjection(Update/RevisionID,Update/DataCluster,Update/Concept,Update/Key)'/></item></exchange> " + // $NON-NLS-1$
                "</xsl:template> </xsl:stylesheet>\n";
                WSTransformerProcessStepE steps1 = MdmserverobjectFactory.eINSTANCE.createWSTransformerProcessStepE();
                inItems = new ArrayList<WSTransformerVariablesMappingE>();
                WSTransformerVariablesMappingE inputLine = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
                // $NON-NLS-1$
                inputLine.setPipelineVariable("_DEFAULT_");
                // $NON-NLS-1$
                inputLine.setPluginVariable("xml");
                inItems.add(inputLine);
                outItems = new ArrayList<WSTransformerVariablesMappingE>();
                WSTransformerVariablesMappingE outputLine = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
                // $NON-NLS-1$
                outputLine.setPipelineVariable("item_xml");
                // $NON-NLS-1$
                outputLine.setPluginVariable("text");
                outItems.add(outputLine);
                steps1.setPluginJNDI(TRANSFORMER_PLUGIN);
                // $NON-NLS-1$
                steps1.setDescription("Stylesheet");
                steps1.setParameters(itemstr);
                steps1.getInputMappings().addAll(inItems);
                steps1.getOutputMappings().addAll(outItems);
                steps1.setDisabled(false);
                // Generate the XSLT step to retrieve the item from an update report
                // step 2
                WSTransformerProcessStepE steps2 = MdmserverobjectFactory.eINSTANCE.createWSTransformerProcessStepE();
                List<WSTransformerVariablesMappingE> inItems2 = new ArrayList<WSTransformerVariablesMappingE>();
                WSTransformerVariablesMappingE inputLine2 = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
                // $NON-NLS-1$
                inputLine2.setPipelineVariable("item_xml");
                // $NON-NLS-1$
                inputLine2.setPluginVariable("law_text");
                inItems2.add(inputLine2);
                List<WSTransformerVariablesMappingE> outItems2 = new ArrayList<WSTransformerVariablesMappingE>();
                WSTransformerVariablesMappingE outputLine2 = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
                // $NON-NLS-1$
                outputLine2.setPipelineVariable("decode_xml");
                // $NON-NLS-1$
                outputLine2.setPluginVariable("codec_text");
                outItems2.add(outputLine2);
                // $NON-NLS-1$
                steps2.setPluginJNDI("amalto/local/transformer/plugin/codec");
                // $NON-NLS-1$
                steps2.setDescription("Escape the item XML");
                String parameter = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "<parameters>\n" + "<method>DECODE</method>\n" + "<algorithm>XMLESCAPE</algorithm>\n" + // $NON-NLS-1$
                "</parameters>\n";
                steps2.setParameters(parameter);
                steps2.getInputMappings().addAll(inItems2);
                steps2.getOutputMappings().addAll(outItems2);
                steps2.setDisabled(false);
                // step 3
                WSTransformerProcessStepE steps3 = MdmserverobjectFactory.eINSTANCE.createWSTransformerProcessStepE();
                List<WSTransformerVariablesMappingE> inItems3 = new ArrayList<WSTransformerVariablesMappingE>();
                WSTransformerVariablesMappingE inputLine3 = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
                // $NON-NLS-1$
                inputLine3.setPipelineVariable("decode_xml");
                // $NON-NLS-1$
                inputLine3.setPluginVariable("text");
                inItems3.add(inputLine3);
                List<WSTransformerVariablesMappingE> outItems3 = new ArrayList<WSTransformerVariablesMappingE>();
                WSTransformerVariablesMappingE outputLine3 = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
                // $NON-NLS-1$
                outputLine3.setPipelineVariable("output");
                // $NON-NLS-1$
                outputLine3.setPluginVariable("result");
                outItems3.add(outputLine3);
                // $NON-NLS-1$
                steps3.setPluginJNDI("amalto/local/transformer/plugin/callJob");
                // $NON-NLS-1$
                steps3.setDescription("Invoke the job");
                input = new WSTransformerVariablesMapping[1];
                // $NON-NLS-1$ //$NON-NLS-2$
                input[0] = new WSTransformerVariablesMapping(null, "_DEFAULT_", "xml");
                output = new WSTransformerVariablesMapping[1];
                // $NON-NLS-1$ //$NON-NLS-2$
                output[0] = new WSTransformerVariablesMapping(null, "item_xml", "text");
                steps3.setParameters(parameter);
                steps3.getInputMappings().addAll(inItems3);
                steps3.getOutputMappings().addAll(outItems3);
                steps3.setDisabled(false);
                parameter = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                "<configuration>\n" + "<url>" + url + "</url>\n" + "<contextParam>\n" + "<name>xmlInput</name>\n" + "<value>{decode_xml}</value>\n" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "</contextParam>\n" + // $NON-NLS-1$
                "</configuration>\n";
                steps3.setParameters(parameter);
                steps.add(steps1);
                steps.add(steps2);
                steps.add(steps3);
                break;
            case INTEGRATED:
                WSTransformerProcessStepE step1 = MdmserverobjectFactory.eINSTANCE.createWSTransformerProcessStepE();
                inItems = new ArrayList<WSTransformerVariablesMappingE>();
                inputLine = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
                // $NON-NLS-1$
                inputLine.setPipelineVariable("_DEFAULT_");
                // $NON-NLS-1$
                inputLine.setPluginVariable("text");
                inItems.add(inputLine);
                outItems = new ArrayList<WSTransformerVariablesMappingE>();
                outputLine = MdmserverobjectFactory.eINSTANCE.createWSTransformerVariablesMappingE();
                // $NON-NLS-1$
                outputLine.setPipelineVariable("item_xml");
                // $NON-NLS-1$
                outputLine.setPluginVariable("result");
                outItems.add(outputLine);
                // $NON-NLS-1$
                step1.setPluginJNDI("amalto/local/transformer/plugin/callJob");
                // $NON-NLS-1$
                step1.setDescription("Invoke the job");
                step1.setParameters(// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "<configuration>\n" + "<url>" + url + "</url>\n" + // $NON-NLS-1$
                "</configuration>\n");
                step1.getInputMappings().addAll(inItems);
                step1.getOutputMappings().addAll(outItems);
                step1.setDisabled(false);
                steps.add(step1);
                break;
            default:
                log.warn(Messages.bind(Messages.GenerateJobXX_UNSupportedType, executionParameter));
                steps = Collections.emptyList();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    try {
        // Generate the job call
        transformer.setName(getNewProcessName(jobName));
        transformer.setDescription(Messages.bind(Messages.GenerateJobXX_ProcessCallJob, jobName));
        transformer.getProcessSteps().addAll(steps);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return transformer;
}
Also used : WSTransformerVariablesMappingE(org.talend.mdm.repository.model.mdmserverobject.WSTransformerVariablesMappingE) ArrayList(java.util.ArrayList) Execution(org.talend.mdm.repository.ui.dialogs.job.JobOptionsDialog.Execution) WSTransformerV2E(org.talend.mdm.repository.model.mdmserverobject.WSTransformerV2E) WSTransformerVariablesMapping(com.amalto.workbench.webservices.WSTransformerVariablesMapping) Parameter(org.talend.mdm.repository.ui.dialogs.job.JobOptionsDialog.Parameter) WSTransformerProcessStepE(org.talend.mdm.repository.model.mdmserverobject.WSTransformerProcessStepE)

Example 2 with Parameter

use of org.talend.mdm.repository.ui.dialogs.job.JobOptionsDialog.Parameter in project tmdm-studio-se by Talend.

the class GenerateJobTriggerAction method createTrigger.

/**
 * DOC jsxie Comment method "createTrigger".
 *
 * @param dialog
 * @param jobVersion2
 */
private WSRoutingRuleE createTrigger(String jobName, String jobVersion, JobOptionsDialog dialog) {
    WSRoutingRuleE routingRule = MdmserverobjectFactory.eINSTANCE.createWSRoutingRuleE();
    try {
        // $NON-NLS-1$
        String server = "http://localhost:8180";
        Execution execution = dialog.getExecution();
        // $NON-NLS-1$
        String url = "";
        switch(execution) {
            case EMBEDDED:
                // $NON-NLS-1$ //$NON-NLS-2$
                url = "ltj://" + jobName + "/" + jobVersion;
                break;
            case WEB_SERVICE:
                url = Messages.bind(Messages.GenerateJobXX_UrlString, server, jobName, jobVersion, jobName);
                break;
        }
        Parameter executionParameter = dialog.getParameter();
        // $NON-NLS-1$
        String parameter = "";
        switch(executionParameter) {
            case CONTEXT_VARIABLE:
                parameter = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "<configuration>\n" + "<url>" + url + "</url><contextParam>\n" + "<name>xmlInput</name>\n" + "<value>{exchange_data}</value>\n" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "</contextParam>\n" + // $NON-NLS-1$
                "</configuration>\n";
                break;
            case INTEGRATED:
                parameter = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                "<configuration>\n" + "<url>" + url + "</url>" + // $NON-NLS-1$
                "</configuration>\n";
                break;
        }
        // Generate the job call
        // create default CREATE operation express
        WSRoutingRuleExpressionE expression1 = MdmserverobjectFactory.eINSTANCE.createWSRoutingRuleExpressionE();
        // $NON-NLS-1$
        expression1.setName("C1");
        // $NON-NLS-1$
        expression1.setXpath("Update/OperationType");
        expression1.setWsOperator(newContainRoutingRuleOperator());
        // $NON-NLS-1$
        expression1.setValue("CREATE");
        WSRoutingRuleExpressionE expression2 = MdmserverobjectFactory.eINSTANCE.createWSRoutingRuleExpressionE();
        // $NON-NLS-1$
        expression2.setName("C2");
        // $NON-NLS-1$
        expression2.setXpath("Update/OperationType");
        expression2.setWsOperator(newContainRoutingRuleOperator());
        // $NON-NLS-1$
        expression2.setValue("UPDATE");
        WSRoutingRuleExpressionE expression3 = MdmserverobjectFactory.eINSTANCE.createWSRoutingRuleExpressionE();
        // $NON-NLS-1$
        expression3.setName("C3");
        // $NON-NLS-1$
        expression3.setXpath("Update/OperationType");
        expression3.setWsOperator(newContainRoutingRuleOperator());
        // $NON-NLS-1$
        expression3.setValue("DELETE");
        routingRule.setName(getNewTriggerName(jobName));
        // $NON-NLS-1$
        routingRule.setDescription("Trigger that calls the Talend Job: " + jobName);
        routingRule.setSynchronous(false);
        // $NON-NLS-1$
        routingRule.setConcept("Update");
        // $NON-NLS-1$
        routingRule.setServiceJNDI("amalto/local/service/callJob");
        routingRule.setParameters(parameter);
        routingRule.setCondition(null);
        routingRule.setDeactive(false);
        routingRule.getWsRoutingRuleExpressions().add(expression1);
        routingRule.getWsRoutingRuleExpressions().add(expression2);
        routingRule.getWsRoutingRuleExpressions().add(expression3);
        // $NON-NLS-1$
        routingRule.setCondition("C1 Or C2 Or C3");
        routingRule.setDeactive(false);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return routingRule;
}
Also used : WSRoutingRuleExpressionE(org.talend.mdm.repository.model.mdmserverobject.WSRoutingRuleExpressionE) Execution(org.talend.mdm.repository.ui.dialogs.job.JobOptionsDialog.Execution) Parameter(org.talend.mdm.repository.ui.dialogs.job.JobOptionsDialog.Parameter) WSRoutingRuleE(org.talend.mdm.repository.model.mdmserverobject.WSRoutingRuleE)

Aggregations

Execution (org.talend.mdm.repository.ui.dialogs.job.JobOptionsDialog.Execution)2 Parameter (org.talend.mdm.repository.ui.dialogs.job.JobOptionsDialog.Parameter)2 WSTransformerVariablesMapping (com.amalto.workbench.webservices.WSTransformerVariablesMapping)1 ArrayList (java.util.ArrayList)1 WSRoutingRuleE (org.talend.mdm.repository.model.mdmserverobject.WSRoutingRuleE)1 WSRoutingRuleExpressionE (org.talend.mdm.repository.model.mdmserverobject.WSRoutingRuleExpressionE)1 WSTransformerProcessStepE (org.talend.mdm.repository.model.mdmserverobject.WSTransformerProcessStepE)1 WSTransformerV2E (org.talend.mdm.repository.model.mdmserverobject.WSTransformerV2E)1 WSTransformerVariablesMappingE (org.talend.mdm.repository.model.mdmserverobject.WSTransformerVariablesMappingE)1