Search in sources :

Example 1 with LDAPAttribute

use of netscape.ldap.LDAPAttribute in project pentaho-kettle by pentaho.

the class LDIFInputDialog method get.

private void get() {
    try {
        LDIFInputMeta meta = new LDIFInputMeta();
        getInfo(meta);
        FileInputList inputList = meta.getFiles(transMeta);
        // Clear Fields Grid
        wFields.removeAll();
        if (inputList.getFiles().size() > 0) {
            // Open the file (only first file)...
            LDIF InputLDIF = new LDIF(KettleVFS.getFilename(inputList.getFile(0)));
            HashSet<String> attributeSet = new HashSet<String>();
            // CHECKSTYLE:LineLength:OFF
            for (LDIFRecord recordLDIF = InputLDIF.nextRecord(); recordLDIF != null; recordLDIF = InputLDIF.nextRecord()) {
                // Get LDIF Content
                LDIFContent contentLDIF = recordLDIF.getContent();
                if (contentLDIF.getType() == LDIFContent.ATTRIBUTE_CONTENT) {
                    // Get only ATTRIBUTE_CONTENT
                    LDIFAttributeContent attrContentLDIF = (LDIFAttributeContent) contentLDIF;
                    LDAPAttribute[] attributes_LDIF = attrContentLDIF.getAttributes();
                    for (int j = 0; j < attributes_LDIF.length; j++) {
                        LDAPAttribute attribute_DIF = attributes_LDIF[j];
                        String attributeName = attribute_DIF.getName();
                        if (!attributeSet.contains(attributeName)) {
                            // Get attribut Name
                            TableItem item = new TableItem(wFields.table, SWT.NONE);
                            item.setText(1, attributeName);
                            item.setText(2, attributeName);
                            String attributeValue = GetValue(attributes_LDIF, attributeName);
                            if (IsDate(attributeValue)) {
                                item.setText(3, "Date");
                            } else if (IsInteger(attributeValue)) {
                                item.setText(3, "Integer");
                            } else if (IsNumber(attributeValue)) {
                                item.setText(3, "Number");
                            } else {
                                item.setText(3, "String");
                            }
                            attributeSet.add(attributeName);
                        }
                    }
                }
            }
        }
        wFields.removeEmptyRows();
        wFields.setRowNums();
        wFields.optWidth(true);
    } catch (KettleException e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "LDIFInputMeta.ErrorRetrieveData.DialogTitle"), BaseMessages.getString(PKG, "LDIFInputMeta.ErrorRetrieveData.DialogMessage"), e);
    } catch (Exception e) {
        new ErrorDialog(shell, BaseMessages.getString(PKG, "LDIFInputMeta.ErrorRetrieveData.DialogTitle"), BaseMessages.getString(PKG, "LDIFInputMeta.ErrorRetrieveData.DialogMessage"), e);
    }
}
Also used : LDAPAttribute(netscape.ldap.LDAPAttribute) KettleException(org.pentaho.di.core.exception.KettleException) TableItem(org.eclipse.swt.widgets.TableItem) LDIFContent(netscape.ldap.util.LDIFContent) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) KettleException(org.pentaho.di.core.exception.KettleException) LDIFInputMeta(org.pentaho.di.trans.steps.ldifinput.LDIFInputMeta) LDIF(netscape.ldap.util.LDIF) LDIFRecord(netscape.ldap.util.LDIFRecord) LDIFAttributeContent(netscape.ldap.util.LDIFAttributeContent) FileInputList(org.pentaho.di.core.fileinput.FileInputList) HashSet(java.util.HashSet)

Example 2 with LDAPAttribute

use of netscape.ldap.LDAPAttribute in project pentaho-kettle by pentaho.

the class LDIFInput method GetValue.

@SuppressWarnings("unchecked")
private String GetValue(LDAPAttribute[] attributes_LDIF, String AttributValue) {
    String Stringvalue = null;
    int i = 0;
    for (int j = 0; j < attributes_LDIF.length; j++) {
        LDAPAttribute attribute_DIF = attributes_LDIF[j];
        if (attribute_DIF.getName().equalsIgnoreCase(AttributValue)) {
            Enumeration<String> valuesLDIF = attribute_DIF.getStringValues();
            while (valuesLDIF.hasMoreElements()) {
                String valueLDIF = valuesLDIF.nextElement();
                if (i == 0) {
                    Stringvalue = valueLDIF;
                } else {
                    Stringvalue = Stringvalue + data.multiValueSeparator + valueLDIF;
                }
                i++;
            }
        }
    }
    return Stringvalue;
}
Also used : LDAPAttribute(netscape.ldap.LDAPAttribute)

Example 3 with LDAPAttribute

use of netscape.ldap.LDAPAttribute in project pentaho-kettle by pentaho.

the class LDIFInputDialog method GetValue.

@SuppressWarnings("unchecked")
private String GetValue(LDAPAttribute[] attributes_LDIF, String AttributValue) {
    String Stringvalue = null;
    for (int j = 0; j < attributes_LDIF.length; j++) {
        LDAPAttribute attribute_DIF = attributes_LDIF[j];
        if (attribute_DIF.getName().equalsIgnoreCase(AttributValue)) {
            Enumeration<String> valuesLDIF = attribute_DIF.getStringValues();
            // Get the first occurence
            Stringvalue = valuesLDIF.nextElement();
        }
    }
    return Stringvalue;
}
Also used : LDAPAttribute(netscape.ldap.LDAPAttribute)

Aggregations

LDAPAttribute (netscape.ldap.LDAPAttribute)3 HashSet (java.util.HashSet)1 LDIF (netscape.ldap.util.LDIF)1 LDIFAttributeContent (netscape.ldap.util.LDIFAttributeContent)1 LDIFContent (netscape.ldap.util.LDIFContent)1 LDIFRecord (netscape.ldap.util.LDIFRecord)1 TableItem (org.eclipse.swt.widgets.TableItem)1 KettleException (org.pentaho.di.core.exception.KettleException)1 FileInputList (org.pentaho.di.core.fileinput.FileInputList)1 LDIFInputMeta (org.pentaho.di.trans.steps.ldifinput.LDIFInputMeta)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1