Search in sources :

Example 1 with ProjectConfig

use of org.apache.hop.projects.project.ProjectConfig in project hop by apache.

the class ProjectsConfig method addProjectConfig.

public void addProjectConfig(ProjectConfig projectConfig) {
    ProjectConfig existing = findProjectConfig(projectConfig.getProjectName());
    if (existing == null) {
        projectConfigurations.add(projectConfig);
    } else {
        existing.setProjectName(projectConfig.getProjectName());
        existing.setProjectHome(projectConfig.getProjectHome());
        existing.setConfigFilename(projectConfig.getConfigFilename());
    }
}
Also used : ProjectConfig(org.apache.hop.projects.project.ProjectConfig)

Example 2 with ProjectConfig

use of org.apache.hop.projects.project.ProjectConfig 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 ProjectConfig

use of org.apache.hop.projects.project.ProjectConfig 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 ProjectConfig

use of org.apache.hop.projects.project.ProjectConfig 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)

Example 5 with ProjectConfig

use of org.apache.hop.projects.project.ProjectConfig in project hop by apache.

the class ProjectsGuiPlugin method selectProject.

@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_PROJECT_COMBO, type = GuiToolbarElementType.COMBO, comboValuesMethod = "getProjectsList", extraWidth = 200, toolTip = "i18n::HopGui.Toolbar.ProjectsList.Tooltip")
public void selectProject() {
    HopGui hopGui = HopGui.getInstance();
    Combo combo = getProjectsCombo();
    if (combo == null) {
        return;
    }
    String projectName = combo.getText();
    if (StringUtils.isEmpty(projectName)) {
        return;
    }
    ProjectsConfig config = ProjectsConfigSingleton.getConfig();
    ProjectConfig projectConfig = config.findProjectConfig(projectName);
    // What is the last used environment?
    // 
    LifecycleEnvironment environment = null;
    // 
    try {
        List<AuditEvent> environmentAuditEvents = AuditManager.findEvents(ProjectsUtil.STRING_PROJECTS_AUDIT_GROUP, ProjectsUtil.STRING_ENVIRONMENT_AUDIT_TYPE, "open", 100, true);
        for (AuditEvent auditEvent : environmentAuditEvents) {
            String environmentName = auditEvent.getName();
            if (StringUtils.isNotEmpty(environmentName)) {
                environment = config.findEnvironment(environmentName);
                // 
                if (projectName.equals(environment.getProjectName())) {
                    // We found what we've been looking for
                    break;
                } else {
                    // The project doesn't to the last selected environment
                    // Since we selected the project it is the driver of the selection.
                    // Keep looking.
                    // 
                    environment = null;
                }
            }
        }
    } catch (Exception e) {
        LogChannel.UI.logError("Error reading the last used environment from the audit logs", e);
    }
    // 
    if (environment == null) {
        List<LifecycleEnvironment> environments = config.findEnvironmentsOfProject(projectName);
        if (!environments.isEmpty()) {
            environment = environments.get(0);
        }
    }
    try {
        Project project = projectConfig.loadProject(hopGui.getVariables());
        if (project != null) {
            enableHopGuiProject(projectName, project, environment);
        } else {
            hopGui.getLog().logError("Unable to find project '" + projectName + "'");
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.ChangeProject.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.ChangeProject.Error.Dialog.Message", projectName), 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) Combo(org.eclipse.swt.widgets.Combo) AuditEvent(org.apache.hop.history.AuditEvent) 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

ProjectConfig (org.apache.hop.projects.project.ProjectConfig)25 ProjectsConfig (org.apache.hop.projects.config.ProjectsConfig)20 HopException (org.apache.hop.core.exception.HopException)16 Project (org.apache.hop.projects.project.Project)12 HopGui (org.apache.hop.ui.hopgui.HopGui)10 IOException (java.io.IOException)9 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 GuiToolbarElement (org.apache.hop.core.gui.plugin.toolbar.GuiToolbarElement)8 LifecycleEnvironment (org.apache.hop.projects.environment.LifecycleEnvironment)6 Combo (org.eclipse.swt.widgets.Combo)6 FileObject (org.apache.commons.vfs2.FileObject)5 AuditEvent (org.apache.hop.history.AuditEvent)3 ProjectDialog (org.apache.hop.projects.project.ProjectDialog)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 OutputStream (java.io.OutputStream)2 HopExtensionPoint (org.apache.hop.core.extension.HopExtensionPoint)2 ILogChannel (org.apache.hop.core.logging.ILogChannel)2 IVariables (org.apache.hop.core.variables.IVariables)2 PipelineRunConfiguration (org.apache.hop.pipeline.config.PipelineRunConfiguration)2