Search in sources :

Example 1 with StringSearchResult

use of org.pentaho.di.core.reflection.StringSearchResult in project pentaho-kettle by pentaho.

the class JobMeta method getUsedVariables.

/**
 * Gets the used variables.
 *
 * @return the used variables
 */
public List<String> getUsedVariables() {
    // Get the list of Strings.
    List<StringSearchResult> stringList = getStringList(true, true, false);
    List<String> varList = new ArrayList<String>();
    // Look around in the strings, see what we find...
    for (StringSearchResult result : stringList) {
        StringUtil.getUsedVariables(result.getString(), varList, false);
    }
    return varList;
}
Also used : ArrayList(java.util.ArrayList) StringSearchResult(org.pentaho.di.core.reflection.StringSearchResult)

Example 2 with StringSearchResult

use of org.pentaho.di.core.reflection.StringSearchResult in project pentaho-kettle by pentaho.

the class JobMeta method getStringList.

/**
 * Get a list of all the strings used in this job.
 *
 * @return A list of StringSearchResult with strings used in the job
 */
public List<StringSearchResult> getStringList(boolean searchSteps, boolean searchDatabases, boolean searchNotes) {
    List<StringSearchResult> stringList = new ArrayList<StringSearchResult>();
    if (searchSteps) {
        // vars are...
        for (int i = 0; i < nrJobEntries(); i++) {
            JobEntryCopy entryMeta = getJobEntry(i);
            stringList.add(new StringSearchResult(entryMeta.getName(), entryMeta, this, BaseMessages.getString(PKG, "JobMeta.SearchMetadata.JobEntryName")));
            if (entryMeta.getDescription() != null) {
                stringList.add(new StringSearchResult(entryMeta.getDescription(), entryMeta, this, BaseMessages.getString(PKG, "JobMeta.SearchMetadata.JobEntryDescription")));
            }
            JobEntryInterface metaInterface = entryMeta.getEntry();
            StringSearcher.findMetaData(metaInterface, 1, stringList, entryMeta, this);
        }
    }
    // are...
    if (searchDatabases) {
        for (int i = 0; i < nrDatabases(); i++) {
            DatabaseMeta meta = getDatabase(i);
            stringList.add(new StringSearchResult(meta.getName(), meta, this, BaseMessages.getString(PKG, "JobMeta.SearchMetadata.DatabaseConnectionName")));
            if (meta.getHostname() != null) {
                stringList.add(new StringSearchResult(meta.getHostname(), meta, this, BaseMessages.getString(PKG, "JobMeta.SearchMetadata.DatabaseHostName")));
            }
            if (meta.getDatabaseName() != null) {
                stringList.add(new StringSearchResult(meta.getDatabaseName(), meta, this, BaseMessages.getString(PKG, "JobMeta.SearchMetadata.DatabaseName")));
            }
            if (meta.getUsername() != null) {
                stringList.add(new StringSearchResult(meta.getUsername(), meta, this, BaseMessages.getString(PKG, "JobMeta.SearchMetadata.DatabaseUsername")));
            }
            if (meta.getPluginId() != null) {
                stringList.add(new StringSearchResult(meta.getPluginId(), meta, this, BaseMessages.getString(PKG, "JobMeta.SearchMetadata.DatabaseTypeDescription")));
            }
            if (meta.getDatabasePortNumberString() != null) {
                stringList.add(new StringSearchResult(meta.getDatabasePortNumberString(), meta, this, BaseMessages.getString(PKG, "JobMeta.SearchMetadata.DatabasePort")));
            }
            if (meta.getServername() != null) {
                stringList.add(new StringSearchResult(meta.getServername(), meta, this, BaseMessages.getString(PKG, "JobMeta.SearchMetadata.DatabaseServer")));
            }
            // {
            if (meta.getPassword() != null) {
                stringList.add(new StringSearchResult(meta.getPassword(), meta, this, BaseMessages.getString(PKG, "JobMeta.SearchMetadata.DatabasePassword")));
            // }
            }
        }
    }
    // are...
    if (searchNotes) {
        for (int i = 0; i < nrNotes(); i++) {
            NotePadMeta meta = getNote(i);
            if (meta.getNote() != null) {
                stringList.add(new StringSearchResult(meta.getNote(), meta, this, BaseMessages.getString(PKG, "JobMeta.SearchMetadata.NotepadText")));
            }
        }
    }
    return stringList;
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) ArrayList(java.util.ArrayList) StringSearchResult(org.pentaho.di.core.reflection.StringSearchResult) NotePadMeta(org.pentaho.di.core.NotePadMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 3 with StringSearchResult

use of org.pentaho.di.core.reflection.StringSearchResult in project pentaho-kettle by pentaho.

the class Spoon method searchMetaData.

/**
 * Search the transformation meta-data.
 */
public void searchMetaData() {
    TransMeta[] transMetas = getLoadedTransformations();
    JobMeta[] jobMetas = getLoadedJobs();
    if ((transMetas == null || transMetas.length == 0) && (jobMetas == null || jobMetas.length == 0)) {
        return;
    }
    EnterSearchDialog esd = new EnterSearchDialog(shell);
    if (!esd.open()) {
        return;
    }
    List<Object[]> rows = new ArrayList<>();
    for (TransMeta transMeta : transMetas) {
        String filter = esd.getFilterString();
        if (filter != null) {
            filter = filter.toUpperCase();
        }
        List<StringSearchResult> stringList = transMeta.getStringList(esd.isSearchingSteps(), esd.isSearchingDatabases(), esd.isSearchingNotes());
        for (StringSearchResult result : stringList) {
            boolean add = Utils.isEmpty(filter);
            if (filter != null && result.getString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getFieldName().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getParentObject().toString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getGrandParentObject().toString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (add) {
                rows.add(result.toRow());
            }
        }
    }
    for (JobMeta jobMeta : jobMetas) {
        String filter = esd.getFilterString();
        if (filter != null) {
            filter = filter.toUpperCase();
        }
        List<StringSearchResult> stringList = jobMeta.getStringList(esd.isSearchingSteps(), esd.isSearchingDatabases(), esd.isSearchingNotes());
        for (StringSearchResult result : stringList) {
            boolean add = Utils.isEmpty(filter);
            if (filter != null && result.getString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getFieldName().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getParentObject().toString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (filter != null && result.getGrandParentObject().toString().toUpperCase().contains(filter)) {
                add = true;
            }
            if (add) {
                rows.add(result.toRow());
            }
        }
    }
    if (rows.size() != 0) {
        PreviewRowsDialog prd = new PreviewRowsDialog(shell, Variables.getADefaultVariableSpace(), SWT.NONE, BaseMessages.getString(PKG, "Spoon.StringSearchResult.Subtitle"), StringSearchResult.getResultRowMeta(), rows);
        String title = BaseMessages.getString(PKG, "Spoon.StringSearchResult.Title");
        String message = BaseMessages.getString(PKG, "Spoon.StringSearchResult.Message");
        prd.setTitleMessage(title, message);
        prd.open();
    } else {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
        mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NothingFound.Message"));
        // Sorry!
        mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NothingFound.Title"));
        mb.open();
    }
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) MessageBox(org.eclipse.swt.widgets.MessageBox) StringSearchResult(org.pentaho.di.core.reflection.StringSearchResult) EnterSearchDialog(org.pentaho.di.ui.core.dialog.EnterSearchDialog)

Example 4 with StringSearchResult

use of org.pentaho.di.core.reflection.StringSearchResult in project pentaho-kettle by pentaho.

the class TransMeta method getUsedVariables.

/**
 * Gets a list of the used variables in this transformation.
 *
 * @return a list of the used variables in this transformation.
 */
public List<String> getUsedVariables() {
    // Get the list of Strings.
    List<StringSearchResult> stringList = getStringList(true, true, false, true);
    List<String> varList = new ArrayList<>();
    // Look around in the strings, see what we find...
    for (int i = 0; i < stringList.size(); i++) {
        StringSearchResult result = stringList.get(i);
        StringUtil.getUsedVariables(result.getString(), varList, false);
    }
    return varList;
}
Also used : ArrayList(java.util.ArrayList) StringSearchResult(org.pentaho.di.core.reflection.StringSearchResult) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 5 with StringSearchResult

use of org.pentaho.di.core.reflection.StringSearchResult in project pentaho-kettle by pentaho.

the class TransMeta method getStringList.

/**
 * Gets a list of all the strings used in this transformation. The parameters indicate which collections to search and
 * which to exclude.
 *
 * @param searchSteps
 *          true if steps should be searched, false otherwise
 * @param searchDatabases
 *          true if databases should be searched, false otherwise
 * @param searchNotes
 *          true if notes should be searched, false otherwise
 * @param includePasswords
 *          true if passwords should be searched, false otherwise
 * @return a list of search results for strings used in the transformation.
 */
public List<StringSearchResult> getStringList(boolean searchSteps, boolean searchDatabases, boolean searchNotes, boolean includePasswords) {
    List<StringSearchResult> stringList = new ArrayList<>();
    if (searchSteps) {
        // Loop over all steps in the transformation and see what the used vars are...
        for (int i = 0; i < nrSteps(); i++) {
            StepMeta stepMeta = getStep(i);
            stringList.add(new StringSearchResult(stepMeta.getName(), stepMeta, this, BaseMessages.getString(PKG, "TransMeta.SearchMetadata.StepName")));
            if (stepMeta.getDescription() != null) {
                stringList.add(new StringSearchResult(stepMeta.getDescription(), stepMeta, this, BaseMessages.getString(PKG, "TransMeta.SearchMetadata.StepDescription")));
            }
            StepMetaInterface metaInterface = stepMeta.getStepMetaInterface();
            StringSearcher.findMetaData(metaInterface, 1, stringList, stepMeta, this);
        }
    }
    // Loop over all steps in the transformation and see what the used vars are...
    if (searchDatabases) {
        for (int i = 0; i < nrDatabases(); i++) {
            DatabaseMeta meta = getDatabase(i);
            stringList.add(new StringSearchResult(meta.getName(), meta, this, BaseMessages.getString(PKG, "TransMeta.SearchMetadata.DatabaseConnectionName")));
            if (meta.getHostname() != null) {
                stringList.add(new StringSearchResult(meta.getHostname(), meta, this, BaseMessages.getString(PKG, "TransMeta.SearchMetadata.DatabaseHostName")));
            }
            if (meta.getDatabaseName() != null) {
                stringList.add(new StringSearchResult(meta.getDatabaseName(), meta, this, BaseMessages.getString(PKG, "TransMeta.SearchMetadata.DatabaseName")));
            }
            if (meta.getUsername() != null) {
                stringList.add(new StringSearchResult(meta.getUsername(), meta, this, BaseMessages.getString(PKG, "TransMeta.SearchMetadata.DatabaseUsername")));
            }
            if (meta.getPluginId() != null) {
                stringList.add(new StringSearchResult(meta.getPluginId(), meta, this, BaseMessages.getString(PKG, "TransMeta.SearchMetadata.DatabaseTypeDescription")));
            }
            if (meta.getDatabasePortNumberString() != null) {
                stringList.add(new StringSearchResult(meta.getDatabasePortNumberString(), meta, this, BaseMessages.getString(PKG, "TransMeta.SearchMetadata.DatabasePort")));
            }
            if (meta.getServername() != null) {
                stringList.add(new StringSearchResult(meta.getServername(), meta, this, BaseMessages.getString(PKG, "TransMeta.SearchMetadata.DatabaseServer")));
            }
            if (includePasswords) {
                if (meta.getPassword() != null) {
                    stringList.add(new StringSearchResult(meta.getPassword(), meta, this, BaseMessages.getString(PKG, "TransMeta.SearchMetadata.DatabasePassword")));
                }
            }
        }
    }
    // Loop over all steps in the transformation and see what the used vars are...
    if (searchNotes) {
        for (int i = 0; i < nrNotes(); i++) {
            NotePadMeta meta = getNote(i);
            if (meta.getNote() != null) {
                stringList.add(new StringSearchResult(meta.getNote(), meta, this, BaseMessages.getString(PKG, "TransMeta.SearchMetadata.NotepadText")));
            }
        }
    }
    return stringList;
}
Also used : ArrayList(java.util.ArrayList) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StringSearchResult(org.pentaho.di.core.reflection.StringSearchResult) NotePadMeta(org.pentaho.di.core.NotePadMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Aggregations

ArrayList (java.util.ArrayList)5 StringSearchResult (org.pentaho.di.core.reflection.StringSearchResult)5 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)3 Point (org.pentaho.di.core.gui.Point)3 NotePadMeta (org.pentaho.di.core.NotePadMeta)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 MessageBox (org.eclipse.swt.widgets.MessageBox)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1 JobMeta (org.pentaho.di.job.JobMeta)1 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)1 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)1 TransMeta (org.pentaho.di.trans.TransMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)1 EnterSearchDialog (org.pentaho.di.ui.core.dialog.EnterSearchDialog)1 PreviewRowsDialog (org.pentaho.di.ui.core.dialog.PreviewRowsDialog)1