Search in sources :

Example 1 with LocalWorkflowRunConfiguration

use of org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration in project hop by apache.

the class ProjectsGuiPlugin method addNewProject.

@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_PROJECT_ADD, toolTip = "i18n::HopGui.Toolbar.Project.Add.Tooltip", image = "project-add.svg")
public void addNewProject() {
    HopGui hopGui = HopGui.getInstance();
    IVariables variables = hopGui.getVariables();
    try {
        ProjectsConfig config = ProjectsConfigSingleton.getConfig();
        String standardProjectsFolder = variables.resolve(config.getStandardProjectsFolder());
        String defaultProjectConfigFilename = variables.resolve(config.getDefaultProjectConfigFile());
        ProjectConfig projectConfig = new ProjectConfig("", standardProjectsFolder, defaultProjectConfigFilename);
        Project project = new Project();
        project.setParentProjectName(config.getStandardParentProject());
        ProjectDialog projectDialog = new ProjectDialog(hopGui.getShell(), project, projectConfig, variables, false);
        String projectName = projectDialog.open();
        if (projectName != null) {
            config.addProjectConfig(projectConfig);
            HopConfig.getInstance().saveToFile();
            // Save the project-config.json file as well in the project itself
            // 
            FileObject configFile = HopVfs.getFileObject(projectConfig.getActualProjectConfigFilename(variables));
            if (!configFile.exists()) {
                // Create the empty configuration file if it does not exists
                project.saveToFile();
            } else {
                // If projects exists load configuration
                MessageBox box = new MessageBox(hopGui.getShell(), SWT.ICON_QUESTION | SWT.OK);
                box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.ProjectExists.Dialog.Header"));
                box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.ProjectExists.Dialog.Message"));
                box.open();
                project.readFromFile();
            }
            refreshProjectsList();
            selectProjectInList(projectName);
            enableHopGuiProject(projectName, project, null);
            // Now see if these project contains any local run configurations.
            // If not we can add those automatically
            // 
            // First pipeline
            // 
            IHopMetadataSerializer<PipelineRunConfiguration> prcSerializer = hopGui.getMetadataProvider().getSerializer(PipelineRunConfiguration.class);
            List<PipelineRunConfiguration> pipelineRunConfigs = prcSerializer.loadAll();
            boolean localFound = false;
            for (PipelineRunConfiguration pipelineRunConfig : pipelineRunConfigs) {
                if (pipelineRunConfig.getEngineRunConfiguration() instanceof LocalPipelineRunConfiguration) {
                    localFound = true;
                }
            }
            if (!localFound) {
                PipelineExecutionConfigurationDialog.createLocalPipelineConfiguration(hopGui.getShell(), prcSerializer);
            }
            // Then the local workflow runconfig
            // 
            IHopMetadataSerializer<WorkflowRunConfiguration> wrcSerializer = hopGui.getMetadataProvider().getSerializer(WorkflowRunConfiguration.class);
            localFound = false;
            List<WorkflowRunConfiguration> workflowRunConfigs = wrcSerializer.loadAll();
            for (WorkflowRunConfiguration workflowRunConfig : workflowRunConfigs) {
                if (workflowRunConfig.getEngineRunConfiguration() instanceof LocalWorkflowRunConfiguration) {
                    localFound = true;
                }
            }
            if (!localFound) {
                MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
                box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfig.Dialog.Header"));
                box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfig.Dialog.Message"));
                int anwser = box.open();
                if ((anwser & SWT.YES) != 0) {
                    LocalWorkflowRunConfiguration localWorkflowRunConfiguration = new LocalWorkflowRunConfiguration();
                    localWorkflowRunConfiguration.setEnginePluginId("Local");
                    WorkflowRunConfiguration local = new WorkflowRunConfiguration("local", BaseMessages.getString(PKG, "ProjectGuiPlugin.LocalWFRunConfigDescription.Text"), localWorkflowRunConfiguration);
                    wrcSerializer.save(local);
                }
            }
            // Ask to put the project in a lifecycle environment
            // 
            MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
            box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Header"));
            box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Message1") + Const.CR + BaseMessages.getString(PKG, "ProjectGuiPlugin.Lifecycle.Dialog.Message2"));
            int anwser = box.open();
            if ((anwser & SWT.YES) != 0) {
                addNewEnvironment();
            }
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddProject.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddProject.Error.Dialog.Message"), e);
    }
}
Also used : ProjectDialog(org.apache.hop.projects.project.ProjectDialog) LocalPipelineRunConfiguration(org.apache.hop.pipeline.engines.local.LocalPipelineRunConfiguration) PipelineRunConfiguration(org.apache.hop.pipeline.config.PipelineRunConfiguration) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) MessageBox(org.eclipse.swt.widgets.MessageBox) LocalPipelineRunConfiguration(org.apache.hop.pipeline.engines.local.LocalPipelineRunConfiguration) ProjectConfig(org.apache.hop.projects.project.ProjectConfig) LocalWorkflowRunConfiguration(org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration) Project(org.apache.hop.projects.project.Project) LocalWorkflowRunConfiguration(org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration) WorkflowRunConfiguration(org.apache.hop.workflow.config.WorkflowRunConfiguration) IVariables(org.apache.hop.core.variables.IVariables) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) FileObject(org.apache.commons.vfs2.FileObject) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 2 with LocalWorkflowRunConfiguration

use of org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration in project hop by apache.

the class WorkflowExecutionConfigurationDialog method createLocalWorkflowConfiguration.

public static final String createLocalWorkflowConfiguration(Shell shell, IHopMetadataSerializer<WorkflowRunConfiguration> prcSerializer) {
    try {
        MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
        box.setText(BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.NoRunConfigurationDefined.Title"));
        box.setMessage(BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.NoRunConfigurationDefined.Message"));
        int answer = box.open();
        if ((answer & SWT.YES) != 0) {
            LocalWorkflowRunConfiguration localWorkflowRunConfiguration = new LocalWorkflowRunConfiguration();
            localWorkflowRunConfiguration.setEnginePluginId("Local");
            WorkflowRunConfiguration local = new WorkflowRunConfiguration("local", BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.LocalRunConfiguration.Description"), localWorkflowRunConfiguration);
            prcSerializer.save(local);
            return local.getName();
        }
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.ErrorSavingRunConfiguration.Title"), BaseMessages.getString(PKG, "WorkflowExecutionConfigurationDialog.ErrorSavingRunConfiguration.Message"), e);
    }
    return null;
}
Also used : LocalWorkflowRunConfiguration(org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration) LocalWorkflowRunConfiguration(org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration) WorkflowRunConfiguration(org.apache.hop.workflow.config.WorkflowRunConfiguration) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopExtensionPoint(org.apache.hop.core.extension.HopExtensionPoint) HopException(org.apache.hop.core.exception.HopException)

Aggregations

HopException (org.apache.hop.core.exception.HopException)2 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)2 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)2 WorkflowRunConfiguration (org.apache.hop.workflow.config.WorkflowRunConfiguration)2 LocalWorkflowRunConfiguration (org.apache.hop.workflow.engines.local.LocalWorkflowRunConfiguration)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 FileObject (org.apache.commons.vfs2.FileObject)1 GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)1 IVariables (org.apache.hop.core.variables.IVariables)1 PipelineRunConfiguration (org.apache.hop.pipeline.config.PipelineRunConfiguration)1 LocalPipelineRunConfiguration (org.apache.hop.pipeline.engines.local.LocalPipelineRunConfiguration)1 ProjectsConfig (org.apache.hop.projects.config.ProjectsConfig)1 Project (org.apache.hop.projects.project.Project)1 ProjectConfig (org.apache.hop.projects.project.ProjectConfig)1 ProjectDialog (org.apache.hop.projects.project.ProjectDialog)1 HopGui (org.apache.hop.ui.hopgui.HopGui)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1