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;
}
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;
}
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;
}
}
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);
}
}
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);
}
}
Aggregations