|
From: Irina Z. <i_z...@us...> - 2004-04-27 17:42:31
|
Update of /cvsroot/cobricks/cobricks2/src/org/cobricks/user In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22690/src/org/cobricks/user Modified Files: UserManagerImpl.java Log Message: Index: UserManagerImpl.java =================================================================== RCS file: /cvsroot/cobricks/cobricks2/src/org/cobricks/user/UserManagerImpl.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- UserManagerImpl.java 26 Apr 2004 22:44:07 -0000 1.11 +++ UserManagerImpl.java 27 Apr 2004 17:42:22 -0000 1.12 @@ -1550,75 +1550,7 @@ PreparedStatement preparedStatement) { } - /** - * takes a list of attributes the searched users have to match and - * returns a list of userids of the matching users (as Integer objects) - * - * @param query - Map of attributes of query - * @param orflag - * - * @return List of userids (as Integer objects) - * - * @yahoo.de - **/ - private Collection getUnsortedUserIdList(Map query, boolean orflag) { // TBD: extend profileManager to support orflag and sortby - - Set result = new HashSet(); - List resultTmp = new ArrayList(); - - // for the result of sqlQuery - List of Maps - List fields = new ArrayList(); - fields.add(User.USERID); - fields.add(ANAME); - fields.add(AVALUE); - - int querySize = query.size(); - - if (orflag) { - querySize = 1; - } - - if (!query.isEmpty()) { - resultTmp = dbAccess.sqlSelect(TABLE_USER_ATTR, query, fields); - - if (!resultTmp.isEmpty()) { - // Iterator k = resultTmp.iterator(); - int resultTmpSize = resultTmp.size(); - - logger.debug("result size is " + resultTmpSize); - - Map res = new HashMap(); - String key = ""; - Integer controlUserid = new Integer(0); - int sumOfMatchedCond = 0; - - for (Iterator i = resultTmp.iterator(); i.hasNext();) { - Integer currentUserId = (Integer)((Map)i.next()).get(User.USERID); - - if (currentUserId != null) { - if (orflag) { - result.add(currentUserId); - } else if (!(controlUserid.equals(currentUserId))) { - if (sumOfMatchedCond == querySize) { - result.add(controlUserid); - } - - controlUserid = currentUserId; - sumOfMatchedCond = 1; - } else { - sumOfMatchedCond++; - } - } - } - } else { //redirect to message "There are no users with this attributes" - logger.debug("There are no users with this attributes"); - } - } - - // TBD - return result; - } - + private void doSqlInsert(String tableName, Map fields, Object customFieldValue, String customFieldName) { if (!(customFieldValue instanceof Set)) { @@ -1759,149 +1691,4 @@ return userHandler; } - /** - * - */ - public static class UserPropertiesComparator - implements Comparator { - private static final int SORT_ORDER_ASC = 1; - private static final int SORT_ORDER_DESC = -1; - public static final String SORT_ORDER_NAME_ASC = "asc"; - public static final String SORT_ORDER_NAME_DESC = "desc"; - private String attrNames[]; - private int orders[]; - private boolean userLoginAvialable = false; - private int conditionsAmount; - - public UserPropertiesComparator(String conditions) { - StringTokenizer commaTokenizer = new StringTokenizer(conditions, - ","); - int count = 0; - conditionsAmount = commaTokenizer.countTokens(); - attrNames = new String[conditionsAmount + 1]; - orders = new int[attrNames.length]; - - while (commaTokenizer.hasMoreTokens()) { - String token = commaTokenizer.nextToken(); - int order = SORT_ORDER_ASC; - StringTokenizer spaceTokenizer = new StringTokenizer(token, - " "); - String attrName = spaceTokenizer.nextToken(); - - if (attrName.equals("")) { - attrName = spaceTokenizer.nextToken(); - } - - if (spaceTokenizer.hasMoreTokens()) { - String orderToken = spaceTokenizer.nextToken(); - - if (orderToken.equalsIgnoreCase(SORT_ORDER_NAME_DESC)) { - order = SORT_ORDER_DESC; - } else if (!orderToken.equalsIgnoreCase( - SORT_ORDER_NAME_ASC)) { - logger.warn("unknown sorting order: '" + orderToken - + "' . Assuming ascending order"); - } - } - - attrNames[count] = attrName; - orders[count] = order; - - if (attrName.equalsIgnoreCase(User.USERLOGIN)) { - userLoginAvialable = true; - } - - count++; - } - - if (!userLoginAvialable) { - attrNames[count] = User.USERLOGIN; - orders[count] = SORT_ORDER_ASC; - conditionsAmount++; - } else { - String newAttrNames[] = new String[conditionsAmount]; - int newOrders[] = new int[conditionsAmount]; - - for (int i = 0; i < conditionsAmount; i++) { - newAttrNames[i] = attrNames[i]; - newOrders[i] = orders[i]; - } - - attrNames = newAttrNames; - orders = newOrders; - } - } - - /** - * @return - **/ - public boolean isConditionVoid() { - return (!userLoginAvialable && (attrNames.length == 1)); - } - - public String[] getSortingFields() { - return attrNames; - } - - public int compare(Object o1, Object o2) { - Map user1 = (Map)o1; - - Map user2 = (Map)o2; - - for (int i = 0; i < attrNames.length; i++) { - int comparisonResult = comparePrimitives(user1.get( - attrNames[i]), user2.get(attrNames[i])) * orders[i]; - - if (comparisonResult != 0) { - return comparisonResult; - } - } - - logger.error("MAY DAY!!!"); - - return 0; - } - - private int comparePrimitives(Object o1, Object o2) { - if (o1 == null) { - if (o2 == null) { - return 0; - } else { - return -1; - } - } else if (o2 == null) { - return 1; - } - - if (!o1.getClass().equals(o2.getClass())) { - throw new ArrayIndexOutOfBoundsException("can not compare " - + o1.getClass().getName() + " with " - + o2.getClass().getName()); - } - - if (o1 instanceof String) { - String s1 = (String)o1; - String s2 = (String)o2; - - return s1.compareTo(s2); - } - - if (o1 instanceof Integer) { - Integer i1 = (Integer)o1; - Integer i2 = (Integer)o2; - - return i1.compareTo(i2); - } - - if (o1 instanceof java.sql.Timestamp) { - java.sql.Timestamp t1 = (java.sql.Timestamp)o1; - java.sql.Timestamp t2 = (java.sql.Timestamp)o2; - - return t1.compareTo(t2); - } - - // TBD - return 0; - } - } -} + } |