Search in sources :

Example 1 with LDIF

use of netscape.ldap.util.LDIF 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 LDIF

use of netscape.ldap.util.LDIF in project pentaho-kettle by pentaho.

the class LDIFInput method openNextFile.

private boolean openNextFile() {
    try {
        if (!meta.isFileField()) {
            if (data.filenr >= data.files.nrOfFiles()) {
                if (isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "LDIFInput.Log.FinishedProcessing"));
                }
                return false;
            }
            // Is this the last file?
            data.last_file = (data.filenr == data.files.nrOfFiles() - 1);
            data.file = data.files.getFile(data.filenr);
            // Move file pointer ahead!
            data.filenr++;
        } else {
            // Get row from input rowset & set row busy!
            data.readrow = getRow();
            if (data.readrow == null) {
                if (isDetailed()) {
                    logDetailed(BaseMessages.getString(PKG, "LDIFInput.Log.FinishedProcessing"));
                }
                return false;
            }
            if (first) {
                first = false;
                data.inputRowMeta = getInputRowMeta();
                data.outputRowMeta = data.inputRowMeta.clone();
                meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);
                // Get total previous fields
                data.totalpreviousfields = data.inputRowMeta.size();
                // Create convert meta-data objects that will contain Date & Number formatters
                data.convertRowMeta = data.outputRowMeta.cloneToType(ValueMetaInterface.TYPE_STRING);
                // Check is filename field is provided
                if (Utils.isEmpty(meta.getDynamicFilenameField())) {
                    logError(BaseMessages.getString(PKG, "LDIFInput.Log.NoField"));
                    throw new KettleException(BaseMessages.getString(PKG, "LDIFInput.Log.NoField"));
                }
                // cache the position of the field
                if (data.indexOfFilenameField < 0) {
                    data.indexOfFilenameField = getInputRowMeta().indexOfValue(meta.getDynamicFilenameField());
                    if (data.indexOfFilenameField < 0) {
                        // The field is unreachable !
                        logError(BaseMessages.getString(PKG, "LDIFInput.Log.ErrorFindingField") + "[" + meta.getDynamicFilenameField() + "]");
                        throw new KettleException(BaseMessages.getString(PKG, "LDIFInput.Exception.CouldnotFindField", meta.getDynamicFilenameField()));
                    }
                }
            }
            // End if first
            String filename = getInputRowMeta().getString(data.readrow, data.indexOfFilenameField);
            if (isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "LDIFInput.Log.FilenameInStream", meta.getDynamicFilenameField(), filename));
            }
            data.file = KettleVFS.getFileObject(filename, getTransMeta());
        }
        data.filename = KettleVFS.getFilename(data.file);
        // Add additional fields?
        if (meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0) {
            data.shortFilename = data.file.getName().getBaseName();
        }
        try {
            if (meta.getPathField() != null && meta.getPathField().length() > 0) {
                data.path = KettleVFS.getFilename(data.file.getParent());
            }
            if (meta.isHiddenField() != null && meta.isHiddenField().length() > 0) {
                data.hidden = data.file.isHidden();
            }
            if (meta.getExtensionField() != null && meta.getExtensionField().length() > 0) {
                data.extension = data.file.getName().getExtension();
            }
            if (meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0) {
                data.lastModificationDateTime = new Date(data.file.getContent().getLastModifiedTime());
            }
            if (meta.getUriField() != null && meta.getUriField().length() > 0) {
                data.uriName = data.file.getName().getURI();
            }
            if (meta.getRootUriField() != null && meta.getRootUriField().length() > 0) {
                data.rootUriName = data.file.getName().getRootURI();
            }
            if (meta.getSizeField() != null && meta.getSizeField().length() > 0) {
                data.size = new Long(data.file.getContent().getSize());
            }
        } catch (Exception e) {
            throw new KettleException(e);
        }
        if (isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "LDIFInput.Log.OpeningFile", data.file.toString()));
        }
        if (meta.AddToResultFilename()) {
            // Add this to the result file names...
            ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, data.file, getTransMeta().getName(), getStepname());
            resultFile.setComment(BaseMessages.getString(PKG, "LDIFInput.Log.FileAddedResult"));
            addResultFile(resultFile);
        }
        data.InputLDIF = new LDIF(KettleVFS.getFilename(data.file));
        if (isDetailed()) {
            logDetailed(BaseMessages.getString(PKG, "LDIFInput.Log.FileOpened", data.file.toString()));
        }
    } catch (Exception e) {
        logError(BaseMessages.getString(PKG, "LDIFInput.Log.UnableToOpenFile", "" + data.filenr, data.file.toString(), e.toString()));
        stopAll();
        setErrors(1);
        return false;
    }
    return true;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) LDIF(netscape.ldap.util.LDIF) ResultFile(org.pentaho.di.core.ResultFile) Date(java.util.Date) KettleException(org.pentaho.di.core.exception.KettleException)

Aggregations

LDIF (netscape.ldap.util.LDIF)2 KettleException (org.pentaho.di.core.exception.KettleException)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LDAPAttribute (netscape.ldap.LDAPAttribute)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 ResultFile (org.pentaho.di.core.ResultFile)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