use of org.apache.hop.core.exception.HopException in project hop by apache.
the class PipelineUnitTestEditor method createControl.
@Override
public void createControl(Composite parent) {
PipelineUnitTest pipelineUnitTest = this.getMetadata();
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// The name of the unit test...
//
Label wlName = new Label(parent, SWT.RIGHT);
props.setLook(wlName);
wlName.setText(BaseMessages.getString(PKG, "PipelineUnitTestDialog.Name.Label"));
FormData fdlName = new FormData();
fdlName.top = new FormAttachment(0, margin);
fdlName.left = new FormAttachment(0, 0);
fdlName.right = new FormAttachment(middle, -margin);
wlName.setLayoutData(fdlName);
wName = new Text(parent, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wName);
FormData fdName = new FormData();
fdName.top = new FormAttachment(wlName, 0, SWT.CENTER);
fdName.left = new FormAttachment(middle, 0);
fdName.right = new FormAttachment(100, 0);
wName.setLayoutData(fdName);
Control lastControl = wName;
// The description of the test...
//
Label wlDescription = new Label(parent, SWT.RIGHT);
props.setLook(wlDescription);
wlDescription.setText(BaseMessages.getString(PKG, "PipelineUnitTestDialog.Description.Label"));
FormData fdlDescription = new FormData();
fdlDescription.top = new FormAttachment(lastControl, margin);
fdlDescription.left = new FormAttachment(0, 0);
fdlDescription.right = new FormAttachment(middle, -margin);
wlDescription.setLayoutData(fdlDescription);
wDescription = new Text(parent, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wDescription);
FormData fdDescription = new FormData();
fdDescription.top = new FormAttachment(wlDescription, 0, SWT.CENTER);
fdDescription.left = new FormAttachment(middle, 0);
fdDescription.right = new FormAttachment(100, 0);
wDescription.setLayoutData(fdDescription);
lastControl = wDescription;
// The type of test...
//
Label wlTestType = new Label(parent, SWT.RIGHT);
props.setLook(wlTestType);
wlTestType.setText(BaseMessages.getString(PKG, "PipelineUnitTestDialog.TestType.Label"));
FormData fdlTestType = new FormData();
fdlTestType.top = new FormAttachment(lastControl, margin);
fdlTestType.left = new FormAttachment(0, 0);
fdlTestType.right = new FormAttachment(middle, -margin);
wlTestType.setLayoutData(fdlTestType);
wTestType = new Combo(parent, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
FormData fdTestType = new FormData();
fdTestType.top = new FormAttachment(wlTestType, 0, SWT.CENTER);
fdTestType.left = new FormAttachment(middle, 0);
fdTestType.right = new FormAttachment(100, 0);
wTestType.setLayoutData(fdTestType);
wTestType.setItems(DataSetConst.getTestTypeDescriptions());
lastControl = wTestType;
// The filename of the pipeline to test
//
Label wlPipelineFilename = new Label(parent, SWT.RIGHT);
props.setLook(wlPipelineFilename);
wlPipelineFilename.setText(BaseMessages.getString(PKG, "PipelineUnitTestDialog.PipelineFilename.Label"));
FormData fdlPipelineFilename = new FormData();
fdlPipelineFilename.top = new FormAttachment(lastControl, margin);
fdlPipelineFilename.left = new FormAttachment(0, 0);
fdlPipelineFilename.right = new FormAttachment(middle, -margin);
wlPipelineFilename.setLayoutData(fdlPipelineFilename);
wPipelineFilename = new Text(parent, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wPipelineFilename);
FormData fdPipelineFilename = new FormData();
fdPipelineFilename.top = new FormAttachment(wlPipelineFilename, 0, SWT.CENTER);
fdPipelineFilename.left = new FormAttachment(middle, 0);
fdPipelineFilename.right = new FormAttachment(100, 0);
wPipelineFilename.setLayoutData(fdPipelineFilename);
lastControl = wPipelineFilename;
// The optional filename of the test result...
//
Label wlFilename = new Label(parent, SWT.RIGHT);
props.setLook(wlFilename);
wlFilename.setText(BaseMessages.getString(PKG, "PipelineUnitTestDialog.Filename.Label"));
FormData fdlFilename = new FormData();
fdlFilename.top = new FormAttachment(lastControl, margin);
fdlFilename.left = new FormAttachment(0, 0);
fdlFilename.right = new FormAttachment(middle, -margin);
wlFilename.setLayoutData(fdlFilename);
wFilename = new TextVar(manager.getVariables(), parent, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wFilename);
FormData fdFilename = new FormData();
fdFilename.top = new FormAttachment(wlFilename, 0, SWT.CENTER);
fdFilename.left = new FormAttachment(middle, 0);
fdFilename.right = new FormAttachment(100, 0);
wFilename.setLayoutData(fdFilename);
lastControl = wFilename;
// The base path for relative test path resolution
//
Label wlBasePath = new Label(parent, SWT.RIGHT);
props.setLook(wlBasePath);
wlBasePath.setText(BaseMessages.getString(PKG, "PipelineUnitTestDialog.BasePath.Label"));
FormData fdlBasePath = new FormData();
fdlBasePath.top = new FormAttachment(lastControl, margin);
fdlBasePath.left = new FormAttachment(0, 0);
fdlBasePath.right = new FormAttachment(middle, -margin);
wlBasePath.setLayoutData(fdlBasePath);
wBasePath = new TextVar(manager.getVariables(), parent, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wBasePath);
FormData fdBasePath = new FormData();
fdBasePath.top = new FormAttachment(wlBasePath, 0, SWT.CENTER);
fdBasePath.left = new FormAttachment(middle, 0);
fdBasePath.right = new FormAttachment(100, 0);
wBasePath.setLayoutData(fdBasePath);
lastControl = wBasePath;
// The base path for relative test path resolution
//
Label wlAutoOpen = new Label(parent, SWT.RIGHT);
props.setLook(wlAutoOpen);
wlAutoOpen.setText(BaseMessages.getString(PKG, "PipelineUnitTestDialog.AutoOpen.Label"));
FormData fdlAutoOpen = new FormData();
fdlAutoOpen.top = new FormAttachment(lastControl, margin);
fdlAutoOpen.left = new FormAttachment(0, 0);
fdlAutoOpen.right = new FormAttachment(middle, -margin);
wlAutoOpen.setLayoutData(fdlAutoOpen);
wAutoOpen = new Button(parent, SWT.CHECK);
props.setLook(wAutoOpen);
FormData fdAutoOpen = new FormData();
fdAutoOpen.top = new FormAttachment(wlAutoOpen, 0, SWT.CENTER);
fdAutoOpen.left = new FormAttachment(middle, 0);
fdAutoOpen.right = new FormAttachment(100, 0);
wAutoOpen.setLayoutData(fdAutoOpen);
lastControl = wAutoOpen;
// The list of database replacements in the unit test pipeline
//
Label wlFieldMapping = new Label(parent, SWT.NONE);
wlFieldMapping.setText(BaseMessages.getString(PKG, "PipelineUnitTestDialog.DbReplacements.Label"));
props.setLook(wlFieldMapping);
FormData fdlUpIns = new FormData();
fdlUpIns.left = new FormAttachment(0, 0);
fdlUpIns.top = new FormAttachment(lastControl, 3 * margin);
wlFieldMapping.setLayoutData(fdlUpIns);
lastControl = wlFieldMapping;
// the database replacements
//
List<String> dbNames;
try {
dbNames = metadataProvider.getSerializer(DatabaseMeta.class).listObjectNames();
Collections.sort(dbNames);
} catch (HopException e) {
LogChannel.UI.logError("Error getting list of databases", e);
dbNames = Collections.emptyList();
}
ColumnInfo[] columns = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "PipelineUnitTestDialog.DbReplacement.ColumnInfo.OriginalDb"), ColumnInfo.COLUMN_TYPE_CCOMBO, dbNames.toArray(new String[0]), false), new ColumnInfo(BaseMessages.getString(PKG, "PipelineUnitTestDialog.DbReplacement.ColumnInfo.ReplacementDb"), ColumnInfo.COLUMN_TYPE_CCOMBO, dbNames.toArray(new String[0]), false) };
columns[0].setUsingVariables(true);
columns[1].setUsingVariables(true);
wDbReplacements = new TableView(new Variables(), parent, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, columns, pipelineUnitTest.getTweaks().size(), null, props);
FormData fdDbReplacements = new FormData();
fdDbReplacements.left = new FormAttachment(0, 0);
fdDbReplacements.top = new FormAttachment(lastControl, margin);
fdDbReplacements.right = new FormAttachment(100, 0);
fdDbReplacements.bottom = new FormAttachment(lastControl, 250);
wDbReplacements.setLayoutData(fdDbReplacements);
lastControl = wDbReplacements;
Label wlVariableValues = new Label(parent, SWT.NONE);
wlVariableValues.setText(BaseMessages.getString(PKG, "PipelineUnitTestDialog.VariableValues.Label"));
props.setLook(wlVariableValues);
FormData fdlVariableValues = new FormData();
fdlVariableValues.left = new FormAttachment(0, 0);
fdlVariableValues.top = new FormAttachment(lastControl, margin);
wlVariableValues.setLayoutData(fdlVariableValues);
lastControl = wlVariableValues;
ColumnInfo[] varValColumns = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "PipelineUnitTestDialog.VariableValues.ColumnInfo.VariableName"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "PipelineUnitTestDialog.VariableValues.ColumnInfo.VariableValue"), ColumnInfo.COLUMN_TYPE_TEXT, false) };
varValColumns[0].setUsingVariables(true);
varValColumns[1].setUsingVariables(true);
wVariableValues = new TableView(new Variables(), parent, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL, varValColumns, pipelineUnitTest.getVariableValues().size(), null, props);
FormData fdVariableValues = new FormData();
fdVariableValues.left = new FormAttachment(0, 0);
fdVariableValues.top = new FormAttachment(lastControl, margin);
fdVariableValues.right = new FormAttachment(100, 0);
fdVariableValues.bottom = new FormAttachment(100, -2 * margin);
wVariableValues.setLayoutData(fdVariableValues);
setWidgetsContent();
// Add listener to detect change after loading data
Listener modifyListener = e -> setChanged();
wName.addListener(SWT.Modify, modifyListener);
wDescription.addListener(SWT.Modify, modifyListener);
wTestType.addListener(SWT.Modify, modifyListener);
wPipelineFilename.addListener(SWT.Modify, modifyListener);
wFilename.addListener(SWT.Modify, modifyListener);
wBasePath.addListener(SWT.Modify, modifyListener);
wAutoOpen.addListener(SWT.Selection, modifyListener);
}
use of org.apache.hop.core.exception.HopException in project hop by apache.
the class PipelineUnitTestSetLocationDialog method getSortFields.
protected void getSortFields() {
try {
String datasetName = wDataset.getText();
if (StringUtils.isEmpty(datasetName)) {
throw new HopException("Please select a data set to get order fields from");
}
DataSet dataSet = findDataSet(datasetName);
IRowMeta setRowMeta = dataSet.getSetRowMeta();
String[] setFieldNames = setRowMeta.getFieldNames();
wFieldOrder.clearAll();
for (String setFieldName : setFieldNames) {
TableItem item = new TableItem(wFieldOrder.table, SWT.NONE);
item.setText(1, setFieldName);
}
wFieldOrder.removeEmptyRows();
wFieldOrder.setRowNums();
wFieldOrder.optWidth(true);
} catch (Exception e) {
new ErrorDialog(shell, "Error", "Error getting sort fields", e);
}
}
use of org.apache.hop.core.exception.HopException in project hop by apache.
the class AvroDecode method getStandardHopType.
public static final int getStandardHopType(Schema.Field field) throws HopException {
Schema.Type type = field.schema().getType();
int basicType = getBasicType(type);
if (basicType != 0) {
return basicType;
}
if (type == Schema.Type.UNION) {
// Often we have a union of a type and "null"
for (Schema subType : field.schema().getTypes()) {
if (subType.getType() != Schema.Type.NULL) {
basicType = getBasicType(subType.getType());
if (basicType != 0) {
return basicType;
}
}
}
}
throw new HopException("Schema type '" + type + " isn't handled");
}
use of org.apache.hop.core.exception.HopException in project hop by apache.
the class AvroDecode method processRow.
@Override
public boolean processRow() throws HopException {
Object[] row = getRow();
if (row == null) {
setOutputDone();
return false;
}
if (first) {
first = false;
// The output row
//
data.outputRowMeta = getInputRowMeta().clone();
meta.getFields(data.outputRowMeta, getTransformName(), null, null, this, metadataProvider);
String sourceFieldName = resolve(meta.getSourceFieldName());
data.inputIndex = getInputRowMeta().indexOfValue(sourceFieldName);
if (data.inputIndex < 0) {
throw new HopException("Unable to find Avro source field: " + sourceFieldName);
}
IValueMeta valueMeta = getInputRowMeta().getValueMeta(data.inputIndex);
if (!(valueMeta instanceof ValueMetaAvroRecord)) {
throw new HopException("We can only decode Avro data types and field " + sourceFieldName + " is of type " + valueMeta.getTypeDesc());
}
data.avroValueMeta = (ValueMetaAvroRecord) valueMeta;
}
GenericRecord genericRecord = data.avroValueMeta.getGenericRecord(row[data.inputIndex]);
if (genericRecord != null) {
Schema schema = genericRecord.getSchema();
int idx = getInputRowMeta().size();
Object[] outputRow = RowDataUtil.createResizedCopy(row, data.outputRowMeta.size());
for (TargetField targetField : meta.getTargetFields()) {
String avroFieldName = resolve(targetField.getSourceField());
Schema.Field field = schema.getField(avroFieldName);
Object avroValue = genericRecord.get(avroFieldName);
Object hopValue = getStandardHopObject(field, avroValue);
// Did the user ask for a different data type?
//
IValueMeta standardValueMeta = ValueMetaFactory.createValueMeta("standard", getStandardHopType(field));
IValueMeta targetValueMeta = targetField.createTargetValueMeta(this);
standardValueMeta.setConversionMask(targetValueMeta.getConversionMask());
// Convert the data if needed
//
outputRow[idx++] = targetValueMeta.convertData(standardValueMeta, hopValue);
}
// Pass the row along
//
putRow(data.outputRowMeta, outputRow);
}
return true;
}
use of org.apache.hop.core.exception.HopException in project hop by apache.
the class NeoConnection method test.
/**
* Test this connection to Neo4j
*
* @throws HopException In case anything goes wrong
* @param variables
*/
public void test(IVariables variables) throws HopException {
try (Driver driver = getDriver(LogChannel.GENERAL, variables)) {
SessionConfig.Builder builder = SessionConfig.builder();
if (StringUtils.isNotEmpty(databaseName)) {
builder = builder.withDatabase(variables.resolve(databaseName));
}
try (Session session = driver.session(builder.build())) {
// Do something with the session otherwise it doesn't test the connection
//
Result result = session.run("RETURN 0");
Record record = result.next();
Value value = record.get(0);
int zero = value.asInt();
assert (zero == 0);
} catch (Exception e) {
throw new HopException("Unable to connect to database '" + name + "' : " + e.getMessage(), e);
}
}
}
Aggregations