Search in sources :

Example 6 with WSTransformerV2E

use of org.talend.mdm.repository.model.mdmserverobject.WSTransformerV2E 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 7 with WSTransformerV2E

use of org.talend.mdm.repository.model.mdmserverobject.WSTransformerV2E in project tmdm-studio-se by Talend.

the class GenerateJobTransformerAction method doRun.

@Override
protected void doRun() {
    selectObj = getSelectedObject().get(0);
    JobOptionsDialog dialog = new JobOptionsDialog(getShell(), Messages.JobProcesssOptionsDialogTitle_title, Execution.EMBEDDED);
    dialog.setBlockOnOpen(true);
    int ret = dialog.open();
    if (ret == Dialog.CANCEL) {
        return;
    }
    // $NON-NLS-1$
    String jobName = "";
    // $NON-NLS-1$
    String jobVersion = "";
    // $NON-NLS-1$
    String path = "/other";
    if (selectObj instanceof IRepositoryViewObject) {
        Property property = ((IRepositoryViewObject) selectObj).getProperty();
        if (property != null) {
            jobName = property.getLabel();
            jobVersion = property.getVersion();
        }
    }
    // check exist
    IValidateService validateService = (IValidateService) GlobalServiceRegister.getDefault().getService(IValidateService.class);
    if (validateService != null) {
        boolean result = validateService.validateAndAlertObjectExistence(IServerObjectRepositoryType.TYPE_TRANSFORMERV2, getNewProcessName(jobName), null);
        if (!result) {
            return;
        }
    }
    WSTransformerV2E transformer = createTransformer(jobName, jobVersion, dialog);
    // if the new objectect is opened ,than close it before regenerating
    IRepositoryViewObject toDelete = RepositoryResourceUtil.findViewObjectByName(IServerObjectRepositoryType.TYPE_TRANSFORMERV2, PREFIX + jobName);
    if (toDelete != null) {
        IEditorPart openedEditor = UIUtil.findOpenedEditor(toDelete);
        if (openedEditor != null) {
            UIUtil.closeEditor(openedEditor, false);
        }
        // delete directly
        RepositoryResourceUtil.removeViewObjectPhysically(toDelete, jobVersion);
    }
    AttachToProcessView(jobName, transformer);
}
Also used : WSTransformerV2E(org.talend.mdm.repository.model.mdmserverobject.WSTransformerV2E) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IEditorPart(org.eclipse.ui.IEditorPart) JobOptionsDialog(org.talend.mdm.repository.ui.dialogs.job.JobOptionsDialog) Property(org.talend.core.model.properties.Property) IValidateService(com.amalto.workbench.service.IValidateService)

Aggregations

WSTransformerV2E (org.talend.mdm.repository.model.mdmserverobject.WSTransformerV2E)7 ArrayList (java.util.ArrayList)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 WSTransformerV2Item (org.talend.mdm.repository.model.mdmproperties.WSTransformerV2Item)2 WSTransformerProcessStepE (org.talend.mdm.repository.model.mdmserverobject.WSTransformerProcessStepE)2 WSTransformerVariablesMappingE (org.talend.mdm.repository.model.mdmserverobject.WSTransformerVariablesMappingE)2 IValidateService (com.amalto.workbench.service.IValidateService)1 WSTransformerVariablesMapping (com.amalto.workbench.webservices.WSTransformerVariablesMapping)1 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPartSite (org.eclipse.ui.IWorkbenchPartSite)1 Item (org.talend.core.model.properties.Item)1 ItemState (org.talend.core.model.properties.ItemState)1 ProcessItem (org.talend.core.model.properties.ProcessItem)1 Property (org.talend.core.model.properties.Property)1