Search in sources :

Example 1 with ProjectsConfig

use of org.apache.hop.projects.config.ProjectsConfig in project hop by apache.

the class ManageEnvironmentsOptionPlugin method handleOption.

@Override
public boolean handleOption(ILogChannel log, IHasHopMetadataProvider hasHopMetadataProvider, IVariables variables) throws HopException {
    ProjectsConfig config = ProjectsConfigSingleton.getConfig();
    try {
        boolean changed = false;
        if (createEnvironment) {
            createEnvironment(log, config, variables, hasHopMetadataProvider);
            changed = true;
        } else if (modifyEnvironment) {
            modifyEnvironment(log, config, variables, hasHopMetadataProvider);
            changed = true;
        } else if (deleteEnvironment) {
            deleteEnvironment(log, config, variables);
            changed = true;
        } else if (listEnvironments) {
            listEnvironments(log, config, variables);
            changed = true;
        }
        return changed;
    } catch (Exception e) {
        throw new HopException("Error handling project lifecycle environments configuration options", e);
    }
}
Also used : HopException(org.apache.hop.core.exception.HopException) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) HopException(org.apache.hop.core.exception.HopException)

Example 2 with ProjectsConfig

use of org.apache.hop.projects.config.ProjectsConfig in project hop by apache.

the class ProjectsGuiPlugin method selectProjectInList.

public static void selectProjectInList(String name) {
    GuiToolbarWidgets toolbarWidgets = HopGui.getInstance().getMainToolbarWidgets();
    toolbarWidgets.selectComboItem(ID_TOOLBAR_PROJECT_COMBO, name);
    Combo combo = getProjectsCombo();
    if (combo != null) {
        ProjectsConfig config = ProjectsConfigSingleton.getConfig();
        ProjectConfig projectConfig = config.findProjectConfig(name);
        if (projectConfig != null) {
            String projectHome = projectConfig.getProjectHome();
            if (StringUtils.isNotEmpty(projectHome)) {
                combo.setToolTipText(BaseMessages.getString(PKG, "ProjectGuiPlugin.SelectProject.Tooltip", name, projectHome, projectConfig.getConfigFilename()));
            }
        }
    }
}
Also used : ProjectConfig(org.apache.hop.projects.project.ProjectConfig) GuiToolbarWidgets(org.apache.hop.ui.core.gui.GuiToolbarWidgets) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) Combo(org.eclipse.swt.widgets.Combo)

Example 3 with ProjectsConfig

use of org.apache.hop.projects.config.ProjectsConfig 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 4 with ProjectsConfig

use of org.apache.hop.projects.config.ProjectsConfig in project hop by apache.

the class ProjectsGuiPlugin method deleteSelectedEnvironment.

@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_ENVIRONMENT_DELETE, toolTip = "i18n::HopGui.Toolbar.Environment.Delete.Tooltip", image = "environment-delete.svg", separator = true)
public void deleteSelectedEnvironment() {
    Combo combo = getEnvironmentsCombo();
    if (combo == null) {
        return;
    }
    String environmentName = combo.getText();
    if (StringUtils.isEmpty(environmentName)) {
        return;
    }
    ProjectsConfig config = ProjectsConfigSingleton.getConfig();
    LifecycleEnvironment environment = config.findEnvironment(environmentName);
    if (environment == null) {
        return;
    }
    MessageBox box = new MessageBox(HopGui.getInstance().getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
    box.setText(BaseMessages.getString(PKG, "ProjectGuiPlugin.DeleteEnvironment.Dialog.Header"));
    box.setMessage(BaseMessages.getString(PKG, "ProjectGuiPlugin.DeleteEnvironment.Dialog.Message1", environmentName) + Const.CR + BaseMessages.getString(PKG, "ProjectGuiPlugin.DeleteEnvironment.Dialog.Message2", environment.getProjectName()));
    int anwser = box.open();
    if ((anwser & SWT.YES) != 0) {
        try {
            config.removeEnvironment(environmentName);
            ProjectsConfigSingleton.saveConfig();
            refreshEnvironmentsList();
            selectEnvironmentInList(null);
        } catch (Exception e) {
            new ErrorDialog(HopGui.getInstance().getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.DeleteEnvironment.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.DeleteEnvironment.Error.Dialog.Message", environmentName), e);
        }
    }
}
Also used : LifecycleEnvironment(org.apache.hop.projects.environment.LifecycleEnvironment) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) Combo(org.eclipse.swt.widgets.Combo) 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) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Example 5 with ProjectsConfig

use of org.apache.hop.projects.config.ProjectsConfig in project hop by apache.

the class ProjectsGuiPlugin method addNewEnvironment.

@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_ENVIRONMENT_ADD, toolTip = "i18n::HopGui.Toolbar.Environment.Add.Tooltip", image = "environment-add.svg")
public void addNewEnvironment() {
    HopGui hopGui = HopGui.getInstance();
    try {
        ProjectsConfig config = ProjectsConfigSingleton.getConfig();
        // The default is the active project
        String projectName = getProjectsCombo().getText();
        LifecycleEnvironment environment = new LifecycleEnvironment(null, "", projectName, new ArrayList<>());
        LifecycleEnvironmentDialog dialog = new LifecycleEnvironmentDialog(hopGui.getShell(), environment, hopGui.getVariables());
        String environmentName = dialog.open();
        if (environmentName != null) {
            config.addEnvironment(environment);
            ProjectsConfigSingleton.saveConfig();
            refreshEnvironmentsList();
            selectEnvironmentInList(environmentName);
            ProjectConfig projectConfig = config.findProjectConfig(projectName);
            if (projectConfig != null) {
                Project project = projectConfig.loadProject(hopGui.getVariables());
                enableHopGuiProject(projectName, project, environment);
            }
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddEnvironment.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.AddEnvironment.Error.Dialog.Message"), e);
    }
}
Also used : ProjectConfig(org.apache.hop.projects.project.ProjectConfig) Project(org.apache.hop.projects.project.Project) LifecycleEnvironment(org.apache.hop.projects.environment.LifecycleEnvironment) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) LifecycleEnvironmentDialog(org.apache.hop.projects.environment.LifecycleEnvironmentDialog) HopException(org.apache.hop.core.exception.HopException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) HopGui(org.apache.hop.ui.hopgui.HopGui) GuiToolbarElement(org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)

Aggregations

ProjectsConfig (org.apache.hop.projects.config.ProjectsConfig)33 HopException (org.apache.hop.core.exception.HopException)22 ProjectConfig (org.apache.hop.projects.project.ProjectConfig)20 HopGui (org.apache.hop.ui.hopgui.HopGui)12 IOException (java.io.IOException)11 Project (org.apache.hop.projects.project.Project)11 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)11 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)10 LifecycleEnvironment (org.apache.hop.projects.environment.LifecycleEnvironment)9 Combo (org.eclipse.swt.widgets.Combo)9 FileObject (org.apache.commons.vfs2.FileObject)4 MessageBox (org.eclipse.swt.widgets.MessageBox)4 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)3 AuditEvent (org.apache.hop.history.AuditEvent)3 LifecycleEnvironmentDialog (org.apache.hop.projects.environment.LifecycleEnvironmentDialog)3 ProjectDialog (org.apache.hop.projects.project.ProjectDialog)3 GuiToolbarWidgets (org.apache.hop.ui.core.gui.GuiToolbarWidgets)3 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2