Search in sources :

Example 6 with CamelProcessItem

use of org.talend.camel.core.model.camelProperties.CamelProcessItem in project tesb-studio-se by Talend.

the class JavaCamelJobScriptsExportWSWizardPage method finish.

@Override
public boolean finish() {
    String version = getSelectedJobVersion();
    String destinationKar = getDestinationValue();
    JavaCamelJobScriptsExportWSAction action = null;
    IRunnableWithProgress buildJobHandlerAction = null;
    Map<ExportChoice, Object> exportChoiceMap = getExportChoiceMap();
    boolean needMavenScript = false;
    if (needMavenScript && destinationKar.regionMatches(true, destinationKar.length() - 4, ".kar", 0, 4)) {
        destinationKar = destinationKar.substring(0, destinationKar.length() - 3) + "zip";
    }
    if (exportAsZip) {
        exportChoiceMap.put(ExportChoice.needAssembly, Boolean.TRUE);
    }
    if (new File(destinationKar).exists() && !exportTypeCombo.getText().equals(EXPORTTYPE_SPRING_BOOT_DOCKER_IMAGE)) {
        boolean yes = MessageDialog.openQuestion(getShell(), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.OverwriteKarTitle"), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.OverwriteKarMessage"));
        if (!yes) {
            return false;
        }
    } else if (!exportTypeCombo.getText().equals(EXPORTTYPE_KAR)) {
        exportChoiceMap.put(ExportChoice.needAssembly, Boolean.FALSE);
    }
    if (exportTypeCombo.getText().equals(EXPORTTYPE_SPRING_BOOT) || exportTypeCombo.getText().equals(EXPORTTYPE_SPRING_BOOT_DOCKER_IMAGE)) {
        IRunnableWithProgress worker = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                buildJobWithMaven(exportTypeCombo.getText().equals(EXPORTTYPE_SPRING_BOOT) ? JobExportType.ROUTE : JobExportType.MSESB_IMAGE, monitor);
            }
        };
        try {
            getContainer().run(false, true, worker);
        } catch (Exception e) {
            MessageBoxExceptionHandler.process(e.getCause() == null ? e : e.getCause(), getShell());
            return false;
        }
    } else {
        if (getProcessItem() instanceof CamelProcessItem) {
            CamelProcessItem camelProcessItem = (CamelProcessItem) getProcessItem();
            if (camelProcessItem.isExportMicroService()) {
                camelProcessItem.setExportMicroService(false);
            }
        }
        if (needMavenScript) {
            action = new JavaCamelJobScriptsExportWithMavenAction(exportChoiceMap, nodes[0], version, destinationKar, false);
        } else {
            exportChoiceMap.put(ExportChoice.esbExportType, "kar");
            buildJobHandlerAction = new IRunnableWithProgress() {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    IBuildJobHandler buildJobHandler = BuildJobFactory.createBuildJobHandler(getProcessItem(), getContextName(), version, exportChoiceMap, "ROUTE");
                    Map<String, Object> prepareParams = new HashMap<String, Object>();
                    prepareParams.put(IBuildResourceParametes.OPTION_ITEMS, true);
                    prepareParams.put(IBuildResourceParametes.OPTION_ITEMS_DEPENDENCIES, true);
                    try {
                        buildJobHandler.prepare(monitor, prepareParams);
                        buildJobHandler.build(monitor);
                        IFile targetFile = buildJobHandler.getJobTargetFile();
                        if (targetFile != null && targetFile.exists()) {
                            try {
                                FilesUtils.copyFile(targetFile.getLocation().toFile(), new File(getDestinationValue()));
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    } catch (Exception e) {
                        MessageBoxExceptionHandler.process(e.getCause() == null ? e : e.getCause(), getShell());
                    }
                }
            };
            ProcessorUtilities.setExportAsOSGI(true);
        }
        try {
            if (needMavenScript) {
                getContainer().run(false, true, action);
            } else {
                getContainer().run(false, true, buildJobHandlerAction);
            }
        } catch (Exception e) {
            MessageBoxExceptionHandler.process(e.getCause(), getShell());
            return false;
        }
    }
    return true;
}
Also used : IFile(org.eclipse.core.resources.IFile) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) IOException(java.io.IOException) JavaCamelJobScriptsExportWSAction(org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWSAction) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) JavaCamelJobScriptsExportWithMavenAction(org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWithMavenAction) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap)

Example 7 with CamelProcessItem

use of org.talend.camel.core.model.camelProperties.CamelProcessItem in project tesb-studio-se by Talend.

the class RouteJavaScriptOSGIForESBManager method generateConfig.

@Override
protected void generateConfig(ExportFileResource osgiResource, ProcessItem processItem, IProcess process) throws IOException {
    boolean needBlueprint = true;
    for (String componentName : BuildJobConstants.esbComponents) {
        if (EmfModelUtils.getComponentByName(processItem, componentName) != null) {
            needBlueprint = false;
            break;
        }
    }
    String springContent = null;
    if (processItem instanceof CamelProcessItem) {
        springContent = ((CamelProcessItem) processItem).getSpringContent();
    }
    Map<String, Object> collectRouteInfo = collectRouteInfo(processItem, process);
    Map<String, Element> needHandleElements = new HashMap<>();
    if (springContent != null && springContent.length() > 0) {
        // $NON-NLS-1$
        String springTargetFilePath = collectRouteInfo.get("name").toString().toLowerCase() + ".xml";
        InputStream springContentInputStream = new ByteArrayInputStream(springContent.getBytes());
        handleSpringXml(springTargetFilePath, processItem, springContentInputStream, osgiResource, true, CONVERT_SPRING_IMPORT, needHandleElements);
    }
    if (needBlueprint) {
        // $NON-NLS-1$
        final File targetFile = new File(getTmpFolder() + PATH_SEPARATOR + "blueprint.xml");
        if (needHandleElements.size() > 0) {
            for (String key : needHandleElements.keySet()) {
                if ("propertyPlaceholder".equals(key)) {
                    collectRouteInfo.put(key, needHandleElements.get(key).asXML());
                }
            }
        }
        // $NON-NLS-1$
        TemplateProcessor.processTemplate(// $NON-NLS-1$
        "ROUTE_BLUEPRINT_CONFIG", collectRouteInfo, targetFile, getClass().getResourceAsStream(TEMPLATE_BLUEPRINT_ROUTE), false);
        osgiResource.addResource(FileConstants.BLUEPRINT_FOLDER_NAME, targetFile.toURI().toURL());
    }
}
Also used : CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(org.dom4j.Element) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

CamelProcessItem (org.talend.camel.core.model.camelProperties.CamelProcessItem)7 File (java.io.File)3 IFile (org.eclipse.core.resources.IFile)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Element (org.dom4j.Element)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 Map (java.util.Map)1 IFolder (org.eclipse.core.resources.IFolder)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1