Search in sources :

Example 16 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice in project tesb-studio-se by Talend.

the class BuildDataServiceProvider method createBuildExportHandler.

/*
     * (non-Javadoc)
     *
     * @see org.talend.core.runtime.repository.build.AbstractBuildProvider#createBuildExportHandler(java.util.Map)
     */
@Override
public IBuildExportHandler createBuildExportHandler(Map<String, Object> parameters) {
    if (parameters == null || parameters.isEmpty()) {
        return null;
    }
    final Object item = parameters.get(ITEM);
    if (item == null || !(item instanceof ServiceItem)) {
        return null;
    }
    final Object version = parameters.get(VERSION);
    if (version == null) {
        return null;
    }
    final Object contextGroup = parameters.get(CONTEXT_GROUP);
    if (contextGroup == null) {
        return null;
    }
    Object choiceOption = parameters.get(CHOICE_OPTION);
    if (choiceOption == null) {
        choiceOption = Collections.emptyMap();
    }
    if (!(choiceOption instanceof Map)) {
        return null;
    }
    IBuildJobHandler buildHandler = new BuildDataServiceHandler((ServiceItem) item, version.toString(), contextGroup.toString(), (Map<ExportChoice, Object>) choiceOption);
    return buildHandler;
}
Also used : IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) ServiceItem(org.talend.repository.services.model.services.ServiceItem) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) Map(java.util.Map)

Example 17 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice in project tesb-studio-se by Talend.

the class ExportServiceAction method exportJobsBundle.

private void exportJobsBundle(IProgressMonitor monitor, FeaturesModel feature) throws InvocationTargetException, InterruptedException {
    for (IRepositoryViewObject node : nodes) {
        ProcessItem processItem = (ProcessItem) node.getProperty().getItem();
        String bundleVersion = getBundleVersion();
        if (bundleVersion != null)
            bundleVersion = bundleVersion.replace("-", ".");
        if (exportChoiceMap == null) {
            exportChoiceMap = new HashMap<ExportChoice, Object>();
            exportChoiceMap.put(ExportChoice.needContext, true);
            exportChoiceMap.put(ExportChoice.bundleVersion, bundleVersion);
        } else {
            if (exportChoiceMap.get(ExportChoice.needContext) == null) {
                exportChoiceMap.put(ExportChoice.needContext, true);
            }
            if (exportChoiceMap.get(ExportChoice.bundleVersion) == null) {
                exportChoiceMap.put(ExportChoice.bundleVersion, bundleVersion);
            }
        }
        IBuildJobHandler buildJobOSGiHandler = BuildJobFactory.createBuildJobHandler(processItem, IContext.DEFAULT, processItem.getProperty().getVersion(), exportChoiceMap, JobExportType.OSGI);
        if (buildJobOSGiHandler != null) {
            // buildJobOSGiHandler.generateItemFiles(true, monitor);
            try {
                buildJobOSGiHandler.generateJobFiles(monitor);
                buildJobOSGiHandler.build(monitor);
                // TESB-21586 Windows-specific path objects created by Studio CommandLine when publishing
                IFile serviceTargetFile = buildJobOSGiHandler.getJobTargetFile();
                if (serviceTargetFile != null && serviceTargetFile.exists()) {
                    feature.addBundle(new BundleModel(getGroupId(), serviceManager.getNodeLabel(node), getServiceVersion(), serviceTargetFile.getLocation().toFile()));
                }
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) BundleModel(org.talend.designer.publish.core.models.BundleModel) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 18 with ExportChoice

use of org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice 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)

Aggregations

ExportChoice (org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 File (java.io.File)7 ProcessItem (org.talend.core.model.properties.ProcessItem)7 IOException (java.io.IOException)6 ProcessorException (org.talend.designer.runprocess.ProcessorException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 EnumMap (java.util.EnumMap)4 Map (java.util.Map)4 IFile (org.eclipse.core.resources.IFile)4 IBuildJobHandler (org.talend.core.runtime.process.IBuildJobHandler)4 ExportFileResource (org.talend.repository.documentation.ExportFileResource)4 HashMap (java.util.HashMap)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 JobScriptsManager (org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager)3 URL (java.net.URL)2 Properties (java.util.Properties)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Test (org.junit.Test)2