Search in sources :

Example 1 with DescribedVariable

use of org.apache.hop.core.config.DescribedVariable in project hop by apache.

the class ProjectDialog method getData.

private void getData() {
    wName.setText(Const.NVL(projectConfig.getProjectName(), ""));
    wHome.setText(Const.NVL(projectConfig.getProjectHome(), ""));
    wConfigFile.setText(Const.NVL(projectConfig.getConfigFilename(), ""));
    wDescription.setText(Const.NVL(project.getDescription(), ""));
    wCompany.setText(Const.NVL(project.getCompany(), ""));
    wDepartment.setText(Const.NVL(project.getDepartment(), ""));
    wMetadataBaseFolder.setText(Const.NVL(project.getMetadataBaseFolder(), ""));
    wUnitTestsBasePath.setText(Const.NVL(project.getUnitTestsBasePath(), ""));
    wDataSetCsvFolder.setText(Const.NVL(project.getDataSetsCsvFolder(), ""));
    wEnforceHomeExecution.setSelection(project.isEnforcingExecutionInHome());
    for (int i = 0; i < project.getDescribedVariables().size(); i++) {
        DescribedVariable describedVariable = project.getDescribedVariables().get(i);
        TableItem item = wVariables.table.getItem(i);
        item.setText(1, Const.NVL(describedVariable.getName(), ""));
        item.setText(2, Const.NVL(describedVariable.getValue(), ""));
        item.setText(3, Const.NVL(describedVariable.getDescription(), ""));
    }
    wVariables.setRowNums();
    wVariables.optWidth(true);
    // 
    try {
        wParentProject.setText(Const.NVL(project.getParentProjectName(), ""));
        List<String> names = ProjectsConfigSingleton.getConfig().listProjectConfigNames();
        if (projectConfig.getProjectName() != null) {
            names.remove(projectConfig.getProjectName());
        }
        wParentProject.setItems(names.toArray(new String[0]));
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "ProjectDialog.ProjectList.Error.Dialog.Header"), BaseMessages.getString(PKG, "ProjectDialog.ProjectList.Error.Dialog.Message"), e);
    }
}
Also used : DescribedVariable(org.apache.hop.core.config.DescribedVariable) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) HopException(org.apache.hop.core.exception.HopException)

Example 2 with DescribedVariable

use of org.apache.hop.core.config.DescribedVariable in project hop by apache.

the class ManageConfigFileOptionPlugin method handleOption.

@Override
public boolean handleOption(ILogChannel log, IHasHopMetadataProvider hasHopMetadataProvider, IVariables variables) throws HopException {
    String realConfigFile = variables.resolve(configFile);
    if (StringUtils.isEmpty(realConfigFile)) {
        return false;
    }
    try {
        boolean changed = false;
        DescribedVariablesConfigFile variablesConfigFile = new DescribedVariablesConfigFile(realConfigFile);
        if (HopVfs.fileExists(realConfigFile)) {
            variablesConfigFile.readFromFile();
        }
        // 
        if (configSetVariables != null && configSetVariables.length > 0) {
            for (String varValue : configSetVariables) {
                int equalsIndex = varValue.indexOf("=");
                if (equalsIndex > 0) {
                    String variableName = varValue.substring(0, equalsIndex);
                    String variableValue = varValue.substring(equalsIndex + 1);
                    DescribedVariable describedVariable = variablesConfigFile.findDescribedVariable(variableName);
                    if (describedVariable == null) {
                        describedVariable = new DescribedVariable(variableName, variableValue, "");
                    } else {
                        describedVariable.setValue(variableValue);
                    }
                    variablesConfigFile.setDescribedVariable(describedVariable);
                    changed = true;
                }
            }
        }
        // 
        if (configDescribeVariables != null && configDescribeVariables.length > 0) {
            for (String varDesc : configDescribeVariables) {
                int equalsIndex = varDesc.indexOf("=");
                if (equalsIndex > 0) {
                    String variableName = varDesc.substring(0, equalsIndex);
                    String variableDescription = varDesc.substring(equalsIndex + 1);
                    DescribedVariable describedVariable = variablesConfigFile.findDescribedVariable(variableName);
                    if (describedVariable == null) {
                        describedVariable = new DescribedVariable(variableName, null, variableDescription);
                    } else {
                        describedVariable.setDescription(variableDescription);
                    }
                    variablesConfigFile.setDescribedVariable(describedVariable);
                    changed = true;
                }
            }
        }
        if (changed) {
            variablesConfigFile.saveToFile();
            log.logBasic("Configuration file '" + configFile + "' was modified.");
        }
        return changed;
    } catch (Exception e) {
        throw new HopException("Error managing a configuration file", e);
    }
}
Also used : DescribedVariable(org.apache.hop.core.config.DescribedVariable) HopException(org.apache.hop.core.exception.HopException) DescribedVariablesConfigFile(org.apache.hop.core.config.DescribedVariablesConfigFile) HopException(org.apache.hop.core.exception.HopException)

Example 3 with DescribedVariable

use of org.apache.hop.core.config.DescribedVariable in project hop by apache.

the class ManageProjectsOptionPlugin method modifyProjectSettings.

private boolean modifyProjectSettings(Project project) {
    boolean changed = false;
    if (StringUtils.isNotEmpty(projectParent)) {
        project.setParentProjectName(projectParent);
        changed = true;
    }
    if (StringUtils.isNotEmpty(projectDescription)) {
        project.setDescription(projectDescription);
        changed = true;
    }
    if (StringUtils.isNotEmpty(projectCompany)) {
        project.setCompany(projectCompany);
        changed = true;
    }
    if (StringUtils.isNotEmpty(projectDepartment)) {
        project.setDepartment(projectDepartment);
        changed = true;
    }
    if (StringUtils.isNotEmpty(projectMetadataBaseFolder)) {
        project.setMetadataBaseFolder(projectMetadataBaseFolder);
        changed = true;
    }
    if (StringUtils.isNotEmpty(projectUnitTestsBasePath)) {
        project.setUnitTestsBasePath(projectUnitTestsBasePath);
        changed = true;
    }
    if (StringUtils.isNotEmpty(projectDataSetsCsvFolder)) {
        project.setDataSetsCsvFolder(projectDataSetsCsvFolder);
        changed = true;
    }
    if (StringUtils.isNotEmpty(projectEnforceExecutionInHome)) {
        boolean enabled = "y".equalsIgnoreCase(projectEnforceExecutionInHome) || "true".equalsIgnoreCase(projectEnforceExecutionInHome);
        project.setEnforcingExecutionInHome(enabled);
        changed = true;
    }
    if (projectVariables != null) {
        for (String projectVariable : projectVariables) {
            int equalsIndex = projectVariable.indexOf("=");
            if (equalsIndex > 0) {
                String varName = projectVariable.substring(0, equalsIndex);
                String varValue = projectVariable.substring(equalsIndex + 1);
                DescribedVariable describedVariable = new DescribedVariable(varName, varValue, "");
                project.setDescribedVariable(describedVariable);
                changed = true;
            }
        }
    }
    return changed;
}
Also used : DescribedVariable(org.apache.hop.core.config.DescribedVariable)

Example 4 with DescribedVariable

use of org.apache.hop.core.config.DescribedVariable in project hop by apache.

the class DescribedVariableSearchableAnalyser method search.

@Override
public List<ISearchResult> search(ISearchable<DescribedVariable> searchable, ISearchQuery searchQuery) {
    DescribedVariable describedVariable = searchable.getSearchableObject();
    List<ISearchResult> results = new ArrayList<>();
    matchProperty(searchable, results, searchQuery, "variable name", describedVariable.getName(), describedVariable.getName());
    matchProperty(searchable, results, searchQuery, "variable value", describedVariable.getValue(), describedVariable.getName());
    matchProperty(searchable, results, searchQuery, "variable description", describedVariable.getDescription(), describedVariable.getName());
    return results;
}
Also used : DescribedVariable(org.apache.hop.core.config.DescribedVariable) ArrayList(java.util.ArrayList)

Example 5 with DescribedVariable

use of org.apache.hop.core.config.DescribedVariable in project hop by apache.

the class HopVariablesList method init.

public static void init() throws HopException {
    instance = new HopVariablesList();
    InputStream inputStream = null;
    try {
        HopVariablesList variablesList = getInstance();
        inputStream = variablesList.getClass().getResourceAsStream(Const.HOP_VARIABLES_FILE);
        if (inputStream == null) {
            inputStream = variablesList.getClass().getResourceAsStream("/" + Const.HOP_VARIABLES_FILE);
        }
        if (inputStream == null) {
            throw new HopPluginException("Unable to find standard hop variables definition file: " + Const.HOP_VARIABLES_FILE);
        }
        Document doc = XmlHandler.loadXmlFile(inputStream, null, false, false);
        Node varsNode = XmlHandler.getSubNode(doc, "hop-variables");
        int nrVars = XmlHandler.countNodes(varsNode, "hop-variable");
        for (int i = 0; i < nrVars; i++) {
            Node varNode = XmlHandler.getSubNodeByNr(varsNode, "hop-variable", i);
            String description = XmlHandler.getTagValue(varNode, "description");
            String variable = XmlHandler.getTagValue(varNode, "variable");
            String defaultValue = XmlHandler.getTagValue(varNode, "default-value");
            instance.defaultVariables.add(new DescribedVariable(variable, defaultValue, description));
        }
    } catch (Exception e) {
        throw new HopException("Unable to read file '" + Const.HOP_VARIABLES_FILE + "'", e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                // we do not able to close property file will log it
                LogChannel.GENERAL.logDetailed("Unable to close file hop variables definition file", e);
            }
        }
    }
}
Also used : DescribedVariable(org.apache.hop.core.config.DescribedVariable) HopException(org.apache.hop.core.exception.HopException) InputStream(java.io.InputStream) Node(org.w3c.dom.Node) HopPluginException(org.apache.hop.core.exception.HopPluginException) IOException(java.io.IOException) Document(org.w3c.dom.Document) HopPluginException(org.apache.hop.core.exception.HopPluginException) HopException(org.apache.hop.core.exception.HopException) IOException(java.io.IOException)

Aggregations

DescribedVariable (org.apache.hop.core.config.DescribedVariable)18 HopException (org.apache.hop.core.exception.HopException)8 DescribedVariablesConfigFile (org.apache.hop.core.config.DescribedVariablesConfigFile)3 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)2 HopDescribedVariablesDialog (org.apache.hop.ui.core.dialog.HopDescribedVariablesDialog)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FileObject (org.apache.commons.vfs2.FileObject)1 HopVariablesList (org.apache.hop.core.HopVariablesList)1 HopConfig (org.apache.hop.core.config.HopConfig)1 IConfigFile (org.apache.hop.core.config.IConfigFile)1 ConfigFile (org.apache.hop.core.config.plugin.ConfigFile)1 HopPluginException (org.apache.hop.core.exception.HopPluginException)1 GuiMenuElement (org.apache.hop.core.gui.plugin.menu.GuiMenuElement)1 IVariables (org.apache.hop.core.variables.IVariables)1 Format (org.apache.hop.ui.core.widget.text.Format)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1