Search in sources :

Example 1 with WSPipeline

use of com.amalto.workbench.webservices.WSPipeline in project tmdm-studio-se by Talend.

the class TransformerMainPage method execute.

public void execute() {
    try {
        service = getService();
        if (service == null) {
            return;
        }
        java.util.List<WSTransformerContextPipelinePipelineItem> items = new ArrayList<WSTransformerContextPipelinePipelineItem>();
        for (Line line : cacheList) {
            String variableName = line.keyValues.get(0).value;
            String contentType = line.keyValues.get(1).value;
            String value = line.keyValues.get(2).value;
            items.add(new WSTransformerContextPipelinePipelineItem(variableName, new WSTypedContent(contentType, null, // $NON-NLS-1$
            new WSByteArray(value.getBytes("utf-8")))));
        }
        final WSBackgroundJobPK jobPK = service.executeTransformerV2AsJob(new WSExecuteTransformerV2AsJob(new WSTransformerContext(new WSTransformerContextPipeline(items), null, new WSTransformerV2PK(transformer.getName()))));
        IRunnableWithProgress progress = new IRunnableWithProgress() {

            WSBackgroundJob job = null;

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                /**
                 ****************************************
                 * Watch the Background Job
                 *****************************************
                 */
                try {
                    boolean firstTime = true;
                    do {
                        if (firstTime) {
                            Thread.sleep(1500L);
                            firstTime = false;
                        } else {
                            Thread.sleep(5000L);
                        }
                        if (monitor.isCanceled()) {
                            throw new InterruptedException(Messages.TransformerMainPage_UserCancel);
                        }
                        job = service.getBackgroundJob(new WSGetBackgroundJob(jobPK.getPk()));
                        monitor.subTask(job.getMessage());
                    } while (job.getStatus().equals(BackgroundJobStatusType.RUNNING) || job.getStatus().equals(BackgroundJobStatusType.SCHEDULED));
                    if (job.getStatus().equals(BackgroundJobStatusType.STOPPED)) {
                        getSite().getShell().getDisplay().syncExec(new Runnable() {

                            public void run() {
                                MessageDialog.openError(TransformerMainPage.this.getEditor().getSite().getShell(), Messages.bind(Messages.TransformerMainPage_ErrorMsg, transformer.getName()), job.getMessage());
                            }
                        });
                        throw new XtentisException(Messages.bind(Messages.TransformerMainPage_JobWasStoped, job.getMessage()));
                    }
                    monitor.worked(1);
                    monitor.done();
                    /**
                     ****************************************
                     * Build the result console
                     *****************************************
                     */
                    // Auto sorts the entries
                    final TreeMap pipeline = new TreeMap<String, WSExtractedContent>();
                    WSPipeline wsPipeline = job.getPipeline();
                    java.util.List<WSPipelineTypedContentEntry> entries = wsPipeline.getTypedContentEntry();
                    for (WSPipelineTypedContentEntry entry : entries) {
                        pipeline.put(entry.getOutput(), entry.getWsExtractedContent());
                    }
                    getSite().getShell().getDisplay().asyncExec(new Runnable() {

                        public void run() {
                            try {
                                /*
                                     * ProcessResultsPage page = new ProcessResultsPage(editor,pipeline);
                                     * parent.editor.addPage(page); parent.editor.setActivePage(page.getId());
                                     * 
                                     * parent.editor.getEditorSite().getShell()
                                     */
                                // Shell shell = new Shell(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
                                ProcessResultsDialog dialog = new ProcessResultsDialog(getSite().getShell(), Messages.bind(Messages.TransformerMainPage_DailogTitle, sdf.format(new Date(System.currentTimeMillis()))), pipeline);
                                dialog.setBlockOnOpen(false);
                                dialog.open();
                            } catch (Exception e) {
                                log.error(e.getMessage(), e);
                                throw new RuntimeException(e);
                            }
                        }
                    });
                } catch (Exception e1) {
                    log.error(e1.getMessage(), e1);
                }
            }
        };
        // fork
        new ProgressMonitorDialog(TransformerMainPage.this.getSite().getWorkbenchWindow().getShell()).run(// fork
        true, true, progress);
    } catch (Exception e1) {
        log.error(e1.getMessage(), e1);
    }
}
Also used : ArrayList(java.util.ArrayList) WSBackgroundJob(com.amalto.workbench.webservices.WSBackgroundJob) WSExecuteTransformerV2AsJob(com.amalto.workbench.webservices.WSExecuteTransformerV2AsJob) WSPipeline(com.amalto.workbench.webservices.WSPipeline) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) WSGetBackgroundJob(com.amalto.workbench.webservices.WSGetBackgroundJob) WSBackgroundJobPK(com.amalto.workbench.webservices.WSBackgroundJobPK) ProcessResultsDialog(com.amalto.workbench.dialogs.ProcessResultsDialog) WSTransformerContextPipelinePipelineItem(com.amalto.workbench.webservices.WSTransformerContextPipelinePipelineItem) WSByteArray(com.amalto.workbench.webservices.WSByteArray) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) WSTypedContent(com.amalto.workbench.webservices.WSTypedContent) WSPipelineTypedContentEntry(com.amalto.workbench.webservices.WSPipelineTypedContentEntry) TreeMap(java.util.TreeMap) WSTransformerContext(com.amalto.workbench.webservices.WSTransformerContext) Date(java.util.Date) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) XtentisException(com.amalto.workbench.utils.XtentisException) Line(com.amalto.workbench.models.Line) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WSTransformerV2PK(com.amalto.workbench.webservices.WSTransformerV2PK) WSTransformerContextPipeline(com.amalto.workbench.webservices.WSTransformerContextPipeline) XtentisException(com.amalto.workbench.utils.XtentisException)

Aggregations

ProcessResultsDialog (com.amalto.workbench.dialogs.ProcessResultsDialog)1 Line (com.amalto.workbench.models.Line)1 XtentisException (com.amalto.workbench.utils.XtentisException)1 WSBackgroundJob (com.amalto.workbench.webservices.WSBackgroundJob)1 WSBackgroundJobPK (com.amalto.workbench.webservices.WSBackgroundJobPK)1 WSByteArray (com.amalto.workbench.webservices.WSByteArray)1 WSExecuteTransformerV2AsJob (com.amalto.workbench.webservices.WSExecuteTransformerV2AsJob)1 WSGetBackgroundJob (com.amalto.workbench.webservices.WSGetBackgroundJob)1 WSPipeline (com.amalto.workbench.webservices.WSPipeline)1 WSPipelineTypedContentEntry (com.amalto.workbench.webservices.WSPipelineTypedContentEntry)1 WSTransformerContext (com.amalto.workbench.webservices.WSTransformerContext)1 WSTransformerContextPipeline (com.amalto.workbench.webservices.WSTransformerContextPipeline)1 WSTransformerContextPipelinePipelineItem (com.amalto.workbench.webservices.WSTransformerContextPipelinePipelineItem)1 WSTransformerV2PK (com.amalto.workbench.webservices.WSTransformerV2PK)1 WSTypedContent (com.amalto.workbench.webservices.WSTypedContent)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 TreeMap (java.util.TreeMap)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1