Skip to content

Commit

Permalink
Revert "TEIID-3411 adding the ability to unwrap ldap multi-valued to …
Browse files Browse the repository at this point in the history
…rows"

This reverts commit 1974d47.
  • Loading branch information
shawkins committed May 21, 2015
1 parent de988d4 commit 76fab0b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 215 deletions.
Expand Up @@ -134,7 +134,7 @@ private InitialLdapContext initializeLDAPContext() throws ResourceException {
initContext = new InitialLdapContext(connenv, null);
} catch(NamingException ne){
final String msg = LDAPPlugin.Util.getString("LDAPConnection.directoryNamingError",ne.getExplanation()); //$NON-NLS-1$
throw new ResourceException(msg, ne);
throw new ResourceException(msg);
}
LogManager.logDetail(LogConstants.CTX_CONNECTOR, "Successfully obtained initial LDAP context."); //$NON-NLS-1$
return initContext;
Expand Down
Expand Up @@ -61,7 +61,6 @@ public enum SearchDefaultScope {
private SearchDefaultScope searchDefaultScope = SearchDefaultScope.ONELEVEL_SCOPE;
private boolean usePagination;
private boolean exceptionOnSizeLimitExceeded;
private boolean unwrapMultiValued;

public LDAPExecutionFactory() {
this.setMaxInCriteriaSize(1000);
Expand Down Expand Up @@ -204,14 +203,5 @@ public boolean supportsOnlyLiteralComparison() {
public boolean supportsLikeCriteriaEscapeCharacter() {
return true;
}

@TranslatorProperty(display="Unwrap Multi-valued", description="Set to true to unwrap multi-valued attributes to rows rather than binding as an array or concatenation.")
public boolean isUnwrapMultiValued() {
return this.unwrapMultiValued;
}

public void setUnwrapMultiValued(boolean unwrapMultiValued) {
this.unwrapMultiValued = unwrapMultiValued;
}

}
Expand Up @@ -47,7 +47,6 @@ public static enum Event implements BundleUtil.Event {
TEIID12010,
TEIID12011,
TEIID12012,
TEIID12013,
TEIID12014,
TEIID12013,
}
}
Expand Up @@ -72,7 +72,6 @@
package org.teiid.translator.ldap;

import java.io.IOException;
import java.lang.reflect.Array;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand All @@ -96,7 +95,6 @@
import javax.naming.ldap.SortControl;
import javax.naming.ldap.SortKey;

import org.teiid.core.types.ArrayImpl;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.Column;
Expand All @@ -109,12 +107,11 @@

/**
* LDAPSyncQueryExecution is responsible for executing an LDAP search
* corresponding to a read-only "select" query.
* corresponding to a read-only "select" query from MetaMatrix.
*/
public class LDAPQueryExecution implements ResultSetExecution {

static final String MULTIVALUED_CONCAT = "multivalued-concat"; //$NON-NLS-1$
static final String delimiter = "?"; //$NON-NLS-1$
private static final String delimiter = "?"; //$NON-NLS-1$

private LDAPSearchDetails searchDetails;
private LdapContext ldapCtx;
Expand All @@ -123,7 +120,6 @@ public class LDAPQueryExecution implements ResultSetExecution {
private ExecutionContext executionContext;
private SearchControls ctrls;
private int resultCount;
private Iterator<List<Object>> unwrapIterator;

/**
* Constructor
Expand Down Expand Up @@ -245,12 +241,6 @@ public void close() {
// NamingException
public List<?> next() throws TranslatorException {
try {
if (unwrapIterator != null) {
if (unwrapIterator.hasNext()) {
return unwrapIterator.next();
}
unwrapIterator = null;
}
// The search has been executed, so process up to one batch of
// results.
List<?> result = null;
Expand Down Expand Up @@ -310,45 +300,12 @@ public List<?> next() throws TranslatorException {
// do not include it as an attribute
private List<?> getRow(SearchResult result) throws TranslatorException {
Attributes attrs = result.getAttributes();
String resultDN = result.getNameInNamespace(); // added GHH 20080326
ArrayList<Column> attributeList = searchDetails.getElementList();
final List<Object> row = new ArrayList<Object>(attributeList.size());

int unwrapPos = -1;
for (int i = 0; i < attributeList.size(); i++) {
Column col = attributeList.get(i);
Object val = getValue(col, result, attrs); // GHH 20080326 - added resultDN parameter to call
row.add(val);
if (executionFactory.isUnwrapMultiValued() && !col.getJavaType().isArray() && val != null && val.getClass() == ArrayImpl.class) {
if (unwrapPos > -1) {
throw new TranslatorException(LDAPPlugin.Util.gs(LDAPPlugin.Event.TEIID12014, col, attributeList.get(unwrapPos)));
}
unwrapPos = i;
}
}
List<Object> row = new ArrayList<Object>(attributeList.size());

if (unwrapPos > -1) {
final Object[] val = ((ArrayImpl) row.get(unwrapPos)).getValues();
final int pos = unwrapPos;
unwrapIterator = new Iterator<List<Object>>() {
int i = 0;
@Override
public boolean hasNext() {
return i < val.length;
}
@Override
public List<Object> next() {
List<Object> newRow = new ArrayList<Object>(row);
newRow.set(pos, val[i++]);
return newRow;
}
@Override
public void remove() {

}
};
if (unwrapIterator.hasNext()) {
return unwrapIterator.next();
}
for (Column col : attributeList) {
addResultToRow(col, resultDN, attrs, row); // GHH 20080326 - added resultDN parameter to call
}
return row;
}
Expand All @@ -365,7 +322,7 @@ public void remove() {
// value for that column in the result
// GHH 20080326 - added handling of ClassCastException when non-string
// attribute is returned
private Object getValue(Column modelElement, SearchResult result, Attributes attrs) throws TranslatorException {
private void addResultToRow(Column modelElement, String resultDistinguishedName, Attributes attrs, List<Object> row) throws TranslatorException {

String strResult = null;
String modelAttrName = IQueryToLdapSearchParser.getNameFromElement(modelElement);
Expand All @@ -382,16 +339,22 @@ private Object getValue(Column modelElement, SearchResult result, Attributes att

// If the attribute is not present, we return NULL.
if(resultAttr == null) {
// MPW - 2-20-07 - Changed from returning empty string to returning null.
//row.add("");
//logger.logTrace("Did not find a match for attribute named: " + modelAttrName);
// GHH 20080326 - return DN from input parameter
// if DN attribute is not present in search result
if (modelAttrName.toUpperCase().equals("DN")) { //$NON-NLS-1$
return result.getNameInNamespace();
row.add(resultDistinguishedName);
}
return null;
else {
row.add(null);
}
return;
}
Object objResult = null;
try {
if(TypeFacility.RUNTIME_TYPES.STRING.equals(modelAttrClass) && MULTIVALUED_CONCAT.equalsIgnoreCase(multivalAttr)) {
if(TypeFacility.RUNTIME_TYPES.STRING.equals(modelAttrClass) && "multivalued-concat".equalsIgnoreCase(multivalAttr)) { //$NON-NLS-1$
// mpw 5/09
// Order the multi-valued attrs alphabetically before creating a single string,
// using the delimiter to separate each token
Expand All @@ -413,13 +376,8 @@ private Object getValue(Column modelElement, SearchResult result, Attributes att
multivalSB.append(delimiter);
}
}
return multivalSB.toString();
}
if (modelAttrClass.isArray()) {
return getArray(modelAttrClass.getComponentType(), resultAttr);
}
if (executionFactory.isUnwrapMultiValued() && resultAttr.size() > 1) {
return getArray(modelAttrClass, resultAttr);
row.add(multivalSB.toString());
return;
}

//just a single value
Expand Down Expand Up @@ -456,32 +414,20 @@ private Object getValue(Column modelElement, SearchResult result, Attributes att
if(strResult != null) {
Date dateResult = dateFormat.parse(strResult);
Timestamp tsResult = new Timestamp(dateResult.getTime());
return tsResult;
row.add(tsResult);
} else {
row.add(null);
}
return null;
} catch(ParseException pe) {
throw new TranslatorException(pe, LDAPPlugin.Util.getString("LDAPSyncQueryExecution.timestampParseFailed", modelAttrName)); //$NON-NLS-1$
}

// TODO: Extend support for more types in the future.
// Specifically, add support for byte arrays, since that's actually supported
// in the underlying data source.
} else {
row.add(strResult); //the Teiid type conversion logic will handle refine from here if necessary
}
return strResult; //the Teiid type conversion logic will handle refine from here if necessary
}

private ArrayImpl getArray(Class<?> componentType, Attribute resultAttr)
throws NamingException {
ArrayList<Object> multivalList = new ArrayList<Object>();
NamingEnumeration<?> attrNE = resultAttr.getAll();
int length = 0;
while(attrNE.hasMore()) {
multivalList.add(attrNE.next());
length++;
}
Object[] values = (Object[]) Array.newInstance(componentType, length);
ArrayImpl value = new ArrayImpl(multivalList.toArray(values));
return value;
}

// for testing.
Expand Down
Expand Up @@ -149,7 +149,7 @@ protected LdapContext createSearchContext(String contextName) throws TranslatorE
LogManager.logError(LogConstants.CTX_CONNECTOR, LDAPPlugin.Util.gs(LDAPPlugin.Event.TEIID12002, contextName));
}
final String msg = LDAPPlugin.Util.getString("LDAPSyncQueryExecution.createContextError"); //$NON-NLS-1$
throw new TranslatorException(ne, msg);
throw new TranslatorException(msg);
}
}

Expand Down
Expand Up @@ -68,6 +68,4 @@ TEIID12009=Unknown LDAP Request; the query string must start with [search|create
TEIID12010=The DN is not defined; DN should be the token after the marker tokens [search|create|update|delete]
TEIID12011=attributes are not defined; use "attributes=..." form using the comma delimited to specify all the names.
TEIID12012=create/update operation did not find the value for attribute {0}; Each attribute value is defined as the separate parameter in the procedure call.
TEIID12013=unknown option: {0}

TEIID12014=Cannot have more than one multi-valued attribute unwrapped - {0} {1}
TEIID12013=unknown option: {0}

This file was deleted.

0 comments on commit 76fab0b

Please sign in to comment.