Search in sources :

Example 16 with ProjectsConfig

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

the class HopGuiDirectoryOpenSetDefaultFolder method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, HopGuiDirectoryDialogExtension ext) throws HopException {
    String projectName = HopNamespace.getNamespace();
    if (StringUtil.isEmpty(projectName)) {
        return;
    }
    // 
    if (ext.directoryDialog != null && StringUtils.isNotEmpty(ext.directoryDialog.getFilterPath())) {
        return;
    }
    try {
        ProjectsConfig config = ProjectsConfigSingleton.getConfig();
        ProjectConfig projectConfig = config.findProjectConfig(projectName);
        if (projectConfig == null) {
            return;
        }
        String homeFolder = projectConfig.getProjectHome();
        if (homeFolder != null) {
            IDirectoryDialog dialog = ext.getDirectoryDialog();
            dialog.setFilterPath(homeFolder);
        }
    } catch (Exception e) {
        log.logError("Error setting default folder for project " + projectName, e);
    }
}
Also used : ProjectConfig(org.apache.hop.projects.project.ProjectConfig) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) IDirectoryDialog(org.apache.hop.ui.core.dialog.IDirectoryDialog) HopException(org.apache.hop.core.exception.HopException)

Example 17 with ProjectsConfig

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

the class HopImportCreateProjectIfNotExists method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel iLogChannel, IVariables variables, String projectPath) throws HopException {
    String projectName = "Hop Import Project";
    String envName = "Hop Import Environment";
    HopGui hopGui = HopGui.getInstance();
    ProjectsConfig config = ProjectsConfigSingleton.getConfig();
    // create new project
    if (!StringUtil.isEmpty(projectPath)) {
        String defaultProjectConfigFilename = variables.resolve(config.getDefaultProjectConfigFile());
        ProjectConfig projectConfig = new ProjectConfig(projectName, projectPath, defaultProjectConfigFilename);
        Project project = new Project();
        project.getDescribedVariables().clear();
        project.modifyVariables(variables, projectConfig, Collections.emptyList(), null);
        project.setConfigFilename(projectPath + System.getProperty("file.separator") + "project-config.json");
        config.addProjectConfig(projectConfig);
        HopConfig.getInstance().saveToFile();
        project.saveToFile();
    }
}
Also used : ProjectConfig(org.apache.hop.projects.project.ProjectConfig) Project(org.apache.hop.projects.project.Project) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) HopGui(org.apache.hop.ui.hopgui.HopGui)

Example 18 with ProjectsConfig

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

the class ManageLifecyclesOptionPlugin method createLifecycle.

private void createLifecycle(ILogChannel log) throws Exception {
    ProjectsConfig config = ProjectsConfigSingleton.getConfig();
    validateLifecycleNameSpecified();
    log.logBasic("Creating project lifecycle '" + lifecycleName + "'");
    ProjectLifecycle lifecycle = config.findLifecycle(lifecycleName);
    if (lifecycle != null) {
        throw new HopException("Project lifecycle '" + lifecycleName + "' already exists.");
    }
    lifecycle = new ProjectLifecycle();
    lifecycle.setName(lifecycleName);
    if (lifecycleEnvironments != null) {
        lifecycle.getLifecycleEnvironments().addAll(Arrays.asList(lifecycleEnvironments));
    }
    if (configFilenames != null) {
        lifecycle.getConfigurationFiles().addAll(Arrays.asList(configFilenames));
    }
    config.addLifecycle(lifecycle);
    HopConfig.getInstance().saveToFile();
    log.logBasic("Project lifecycle '" + lifecycleName + "' was created.");
    log.logBasic("Details after creation:");
    logLifecycleDetails(log, lifecycle);
}
Also used : HopException(org.apache.hop.core.exception.HopException) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig)

Example 19 with ProjectsConfig

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

the class Project method verifyProjectsChain.

/**
 * Let's check to see if there isn't an infinite loop in the project definition
 *
 * @throws HopException
 */
public void verifyProjectsChain(String projectName, IVariables variables) throws HopException {
    // 
    if (StringUtils.isEmpty(parentProjectName)) {
        return;
    }
    if (parentProjectName.equals(projectName)) {
        throw new HopException("Parent project '" + parentProjectName + "' can not be the same as the project itself");
    }
    ProjectsConfig config = ProjectsConfigSingleton.getConfig();
    String realParentProjectName = variables.resolve(parentProjectName);
    List<String> projectsList = new ArrayList<>();
    while (StringUtils.isNotEmpty(realParentProjectName)) {
        projectsList.add(realParentProjectName);
        ProjectConfig projectConfig = config.findProjectConfig(realParentProjectName);
        if (projectConfig != null) {
            Project parentProject = projectConfig.loadProject(variables);
            if (parentProject == null) {
                // Can't be loaded, break out of the loop
                realParentProjectName = null;
            } else {
                // 
                if (StringUtils.isEmpty(parentProject.parentProjectName)) {
                    // We're done
                    realParentProjectName = null;
                } else {
                    realParentProjectName = variables.resolve(parentProject.parentProjectName);
                    if (StringUtils.isNotEmpty(realParentProjectName)) {
                        // 
                        if (projectsList.contains(realParentProjectName)) {
                            throw new HopException("There is a loop in the parent projects hierarchy: project " + realParentProjectName + " references itself");
                        }
                    }
                }
            }
        } else {
            // Project not found: config error, stop looking
            realParentProjectName = null;
        }
    }
}
Also used : HopException(org.apache.hop.core.exception.HopException) ProjectsConfig(org.apache.hop.projects.config.ProjectsConfig) ArrayList(java.util.ArrayList)

Example 20 with ProjectsConfig

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

the class ProjectsGuiPlugin method editEnvironment.

// ////////////////////////////////////////////////////////////////////////////////
// Environment toolbar items...
// 
// ////////////////////////////////////////////////////////////////////////////////
@GuiToolbarElement(root = HopGui.ID_MAIN_TOOLBAR, id = ID_TOOLBAR_ENVIRONMENT_LABEL, type = GuiToolbarElementType.LABEL, label = "i18n::HopGui.Toolbar.Environment.Label", toolTip = "i18n::HopGui.Toolbar.Environment.Tooltip", separator = true)
public void editEnvironment() {
    HopGui hopGui = HopGui.getInstance();
    Combo combo = getEnvironmentsCombo();
    if (combo == null) {
        return;
    }
    ProjectsConfig config = ProjectsConfigSingleton.getConfig();
    String environmentName = combo.getText();
    if (StringUtils.isEmpty(environmentName)) {
        return;
    }
    LifecycleEnvironment environment = config.findEnvironment(environmentName);
    if (environment == null) {
        return;
    }
    try {
        LifecycleEnvironmentDialog dialog = new LifecycleEnvironmentDialog(hopGui.getShell(), environment, hopGui.getVariables());
        if (dialog.open() != null) {
            config.addEnvironment(environment);
            ProjectsConfigSingleton.saveConfig();
            refreshEnvironmentsList();
            selectEnvironmentInList(environmentName);
        }
        // 
        if (dialog.isNeedingEnvironmentRefresh() && askAboutProjectRefresh(hopGui)) {
            // Refresh the loaded environment
            // 
            selectEnvironment();
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "ProjectGuiPlugin.EditEnvironment.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectGuiPlugin.EditEnvironment.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) 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