Search in sources :

Example 1 with JavaCamelJobScriptsExportWSAction

use of org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWSAction 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 actionMS = null;
    Map<ExportChoice, Object> exportChoiceMap = getExportChoiceMap();
    boolean needMavenScript = exportChoiceMap.containsKey(ExportChoice.needMavenScript) && exportChoiceMap.get(ExportChoice.needMavenScript) == Boolean.TRUE;
    if (needMavenScript && destinationKar.regionMatches(true, destinationKar.length() - 4, ".kar", 0, 4)) {
        destinationKar = destinationKar.substring(0, destinationKar.length() - 3) + "zip";
    }
    if (new File(destinationKar).exists()) {
        boolean yes = MessageDialog.openQuestion(getShell(), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.OverwriteKarTitle"), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.OverwriteKarMessage"));
        if (!yes) {
            return false;
        }
    }
    if (exportTypeCombo.getText().equals(EXPORTTYPE_SPRING_BOOT)) {
        Bundle bundle = Platform.getBundle(PluginChecker.EXPORT_ROUTE_PLUGIN_ID);
        try {
            if (bundle != null) {
                // Get m2e preferences
                boolean mvnOffline = Platform.getPreferencesService().getBoolean(M2E_CORE, M2_OFFLINE, false, null);
                if (mvnOffline) {
                    // Change mvn to online ONLY if maven is offline needs run this part
                    IPreferenceStore camelStore = CamelDesignerPlugin.getDefault().getPreferenceStore();
                    // camelStore.setValue(TOGGLE_MAVEN_ONLINE, MessageDialogWithToggle.NEVER); //for bebug
                    if (!MessageDialogWithToggle.ALWAYS.equals(camelStore.getString(TOGGLE_MVN_ONLINE))) {
                        MessageDialogWithToggle dlg = MessageDialogWithToggle.openOkCancelConfirm(getShell(), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.MavenConfirm"), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.MavenMesssage"), Messages.getString("JavaCamelJobScriptsExportWSWizardPage.ShowItAgain"), false, camelStore, TOGGLE_MVN_ONLINE);
                        if (dlg.getReturnCode() != IDialogConstants.OK_ID) {
                            return false;
                        }
                    }
                    InstanceScope.INSTANCE.getNode(M2E_CORE).putBoolean(M2_OFFLINE, false);
                }
                Class<?> javaCamelJobScriptsExportMicroServiceAction = bundle.loadClass("org.talend.resources.export.maven.action.JavaCamelJobScriptsExportMicroServiceAction");
                Constructor<?> constructor = javaCamelJobScriptsExportMicroServiceAction.getConstructor(Map.class, List.class, String.class, String.class, String.class);
                actionMS = (IRunnableWithProgress) constructor.newInstance(exportChoiceMap, Arrays.asList(getCheckNodes()), version, destinationKar, "");
                try {
                    getContainer().run(false, true, actionMS);
                } catch (Exception e) {
                    MessageBoxExceptionHandler.process(e.getCause(), getShell());
                    return false;
                } finally {
                    if (mvnOffline) {
                        // restore maven status
                        InstanceScope.INSTANCE.getNode(M2E_CORE).putBoolean(M2_OFFLINE, mvnOffline);
                    }
                }
            }
        } catch (Exception e) {
            MessageBoxExceptionHandler.process(e.getCause(), getShell());
            e.printStackTrace();
        }
    } else {
        if (needMavenScript) {
            action = new JavaCamelJobScriptsExportWithMavenAction(exportChoiceMap, nodes[0], version, destinationKar, false);
        } else {
            action = new JavaCamelJobScriptsExportWSAction(nodes[0], version, destinationKar, false);
        }
        try {
            getContainer().run(false, true, action);
        } catch (InvocationTargetException e) {
            MessageBoxExceptionHandler.process(e.getCause(), getShell());
            return false;
        } catch (InterruptedException e) {
            return false;
        }
        manager = action.getManager();
        // save output directory
        manager.setDestinationPath(destinationKar);
        saveWidgetValues();
    }
    return true;
}
Also used : Bundle(org.osgi.framework.Bundle) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) JavaCamelJobScriptsExportWSAction(org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWSAction) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) JavaCamelJobScriptsExportWithMavenAction(org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWithMavenAction) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) File(java.io.File)

Aggregations

File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 Bundle (org.osgi.framework.Bundle)1 JavaCamelJobScriptsExportWSAction (org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWSAction)1 JavaCamelJobScriptsExportWithMavenAction (org.talend.camel.designer.ui.wizards.actions.JavaCamelJobScriptsExportWithMavenAction)1 ExportChoice (org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice)1