001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchGroupException;
018    import com.liferay.portal.kernel.dao.orm.QueryPos;
019    import com.liferay.portal.kernel.dao.orm.QueryUtil;
020    import com.liferay.portal.kernel.dao.orm.SQLQuery;
021    import com.liferay.portal.kernel.dao.orm.Session;
022    import com.liferay.portal.kernel.dao.orm.Type;
023    import com.liferay.portal.kernel.exception.SystemException;
024    import com.liferay.portal.kernel.util.OrderByComparator;
025    import com.liferay.portal.kernel.util.StringBundler;
026    import com.liferay.portal.kernel.util.StringPool;
027    import com.liferay.portal.kernel.util.StringUtil;
028    import com.liferay.portal.kernel.util.Validator;
029    import com.liferay.portal.model.Group;
030    import com.liferay.portal.model.impl.GroupImpl;
031    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
032    import com.liferay.portal.util.PortalUtil;
033    import com.liferay.portal.util.PropsValues;
034    import com.liferay.util.dao.orm.CustomSQLUtil;
035    
036    import java.util.ArrayList;
037    import java.util.HashSet;
038    import java.util.Iterator;
039    import java.util.LinkedHashMap;
040    import java.util.List;
041    import java.util.Map;
042    import java.util.Set;
043    
044    /**
045     * @author Brian Wing Shun Chan
046     */
047    public class GroupFinderImpl
048            extends BasePersistenceImpl<Group> implements GroupFinder {
049    
050            public static String COUNT_BY_GROUP_ID =
051                    GroupFinder.class.getName() + ".countByGroupId";
052    
053            public static String COUNT_BY_C_N_D =
054                    GroupFinder.class.getName() + ".countByC_N_D";
055    
056            public static String FIND_BY_LIVE_GROUPS =
057                    GroupFinder.class.getName() + ".findByLiveGroups";
058    
059            public static String FIND_BY_NO_LAYOUTS =
060                    GroupFinder.class.getName() + ".findByNoLayouts";
061    
062            public static String FIND_BY_NULL_FRIENDLY_URL =
063                    GroupFinder.class.getName() + ".findByNullFriendlyURL";
064    
065            public static String FIND_BY_SYSTEM =
066                    GroupFinder.class.getName() + ".findBySystem";
067    
068            public static String FIND_BY_C_N =
069                    GroupFinder.class.getName() + ".findByC_N";
070    
071            public static String FIND_BY_C_N_D =
072                    GroupFinder.class.getName() + ".findByC_N_D";
073    
074            public static String JOIN_BY_ACTIVE =
075                    GroupFinder.class.getName() + ".joinByActive";
076    
077            public static String JOIN_BY_CREATOR_USER_ID =
078                    GroupFinder.class.getName() + ".joinByCreatorUserId";
079    
080            public static String JOIN_BY_GROUPS_ORGS =
081                    GroupFinder.class.getName() + ".joinByGroupsOrgs";
082    
083            public static String JOIN_BY_GROUPS_ROLES =
084                    GroupFinder.class.getName() + ".joinByGroupsRoles";
085    
086            public static String JOIN_BY_GROUPS_USER_GROUPS =
087                    GroupFinder.class.getName() + ".joinByGroupsUserGroups";
088    
089            public static String JOIN_BY_LAYOUT_SET =
090                    GroupFinder.class.getName() + ".joinByLayoutSet";
091    
092            public static String JOIN_BY_PAGE_COUNT =
093                    GroupFinder.class.getName() + ".joinByPageCount";
094    
095            public static String JOIN_BY_ROLE_PERMISSIONS =
096                    GroupFinder.class.getName() + ".joinByRolePermissions";
097    
098            public static String JOIN_BY_ROLE_RESOURCE_PERMISSIONS =
099                    GroupFinder.class.getName() + ".joinByRoleResourcePermissions";
100    
101            public static String JOIN_BY_TYPE =
102                    GroupFinder.class.getName() + ".joinByType";
103    
104            public static String JOIN_BY_USER_GROUP_ROLE =
105                    GroupFinder.class.getName() + ".joinByUserGroupRole";
106    
107            public static String JOIN_BY_USERS_GROUPS =
108                    GroupFinder.class.getName() + ".joinByUsersGroups";
109    
110            public int countByG_U(long groupId, long userId) throws SystemException {
111                    LinkedHashMap<String, Object> params1 =
112                            new LinkedHashMap<String, Object>();
113    
114                    params1.put("usersGroups", userId);
115    
116                    LinkedHashMap<String, Object> params2 =
117                            new LinkedHashMap<String, Object>();
118    
119                    params2.put("groupsOrgs", userId);
120    
121                    LinkedHashMap<String, Object> params3 =
122                            new LinkedHashMap<String, Object>();
123    
124                    params3.put("groupsUserGroups", userId);
125    
126                    Session session = null;
127    
128                    try {
129                            session = openSession();
130    
131                            int count = countByGroupId(session, groupId, params1);
132                            count += countByGroupId(session, groupId, params2);
133                            count += countByGroupId(session, groupId, params3);
134    
135                            return count;
136                    }
137                    catch (Exception e) {
138                            throw new SystemException(e);
139                    }
140                    finally {
141                            closeSession(session);
142                    }
143            }
144    
145            public int countByC_N_D(
146                            long companyId, String name, String realName, String description,
147                            LinkedHashMap<String, Object> params)
148                    throws SystemException {
149    
150                    return countByC_C_N_D(
151                            companyId, new long[] {PortalUtil.getClassNameId(Group.class)},
152                            name, realName, description, params);
153            }
154    
155            public int countByC_C_N_D(
156                            long companyId, long[] classNameIds, String name, String realName,
157                            String description, LinkedHashMap<String, Object> params)
158                    throws SystemException {
159    
160                    name = StringUtil.lowerCase(name);
161                    description = StringUtil.lowerCase(description);
162    
163                    if (params == null) {
164                            params = new LinkedHashMap<String, Object>();
165                    }
166    
167                    Long userId = (Long)params.get("usersGroups");
168    
169                    LinkedHashMap<String, Object> params1 = params;
170    
171                    LinkedHashMap<String, Object> params2 =
172                            new LinkedHashMap<String, Object>();
173    
174                    params2.putAll(params1);
175    
176                    if (userId != null) {
177                            params2.remove("usersGroups");
178                            params2.put("groupsOrgs", userId);
179                    }
180    
181                    LinkedHashMap<String, Object> params3 =
182                            new LinkedHashMap<String, Object>();
183    
184                    params3.putAll(params1);
185    
186                    if (userId != null) {
187                            params3.remove("usersGroups");
188                            params3.put("groupsUserGroups", userId);
189                    }
190    
191                    Session session = null;
192    
193                    try {
194                            session = openSession();
195    
196                            Set<Long> groupIds = new HashSet<Long>();
197    
198                            groupIds.addAll(
199                                    countByC_C_N_D(
200                                            session, companyId, classNameIds, name, realName,
201                                            description, params1));
202    
203                            if (Validator.isNotNull(userId)) {
204                                    groupIds.addAll(
205                                            countByC_C_N_D(
206                                                    session, companyId, classNameIds, name, realName,
207                                                    description, params2));
208    
209                                    groupIds.addAll(
210                                            countByC_C_N_D(
211                                                    session, companyId, classNameIds, name, realName,
212                                                    description, params3));
213                            }
214    
215                            return groupIds.size();
216                    }
217                    catch (Exception e) {
218                            throw new SystemException(e);
219                    }
220                    finally {
221                            closeSession(session);
222                    }
223            }
224    
225            public List<Group> findByLiveGroups() throws SystemException {
226                    Session session = null;
227    
228                    try {
229                            session = openSession();
230    
231                            String sql = CustomSQLUtil.get(FIND_BY_LIVE_GROUPS);
232    
233                            SQLQuery q = session.createSQLQuery(sql);
234    
235                            q.addEntity("Group_", GroupImpl.class);
236    
237                            return q.list();
238                    }
239                    catch (Exception e) {
240                            throw new SystemException(e);
241                    }
242                    finally {
243                            closeSession(session);
244                    }
245            }
246    
247            public List<Group> findByNoLayouts(
248                            long classNameId, boolean privateLayout, int start, int end)
249                    throws SystemException {
250    
251                    Session session = null;
252    
253                    try {
254                            session = openSession();
255    
256                            String sql = CustomSQLUtil.get(FIND_BY_SYSTEM);
257    
258                            SQLQuery q = session.createSQLQuery(sql);
259    
260                            q.addEntity("Group_", GroupImpl.class);
261    
262                            QueryPos qPos = QueryPos.getInstance(q);
263    
264                            qPos.add(classNameId);
265                            qPos.add(privateLayout);
266    
267                            return q.list();
268                    }
269                    catch (Exception e) {
270                            throw new SystemException(e);
271                    }
272                    finally {
273                            closeSession(session);
274                    }
275            }
276    
277            public List<Group> findByNullFriendlyURL() throws SystemException {
278                    Session session = null;
279    
280                    try {
281                            session = openSession();
282    
283                            String sql = CustomSQLUtil.get(FIND_BY_NULL_FRIENDLY_URL);
284    
285                            SQLQuery q = session.createSQLQuery(sql);
286    
287                            q.addEntity("Group_", GroupImpl.class);
288    
289                            return q.list();
290                    }
291                    catch (Exception e) {
292                            throw new SystemException(e);
293                    }
294                    finally {
295                            closeSession(session);
296                    }
297            }
298    
299            public List<Group> findBySystem(long companyId) throws SystemException {
300                    Session session = null;
301    
302                    try {
303                            session = openSession();
304    
305                            String sql = CustomSQLUtil.get(FIND_BY_SYSTEM);
306    
307                            SQLQuery q = session.createSQLQuery(sql);
308    
309                            q.addEntity("Group_", GroupImpl.class);
310    
311                            QueryPos qPos = QueryPos.getInstance(q);
312    
313                            qPos.add(companyId);
314    
315                            return q.list();
316                    }
317                    catch (Exception e) {
318                            throw new SystemException(e);
319                    }
320                    finally {
321                            closeSession(session);
322                    }
323            }
324    
325            public Group findByC_N(long companyId, String name)
326                    throws NoSuchGroupException, SystemException {
327    
328                    name = StringUtil.lowerCase(name);
329    
330                    Session session = null;
331    
332                    try {
333                            session = openSession();
334    
335                            String sql = CustomSQLUtil.get(FIND_BY_C_N);
336    
337                            SQLQuery q = session.createSQLQuery(sql);
338    
339                            q.addEntity("Group_", GroupImpl.class);
340    
341                            QueryPos qPos = QueryPos.getInstance(q);
342    
343                            qPos.add(companyId);
344                            qPos.add(name);
345    
346                            List<Group> list = q.list();
347    
348                            if (!list.isEmpty()) {
349                                    return list.get(0);
350                            }
351                    }
352                    catch (Exception e) {
353                            throw new SystemException(e);
354                    }
355                    finally {
356                            closeSession(session);
357                    }
358    
359                    StringBundler sb = new StringBundler(5);
360    
361                    sb.append("No Group exists with the key {companyId=");
362                    sb.append(companyId);
363                    sb.append(", name=");
364                    sb.append(name);
365                    sb.append("}");
366    
367                    throw new NoSuchGroupException(sb.toString());
368            }
369    
370            public List<Group> findByC_N_D(
371                            long companyId, String name, String realName, String description,
372                            LinkedHashMap<String, Object> params, int start, int end,
373                            OrderByComparator obc)
374                    throws SystemException {
375    
376                    return findByC_C_N_D(
377                            companyId, new long[] {PortalUtil.getClassNameId(Group.class)},
378                            name, realName, description,params, start, end, obc);
379            }
380    
381            public List<Group> findByC_C_N_D(
382                            long companyId, long[] classNameIds, String name, String realName,
383                            String description, LinkedHashMap<String, Object> params,
384                            int start, int end, OrderByComparator obc)
385                    throws SystemException {
386    
387                    name = StringUtil.lowerCase(name);
388                    description = StringUtil.lowerCase(description);
389    
390                    if (params == null) {
391                            params = new LinkedHashMap<String, Object>();
392                    }
393    
394                    Long userId = (Long)params.get("usersGroups");
395    
396                    LinkedHashMap<String, Object> params1 = params;
397    
398                    LinkedHashMap<String, Object> params2 =
399                            new LinkedHashMap<String, Object>();
400    
401                    params2.putAll(params1);
402    
403                    if (userId != null) {
404                            params2.remove("usersGroups");
405                            params2.put("groupsOrgs", userId);
406                    }
407    
408                    LinkedHashMap<String, Object> params3 =
409                            new LinkedHashMap<String, Object>();
410    
411                    params3.putAll(params1);
412    
413                    if (userId != null) {
414                            params3.remove("usersGroups");
415                            params3.put("groupsUserGroups", userId);
416                    }
417    
418                    StringBundler sb = new StringBundler();
419    
420                    sb.append("(");
421    
422                    sb.append(CustomSQLUtil.get(FIND_BY_C_N_D));
423    
424                    String sql = sb.toString();
425    
426                    sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params1));
427                    sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params1));
428    
429                    sb.setIndex(0);
430    
431                    sb.append(sql);
432    
433                    sb.append(")");
434    
435                    if (Validator.isNotNull(userId)) {
436                            sb.append(" UNION (");
437    
438                            sb.append(CustomSQLUtil.get(FIND_BY_C_N_D));
439    
440                            sql = sb.toString();
441    
442                            sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params2));
443                            sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params2));
444    
445                            sb.setIndex(0);
446    
447                            sb.append(sql);
448    
449                            sb.append(") UNION (");
450    
451                            sb.append(CustomSQLUtil.get(FIND_BY_C_N_D));
452    
453                            sql = sb.toString();
454    
455                            sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params3));
456                            sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params3));
457    
458                            sb.setIndex(0);
459    
460                            sb.append(sql);
461    
462                            sb.append(")");
463                    }
464    
465                    sql = sb.toString();
466    
467                    sql = StringUtil.replace(
468                            sql, "Group_.classNameId = ?",
469                            "Group_.classNameId = ".concat(
470                                    StringUtil.merge(classNameIds, " OR Group_.classNameId = ")));
471                    sql = CustomSQLUtil.replaceOrderBy(sql, obc);
472    
473                    Session session = null;
474    
475                    try {
476                            session = openSession();
477    
478                            SQLQuery q = session.createSQLQuery(sql);
479    
480                            q.addScalar("groupId", Type.LONG);
481    
482                            QueryPos qPos = QueryPos.getInstance(q);
483    
484                            setJoin(qPos, params1);
485                            qPos.add(companyId);
486                            qPos.add(name);
487                            qPos.add(realName);
488                            qPos.add(name);
489                            qPos.add(description);
490                            qPos.add(description);
491    
492                            if (Validator.isNotNull(userId)) {
493                                    setJoin(qPos, params2);
494                                    qPos.add(companyId);
495                                    qPos.add(name);
496                                    qPos.add(realName);
497                                    qPos.add(name);
498                                    qPos.add(description);
499                                    qPos.add(description);
500    
501                                    setJoin(qPos, params3);
502                                    qPos.add(companyId);
503                                    qPos.add(name);
504                                    qPos.add(realName);
505                                    qPos.add(name);
506                                    qPos.add(description);
507                                    qPos.add(description);
508                            }
509    
510                            List<Group> groups = new ArrayList<Group>();
511    
512                            Iterator<Long> itr = (Iterator<Long>)QueryUtil.iterate(
513                                    q, getDialect(), start, end);
514    
515                            while (itr.hasNext()) {
516                                    long groupId = itr.next();
517    
518                                    Group group = GroupUtil.findByPrimaryKey(groupId);
519    
520                                    groups.add(group);
521                            }
522    
523                            return groups;
524                    }
525                    catch (Exception e) {
526                            throw new SystemException(e);
527                    }
528                    finally {
529                            closeSession(session);
530                    }
531            }
532    
533            protected int countByGroupId(
534                    Session session, long groupId, LinkedHashMap<String, Object> params) {
535    
536                    String sql = CustomSQLUtil.get(COUNT_BY_GROUP_ID);
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(COUNT_COLUMN_NAME, Type.LONG);
544    
545                    QueryPos qPos = QueryPos.getInstance(q);
546    
547                    setJoin(qPos, params);
548                    qPos.add(groupId);
549    
550                    Iterator<Long> itr = q.list().iterator();
551    
552                    if (itr.hasNext()) {
553                            Long count = itr.next();
554    
555                            if (count != null) {
556                                    return count.intValue();
557                            }
558                    }
559    
560                    return 0;
561            }
562    
563            protected List<Long> countByC_C_N_D(
564                    Session session, long companyId, long[] classNameIds, String name,
565                    String realName, String description,
566                    LinkedHashMap<String, Object> params) {
567    
568                    String sql = CustomSQLUtil.get(COUNT_BY_C_N_D);
569    
570                    sql = StringUtil.replace(
571                            sql, "Group_.classNameId = ?",
572                            "Group_.classNameId = ".concat(
573                                    StringUtil.merge(classNameIds, " OR Group_.classNameId = ")));
574                    sql = StringUtil.replace(sql, "[$JOIN$]", getJoin(params));
575                    sql = StringUtil.replace(sql, "[$WHERE$]", getWhere(params));
576    
577                    SQLQuery q = session.createSQLQuery(sql);
578    
579                    q.addScalar("groupId", Type.LONG);
580    
581                    QueryPos qPos = QueryPos.getInstance(q);
582    
583                    setJoin(qPos, params);
584                    qPos.add(companyId);
585                    qPos.add(name);
586                    qPos.add(realName);
587                    qPos.add(name);
588                    qPos.add(description);
589                    qPos.add(description);
590    
591                    return q.list();
592            }
593    
594            protected String getJoin(LinkedHashMap<String, Object> params) {
595                    if ((params == null) || params.isEmpty()) {
596                            return StringPool.BLANK;
597                    }
598    
599                    StringBundler sb = new StringBundler(params.size());
600    
601                    Iterator<Map.Entry<String, Object>> itr = params.entrySet().iterator();
602    
603                    while (itr.hasNext()) {
604                            Map.Entry<String, Object> entry = itr.next();
605    
606                            String key = entry.getKey();
607                            Object value = entry.getValue();
608    
609                            if (Validator.isNotNull(value)) {
610                                    sb.append(getJoin(key));
611                            }
612                    }
613    
614                    return sb.toString();
615            }
616    
617            protected String getJoin(String key) {
618                    String join = StringPool.BLANK;
619    
620                    if (key.equals("groupsOrgs")) {
621                            join = CustomSQLUtil.get(JOIN_BY_GROUPS_ORGS);
622                    }
623                    else if (key.equals("groupsRoles")) {
624                            join = CustomSQLUtil.get(JOIN_BY_GROUPS_ROLES);
625                    }
626                    else if (key.equals("groupsUserGroups")) {
627                            join = CustomSQLUtil.get(JOIN_BY_GROUPS_USER_GROUPS);
628                    }
629                    else if (key.equals("layoutSet")) {
630                            join = CustomSQLUtil.get(JOIN_BY_LAYOUT_SET);
631                    }
632                    else if (key.equals("pageCount")) {
633                            join = CustomSQLUtil.get(JOIN_BY_PAGE_COUNT);
634                    }
635                    else if (key.equals("rolePermissions")) {
636                            if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
637                                    join = CustomSQLUtil.get(JOIN_BY_ROLE_RESOURCE_PERMISSIONS);
638                            }
639                            else {
640                                    join = CustomSQLUtil.get(JOIN_BY_ROLE_PERMISSIONS);
641                            }
642                    }
643                    else if (key.equals("userGroupRole")) {
644                            join = CustomSQLUtil.get(JOIN_BY_USER_GROUP_ROLE);
645                    }
646                    else if (key.equals("usersGroups")) {
647                            join = CustomSQLUtil.get(JOIN_BY_USERS_GROUPS);
648                    }
649    
650                    if (Validator.isNotNull(join)) {
651                            int pos = join.indexOf("WHERE");
652    
653                            if (pos != -1) {
654                                    join = join.substring(0, pos);
655                            }
656                    }
657    
658                    return join;
659            }
660    
661            protected String getWhere(LinkedHashMap<String, Object> params) {
662                    if ((params == null) || params.isEmpty()) {
663                            return StringPool.BLANK;
664                    }
665    
666                    StringBundler sb = new StringBundler(params.size());
667    
668                    Iterator<Map.Entry<String, Object>> itr = params.entrySet().iterator();
669    
670                    while (itr.hasNext()) {
671                            Map.Entry<String, Object> entry = itr.next();
672    
673                            String key = entry.getKey();
674                            Object value = entry.getValue();
675    
676                            if (Validator.isNotNull(value)) {
677                                    sb.append(getWhere(key, value));
678                            }
679                    }
680    
681                    return sb.toString();
682            }
683    
684            protected String getWhere(String key, Object value) {
685                    String join = StringPool.BLANK;
686    
687                    if (key.equals("active")) {
688                            join = CustomSQLUtil.get(JOIN_BY_ACTIVE);
689                    }
690                    else if (key.equals("creatorUserId")) {
691                            join = CustomSQLUtil.get(JOIN_BY_CREATOR_USER_ID);
692                    }
693                    else if (key.equals("groupsOrgs")) {
694                            join = CustomSQLUtil.get(JOIN_BY_GROUPS_ORGS);
695                    }
696                    else if (key.equals("groupsRoles")) {
697                            join = CustomSQLUtil.get(JOIN_BY_GROUPS_ROLES);
698                    }
699                    else if (key.equals("groupsUserGroups")) {
700                            join = CustomSQLUtil.get(JOIN_BY_GROUPS_USER_GROUPS);
701                    }
702                    else if (key.equals("layoutSet")) {
703                            join = CustomSQLUtil.get(JOIN_BY_LAYOUT_SET);
704                    }
705                    else if (key.equals("pageCount")) {
706                            join = CustomSQLUtil.get(JOIN_BY_PAGE_COUNT);
707                    }
708                    else if (key.equals("rolePermissions")) {
709                            if (PropsValues.PERMISSIONS_USER_CHECK_ALGORITHM == 6) {
710                                    join = CustomSQLUtil.get(JOIN_BY_ROLE_RESOURCE_PERMISSIONS);
711                            }
712                            else {
713                                    join = CustomSQLUtil.get(JOIN_BY_ROLE_PERMISSIONS);
714                            }
715                    }
716                    else if (key.equals("type")) {
717                            join = CustomSQLUtil.get(JOIN_BY_TYPE);
718                    }
719                    else if (key.equals("types")) {
720                            List<Integer> types = (List<Integer>)value;
721    
722                            if (!types.isEmpty()) {
723                                    StringBundler sb = new StringBundler(types.size() * 2 + 1);
724    
725                                    sb.append("WHERE (");
726    
727                                    for (int i = 0; i < types.size(); i++) {
728                                            sb.append("(Group_.type_ = ?) ");
729    
730                                            if ((i + 1) < types.size()) {
731                                                    sb.append("OR ");
732                                            }
733                                    }
734    
735                                    sb.append(")");
736    
737                                    join = sb.toString();
738                            }
739                    }
740                    else if (key.equals("userGroupRole")) {
741                            join = CustomSQLUtil.get(JOIN_BY_USER_GROUP_ROLE);
742                    }
743                    else if (key.equals("usersGroups")) {
744                            join = CustomSQLUtil.get(JOIN_BY_USERS_GROUPS);
745                    }
746    
747                    if (Validator.isNotNull(join)) {
748                            int pos = join.indexOf("WHERE");
749    
750                            if (pos != -1) {
751                                    join = join.substring(pos + 5, join.length()).concat(" AND ");
752                            }
753                            else {
754                                    join = StringPool.BLANK;
755                            }
756                    }
757    
758                    return join;
759            }
760    
761            protected void setJoin(
762                    QueryPos qPos, LinkedHashMap<String, Object> params) {
763    
764                    if (params != null) {
765                            Iterator<Map.Entry<String, Object>> itr =
766                                    params.entrySet().iterator();
767    
768                            while (itr.hasNext()) {
769                                    Map.Entry<String, Object> entry = itr.next();
770    
771                                    String key = entry.getKey();
772    
773                                    if (key.equals("active") || key.equals("layoutSet")) {
774                                            Boolean value = (Boolean)entry.getValue();
775    
776                                            qPos.add(value);
777                                    }
778                                    else if (key.equals("pageCount")) {
779                                    }
780                                    else if (key.equals("rolePermissions")) {
781                                            List<Object> values = (List<Object>)entry.getValue();
782    
783                                            for (int i = 0; i < values.size(); i++) {
784                                                    Object value = values.get(i);
785    
786                                                    if (value instanceof Integer) {
787                                                            Integer valueInteger = (Integer)value;
788    
789                                                            qPos.add(valueInteger);
790                                                    }
791                                                    else if (value instanceof Long) {
792                                                            Long valueLong = (Long)value;
793    
794                                                            qPos.add(valueLong);
795                                                    }
796                                                    else if (value instanceof String) {
797                                                            String valueString = (String)value;
798    
799                                                            qPos.add(valueString);
800                                                    }
801                                            }
802                                    }
803                                    else if (key.equals("types")) {
804                                            List<Integer> values = (List<Integer>)entry.getValue();
805    
806                                            for (int i = 0; i < values.size(); i++) {
807                                                    Integer value = values.get(i);
808    
809                                                    qPos.add(value);
810                                            }
811                                    }
812                                    else if (key.equals("userGroupRole")) {
813                                            List<Long> values = (List<Long>)entry.getValue();
814    
815                                            Long userId = values.get(0);
816                                            Long roleId = values.get(1);
817    
818                                            qPos.add(userId);
819                                            qPos.add(roleId);
820                                    }
821                                    else {
822                                            Object value = entry.getValue();
823    
824                                            if (value instanceof Integer) {
825                                                    Integer valueInteger = (Integer)value;
826    
827                                                    if (Validator.isNotNull(valueInteger)) {
828                                                            qPos.add(valueInteger);
829                                                    }
830                                            }
831                                            else if (value instanceof Long) {
832                                                    Long valueLong = (Long)value;
833    
834                                                    if (Validator.isNotNull(valueLong)) {
835                                                            qPos.add(valueLong);
836                                                    }
837                                            }
838                                            else if (value instanceof String) {
839                                                    String valueString = (String)value;
840    
841                                                    if (Validator.isNotNull(valueString)) {
842                                                            qPos.add(valueString);
843                                                    }
844                                            }
845                                    }
846                            }
847                    }
848            }
849    
850    }