Search in sources :

Example 96 with RowMetaAndData

use of org.apache.hop.core.RowMetaAndData in project hop by apache.

the class ActionDeleteFolders method execute.

@Override
public Result execute(Result result, int nr) throws HopException {
    List<RowMetaAndData> rows = result.getRows();
    result.setNrErrors(1);
    result.setResult(false);
    nrErrors = 0;
    nrSuccess = 0;
    successConditionBroken = false;
    successConditionBrokenExit = false;
    nrLimitFolders = Const.toInt(resolve(getLimitFolders()), 10);
    if (argFromPrevious && log.isDetailed()) {
        logDetailed(BaseMessages.getString(PKG, "ActionDeleteFolders.FoundPreviousRows", String.valueOf((rows != null ? rows.size() : 0))));
    }
    if (argFromPrevious && rows != null) {
        for (int iteration = 0; iteration < rows.size() && !parentWorkflow.isStopped(); iteration++) {
            if (successConditionBroken) {
                logError(BaseMessages.getString(PKG, "ActionDeleteFolders.Error.SuccessConditionbroken", "" + nrErrors));
                result.setNrErrors(nrErrors);
                result.setNrLinesDeleted(nrSuccess);
                return result;
            }
            RowMetaAndData resultRow = rows.get(iteration);
            String argsPrevious = resultRow.getString(0, null);
            if (!Utils.isEmpty(argsPrevious)) {
                if (deleteFolder(argsPrevious)) {
                    updateSuccess();
                } else {
                    updateErrors();
                }
            } else {
                // empty filename !
                logError(BaseMessages.getString(PKG, "ActionDeleteFolders.Error.EmptyLine"));
            }
        }
    } else if (arguments != null) {
        for (int i = 0; i < arguments.length && !parentWorkflow.isStopped(); i++) {
            if (successConditionBroken) {
                logError(BaseMessages.getString(PKG, "ActionDeleteFolders.Error.SuccessConditionbroken", "" + nrErrors));
                result.setNrErrors(nrErrors);
                result.setNrLinesDeleted(nrSuccess);
                return result;
            }
            String realfilename = resolve(arguments[i]);
            if (!Utils.isEmpty(realfilename)) {
                if (deleteFolder(realfilename)) {
                    updateSuccess();
                } else {
                    updateErrors();
                }
            } else {
                // empty filename !
                logError(BaseMessages.getString(PKG, "ActionDeleteFolders.Error.EmptyLine"));
            }
        }
    }
    if (log.isDetailed()) {
        logDetailed("=======================================");
        logDetailed(BaseMessages.getString(PKG, "ActionDeleteFolders.Log.Info.NrError", "" + nrErrors));
        logDetailed(BaseMessages.getString(PKG, "ActionDeleteFolders.Log.Info.NrDeletedFolders", "" + nrSuccess));
        logDetailed("=======================================");
    }
    result.setNrErrors(nrErrors);
    result.setNrLinesDeleted(nrSuccess);
    if (getSuccessStatus()) {
        result.setResult(true);
    }
    return result;
}
Also used : RowMetaAndData(org.apache.hop.core.RowMetaAndData)

Example 97 with RowMetaAndData

use of org.apache.hop.core.RowMetaAndData in project hop by apache.

the class ActionDosToUnix method execute.

@Override
public Result execute(Result previousResult, int nr) throws HopException {
    Result result = previousResult;
    result.setNrErrors(1);
    result.setResult(false);
    List<RowMetaAndData> rows = previousResult.getRows();
    RowMetaAndData resultRow = null;
    nrErrors = 0;
    nrProcessedFiles = 0;
    nrErrorFiles = 0;
    limitFiles = Const.toInt(resolve(getNrErrorsLessThan()), 10);
    successConditionBroken = false;
    successConditionBrokenExit = false;
    tempFolder = resolve("%%java.io.tmpdir%%");
    // Get source and destination files, also wildcard
    String[] vSourceFileFolder = sourceFileFolder;
    String[] vwildcard = wildcard;
    if (argFromPrevious) {
        if (isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "JobDosToUnix.Log.ArgFromPrevious.Found", (rows != null ? rows.size() : 0) + ""));
        }
    }
    if (argFromPrevious && rows != null) {
        // Copy the input row to the (command line) arguments
        for (int iteration = 0; iteration < rows.size() && !parentWorkflow.isStopped(); iteration++) {
            if (successConditionBroken) {
                if (!successConditionBrokenExit) {
                    logError(BaseMessages.getString(PKG, "ActionDosToUnix.Error.SuccessConditionbroken", "" + nrAllErrors));
                    successConditionBrokenExit = true;
                }
                result.setEntryNr(nrAllErrors);
                result.setNrLinesRejected(nrErrorFiles);
                result.setNrLinesWritten(nrProcessedFiles);
                return result;
            }
            resultRow = rows.get(iteration);
            // Get source and destination file names, also wildcard
            String vSourceFileFolderPrevious = resultRow.getString(0, null);
            String vWildcardPrevious = resultRow.getString(1, null);
            int conversionType = ActionDosToUnix.getConversionTypeByCode(resultRow.getString(2, null));
            if (isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "JobDosToUnix.Log.ProcessingRow", vSourceFileFolderPrevious, vWildcardPrevious));
            }
            processFileFolder(vSourceFileFolderPrevious, vWildcardPrevious, conversionType, parentWorkflow, result);
        }
    } else if (vSourceFileFolder != null) {
        for (int i = 0; i < vSourceFileFolder.length && !parentWorkflow.isStopped(); i++) {
            if (successConditionBroken) {
                if (!successConditionBrokenExit) {
                    logError(BaseMessages.getString(PKG, "ActionDosToUnix.Error.SuccessConditionbroken", "" + nrAllErrors));
                    successConditionBrokenExit = true;
                }
                result.setEntryNr(nrAllErrors);
                result.setNrLinesRejected(nrErrorFiles);
                result.setNrLinesWritten(nrProcessedFiles);
                return result;
            }
            if (isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "ActionDosToUnix.Log.ProcessingRow", vSourceFileFolder[i], vwildcard[i]));
            }
            processFileFolder(vSourceFileFolder[i], vwildcard[i], conversionTypes[i], parentWorkflow, result);
        }
    }
    // Success Condition
    result.setNrErrors(nrAllErrors);
    result.setNrLinesRejected(nrErrorFiles);
    result.setNrLinesWritten(nrProcessedFiles);
    if (getSuccessStatus()) {
        result.setNrErrors(0);
        result.setResult(true);
    }
    displayResults();
    return result;
}
Also used : RowMetaAndData(org.apache.hop.core.RowMetaAndData) Result(org.apache.hop.core.Result)

Example 98 with RowMetaAndData

use of org.apache.hop.core.RowMetaAndData in project hop by apache.

the class TestingGuiPlugin method selectUnitTestFromAllTests.

/**
 * List all unit tests which are defined And allow the user to select one
 */
public RowMetaAndData selectUnitTestFromAllTests() {
    HopGui hopGui = HopGui.getInstance();
    IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
    IRowMeta rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("Unit test"));
    rowMeta.addValueMeta(new ValueMetaString("Description"));
    rowMeta.addValueMeta(new ValueMetaString("Filename"));
    List<RowMetaAndData> rows = new ArrayList<>();
    try {
        IHopMetadataSerializer<PipelineUnitTest> testSerializer = metadataProvider.getSerializer(PipelineUnitTest.class);
        List<String> testNames = testSerializer.listObjectNames();
        for (String testName : testNames) {
            PipelineUnitTest unitTest = testSerializer.load(testName);
            Object[] row = RowDataUtil.allocateRowData(rowMeta.size());
            row[0] = testName;
            row[1] = unitTest.getDescription();
            row[2] = unitTest.getPipelineFilename();
            rows.add(new RowMetaAndData(rowMeta, row));
        }
        // Now show a selection dialog...
        // 
        SelectRowDialog dialog = new SelectRowDialog(hopGui.getShell(), new Variables(), SWT.DIALOG_TRIM | SWT.MAX | SWT.RESIZE, rows);
        RowMetaAndData selection = dialog.open();
        if (selection != null) {
            return selection;
        }
        return null;
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "TestingGuiPlugin.SelectUnitTestFromAllTests.Error.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.SelectUnitTestFromAllTests.Error.Message"), e);
        return null;
    }
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) ArrayList(java.util.ArrayList) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) SelectRowDialog(org.apache.hop.ui.core.dialog.SelectRowDialog) HopException(org.apache.hop.core.exception.HopException) HopTransformException(org.apache.hop.core.exception.HopTransformException) HopValueException(org.apache.hop.core.exception.HopValueException) HopPluginException(org.apache.hop.core.exception.HopPluginException) IVariables(org.apache.hop.core.variables.IVariables) Variables(org.apache.hop.core.variables.Variables) RowMetaAndData(org.apache.hop.core.RowMetaAndData) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) HopGui(org.apache.hop.ui.hopgui.HopGui)

Example 99 with RowMetaAndData

use of org.apache.hop.core.RowMetaAndData in project hop by apache.

the class TestingGuiPlugin method openUnitTestPipeline.

public void openUnitTestPipeline(IVariables variables) {
    try {
        HopGui hopGui = HopGui.getInstance();
        IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
        RowMetaAndData selection = selectUnitTestFromAllTests();
        if (selection != null) {
            String filename = selection.getString(2, null);
            if (StringUtils.isNotEmpty(filename)) {
                // Load the unit test...
                // 
                String unitTestName = selection.getString(0, null);
                PipelineUnitTest targetTest = metadataProvider.getSerializer(PipelineUnitTest.class).load(unitTestName);
                if (targetTest != null) {
                    String completeFilename = targetTest.calculateCompletePipelineFilename(variables);
                    hopGui.fileDelegate.fileOpen(completeFilename);
                    PipelineMeta pipelineMeta = getActivePipelineMeta();
                    if (pipelineMeta != null) {
                        switchUnitTest(targetTest, pipelineMeta);
                    }
                }
            } else {
                throw new HopException("No filename found in the selected test");
            }
        }
    } catch (Exception e) {
        new ErrorDialog(HopGui.getInstance().getShell(), BaseMessages.getString(PKG, "TestingGuiPlugin.OpenUnitTestPipeline.Error.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.OpenUnitTestPipeline.Error.Message"), e);
    }
}
Also used : RowMetaAndData(org.apache.hop.core.RowMetaAndData) HopException(org.apache.hop.core.exception.HopException) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) HopException(org.apache.hop.core.exception.HopException) HopTransformException(org.apache.hop.core.exception.HopTransformException) HopValueException(org.apache.hop.core.exception.HopValueException) HopPluginException(org.apache.hop.core.exception.HopPluginException) HopGui(org.apache.hop.ui.hopgui.HopGui) PipelineMeta(org.apache.hop.pipeline.PipelineMeta)

Example 100 with RowMetaAndData

use of org.apache.hop.core.RowMetaAndData in project hop by apache.

the class FilesFromResultMeta method getFields.

@Override
public void getFields(IRowMeta r, String name, IRowMeta[] info, TransformMeta nextTransform, IVariables variables, IHopMetadataProvider metadataProvider) throws HopTransformException {
    // Add the fields from a ResultFile
    try {
        ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, HopVfs.getFileObject("foo.bar"), "parentOrigin", "origin");
        RowMetaAndData add = resultFile.getRow();
        // Set the origin on the fields...
        for (int i = 0; i < add.size(); i++) {
            add.getValueMeta(i).setOrigin(name);
        }
        r.addRowMeta(add.getRowMeta());
    } catch (HopFileException e) {
        throw new HopTransformException(e);
    }
}
Also used : RowMetaAndData(org.apache.hop.core.RowMetaAndData) HopFileException(org.apache.hop.core.exception.HopFileException) HopTransformException(org.apache.hop.core.exception.HopTransformException) ResultFile(org.apache.hop.core.ResultFile)

Aggregations

RowMetaAndData (org.apache.hop.core.RowMetaAndData)101 IRowMeta (org.apache.hop.core.row.IRowMeta)34 HopException (org.apache.hop.core.exception.HopException)30 ArrayList (java.util.ArrayList)24 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)23 RowMeta (org.apache.hop.core.row.RowMeta)20 Result (org.apache.hop.core.Result)14 IValueMeta (org.apache.hop.core.row.IValueMeta)14 HopValueException (org.apache.hop.core.exception.HopValueException)12 ValueMetaInteger (org.apache.hop.core.row.value.ValueMetaInteger)12 Test (org.junit.Test)12 HopTransformException (org.apache.hop.core.exception.HopTransformException)10 ICheckResult (org.apache.hop.core.ICheckResult)9 BeanInjector (org.apache.hop.core.injection.bean.BeanInjector)7 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)7 FileObject (org.apache.commons.vfs2.FileObject)6 HopDatabaseException (org.apache.hop.core.exception.HopDatabaseException)6 Pipeline (org.apache.hop.pipeline.Pipeline)6 RowProducer (org.apache.hop.pipeline.RowProducer)6 Date (java.util.Date)5