use of netscape.ldap.util.LDIFContent 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);
}
}
use of netscape.ldap.util.LDIFContent in project pentaho-kettle by pentaho.
the class LDIFInput method getOneRow.
private Object[] getOneRow() throws KettleException {
try {
if (meta.isFileField()) {
while ((data.readrow == null || ((data.recordLDIF = data.InputLDIF.nextRecord()) == null))) {
if (!openNextFile()) {
return null;
}
}
} else {
while ((data.file == null) || ((data.recordLDIF = data.InputLDIF.nextRecord()) == null)) {
if (!openNextFile()) {
return null;
}
}
}
} catch (Exception IO) {
return null;
}
// Get LDIF Content
LDIFContent contentLDIF = data.recordLDIF.getContent();
String contentTYPE = "ATTRIBUTE_CONTENT";
switch(contentLDIF.getType()) {
case LDIFContent.DELETE_CONTENT:
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "LDIFInput.Log.ContentType", "DELETE_CONTENT"));
}
contentTYPE = "DELETE_CONTENT";
break;
case LDIFContent.ADD_CONTENT:
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "LDIFInput.Log.ContentType", "ADD_CONTENT"));
}
contentTYPE = "ADD_CONTENT";
break;
case LDIFContent.MODDN_CONTENT:
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "LDIFInput.Log.ContentType", "MODDN_CONTENT"));
}
contentTYPE = "MODDN_CONTENT";
break;
case LDIFContent.MODIFICATION_CONTENT:
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "LDIFInput.Log.ContentType", "MODIFICATION_CONTENT"));
}
contentTYPE = "MODIFICATION_CONTENT";
break;
default:
if (isDetailed()) {
logDetailed(BaseMessages.getString(PKG, "LDIFInput.Log.ContentType", "ATTRIBUTE_CONTENT"));
}
break;
}
// Get only ATTRIBUTE_CONTENT
LDIFAttributeContent attrContentLDIF = (LDIFAttributeContent) contentLDIF;
data.attributes_LDIF = attrContentLDIF.getAttributes();
// Build an empty row based on the meta-data
Object[] outputRowData = buildEmptyRow();
// Create new row or clone
if (meta.isFileField()) {
System.arraycopy(data.readrow, 0, outputRowData, 0, data.readrow.length);
}
try {
// Execute for each Input field...
for (int i = 0; i < meta.getInputFields().length; i++) {
LDIFInputField ldifInputField = meta.getInputFields()[i];
// Get the Attribut to look for
String AttributValue = environmentSubstitute(ldifInputField.getAttribut());
String Value = GetValue(data.attributes_LDIF, AttributValue);
// Do trimming
switch(ldifInputField.getTrimType()) {
case LDIFInputField.TYPE_TRIM_LEFT:
Value = Const.ltrim(Value);
break;
case LDIFInputField.TYPE_TRIM_RIGHT:
Value = Const.rtrim(Value);
break;
case LDIFInputField.TYPE_TRIM_BOTH:
Value = Const.trim(Value);
break;
default:
break;
}
// Do conversions
//
ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta(data.totalpreviousfields + i);
ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta(data.totalpreviousfields + i);
outputRowData[data.totalpreviousfields + i] = targetValueMeta.convertData(sourceValueMeta, Value);
// Do we need to repeat this field if it is null?
if (meta.getInputFields()[i].isRepeated()) {
if (data.previousRow != null && Utils.isEmpty(Value)) {
outputRowData[data.totalpreviousfields + i] = data.previousRow[data.totalpreviousfields + i];
}
}
}
// End of loop over fields...
int rowIndex = data.totalpreviousfields + meta.getInputFields().length;
// See if we need to add the filename to the row...
if (meta.includeFilename() && !Utils.isEmpty(meta.getFilenameField())) {
outputRowData[rowIndex++] = data.filename;
}
// See if we need to add the row number to the row...
if (meta.includeRowNumber() && !Utils.isEmpty(meta.getRowNumberField())) {
outputRowData[data.totalpreviousfields + rowIndex++] = new Long(data.rownr);
}
// See if we need to add the content type to the row...
if (meta.includeContentType() && !Utils.isEmpty(meta.getContentTypeField())) {
outputRowData[data.totalpreviousfields + rowIndex++] = contentTYPE;
}
// See if we need to add the DN to the row...
if (meta.IncludeDN() && !Utils.isEmpty(meta.getDNField())) {
outputRowData[data.totalpreviousfields + rowIndex++] = data.recordLDIF.getDN();
}
// Possibly add short filename...
if (meta.getShortFileNameField() != null && meta.getShortFileNameField().length() > 0) {
outputRowData[rowIndex++] = data.shortFilename;
}
// Add Extension
if (meta.getExtensionField() != null && meta.getExtensionField().length() > 0) {
outputRowData[rowIndex++] = data.extension;
}
// add path
if (meta.getPathField() != null && meta.getPathField().length() > 0) {
outputRowData[rowIndex++] = data.path;
}
// Add Size
if (meta.getSizeField() != null && meta.getSizeField().length() > 0) {
outputRowData[rowIndex++] = new Long(data.size);
}
// add Hidden
if (meta.isHiddenField() != null && meta.isHiddenField().length() > 0) {
outputRowData[rowIndex++] = new Boolean(data.hidden);
}
// Add modification date
if (meta.getLastModificationDateField() != null && meta.getLastModificationDateField().length() > 0) {
outputRowData[rowIndex++] = data.lastModificationDateTime;
}
// Add Uri
if (meta.getUriField() != null && meta.getUriField().length() > 0) {
outputRowData[rowIndex++] = data.uriName;
}
// Add RootUri
if (meta.getRootUriField() != null && meta.getRootUriField().length() > 0) {
outputRowData[rowIndex++] = data.rootUriName;
}
RowMetaInterface irow = getInputRowMeta();
// copy it to make
data.previousRow = irow == null ? outputRowData : irow.cloneRow(outputRowData);
// surely the next step doesn't change it in between...
incrementLinesInput();
data.rownr++;
} catch (Exception e) {
throw new KettleException(BaseMessages.getString(PKG, "LDIFInput.Exception.UnableToReadFile", data.file.toString()), e);
}
return outputRowData;
}
Aggregations