001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.persistence;
022:
023: import com.liferay.portal.NoSuchGroupException;
024: import com.liferay.portal.SystemException;
025: import com.liferay.portal.kernel.util.ArrayUtil;
026: import com.liferay.portal.kernel.util.GetterUtil;
027: import com.liferay.portal.kernel.util.OrderByComparator;
028: import com.liferay.portal.kernel.util.StringMaker;
029: import com.liferay.portal.kernel.util.StringPool;
030: import com.liferay.portal.kernel.util.StringUtil;
031: import com.liferay.portal.kernel.util.Validator;
032: import com.liferay.portal.model.Group;
033: import com.liferay.portal.model.LayoutSet;
034: import com.liferay.portal.model.Permission;
035: import com.liferay.portal.model.Resource;
036: import com.liferay.portal.model.ResourceCode;
037: import com.liferay.portal.model.UserGroupRole;
038: import com.liferay.portal.model.impl.GroupImpl;
039: import com.liferay.portal.model.impl.GroupModelImpl;
040: import com.liferay.portal.model.impl.LayoutSetModelImpl;
041: import com.liferay.portal.model.impl.PermissionModelImpl;
042: import com.liferay.portal.model.impl.ResourceCodeModelImpl;
043: import com.liferay.portal.model.impl.ResourceModelImpl;
044: import com.liferay.portal.model.impl.RoleModelImpl;
045: import com.liferay.portal.model.impl.UserGroupRoleModelImpl;
046: import com.liferay.portal.model.impl.UserModelImpl;
047: import com.liferay.portal.spring.hibernate.CustomSQLUtil;
048: import com.liferay.portal.spring.hibernate.FinderCache;
049: import com.liferay.portal.spring.hibernate.HibernateUtil;
050: import com.liferay.util.dao.hibernate.QueryPos;
051: import com.liferay.util.dao.hibernate.QueryUtil;
052:
053: import java.util.ArrayList;
054: import java.util.Iterator;
055: import java.util.LinkedHashMap;
056: import java.util.List;
057: import java.util.Map;
058:
059: import org.hibernate.Hibernate;
060: import org.hibernate.SQLQuery;
061: import org.hibernate.Session;
062:
063: /**
064: * <a href="GroupFinderImpl.java.html"><b><i>View Source</i></b></a>
065: *
066: * @author Brian Wing Shun Chan
067: *
068: */
069: public class GroupFinderImpl implements GroupFinder {
070:
071: public static String COUNT_BY_GROUP_ID = GroupFinder.class
072: .getName()
073: + ".countByGroupId";
074:
075: public static String COUNT_BY_C_N_D = GroupFinder.class.getName()
076: + ".countByC_N_D";
077:
078: public static String FIND_BY_C_N = GroupFinder.class.getName()
079: + ".findByC_N";
080:
081: public static String FIND_BY_C_N_D = GroupFinder.class.getName()
082: + ".findByC_N_D";
083:
084: public static String JOIN_BY_ACTIVE = GroupFinder.class.getName()
085: + ".joinByActive";
086:
087: public static String JOIN_BY_CREATOR_USER_ID = GroupFinder.class
088: .getName()
089: + ".joinByCreatorUserId";
090:
091: public static String JOIN_BY_GROUPS_ORGS = GroupFinder.class
092: .getName()
093: + ".joinByGroupsOrgs";
094:
095: public static String JOIN_BY_GROUPS_ROLES = GroupFinder.class
096: .getName()
097: + ".joinByGroupsRoles";
098:
099: public static String JOIN_BY_GROUPS_USER_GROUPS = GroupFinder.class
100: .getName()
101: + ".joinByGroupsUserGroups";
102:
103: public static String JOIN_BY_LAYOUT_SET = GroupFinder.class
104: .getName()
105: + ".joinByLayoutSet";
106:
107: public static String JOIN_BY_PAGE_COUNT = GroupFinder.class
108: .getName()
109: + ".joinByPageCount";
110:
111: public static String JOIN_BY_ROLE_PERMISSIONS = GroupFinder.class
112: .getName()
113: + ".joinByRolePermissions";
114:
115: public static String JOIN_BY_TYPE = GroupFinder.class.getName()
116: + ".joinByType";
117:
118: public static String JOIN_BY_USER_GROUP_ROLE = GroupFinder.class
119: .getName()
120: + ".joinByUserGroupRole";
121:
122: public static String JOIN_BY_USERS_GROUPS = GroupFinder.class
123: .getName()
124: + ".joinByUsersGroups";
125:
126: public int countByG_U(long groupId, long userId)
127: throws SystemException {
128: String finderSQL = Group.class.getName();
129: boolean[] finderClassNamesCacheEnabled = new boolean[] {
130: GroupModelImpl.CACHE_ENABLED,
131: GroupModelImpl.CACHE_ENABLED_GROUPS_ORGS,
132: GroupModelImpl.CACHE_ENABLED_GROUPS_USERGROUPS,
133: UserModelImpl.CACHE_ENABLED_USERS_GROUPS,
134: UserModelImpl.CACHE_ENABLED_USERS_ORGS,
135: UserModelImpl.CACHE_ENABLED_USERS_USERGROUPS };
136: String[] finderClassNames = new String[] {
137: Group.class.getName(), "Groups_Orgs",
138: "Groups_UserGroups", "Users_Groups", "Users_Orgs",
139: "Users_UserGroups" };
140: String finderMethodName = "customCountByG_U";
141: String finderParams[] = new String[] { Long.class.getName(),
142: Long.class.getName() };
143: Object finderArgs[] = new Object[] { new Long(groupId),
144: new Long(userId) };
145:
146: Object result = null;
147:
148: if (!ArrayUtil.contains(finderClassNamesCacheEnabled, false)) {
149: result = FinderCache.getResult(finderSQL, finderClassNames,
150: finderMethodName, finderParams, finderArgs);
151: }
152:
153: if (result == null) {
154: Long userIdObj = new Long(userId);
155:
156: LinkedHashMap params1 = new LinkedHashMap();
157:
158: params1.put("usersGroups", userIdObj);
159:
160: LinkedHashMap params2 = new LinkedHashMap();
161:
162: params2.put("groupsOrgs", userIdObj);
163:
164: LinkedHashMap params3 = new LinkedHashMap();
165:
166: params3.put("groupsUserGroups", userIdObj);
167:
168: Session session = null;
169:
170: try {
171: session = HibernateUtil.openSession();
172:
173: int count = countByGroupId(session, groupId, params1);
174: count += countByGroupId(session, groupId, params2);
175: count += countByGroupId(session, groupId, params3);
176:
177: FinderCache.putResult(finderSQL,
178: finderClassNamesCacheEnabled, finderClassNames,
179: finderMethodName, finderParams, finderArgs,
180: new Long(count));
181:
182: return count;
183: } catch (Exception e) {
184: throw new SystemException(e);
185: } finally {
186: HibernateUtil.closeSession(session);
187: }
188: } else {
189: return ((Long) result).intValue();
190: }
191: }
192:
193: public int countByC_N_D(long companyId, String name,
194: String description, LinkedHashMap params)
195: throws SystemException {
196:
197: name = StringUtil.lowerCase(name);
198: description = StringUtil.lowerCase(description);
199:
200: if (params == null) {
201: params = new LinkedHashMap();
202: }
203:
204: Long userId = (Long) params.get("usersGroups");
205:
206: LinkedHashMap params1 = params;
207:
208: LinkedHashMap params2 = new LinkedHashMap();
209:
210: params2.putAll(params1);
211:
212: if (userId != null) {
213: params2.remove("usersGroups");
214: params2.put("groupsOrgs", userId);
215: }
216:
217: LinkedHashMap params3 = new LinkedHashMap();
218:
219: params3.putAll(params1);
220:
221: if (userId != null) {
222: params3.remove("usersGroups");
223: params3.put("groupsUserGroups", userId);
224: }
225:
226: Session session = null;
227:
228: try {
229: session = HibernateUtil.openSession();
230:
231: int count = countByC_N_D(session, companyId, name,
232: description, params1);
233:
234: if (Validator.isNotNull(userId)) {
235: count += countByC_N_D(session, companyId, name,
236: description, params2);
237:
238: count += countByC_N_D(session, companyId, name,
239: description, params3);
240: }
241:
242: return count;
243: } catch (Exception e) {
244: throw new SystemException(e);
245: } finally {
246: HibernateUtil.closeSession(session);
247: }
248: }
249:
250: public Group findByC_N(long companyId, String name)
251: throws NoSuchGroupException, SystemException {
252:
253: name = StringUtil.lowerCase(name);
254:
255: boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
256: String finderClassName = Group.class.getName();
257: String finderMethodName = "customFindByC_N";
258: String finderParams[] = new String[] { Long.class.getName(),
259: String.class.getName() };
260: Object finderArgs[] = new Object[] { new Long(companyId), name };
261:
262: Object result = FinderCache.getResult(finderClassName,
263: finderMethodName, finderParams, finderArgs);
264:
265: if (result == null) {
266: Session session = null;
267:
268: try {
269: session = HibernateUtil.openSession();
270:
271: String sql = CustomSQLUtil.get(FIND_BY_C_N);
272:
273: SQLQuery q = session.createSQLQuery(sql);
274:
275: q.addEntity("Group_", GroupImpl.class);
276:
277: QueryPos qPos = QueryPos.getInstance(q);
278:
279: qPos.add(companyId);
280: qPos.add(name);
281:
282: Iterator itr = q.list().iterator();
283:
284: if (itr.hasNext()) {
285: Group group = (Group) itr.next();
286:
287: FinderCache.putResult(finderClassNameCacheEnabled,
288: finderClassName, finderMethodName,
289: finderParams, finderArgs, group);
290:
291: return group;
292: }
293: } catch (Exception e) {
294: throw new SystemException(e);
295: } finally {
296: HibernateUtil.closeSession(session);
297: }
298:
299: StringMaker sm = new StringMaker();
300:
301: sm.append("No Group exists with the key {companyId=");
302: sm.append(companyId);
303: sm.append(", name=");
304: sm.append(name);
305: sm.append("}");
306:
307: throw new NoSuchGroupException(sm.toString());
308: } else {
309: return (Group) result;
310: }
311: }
312:
313: public List findByC_N_D(long companyId, String name,
314: String description, LinkedHashMap params, int begin,
315: int end, OrderByComparator obc) throws SystemException {
316:
317: name = StringUtil.lowerCase(name);
318: description = StringUtil.lowerCase(description);
319:
320: if (params == null) {
321: params = new LinkedHashMap();
322: }
323:
324: Long userId = (Long) params.get("usersGroups");
325:
326: LinkedHashMap params1 = params;
327:
328: LinkedHashMap params2 = new LinkedHashMap();
329:
330: params2.putAll(params1);
331:
332: if (userId != null) {
333: params2.remove("usersGroups");
334: params2.put("groupsOrgs", userId);
335: }
336:
337: LinkedHashMap params3 = new LinkedHashMap();
338:
339: params3.putAll(params1);
340:
341: if (userId != null) {
342: params3.remove("usersGroups");
343: params3.put("groupsUserGroups", userId);
344: }
345:
346: StringMaker sm = new StringMaker();
347:
348: sm.append("(");
349:
350: sm.append(CustomSQLUtil.get(FIND_BY_C_N_D));
351:
352: String sql = sm.toString();
353:
354: sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params1));
355: sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params1));
356:
357: sm = new StringMaker();
358:
359: sm.append(sql);
360:
361: sm.append(")");
362:
363: if (Validator.isNotNull(userId)) {
364: sm.append(" UNION (");
365:
366: sm.append(CustomSQLUtil.get(FIND_BY_C_N_D));
367:
368: sql = sm.toString();
369:
370: sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params2));
371: sql = StringUtil.replace(sql, "[$WHERE$]",
372: getWhere(params2));
373:
374: sm = new StringMaker();
375:
376: sm.append(sql);
377:
378: sm.append(") UNION (");
379:
380: sm.append(CustomSQLUtil.get(FIND_BY_C_N_D));
381:
382: sql = sm.toString();
383:
384: sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params3));
385: sql = StringUtil.replace(sql, "[$WHERE$]",
386: getWhere(params3));
387:
388: sm = new StringMaker();
389:
390: sm.append(sql);
391:
392: sm.append(")");
393: }
394:
395: sql = sm.toString();
396: sql = CustomSQLUtil.replaceOrderBy(sql, obc);
397:
398: String finderSQL = sql;
399: boolean[] finderClassNamesCacheEnabled = new boolean[] {
400: GroupModelImpl.CACHE_ENABLED,
401: LayoutSetModelImpl.CACHE_ENABLED,
402: PermissionModelImpl.CACHE_ENABLED,
403: ResourceModelImpl.CACHE_ENABLED,
404: ResourceCodeModelImpl.CACHE_ENABLED,
405: UserGroupRoleModelImpl.CACHE_ENABLED,
406: GroupModelImpl.CACHE_ENABLED_GROUPS_ORGS,
407: GroupModelImpl.CACHE_ENABLED_GROUPS_ROLES,
408: GroupModelImpl.CACHE_ENABLED_GROUPS_USERGROUPS,
409: RoleModelImpl.CACHE_ENABLED_ROLES_PERMISSIONS,
410: UserModelImpl.CACHE_ENABLED_USERS_GROUPS,
411: UserModelImpl.CACHE_ENABLED_USERS_ORGS,
412: UserModelImpl.CACHE_ENABLED_USERS_USERGROUPS };
413: String[] finderClassNames = new String[] {
414: Group.class.getName(), LayoutSet.class.getName(),
415: Permission.class.getName(), Resource.class.getName(),
416: ResourceCode.class.getName(),
417: UserGroupRole.class.getName(), "Groups_Orgs",
418: "Groups_Roles", "Groups_UserGroups",
419: "Roles_Permissions", "Users_Groups", "Users_Orgs",
420: "Users_UserGroups" };
421: String finderMethodName = "customFindByC_N_D";
422: String finderParams[] = new String[] { Long.class.getName(),
423: String.class.getName(), String.class.getName(),
424: LinkedHashMap.class.getName(), String.class.getName(),
425: String.class.getName() };
426: Object finderArgs[] = new Object[] { new Long(companyId), name,
427: description, params.toString(), String.valueOf(begin),
428: String.valueOf(end) };
429:
430: Object result = null;
431:
432: if (!ArrayUtil.contains(finderClassNamesCacheEnabled, false)) {
433: result = FinderCache.getResult(finderSQL, finderClassNames,
434: finderMethodName, finderParams, finderArgs);
435: }
436:
437: if (result == null) {
438: Session session = null;
439:
440: try {
441: session = HibernateUtil.openSession();
442:
443: SQLQuery q = session.createSQLQuery(sql);
444:
445: q.addScalar("groupId", Hibernate.STRING);
446:
447: QueryPos qPos = QueryPos.getInstance(q);
448:
449: setJoin(qPos, params1);
450: qPos.add(companyId);
451: qPos.add(name);
452: qPos.add(name);
453: qPos.add(description);
454: qPos.add(description);
455:
456: if (Validator.isNotNull(userId)) {
457: setJoin(qPos, params2);
458: qPos.add(companyId);
459: qPos.add(name);
460: qPos.add(name);
461: qPos.add(description);
462: qPos.add(description);
463:
464: setJoin(qPos, params3);
465: qPos.add(companyId);
466: qPos.add(name);
467: qPos.add(name);
468: qPos.add(description);
469: qPos.add(description);
470: }
471:
472: List list = new ArrayList();
473:
474: Iterator itr = QueryUtil.iterate(q, HibernateUtil
475: .getDialect(), begin, end);
476:
477: while (itr.hasNext()) {
478: long groupId = GetterUtil.getLong((String) itr
479: .next());
480:
481: Group group = GroupUtil.findByPrimaryKey(groupId);
482:
483: list.add(group);
484: }
485:
486: FinderCache.putResult(finderSQL,
487: finderClassNamesCacheEnabled, finderClassNames,
488: finderMethodName, finderParams, finderArgs,
489: list);
490:
491: return list;
492: } catch (Exception e) {
493: throw new SystemException(e);
494: } finally {
495: HibernateUtil.closeSession(session);
496: }
497: } else {
498: return (List) result;
499: }
500: }
501:
502: protected int countByGroupId(Session session, long groupId,
503: LinkedHashMap params) throws SystemException {
504:
505: String sql = CustomSQLUtil.get(COUNT_BY_GROUP_ID);
506:
507: sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params));
508: sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params));
509:
510: SQLQuery q = session.createSQLQuery(sql);
511:
512: q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
513:
514: QueryPos qPos = QueryPos.getInstance(q);
515:
516: setJoin(qPos, params);
517: qPos.add(groupId);
518:
519: Iterator itr = q.list().iterator();
520:
521: if (itr.hasNext()) {
522: Long count = (Long) itr.next();
523:
524: if (count != null) {
525: return count.intValue();
526: }
527: }
528:
529: return 0;
530: }
531:
532: protected int countByC_N_D(Session session, long companyId,
533: String name, String description, LinkedHashMap params)
534: throws SystemException {
535:
536: String sql = CustomSQLUtil.get(COUNT_BY_C_N_D);
537:
538: sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params));
539: sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params));
540:
541: SQLQuery q = session.createSQLQuery(sql);
542:
543: q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
544:
545: QueryPos qPos = QueryPos.getInstance(q);
546:
547: setJoin(qPos, params);
548: qPos.add(companyId);
549: qPos.add(name);
550: qPos.add(name);
551: qPos.add(description);
552: qPos.add(description);
553:
554: Iterator itr = q.list().iterator();
555:
556: if (itr.hasNext()) {
557: Long count = (Long) itr.next();
558:
559: if (count != null) {
560: return count.intValue();
561: }
562: }
563:
564: return 0;
565: }
566:
567: protected String getJoin(LinkedHashMap params) {
568: if (params == null) {
569: return StringPool.BLANK;
570: }
571:
572: StringMaker sm = new StringMaker();
573:
574: Iterator itr = params.entrySet().iterator();
575:
576: while (itr.hasNext()) {
577: Map.Entry entry = (Map.Entry) itr.next();
578:
579: String key = (String) entry.getKey();
580: Object value = entry.getValue();
581:
582: if (Validator.isNotNull(value)) {
583: sm.append(getJoin(key));
584: }
585: }
586:
587: return sm.toString();
588: }
589:
590: protected String getJoin(String key) {
591: String join = StringPool.BLANK;
592:
593: if (key.equals("groupsOrgs")) {
594: join = CustomSQLUtil.get(JOIN_BY_GROUPS_ORGS);
595: } else if (key.equals("groupsRoles")) {
596: join = CustomSQLUtil.get(JOIN_BY_GROUPS_ROLES);
597: } else if (key.equals("groupsUserGroups")) {
598: join = CustomSQLUtil.get(JOIN_BY_GROUPS_USER_GROUPS);
599: } else if (key.equals("layoutSet")) {
600: join = CustomSQLUtil.get(JOIN_BY_LAYOUT_SET);
601: } else if (key.equals("pageCount")) {
602: join = CustomSQLUtil.get(JOIN_BY_PAGE_COUNT);
603: } else if (key.equals("rolePermissions")) {
604: join = CustomSQLUtil.get(JOIN_BY_ROLE_PERMISSIONS);
605: } else if (key.equals("userGroupRole")) {
606: join = CustomSQLUtil.get(JOIN_BY_USER_GROUP_ROLE);
607: } else if (key.equals("usersGroups")) {
608: join = CustomSQLUtil.get(JOIN_BY_USERS_GROUPS);
609: }
610:
611: if (Validator.isNotNull(join)) {
612: int pos = join.indexOf("WHERE");
613:
614: if (pos != -1) {
615: join = join.substring(0, pos);
616: }
617: }
618:
619: return join;
620: }
621:
622: protected String getWhere(LinkedHashMap params) {
623: if (params == null) {
624: return StringPool.BLANK;
625: }
626:
627: StringMaker sm = new StringMaker();
628:
629: Iterator itr = params.entrySet().iterator();
630:
631: while (itr.hasNext()) {
632: Map.Entry entry = (Map.Entry) itr.next();
633:
634: String key = (String) entry.getKey();
635: Object value = entry.getValue();
636:
637: if (Validator.isNotNull(value)) {
638: sm.append(getWhere(key, value));
639: }
640: }
641:
642: return sm.toString();
643: }
644:
645: protected String getWhere(String key, Object value) {
646: String join = StringPool.BLANK;
647:
648: if (key.equals("active")) {
649: join = CustomSQLUtil.get(JOIN_BY_ACTIVE);
650: } else if (key.equals("creatorUserId")) {
651: join = CustomSQLUtil.get(JOIN_BY_CREATOR_USER_ID);
652: } else if (key.equals("groupsOrgs")) {
653: join = CustomSQLUtil.get(JOIN_BY_GROUPS_ORGS);
654: } else if (key.equals("groupsRoles")) {
655: join = CustomSQLUtil.get(JOIN_BY_GROUPS_ROLES);
656: } else if (key.equals("groupsUserGroups")) {
657: join = CustomSQLUtil.get(JOIN_BY_GROUPS_USER_GROUPS);
658: } else if (key.equals("layoutSet")) {
659: join = CustomSQLUtil.get(JOIN_BY_LAYOUT_SET);
660: } else if (key.equals("pageCount")) {
661: join = CustomSQLUtil.get(JOIN_BY_PAGE_COUNT);
662: } else if (key.equals("rolePermissions")) {
663: join = CustomSQLUtil.get(JOIN_BY_ROLE_PERMISSIONS);
664: } else if (key.equals("type")) {
665: join = CustomSQLUtil.get(JOIN_BY_TYPE);
666: } else if (key.equals("types")) {
667: List types = (List) value;
668:
669: StringMaker sm = new StringMaker();
670:
671: sm.append("WHERE (");
672:
673: for (int i = 0; i < types.size(); i++) {
674: sm.append("(Group_.type_ = ?) ");
675:
676: if ((i + 1) < types.size()) {
677: sm.append("OR ");
678: }
679: }
680:
681: sm.append(")");
682:
683: join = sm.toString();
684: } else if (key.equals("userGroupRole")) {
685: join = CustomSQLUtil.get(JOIN_BY_USER_GROUP_ROLE);
686: } else if (key.equals("usersGroups")) {
687: join = CustomSQLUtil.get(JOIN_BY_USERS_GROUPS);
688: }
689:
690: if (Validator.isNotNull(join)) {
691: int pos = join.indexOf("WHERE");
692:
693: if (pos != -1) {
694: StringMaker sm = new StringMaker();
695:
696: sm.append(join.substring(pos + 5, join.length()));
697: sm.append(" AND ");
698:
699: join = sm.toString();
700: }
701: }
702:
703: return join;
704: }
705:
706: protected void setJoin(QueryPos qPos, LinkedHashMap params) {
707: if (params != null) {
708: Iterator itr = params.entrySet().iterator();
709:
710: while (itr.hasNext()) {
711: Map.Entry entry = (Map.Entry) itr.next();
712:
713: String key = (String) entry.getKey();
714:
715: if (key.equals("active") || key.equals("layoutSet")) {
716: Boolean value = (Boolean) entry.getValue();
717:
718: qPos.add(value);
719: } else if (key.equals("pageCount")) {
720: } else if (key.equals("rolePermissions")) {
721: List values = (List) entry.getValue();
722:
723: for (int i = 0; i < values.size(); i++) {
724: Object value = values.get(i);
725:
726: if (value instanceof Integer) {
727: Integer valueInteger = (Integer) value;
728:
729: qPos.add(valueInteger);
730: } else if (value instanceof Long) {
731: Long valueLong = (Long) value;
732:
733: qPos.add(valueLong);
734: } else if (value instanceof String) {
735: String valueString = (String) value;
736:
737: qPos.add(valueString);
738: }
739: }
740: } else if (key.equals("types")) {
741: List values = (List) entry.getValue();
742:
743: for (int i = 0; i < values.size(); i++) {
744: Integer value = (Integer) values.get(i);
745:
746: qPos.add(value);
747: }
748: } else if (key.equals("userGroupRole")) {
749: List values = (List) entry.getValue();
750:
751: Long userId = (Long) values.get(0);
752: Long roleId = (Long) values.get(1);
753:
754: qPos.add(userId);
755: qPos.add(roleId);
756: } else {
757: Object value = entry.getValue();
758:
759: if (value instanceof Long) {
760: Long valueLong = (Long) value;
761:
762: if (Validator.isNotNull(valueLong)) {
763: qPos.add(valueLong);
764: }
765: } else if (value instanceof String) {
766: String valueString = (String) value;
767:
768: if (Validator.isNotNull(valueString)) {
769: qPos.add(valueString);
770: }
771: }
772: }
773: }
774: }
775: }
776:
777: }
|