use of org.pentaho.di.trans.steps.ldapinput.LDAPConnection in project pentaho-kettle by pentaho.
the class LDAPInputDialog method get.
private void get() {
LDAPConnection connection = null;
try {
LDAPInputMeta meta = new LDAPInputMeta();
getInfo(meta);
// Clear Fields Grid
wFields.removeAll();
// Defined a LDAP connection
connection = new LDAPConnection(log, transMeta, meta, null);
// connect ...
if (meta.UseAuthentication()) {
String username = transMeta.environmentSubstitute(meta.getUserName());
String password = Encr.decryptPasswordOptionallyEncrypted(transMeta.environmentSubstitute(meta.getPassword()));
connection.connect(username, password);
} else {
connection.connect();
}
// return fields
RowMeta listattributes = connection.getFields(transMeta.environmentSubstitute(meta.getSearchBase()));
String[] fieldsName = new String[listattributes.size()];
for (int i = 0; i < listattributes.size(); i++) {
ValueMetaInterface v = listattributes.getValueMeta(i);
fieldsName[i] = v.getName();
// Get Column Name
TableItem item = new TableItem(wFields.table, SWT.NONE);
item.setText(1, v.getName());
item.setText(2, v.getName());
if (LDAPInputField.binaryAttributes.contains(v.getName())) {
item.setText(3, BaseMessages.getString(PKG, "LDAPInputField.FetchAttributeAs.Binary"));
} else {
item.setText(3, BaseMessages.getString(PKG, "LDAPInputField.FetchAttributeAs.String"));
}
item.setText(4, BaseMessages.getString(PKG, "System.Combo.No"));
item.setText(5, v.getTypeDesc());
}
colinf[1].setComboValues(fieldsName);
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "LDAPInputDialog.ErrorGettingColums.DialogTitle"), BaseMessages.getString(PKG, "LDAPInputDialog.ErrorGettingColums.DialogMessage"), e);
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "LDAPInputDialog.ErrorGettingColums.DialogTitle"), BaseMessages.getString(PKG, "LDAPInputDialog.ErrorGettingColums.DialogMessage"), e);
} finally {
if (connection != null) {
try {
connection.close();
} catch (Exception e) {
/* Ignore */
}
}
}
}
use of org.pentaho.di.trans.steps.ldapinput.LDAPConnection in project pentaho-kettle by pentaho.
the class LDAPOutputDialog method getLDAPFields.
public RowMetaInterface getLDAPFields() throws KettleException {
LDAPConnection connection = null;
try {
LDAPOutputMeta meta = new LDAPOutputMeta();
getInfo(meta);
// Defined a LDAP connection
connection = new LDAPConnection(log, transMeta, meta, null);
// connect ...
if (wusingAuthentication.getSelection()) {
String username = transMeta.environmentSubstitute(wUserName.getText());
String password = Encr.decryptPasswordOptionallyEncrypted(transMeta.environmentSubstitute(wPassword.getText()));
connection.connect(username, password);
} else {
connection.connect();
}
return connection.getFields(transMeta.environmentSubstitute(wBaseDN.getText()));
} finally {
if (connection != null) {
try {
connection.close();
} catch (Exception e) {
/* Ignore */
}
}
}
}
use of org.pentaho.di.trans.steps.ldapinput.LDAPConnection in project pentaho-kettle by pentaho.
the class LDAPOutput method init.
public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
meta = (LDAPOutputMeta) smi;
data = (LDAPOutputData) sdi;
if (super.init(smi, sdi)) {
try {
// Define new LDAP connection
data.connection = new LDAPConnection(log, this, meta, null);
// connect
if (meta.UseAuthentication()) {
String username = environmentSubstitute(meta.getUserName());
String password = Encr.decryptPasswordOptionallyEncrypted(environmentSubstitute(meta.getPassword()));
data.connection.connect(username, password);
} else {
data.connection.connect();
}
data.separator = environmentSubstitute(meta.getMultiValuedSeparator());
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "LDAPOutput.Error.Init", e));
stopAll();
setErrors(1);
return false;
}
return true;
}
return false;
}
use of org.pentaho.di.trans.steps.ldapinput.LDAPConnection in project pentaho-kettle by pentaho.
the class LDAPInputDialog method test.
private void test() {
LDAPConnection connection = null;
try {
LDAPInputMeta meta = new LDAPInputMeta();
getInfo(meta);
// Defined a LDAP connection
connection = new LDAPConnection(log, transMeta, meta, null);
// connect...
if (wusingAuthentication.getSelection()) {
connection.connect(transMeta.environmentSubstitute(meta.getUserName()), Encr.decryptPasswordOptionallyEncrypted(transMeta.environmentSubstitute(meta.getPassword())));
} else {
connection.connect();
}
// We are successfully connected
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "LDAPInputDialog.Connected.OK") + Const.CR);
mb.setText(BaseMessages.getString(PKG, "LDAPInputDialog.Connected.Title.Ok"));
mb.open();
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "LDAPInputDialog.Connected.Title.Error"), BaseMessages.getString(PKG, "LDAPInputDialog.Connected.NOK"), e);
} finally {
if (connection != null) {
// Disconnect ...
try {
connection.close();
} catch (Exception e) {
/* Ignore */
}
}
}
}
use of org.pentaho.di.trans.steps.ldapinput.LDAPConnection in project pentaho-kettle by pentaho.
the class LDAPOutputDialog method generateMappings.
/**
* Reads in the fields from the previous steps and from the ONE next step and opens an EnterMappingDialog with this
* information. After the user did the mapping, those information is put into the Select/Rename table.
*/
private void generateMappings() {
// Determine the source and target fields...
//
RowMetaInterface sourceFields;
RowMetaInterface targetFields = new RowMeta();
try {
sourceFields = transMeta.getPrevStepFields(stepMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "LDAPOutputDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "LDAPOutputDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
LDAPConnection connection = null;
try {
// return fields
targetFields = getLDAPFields();
} catch (Exception e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "LDAPOutputDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "LDAPOutputDialog.DoMapping.UnableToFindTargetFields.Message"), e);
return;
} finally {
if (connection != null) {
try {
connection.close();
} catch (Exception e) {
/* Ignore */
}
}
}
String[] inputNames = new String[sourceFields.size()];
for (int i = 0; i < sourceFields.size(); i++) {
ValueMetaInterface value = sourceFields.getValueMeta(i);
inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
}
// Create the existing mapping list...
//
List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
StringBuilder missingSourceFields = new StringBuilder();
StringBuilder missingTargetFields = new StringBuilder();
int nrFields = wReturn.nrNonEmpty();
for (int i = 0; i < nrFields; i++) {
TableItem item = wReturn.getNonEmpty(i);
String source = item.getText(2);
String target = item.getText(1);
int sourceIndex = sourceFields.indexOfValue(source);
if (sourceIndex < 0) {
missingSourceFields.append(Const.CR + " " + source + " --> " + target);
}
int targetIndex = targetFields.indexOfValue(target);
if (targetIndex < 0) {
missingTargetFields.append(Const.CR + " " + source + " --> " + target);
}
if (sourceIndex < 0 || targetIndex < 0) {
continue;
}
SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
mappings.add(mapping);
}
//
if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
String message = "";
if (missingSourceFields.length() > 0) {
message += BaseMessages.getString(PKG, "LDAPOutputDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "LDAPOutputDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "LDAPOutputDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "LDAPOutputDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(LDAPOutputDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
mappings = d.open();
//
if (mappings != null) {
// Clear and re-populate!
//
wReturn.table.removeAll();
wReturn.table.setItemCount(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
TableItem item = wReturn.table.getItem(i);
item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
}
wReturn.setRowNums();
wReturn.optWidth(true);
}
}
Aggregations