diff --git a/adapters/dynamoDB_adapters/src/main/java/org/atomhopper/dynamodb/adapter/DynamoDBFeedSource.java b/adapters/dynamoDB_adapters/src/main/java/org/atomhopper/dynamodb/adapter/DynamoDBFeedSource.java index a45677b2..359bcd86 100644 --- a/adapters/dynamoDB_adapters/src/main/java/org/atomhopper/dynamodb/adapter/DynamoDBFeedSource.java +++ b/adapters/dynamoDB_adapters/src/main/java/org/atomhopper/dynamodb/adapter/DynamoDBFeedSource.java @@ -2,13 +2,13 @@ import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; -import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBQueryExpression; import com.amazonaws.services.dynamodbv2.document.*; import com.amazonaws.services.dynamodbv2.document.spec.QuerySpec; import com.amazonaws.services.dynamodbv2.document.utils.ValueMap; -import com.amazonaws.services.dynamodbv2.model.AttributeValue; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; +import com.unboundid.ldap.sdk.Filter; +import com.unboundid.ldap.sdk.LDAPException; import com.yammer.metrics.Metrics; import com.yammer.metrics.core.TimerContext; import org.apache.abdera.Abdera; @@ -41,11 +41,8 @@ import java.net.URL; import java.net.URLEncoder; import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.Stream; import static org.apache.abdera.i18n.text.UrlEncoding.decode; @@ -157,24 +154,27 @@ public List getFeedBackward(String feedName, //Dynamodb query implementation Map map = new HashMap(); String filters = sqlBac.getFilters(map); - String feedNameFilter = "feed = :feedName and "; - // SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - // dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); - String dateLastUpdated = markerTimestamp; - Map valueMap = new HashMap(); - valueMap.put(":id", new AttributeValue().withS(String.valueOf(markerId))); - valueMap.put(":dateLastUpdated", new AttributeValue().withS(dateLastUpdated)); - valueMap.put(":feedName", new AttributeValue().withS(feedName)); - for (Map.Entry res : map.entrySet()) { - valueMap.put(res.getKey(), new AttributeValue().withS(res.getValue())); - } - DynamoDBQueryExpression querySpec = new DynamoDBQueryExpression() - .withKeyConditionExpression("entryId = :id and dateLastUpdated <= :dateLastUpdated") - .withScanIndexForward(false) - .withLimit(pageSize).addExpressionAttributeNamesEntry(markerId, dateLastUpdated) - .withFilterExpression(feedNameFilter + filters) - .withExpressionAttributeValues(valueMap); - feedPage = mapper.query(PersistedEntry.class, querySpec); + + if(null != filters){ + ValueMap valueMap2 = new ValueMap(); + valueMap2.withString(":feed", feedName); + valueMap2.withString(":dateLastUpdated", markerTimestamp); + String feedNameFilter = "dateLastUpdated <= :dateLastUpdated"; + for (Map.Entry res : map.entrySet()) { + valueMap2.withString(res.getKey(), res.getValue()); + } + LOG.error("filterString: " + feedNameFilter + filters); + List result = getQueryBuilderMethod(dynamoDB, "feed = :feed and " + getTimeStampValueFilter(PageDirection.BACKWARD) , filters, pageSize,valueMap2, true); + feedPage = JsonUtil.getPersistenceEntity(result); + }else{ + ValueMap valueMap2 = new ValueMap(); + valueMap2.withString(":feed", feedName); + valueMap2.withString(":dateLastUpdated", markerTimestamp); + String feedNameFilter = "dateLastUpdated <= :dateLastUpdated"; + LOG.error("filterString: " + feedNameFilter + filters); + List result = getQueryBuilderMethod(dynamoDB, "feed = :feed and " + getTimeStampValueFilter(PageDirection.BACKWARD) ,null, pageSize,valueMap2, true); + feedPage = JsonUtil.getPersistenceEntity(result); + } return feedPage; } @@ -201,37 +201,23 @@ public List getFeedForward(String feedName, //Dynamodb query implementation Map map = new HashMap(); String filters = sqlBac.getFilters(map); - - // SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - // dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); - String dateLastUpdated = markerTimestamp; - Map valueMap = new HashMap(); - valueMap.put(":id", new AttributeValue().withS(String.valueOf(markerId))); - valueMap.put(":dateLastUpdated", new AttributeValue().withS(dateLastUpdated)); - valueMap.put(":feedName", new AttributeValue().withS(feedName)); - for (Map.Entry res : map.entrySet()) { - valueMap.put(res.getKey(), new AttributeValue().withS(res.getValue())); - } - DynamoDBQueryExpression querySpec; if(null != filters){ - String feedNameFilter = "feed= :feedName and "; - querySpec = new DynamoDBQueryExpression() - .withKeyConditionExpression("entryId = :id and dateLastUpdated >= :dateLastUpdated") - .withScanIndexForward(true) - .withLimit(pageSize) - .withFilterExpression(feedNameFilter + filters) - .withExpressionAttributeValues(valueMap); + ValueMap valueMap2 = new ValueMap(); + valueMap2.withString(":feed", feedName); + valueMap2.withString(":dateLastUpdated", markerTimestamp); + for (Map.Entry res : map.entrySet()) { + valueMap2.withString(res.getKey(), res.getValue()); + } + List result = getQueryBuilderMethod(dynamoDB, "feed = :feed and " + "dateLastUpdated >= :dateLastUpdated" , filters, pageSize,valueMap2, true); + feedPage = JsonUtil.getPersistenceEntity(result); }else{ - String feedNameFilter = "feed= :feedName"; - querySpec = new DynamoDBQueryExpression() - .withKeyConditionExpression("entryId = :id and dateLastUpdated >= :dateLastUpdated") - .withScanIndexForward(true) - .withLimit(pageSize) - .withFilterExpression(feedNameFilter) - .withExpressionAttributeValues(valueMap); + ValueMap valueMap2 = new ValueMap(); + valueMap2.withString(":feed", feedName); + valueMap2.withString(":dateLastUpdated", markerTimestamp); + List result = getQueryBuilderMethod(dynamoDB, "feed = :feed and " + "dateLastUpdated >= :dateLastUpdated" , null, pageSize,valueMap2, true); + feedPage = JsonUtil.getPersistenceEntity(result); } - feedPage = mapper.query(PersistedEntry.class, querySpec); - int abc = feedPage.size(); + return feedPage; } @@ -409,6 +395,7 @@ private AdapterResponse getFeedPage(GetFeedRequest getFeedRequest, String pageDirection, searchString, pageSize), getFeedRequest, pageSize); + LOG.error("getFeedPage: " + feed ); return ResponseBuilder.found(feed); } @@ -427,6 +414,7 @@ private List enhancedGetFeedPage(final String feedName, final St final String markerId, final PageDirection direction, final String searchString, final int pageSize) { + LOG.error("enhancedGetFeedPage START"); List feedPage = new LinkedList(); TimerContext context = null; @@ -474,7 +462,7 @@ private List enhancedGetFeedPage(final String feedName, final St } finally { stopTimer(context); } - + LOG.error("enhancedGetFeedPage END"); return feedPage; } @@ -507,19 +495,25 @@ private AdapterResponse getLastPage(GetFeedRequest getFeedRequest, int pag * @param searchString: Search Category to be passed * @return List of persistent Object for union results */ - private List enhancedGetLastPage(final String feedName, final int pageSize, - final String searchString) { + private List enhancedGetLastPage(final String feedName, final int pageSize, final String searchString) { List categoriesList = getSearchToSqlConverter().getParamsFromSearchString(searchString); int numCats = categoriesList.size(); - - String filterExpression = null; - - if (numCats > 0) { - filterExpression = "(contains(categories, :categories))"; + int counter = numCats; + + StringBuilder filterExpr = null; + if (counter > 0) { + filterExpr = new StringBuilder(); + filterExpr.append("(contains(categories, :categories").append(numCats - counter).append(")"); + counter--; + while(counter > 0){ + filterExpr.append(" and contains(categories, :categories").append(numCats - counter).append(")"); + counter--; + } + filterExpr.append(")"); } - - TimerContext context = null; + + TimerContext context = null; try { if (numCats > 0) { context = startTimer( @@ -531,23 +525,20 @@ private List enhancedGetLastPage(final String feedName, final in List feedPage; ValueMap valueMap = new ValueMap(); valueMap.withString(":feed", feedName); - feedPage = getQueryBuilderMethod(dynamoDB, "feed = :feed and dateLastUpdated < :dateLastUpdated" ,filterExpression, pageSize, valueMap, true); - // comparator is written to perform sorting based on if two dates are equal then sort output based on entryId in desc order - List persistedEntryList = JsonUtil.getPersistenceEntity(feedPage); - Collections.sort(persistedEntryList, (a, b) -> { - SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - String dateLastUpdated = dateFormatter.format(a.getDateLastUpdated()); - String dateLastUpdatedNextDate = dateFormatter.format(b.getDateLastUpdated()); - if (dateLastUpdatedNextDate.equals(dateLastUpdated)) { - return b.getEntryId().compareTo(a.getEntryId()); + for(int i = 0; i < categoriesList.size() ; i++){ + String s = categoriesList.get(i); + if(s.charAt(0) == '{'){ + valueMap.withString(":categories"+i, s.substring(1,s.length() -1)); + }else{ + valueMap.withString(":categories"+i, s); } - return -1; - }); - + } + feedPage = getQueryBuilderMethod(dynamoDB, "feed = :feed",null != filterExpr? filterExpr.toString(): null, pageSize, valueMap, true); + List persistedEntryList = JsonUtil.getPersistenceEntity(feedPage); + return persistedEntryList; } finally { stopTimer(context); } - return null; } /** @@ -607,19 +598,44 @@ private String getMetricBucketForPageSize(int pageSize) { private List getFeedHead(final String feedName, final int pageSize, final String searchString) { List categoriesList = getSearchToSqlConverter().getParamsFromSearchString(searchString); int numCats = categoriesList.size(); - - - String filterExpression = null; - - if (numCats > 0) { - filterExpression = "(contains(categories, :categories))"; + int counter = numCats; + + LOG.error("Filter String finding"); + String filterString = null; + LOG.error("searchString: " + searchString); + if(null != searchString && searchString.startsWith("(")){ + String searchS = textToLDapSearch(searchString); + Filter filter = null; + try { + filter = Filter.create(searchS); + LOG.error("filter" + filter); + } catch (LDAPException ex) { + LOG.error("Eception: " + ex); + } + if(null != filter){ + filterString = getSearchToSqlConverter().getSqlFromLdapFilter(filter); + LOG.error("finalString " + filterString); + } + }else if(null != searchString && searchString.startsWith("+")){ + StringBuilder filterExpr = null; + if (counter > 0) { + filterExpr = new StringBuilder(); + filterExpr.append("(contains(categories, :categories").append(numCats - counter).append(")"); + counter--; + while(counter > 0){ + filterExpr.append(" and contains(categories, :categories").append(numCats - counter).append(")"); + counter--; + } + filterExpr.append(")"); + filterString = filterExpr.toString(); + } } + TimerContext context = null; try { if (numCats > 0) { - context = startTimer( - String.format("db-get-feed-head-with-cats-%s", getMetricBucketForPageSize(pageSize))); + context = startTimer(String.format("db-get-feed-head-with-cats-%s", getMetricBucketForPageSize(pageSize))); } else { context = startTimer(String.format("db-get-feed-head-%s", getMetricBucketForPageSize(pageSize))); } @@ -627,10 +643,15 @@ private List getFeedHead(final String feedName, final int pageSi List feedPage; ValueMap valueMap = new ValueMap(); valueMap.withString(":feed", feedName); - for(String s: categoriesList){ - valueMap.withString(":categories", s); + for(int i = 0; i < categoriesList.size() ; i++){ + String s = categoriesList.get(i); + if(s.charAt(0) == '{'){ + valueMap.withString(":categories"+i, s.substring(1,s.length() -1)); + }else{ + valueMap.withString(":categories"+i, s); + } } - feedPage = getQueryBuilderMethod(dynamoDB, "feed = :feed",filterExpression, pageSize, valueMap, false); + feedPage = getQueryBuilderMethod(dynamoDB, "feed = :feed",null != filterString? filterString.toString(): null, pageSize, valueMap, false); List persistedEntryList = JsonUtil.getPersistenceEntity(feedPage); return persistedEntryList; } finally { @@ -662,7 +683,8 @@ private TimerContext startTimer(String name) { } private Feed hydrateFeed(Abdera abdera, List persistedEntries, - GetFeedRequest getFeedRequest, final int pageSize) { + GetFeedRequest getFeedRequest, final int pageSize) { + LOG.error("hydrateFeed START"); final Feed hydratedFeed = abdera.newFeed(); final String baseFeedUri = decode(getFeedRequest.urlFor( new EnumKeyedTemplateParameters(URITemplate.FEED))); @@ -694,9 +716,8 @@ private Feed hydrateFeed(Abdera abdera, List persistedEntries, .setRel(helper.getPrevLink()); final PersistedEntry lastEntryInCollection = persistedEntries.get(persistedEntries.size() - 1); - nextEntry = getNextMarker(lastEntryInCollection, getFeedRequest.getFeedName(), searchString); - + LOG.error("nextEntry: " + nextEntry); if (nextEntry != null) { // Set the next link hydratedFeed.addLink(new StringBuilder().append(baseFeedUri) @@ -713,7 +734,7 @@ private Feed hydrateFeed(Abdera abdera, List persistedEntries, .append(DynamoDBConstant.AND_DIRECTION_EQ_BACKWARD).toString()) .setRel(FeedSource.REL_ARCHIVE_NEXT); } - + LOG.error("dddddddddd"); for (PersistedEntry persistedFeedEntry : persistedEntries) { hydratedFeed.addEntry(hydrateEntry(persistedFeedEntry, abdera)); } @@ -732,7 +753,7 @@ private Feed hydrateFeed(Abdera abdera, List persistedEntries, LOG.warn("User requested " + getFeedRequest.getFeedName() + " feed with limit " + pageSize + ", but no entries are available"); } } - + LOG.error("hydrateFeed END"); return hydratedFeed; } @@ -746,14 +767,38 @@ private Feed hydrateFeed(Abdera abdera, List persistedEntries, */ private PersistedEntry getNextMarker(final PersistedEntry persistedEntry, final String feedName, final String searchString) { + LOG.error("getNextMarker START"); + LOG.error("searchString NextMarker: " + searchString); List categoriesList = getSearchToSqlConverter().getParamsFromSearchString(searchString); int numCats = categoriesList.size(); - - String filterExpression = null; - - if (numCats > 0) { - filterExpression = "(contains(categories, :categories))"; + int counter = numCats; + LOG.error("counter: " + counter); + String filterString = null; + if(null != searchString && searchString.startsWith("(")){ + String searchS = textToLDapSearch(searchString); + Filter filter = null; + try { + filter = Filter.create(searchS); + } catch (LDAPException ex) { + LOG.error("Eception: " + ex); + } + if(null != filter){ + filterString = getSearchToSqlConverter().getSqlFromLdapFilter(filter); + } + }else if(null != searchString && searchString.startsWith("+")){ + StringBuilder filterExpr = null; + if (counter > 0) { + filterExpr = new StringBuilder(); + filterExpr.append("(contains(categories, :categories").append(numCats - counter).append(")"); + counter--; + while(counter > 0){ + filterExpr.append(" and contains(categories, :categories").append(numCats - counter).append(")"); + counter--; + } + filterExpr.append(")"); + filterString = filterExpr.toString(); + } } @@ -761,23 +806,27 @@ private PersistedEntry getNextMarker(final PersistedEntry persistedEntry, final List firstUnionPersistentList; ValueMap valueMap = new ValueMap(); valueMap.withString(":feed", persistedEntry.getFeed()); + valueMap.withString(":dateLastUpdated", persistedEntry.getDateLastUpdated()); - for(String s: categoriesList){ + for(int i = 0; i < categoriesList.size() ; i++){ + String s = categoriesList.get(i); if(s.charAt(0) == '{'){ - valueMap.withString(":categories", s.substring(1,s.length() -1)); + valueMap.withString(":categories"+i, s.substring(1,s.length() -1)); }else{ - valueMap.withString(":categories", s); + valueMap.withString(":categories"+i, s); } - } - firstUnionPersistentList = getQueryBuilderMethod(dynamoDB, "feed = :feed ",filterExpression, valueMap); + firstUnionPersistentList = getQueryBuilderMethod(dynamoDB, "feed = :feed and dateLastUpdated > :dateLastUpdated",null!=filterString ? filterString.toString():null,1, valueMap,false); + List persistedEntryList = JsonUtil.getPersistenceEntity(firstUnionPersistentList); - return persistedEntryList.get(0); + LOG.error("getNextMarker END"); + return persistedEntryList.size() > 0 ? persistedEntryList.get(0) : null; } private void addFeedSelfLink(Feed feed, String baseFeedUri, GetFeedRequest getFeedRequest, int pageSize, String searchString) { + LOG.error("addFeedSelfLink START"); StringBuilder queryParams = new StringBuilder(); boolean markerIsSet = false; @@ -804,6 +853,7 @@ private void addFeedSelfLink(Feed feed, String baseFeedUri, GetFeedRequest getFe } } feed.addLink(queryParams.toString()).setRel(Link.REL_SELF); + LOG.error("addFeedSelfLink END"); } @@ -860,6 +910,7 @@ private String urlEncode(String searchString) { * @return : list of entry found if that exits in dynamodb with the entryId and feedName. */ private List getEntry(String entryId, final String feedName) { + LOG.error("getEntry START"); Gson gson = new Gson(); List persistedEntriesObject = new ArrayList(); Table table = dynamoDB.getTable(DynamoDBConstant.ENTRIES); @@ -875,6 +926,7 @@ private List getEntry(String entryId, final String feedName) { Item item = itemsIterator.next(); persistedEntriesObject.add(gson.fromJson(item.toJSONPretty(), PersistedEntry.class)); } + LOG.error("getEntry END"); return persistedEntriesObject; } @@ -891,27 +943,35 @@ public List getQueryBuilderMethod(DynamoDB dynamoDB, String conditionExp List feedPage = new ArrayList<>(); Table table = dynamoDB.getTable("entries"); Index index = table.getIndex("global-feed-index"); + LOG.error("conditionExpression: " + conditionExpression); + LOG.error("filterExpression: " + filterExpression); + LOG.error("valueMap: " + valueMap); + LOG.error("pageSize: " + pageSize); QuerySpec spec = null; if(null!= filterExpression){ + LOG.error("if me gaya"); spec = new QuerySpec() .withKeyConditionExpression(conditionExpression) .withFilterExpression(filterExpression) .withValueMap(valueMap) - .withMaxPageSize(pageSize)// for no of page limit to be displayed + .withMaxResultSize(pageSize)// for no of page limit to be displayed .withScanIndexForward(orderBy); }else{ + LOG.error("else me gaya"); spec = new QuerySpec() .withKeyConditionExpression(conditionExpression) .withValueMap(valueMap) - .withMaxPageSize(pageSize)// for no of page limit to be displayed + .withMaxResultSize(pageSize)// for no of page limit to be displayed .withScanIndexForward(orderBy); } // for descending order sorting on lastDateUpdated ItemCollection persistedEntryItems = null; try{ + LOG.error("before query"); persistedEntryItems = index.query(spec); + LOG.error("after query"); }catch(Exception e){ - LOG.error("Exception " + e + e.getMessage()); + LOG.error("Exception " + e + e.getMessage()); } Iterator itemsIterator = persistedEntryItems.iterator(); @@ -919,6 +979,12 @@ public List getQueryBuilderMethod(DynamoDB dynamoDB, String conditionExp Item item = itemsIterator.next(); feedPage.add(item.toJSONPretty()); } + if(null != feedPage){ + LOG.error("feedPage Size: " + feedPage.size()); + } + else{ + LOG.error("feedPage is null"); + } return feedPage; } @@ -963,4 +1029,11 @@ public List getQueryBuilderMethod(DynamoDB dynamoDB, String conditionExp } return feedPage; } + + private String textToLDapSearch(String searchString) { + searchString = searchString.replace("(AND", "(&"); + searchString = searchString.replace("(OR", "(|"); + searchString = searchString.replace("(NOT", "(!"); + return searchString; + } } diff --git a/adapters/dynamoDB_adapters/src/main/java/org/atomhopper/dynamodb/query/SQLToNoSqlConverter.java b/adapters/dynamoDB_adapters/src/main/java/org/atomhopper/dynamodb/query/SQLToNoSqlConverter.java index 90b2153d..140f95c8 100644 --- a/adapters/dynamoDB_adapters/src/main/java/org/atomhopper/dynamodb/query/SQLToNoSqlConverter.java +++ b/adapters/dynamoDB_adapters/src/main/java/org/atomhopper/dynamodb/query/SQLToNoSqlConverter.java @@ -3,6 +3,8 @@ import com.unboundid.ldap.sdk.Filter; import com.unboundid.ldap.sdk.LDAPException; import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.*; @@ -36,6 +38,8 @@ */ public class SQLToNoSqlConverter { + static Logger LOG = LoggerFactory.getLogger(SQLToNoSqlConverter.class); + public static final String BAD_SEARCH_REGEX = ".*(\"|,).*"; public static final String BAD_CHAR_MSG = "Invalid Search Parameter: '\"' ',' not allowed."; @@ -44,12 +48,12 @@ public class SQLToNoSqlConverter { private static final String OPEN_CURLY_BRACKET = "{"; private static final String CLOSED_CURLY_BRACKET = "}"; private static final String PLUS_SIGN = "+"; - private static final String AND = " AND "; - private static final String OR = " OR "; + private static final String AND = " and "; + private static final String OR = " or "; private static final String NOT = " not "; private static final String CATEGORY = "cat"; - private static final String CATEGORY_STRING = " (contains(categories, :categories)) "; + private static final String CATEGORY_STRING = "contains(categories, :categories%d)"; public static final String OLD_CATEGORY_STRING = " categories && ?::varchar[] "; @@ -59,6 +63,8 @@ public class SQLToNoSqlConverter { private Map mapPrefix = new HashMap(); + private int key = 0; + public SQLToNoSqlConverter() { } public SQLToNoSqlConverter(Map mapper, String split ) { @@ -163,6 +169,68 @@ private List getParametersForClassicSearchFormat(String searchString) { return params; } + public String getSqlFromLdapFilter(Filter filter) { + LOG.error("inside the LDAP filter"); + LOG.error("filter: " + filter); + StringBuilder sql = new StringBuilder(); + + Filter[] filters = filter.getComponents(); + LOG.error("filter and" + filters); + Filter notFilter = filter.getNOTComponent(); + LOG.error("NOt vale : " + notFilter); + + switch (filter.getFilterType()) { + + case Filter.FILTER_TYPE_AND: + for (int x=0 ; x < filters.length; x++) { + if (x == 0) { + sql.append(OPEN_PARENS); + } + if (x > 0) { + sql.append(AND); + } + sql.append(getSqlFromLdapFilter(filters[x])); + if (x == filters.length - 1) { + sql.append(CLOSED_PARENS); + } + } + break; + + case Filter.FILTER_TYPE_OR: + for (int x=0 ; x < filters.length; x++) { + if (x == 0) { + sql.append(OPEN_PARENS); + } + if (x > 0) { + sql.append(OR); + } + sql.append(getSqlFromLdapFilter(filters[x])); + if (x == filters.length - 1) { + sql.append(CLOSED_PARENS); + } + } + break; + + case Filter.FILTER_TYPE_NOT: + sql.append(OPEN_PARENS); + sql.append(NOT); + sql.append(getSqlFromLdapFilter(notFilter)); + sql.append(CLOSED_PARENS); + break; + + case Filter.FILTER_TYPE_EQUALITY: + + if (!filter.getAttributeName().equals(CATEGORY)) { + throw new IllegalArgumentException("Invalid Search Parameter: LDAP attribute name must be 'cat'"); + } + sql.append(String.format(CATEGORY_STRING,key)); + key++; + break; + } + LOG.error("Final SQL string2: " + sql.toString()); + return sql.toString(); + } + private String getSqlFromLdapFilter(Filter filter,Map a) { StringBuilder sql = new StringBuilder(); @@ -214,8 +282,8 @@ private String getSqlFromLdapFilter(Filter filter,Map a) { throw new IllegalArgumentException("Invalid Search Parameter: LDAP attribute name must be 'cat'"); } //String key = UUID.randomUUID().toString(); - a.put(":categories",filter.getAssertionValue()); - sql.append(CATEGORY_STRING); + a.put(":categories" + key,filter.getAssertionValue()); + sql.append(String.format(CATEGORY_STRING,key)); break; }