use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class XMLInputMeta method getFields.
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
for (int i = 0; i < inputFields.length; i++) {
XMLInputField field = inputFields[i];
int type = field.getType();
if (type == ValueMeta.TYPE_NONE) {
type = ValueMeta.TYPE_STRING;
}
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(field.getName(), type);
v.setLength(field.getLength(), field.getPrecision());
v.setConversionMask(field.getFormat());
v.setDecimalSymbol(field.getDecimalSymbol());
v.setGroupingSymbol(field.getGroupSymbol());
v.setTrimType(field.getTrimType());
v.setCurrencySymbol(field.getCurrencySymbol());
v.setOrigin(name);
r.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (includeFilename) {
ValueMetaInterface v = new ValueMeta(filenameField, ValueMeta.TYPE_STRING);
v.setLength(100);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMeta(rowNumberField, ValueMeta.TYPE_INTEGER);
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH);
v.setOrigin(name);
r.addValueMeta(v);
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class JobEntryXSLT method execute.
public Result execute(Result previousResult, int nr) throws KettleException {
Result result = previousResult;
int NrErrors = 0;
int NrSuccess = 0;
// Check output parameters
int nrOutputProps = getOutputPropertyName() == null ? 0 : getOutputPropertyName().length;
if (nrOutputProps > 0) {
outputProperties = new Properties();
for (int i = 0; i < nrOutputProps; i++) {
outputProperties.put(getOutputPropertyName()[i], environmentSubstitute(getOutputPropertyValue()[i]));
}
setOutputProperties = true;
}
// Check parameters
nrParams = getParameterField() == null ? 0 : getParameterField().length;
if (nrParams > 0) {
nameOfParams = new String[nrParams];
valueOfParams = new String[nrParams];
for (int i = 0; i < nrParams; i++) {
String name = environmentSubstitute(getParameterName()[i]);
String value = environmentSubstitute(getParameterField()[i]);
if (Utils.isEmpty(value)) {
throw new KettleStepException(BaseMessages.getString(PKG, "Xslt.Exception.ParameterFieldMissing", name, i));
}
nameOfParams[i] = name;
valueOfParams[i] = value;
}
useParameters = true;
}
List<RowMetaAndData> rows = result.getRows();
if (isFilenamesFromPrevious()) {
if (log.isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "JobEntryXSLT.Log.ArgFromPrevious.Found", (rows != null ? rows.size() : 0) + ""));
}
}
if (isFilenamesFromPrevious() && rows != null) {
// Copy the input row to the (command line) arguments
RowMetaAndData resultRow = null;
for (int iteration = 0; iteration < rows.size() && !parentJob.isStopped(); iteration++) {
resultRow = rows.get(iteration);
// Get filenames (xml, xsl, output filename)
String xmlfilename_previous = resultRow.getString(0, null);
String xslfilename_previous = resultRow.getString(1, null);
String ouputfilename_previous = resultRow.getString(2, null);
if (!Utils.isEmpty(xmlfilename_previous) && !Utils.isEmpty(xslfilename_previous) && !Utils.isEmpty(ouputfilename_previous)) {
if (processOneXMLFile(xmlfilename_previous, xslfilename_previous, ouputfilename_previous, result, parentJob)) {
NrSuccess++;
} else {
NrErrors++;
}
} else {
// We failed!
logError(BaseMessages.getString(PKG, "JobEntryXSLT.AllFilesNotNull.Label"));
NrErrors++;
}
}
} else {
String realxmlfilename = getRealxmlfilename();
String realxslfilename = getRealxslfilename();
String realoutputfilename = getoutputfilename();
if (!Utils.isEmpty(realxmlfilename) && !Utils.isEmpty(realxslfilename) && !Utils.isEmpty(realoutputfilename)) {
if (processOneXMLFile(realxmlfilename, realxslfilename, realoutputfilename, result, parentJob)) {
NrSuccess++;
} else {
NrErrors++;
}
} else {
// We failed!
logError(BaseMessages.getString(PKG, "JobEntryXSLT.AllFilesNotNull.Label"));
NrErrors++;
}
}
result.setResult(NrErrors == 0);
result.setNrErrors(NrErrors);
result.setNrLinesWritten(NrSuccess);
return result;
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class GetXMLDataMeta method getFields.
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
int i;
for (i = 0; i < inputFields.length; i++) {
GetXMLDataField field = inputFields[i];
int type = field.getType();
if (type == ValueMeta.TYPE_NONE) {
type = ValueMeta.TYPE_STRING;
}
try {
ValueMetaInterface v = ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
v.setLength(field.getLength());
v.setPrecision(field.getPrecision());
v.setOrigin(name);
v.setConversionMask(field.getFormat());
v.setDecimalSymbol(field.getDecimalSymbol());
v.setGroupingSymbol(field.getGroupSymbol());
v.setCurrencySymbol(field.getCurrencySymbol());
r.addValueMeta(v);
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (includeFilename) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(filenameField), ValueMeta.TYPE_STRING);
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(rowNumberField), ValueMeta.TYPE_INTEGER);
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getShortFileNameField()), ValueMeta.TYPE_STRING);
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getExtensionField() != null && getExtensionField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getExtensionField()), ValueMeta.TYPE_STRING);
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getPathField() != null && getPathField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getPathField()), ValueMeta.TYPE_STRING);
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getSizeField() != null && getSizeField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getSizeField()), ValueMeta.TYPE_INTEGER);
v.setOrigin(name);
v.setLength(9);
r.addValueMeta(v);
}
if (isHiddenField() != null && isHiddenField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(isHiddenField()), ValueMeta.TYPE_BOOLEAN);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getLastModificationDateField()), ValueMeta.TYPE_DATE);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getUriField() != null && getUriField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getUriField()), ValueMeta.TYPE_STRING);
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
if (getRootUriField() != null && getRootUriField().length() > 0) {
ValueMetaInterface v = new ValueMeta(space.environmentSubstitute(getRootUriField()), ValueMeta.TYPE_STRING);
v.setLength(100, -1);
v.setOrigin(name);
r.addValueMeta(v);
}
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class JmsProducerDialog method open.
@Override
public String open() {
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.MIN | SWT.MAX | SWT.RESIZE);
props.setLook(shell);
setShellImage(shell, meta);
shell.setMinimumSize(SHELL_MIN_WIDTH, SHELL_MIN_HEIGHT);
changed = meta.hasChanged();
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = 15;
formLayout.marginHeight = 15;
shell.setLayout(formLayout);
shell.setText(BaseMessages.getString(PKG, "JmsProducerDialog.Shell.Title"));
Label wicon = new Label(shell, SWT.RIGHT);
wicon.setImage(getImage());
FormData fdlicon = new FormData();
fdlicon.top = new FormAttachment(0, 0);
fdlicon.right = new FormAttachment(100, 0);
wicon.setLayoutData(fdlicon);
props.setLook(wicon);
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "JmsProducerDialog.Stepname.Label"));
props.setLook(wlStepname);
fdlStepname = new FormData();
fdlStepname.left = new FormAttachment(0, 0);
fdlStepname.top = new FormAttachment(0, 0);
wlStepname.setLayoutData(fdlStepname);
wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wStepname.setText(stepname);
props.setLook(wStepname);
wStepname.addModifyListener(lsMod);
fdStepname = new FormData();
fdStepname.width = 250;
fdStepname.left = new FormAttachment(0, 0);
fdStepname.top = new FormAttachment(wlStepname, 5);
wStepname.setLayoutData(fdStepname);
Label spacer = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR);
props.setLook(spacer);
FormData fdSpacer = new FormData();
fdSpacer.height = 2;
fdSpacer.left = new FormAttachment(0, 0);
fdSpacer.top = new FormAttachment(wStepname, 15);
fdSpacer.right = new FormAttachment(100, 0);
fdSpacer.width = 497;
spacer.setLayoutData(fdSpacer);
// Start of tabbed display
wTabFolder = new CTabFolder(shell, SWT.BORDER);
props.setLook(wTabFolder, Props.WIDGET_STYLE_TAB);
wTabFolder.setSimple(false);
wTabFolder.setUnselectedCloseVisible(true);
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
FormData fdCancel = new FormData();
fdCancel.right = new FormAttachment(100, 0);
fdCancel.bottom = new FormAttachment(100, 0);
wCancel.setLayoutData(fdCancel);
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
FormData fdOk = new FormData();
fdOk.right = new FormAttachment(wCancel, -5);
fdOk.bottom = new FormAttachment(100, 0);
wOK.setLayoutData(fdOk);
Label hSpacer = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR);
props.setLook(hSpacer);
FormData fdhSpacer = new FormData();
fdhSpacer.height = 2;
fdhSpacer.left = new FormAttachment(0, 0);
fdhSpacer.bottom = new FormAttachment(wCancel, -15);
fdhSpacer.right = new FormAttachment(100, 0);
hSpacer.setLayoutData(fdhSpacer);
FormData fdTabFolder = new FormData();
fdTabFolder.left = new FormAttachment(0, 0);
fdTabFolder.top = new FormAttachment(spacer, 15);
fdTabFolder.bottom = new FormAttachment(hSpacer, -15);
fdTabFolder.right = new FormAttachment(100, 0);
wTabFolder.setLayoutData(fdTabFolder);
// Setup Tab
wSetupTab = new CTabItem(wTabFolder, SWT.NONE);
wSetupTab.setText(BaseMessages.getString(PKG, "JmsProducerDialog.SetupTab"));
wSetupComp = new Composite(wTabFolder, SWT.NONE);
props.setLook(wSetupComp);
FormLayout setupLayout = new FormLayout();
setupLayout.marginHeight = 15;
setupLayout.marginWidth = 15;
wSetupComp.setLayout(setupLayout);
connectionForm = new ConnectionForm(wSetupComp, props, transMeta, lsMod, jmsDelegate);
Group group = connectionForm.layoutForm();
destinationForm = new DestinationForm(wSetupComp, group, props, transMeta, lsMod, jmsDelegate.destinationType, jmsDelegate.destinationName);
Composite destinationFormComposite = destinationForm.layoutForm();
Label lbMessageField = new Label(wSetupComp, SWT.LEFT);
props.setLook(lbMessageField);
lbMessageField.setText(getString(PKG, "JmsProducerDialog.MessageField"));
FormData fdMessage = new FormData();
fdMessage.left = new FormAttachment(0, 0);
fdMessage.top = new FormAttachment(destinationFormComposite, 15);
fdMessage.width = 250;
lbMessageField.setLayoutData(fdMessage);
wMessageField = new ComboVar(transMeta, wSetupComp, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wMessageField);
wMessageField.addModifyListener(lsMod);
FormData fdMessageField = new FormData();
fdMessageField.left = new FormAttachment(0, 0);
fdMessageField.top = new FormAttachment(lbMessageField, 5);
fdMessageField.width = 250;
wMessageField.setLayoutData(fdMessageField);
Listener lsMessageFocus = e -> {
String current = wMessageField.getText();
wMessageField.getCComboWidget().removeAll();
wMessageField.setText(current);
try {
RowMetaInterface rmi = transMeta.getPrevStepFields(meta.getParentStepMeta().getName());
List ls = rmi.getValueMetaList();
for (Object l : ls) {
ValueMetaBase vmb = (ValueMetaBase) l;
wMessageField.add(vmb.getName());
}
} catch (KettleStepException ex) {
// do nothing
}
};
wMessageField.getCComboWidget().addListener(SWT.FocusIn, lsMessageFocus);
FormData fdSetupComp = new FormData();
fdSetupComp.left = new FormAttachment(0, 0);
fdSetupComp.top = new FormAttachment(0, 0);
fdSetupComp.right = new FormAttachment(100, 0);
fdSetupComp.bottom = new FormAttachment(100, 0);
wSetupComp.setLayoutData(fdSetupComp);
wSetupComp.layout();
wSetupTab.setControl(wSetupComp);
wTabFolder.setSelection(0);
wOK.addListener(SWT.Selection, lsOK);
wCancel.addListener(SWT.Selection, lsCancel);
// get data for message field, other fields data is loaded by the forms
wMessageField.setText(nullToEmpty(meta.getFieldToSend()));
setSize();
meta.setChanged(changed);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return stepname;
}
use of org.pentaho.di.core.exception.KettleStepException in project pentaho-kettle by pentaho.
the class MQTTProducer method processRow.
@Override
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
Object[] row = getRow();
if (null == row) {
setOutputDone();
if (null != data.mqttClient) {
try {
data.mqttClient.disconnect();
data.mqttClient.close();
} catch (MqttException e) {
logError(e.getMessage(), e);
}
}
return false;
}
if (first) {
logDebug("Publishing using a quality of service level of " + environmentSubstitute(meta.getQOS()));
data.messageFieldIndex = getInputRowMeta().indexOfValue(environmentSubstitute(meta.getMessageField()));
try {
data.mqttClient = MQTTClientBuilder.builder().withBroker(meta.getMqttServer()).withTopics(Collections.singletonList(meta.getTopic())).withClientId(meta.getClientId()).withQos(meta.getQOS()).withStep(this).withUsername(meta.getUsername()).withPassword(meta.getPassword()).withSslConfig(meta.getSslConfig()).withIsSecure(meta.isUseSsl()).withKeepAliveInterval(meta.getKeepAliveInterval()).withMaxInflight(meta.getMaxInflight()).withConnectionTimeout(meta.getConnectionTimeout()).withCleanSession(meta.getCleanSession()).withStorageLevel(meta.getStorageLevel()).withServerUris(meta.getServerUris()).withMqttVersion(meta.getMqttVersion()).withAutomaticReconnect(meta.getAutomaticReconnect()).buildAndConnect();
} catch (MqttException e) {
stopAll();
logError(e.toString());
return false;
}
first = false;
}
MqttMessage mqttMessage = new MqttMessage();
try {
mqttMessage.setQos(Integer.parseInt(environmentSubstitute(meta.getQOS())));
} catch (NumberFormatException e) {
throw new KettleStepException(BaseMessages.getString(PKG, "MQTTProducer.Error.QOS", environmentSubstitute(meta.getQOS())));
}
mqttMessage.setPayload((row[data.messageFieldIndex]).toString().getBytes(defaultCharset()));
try {
data.mqttClient.publish(environmentSubstitute(meta.getTopic()), mqttMessage);
incrementLinesOutput();
// copy row to possible alternate rowset(s).
putRow(getInputRowMeta(), row);
if (checkFeedback(getLinesRead())) {
if (log.isBasic()) {
logBasic(BaseMessages.getString(PKG, "MQTTProducer.Log.LineNumber") + getLinesRead());
}
}
} catch (MqttException e) {
logError(BaseMessages.getString(PKG, "MQTTProducer.Error.QOSNotSupported", meta.getQOS()));
logError(e.getMessage(), e);
setErrors(1);
stopAll();
}
return true;
}
Aggregations