Example usage for com.liferay.portal.kernel.util StringPool OPEN_PARENTHESIS

List of usage examples for com.liferay.portal.kernel.util StringPool OPEN_PARENTHESIS

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool OPEN_PARENTHESIS.

Prototype

String OPEN_PARENTHESIS

To view the source code for com.liferay.portal.kernel.util StringPool OPEN_PARENTHESIS.

Click Source Link

Usage

From source file:org.oep.ssomgt.service.persistence.AppRole2JobPosPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of app role2 job poses where companyId = ? and jobPosId = any ?.
 *
 * @param companyId the company ID/*from w  ww  .  j  a va 2  s  .co  m*/
 * @param jobPosIds the job pos IDs
 * @return the number of matching app role2 job poses
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByC_InJobPos(long companyId, long[] jobPosIds) throws SystemException {
    Object[] finderArgs = new Object[] { companyId, StringUtil.merge(jobPosIds) };

    Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_INJOBPOS, finderArgs,
            this);

    if (count == null) {
        StringBundler query = new StringBundler();

        query.append(_SQL_COUNT_APPROLE2JOBPOS_WHERE);

        boolean conjunctionable = false;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_C_INJOBPOS_COMPANYID_5);

        conjunctionable = true;

        if ((jobPosIds == null) || (jobPosIds.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < jobPosIds.length; i++) {
                query.append(_FINDER_COLUMN_C_INJOBPOS_JOBPOSID_5);

                if ((i + 1) < jobPosIds.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(companyId);

            if (jobPosIds != null) {
                qPos.add(jobPosIds);
            }

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_INJOBPOS, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_INJOBPOS, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:org.oep.ssomgt.service.persistence.AppRole2JobPosPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the app role2 job poses where companyId = &#63; and groupId = &#63; and jobPosId = any &#63;.
 *
 * <p>//w w w . j  a va2  s .co  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link org.oep.ssomgt.model.impl.AppRole2JobPosModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param companyId the company ID
 * @param groupId the group ID
 * @param jobPosIds the job pos IDs
 * @param start the lower bound of the range of app role2 job poses
 * @param end the upper bound of the range of app role2 job poses (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching app role2 job poses
 * @throws SystemException if a system exception occurred
 */
@Override
public List<AppRole2JobPos> findByC_G_InJobPos(long companyId, long groupId, long[] jobPosIds, int start,
        int end, OrderByComparator orderByComparator) throws SystemException {
    if ((jobPosIds != null) && (jobPosIds.length == 1)) {
        return findByC_G_InJobPos(companyId, groupId, jobPosIds[0], start, end, orderByComparator);
    }

    boolean pagination = true;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderArgs = new Object[] { companyId, groupId, StringUtil.merge(jobPosIds) };
    } else {
        finderArgs = new Object[] { companyId, groupId, StringUtil.merge(jobPosIds),

                start, end, orderByComparator };
    }

    List<AppRole2JobPos> list = (List<AppRole2JobPos>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_INJOBPOS, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (AppRole2JobPos appRole2JobPos : list) {
            if ((companyId != appRole2JobPos.getCompanyId()) || (groupId != appRole2JobPos.getGroupId())
                    || !ArrayUtil.contains(jobPosIds, appRole2JobPos.getJobPosId())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = new StringBundler();

        query.append(_SQL_SELECT_APPROLE2JOBPOS_WHERE);

        boolean conjunctionable = false;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_C_G_INJOBPOS_COMPANYID_5);

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_C_G_INJOBPOS_GROUPID_5);

        conjunctionable = true;

        if ((jobPosIds == null) || (jobPosIds.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < jobPosIds.length; i++) {
                query.append(_FINDER_COLUMN_C_G_INJOBPOS_JOBPOSID_5);

                if ((i + 1) < jobPosIds.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(AppRole2JobPosModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(companyId);

            qPos.add(groupId);

            if (jobPosIds != null) {
                qPos.add(jobPosIds);
            }

            if (!pagination) {
                list = (List<AppRole2JobPos>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<AppRole2JobPos>(list);
            } else {
                list = (List<AppRole2JobPos>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_INJOBPOS, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_G_INJOBPOS, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:org.oep.ssomgt.service.persistence.AppRole2JobPosPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of app role2 job poses where companyId = &#63; and groupId = &#63; and jobPosId = any &#63;.
 *
 * @param companyId the company ID//from w  ww  .ja  va  2  s  .c o m
 * @param groupId the group ID
 * @param jobPosIds the job pos IDs
 * @return the number of matching app role2 job poses
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByC_G_InJobPos(long companyId, long groupId, long[] jobPosIds) throws SystemException {
    Object[] finderArgs = new Object[] { companyId, groupId, StringUtil.merge(jobPosIds) };

    Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_G_INJOBPOS, finderArgs,
            this);

    if (count == null) {
        StringBundler query = new StringBundler();

        query.append(_SQL_COUNT_APPROLE2JOBPOS_WHERE);

        boolean conjunctionable = false;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_C_G_INJOBPOS_COMPANYID_5);

        conjunctionable = true;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_C_G_INJOBPOS_GROUPID_5);

        conjunctionable = true;

        if ((jobPosIds == null) || (jobPosIds.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < jobPosIds.length; i++) {
                query.append(_FINDER_COLUMN_C_G_INJOBPOS_JOBPOSID_5);

                if ((i + 1) < jobPosIds.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(companyId);

            qPos.add(groupId);

            if (jobPosIds != null) {
                qPos.add(jobPosIds);
            }

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_G_INJOBPOS, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_G_INJOBPOS, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:org.opencps.accountmgt.service.impl.BusinessLocalServiceImpl.java

License:Open Source License

public Business addBusiness(String fullName, String enName, String shortName, String businessType,
        String idNumber, String address, String cityCode, String districtCode, String wardCode, String cityName,
        String districtName, String wardName, String telNo, String email, String representativeName,
        String representativeRole, String[] businessDomainCodes, int birthDateDay, int birthDateMonth,
        int birthDateYear, long repositoryId, String sourceFileName, String contentType, String title,
        InputStream inputStream, long size, ServiceContext serviceContext)
        throws SystemException, PortalException {

    Role roleDefault = null;/*from  w w w .  ja va 2  s .c  o  m*/

    try {
        roleDefault = RoleLocalServiceUtil.getRole(serviceContext.getCompanyId(),
                WebKeys.CITIZEN_BUSINESS_ROLE_NAME);
    } catch (Exception e) {
        _log.info("ROLE CITIZEN IS NULL");
    }

    long businessId = counterLocalService.increment(Business.class.getName());

    Business business = businessPersistence.create(businessId);

    Date now = new Date();

    PortletUtil.SplitName spn = PortletUtil.splitName(fullName);

    boolean autoPassword = true;
    boolean autoScreenName = true;
    boolean sendEmail = false;

    long[] groupIds = null;
    long[] organizationIds = null;
    long[] roleIds = null;
    long[] userGroupIds = null;

    String password1 = null;
    String password2 = null;
    String screenName = null;

    //add default role
    if (Validator.isNotNull(roleDefault)) {
        roleIds = new long[] { roleDefault.getRoleId() };
    }

    UserGroup userGroup = null;
    try {
        userGroup = UserGroupLocalServiceUtil.getUserGroup(serviceContext.getCompanyId(),
                PortletPropsValues.USERMGT_USERGROUP_NAME_BUSINESS);
    } catch (Exception e) {
        _log.warn(e.getMessage());
    }

    if (userGroup == null) {
        userGroup = UserGroupLocalServiceUtil.addUserGroup(serviceContext.getUserId(),
                serviceContext.getCompanyId(), PortletPropsValues.USERMGT_USERGROUP_NAME_BUSINESS,
                StringPool.BLANK, serviceContext);

    }

    if (userGroup != null) {
        userGroupIds = new long[] { userGroup.getUserGroupId() };
    }

    password1 = PwdGenerator.getPassword();
    password2 = password1;

    Role adminRole = RoleLocalServiceUtil.getRole(serviceContext.getCompanyId(), "Administrator");
    List<User> adminUsers = UserLocalServiceUtil.getRoleUsers(adminRole.getRoleId());

    PrincipalThreadLocal.setName(adminUsers.get(0).getUserId());
    PermissionChecker permissionChecker;
    try {
        permissionChecker = PermissionCheckerFactoryUtil.create(adminUsers.get(0));
        PermissionThreadLocal.setPermissionChecker(permissionChecker);
    } catch (Exception e) {
        _log.error(e);
    }

    User mappingUser = userService.addUserWithWorkflow(serviceContext.getCompanyId(), autoPassword, password1,
            password2, autoScreenName, screenName, email, 0L, StringPool.BLANK, LocaleUtil.getDefault(),
            spn.getFirstName(), spn.getMidName(), spn.getLastName(), 0, 0, true, birthDateMonth, birthDateDay,
            birthDateYear, "Business", groupIds, organizationIds, roleIds, userGroupIds,
            new ArrayList<Address>(), new ArrayList<EmailAddress>(), new ArrayList<Phone>(),
            new ArrayList<Website>(), new ArrayList<AnnouncementsDelivery>(), sendEmail, serviceContext);

    int status = WorkflowConstants.STATUS_INACTIVE;

    Organization org = OrganizationLocalServiceUtil.addOrganization(mappingUser.getUserId(), 0,
            fullName + StringPool.OPEN_PARENTHESIS + idNumber + StringPool.CLOSE_PARENTHESIS,
            OrganizationConstants.TYPE_REGULAR_ORGANIZATION, 0, 0,
            ListTypeConstants.ORGANIZATION_STATUS_DEFAULT, enName, true, serviceContext);

    userService.addOrganizationUsers(org.getOrganizationId(), new long[] { mappingUser.getUserId() });

    mappingUser = userService.updateStatus(mappingUser.getUserId(), status);

    String[] folderNames = new String[] { PortletConstants.DestinationRoot.BUSINESS.toString(), cityName,
            districtName, wardName, String.valueOf(mappingUser.getUserId()) };

    String destination = PortletUtil.getDestinationFolder(folderNames);

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    FileEntry fileEntry = null;

    if (size > 0 && inputStream != null) {
        DLFolder dlFolder = DLFolderUtil.getTargetFolder(mappingUser.getUserId(),
                serviceContext.getScopeGroupId(), repositoryId, false, 0, destination, StringPool.BLANK, false,
                serviceContext);

        fileEntry = DLAppServiceUtil.addFileEntry(repositoryId, dlFolder.getFolderId(), sourceFileName,
                contentType, title, StringPool.BLANK, StringPool.BLANK, inputStream, size, serviceContext);
    }

    business.setAccountStatus(PortletConstants.ACCOUNT_STATUS_REGISTERED);
    business.setAddress(address);
    business.setAttachFile(fileEntry != null ? fileEntry.getFileEntryId() : 0);
    business.setBusinessType(businessType);
    business.setCityCode(cityCode);
    business.setCompanyId(serviceContext.getCompanyId());
    business.setCreateDate(now);
    business.setDistrictCode(districtCode);
    business.setEmail(email);
    business.setEnName(enName);
    business.setGroupId(serviceContext.getScopeGroupId());
    business.setIdNumber(idNumber);

    business.setMappingOrganizationId(org != null ? org.getOrganizationId() : 0L);

    business.setMappingUserId(mappingUser.getUserId());
    business.setModifiedDate(now);
    business.setName(fullName);
    business.setRepresentativeName(representativeName);
    business.setRepresentativeRole(representativeRole);
    business.setShortName(shortName);
    business.setTelNo(telNo);
    business.setUserId(mappingUser.getUserId());

    business.setUuid(PortalUUIDUtil.generate());
    business.setWardCode(wardCode);

    business = businessPersistence.update(business);

    if (businessDomainCodes != null && businessDomainCodes.length > 0) {
        for (int b = 0; b < businessDomainCodes.length; b++) {
            BusinessDomain domain = new BusinessDomainImpl();
            domain.setBusinessId(businessId);
            domain.setBusinessDomainId(businessDomainCodes[b]);
            businessDomainPersistence.update(domain);
        }
    }

    return business;
}

From source file:org.opencps.usermgt.service.persistence.EmployeePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the employees that the user has permission to view where groupId = &#63; and fullName LIKE any &#63; and workingUnitId = &#63;.
 *
 * <p>/*w ww  .  j  ava2s  . c o  m*/
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link org.opencps.usermgt.model.impl.EmployeeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param groupId the group ID
 * @param fullNames the full names
 * @param workingUnitId the working unit ID
 * @param start the lower bound of the range of employees
 * @param end the upper bound of the range of employees (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching employees that the user has permission to view
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Employee> filterFindByG_N_W(long groupId, String[] fullNames, long workingUnitId, int start,
        int end, OrderByComparator orderByComparator) throws SystemException {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_N_W(groupId, fullNames, workingUnitId, start, end, orderByComparator);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_EMPLOYEE_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_EMPLOYEE_NO_INLINE_DISTINCT_WHERE_1);
    }

    boolean conjunctionable = false;

    if (conjunctionable) {
        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_N_W_GROUPID_5);

    conjunctionable = true;

    if ((fullNames == null) || (fullNames.length > 0)) {
        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(StringPool.OPEN_PARENTHESIS);

        for (int i = 0; i < fullNames.length; i++) {
            String fullName = fullNames[i];

            if (fullName == null) {
                query.append(_FINDER_COLUMN_G_N_W_FULLNAME_4);
            } else if (fullName.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_G_N_W_FULLNAME_6);
            } else {
                query.append(_FINDER_COLUMN_G_N_W_FULLNAME_5);
            }

            if ((i + 1) < fullNames.length) {
                query.append(WHERE_OR);
            }
        }

        query.append(StringPool.CLOSE_PARENTHESIS);

        conjunctionable = true;
    }

    if (conjunctionable) {
        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_N_W_WORKINGUNITID_5);

    conjunctionable = true;

    if (!getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_EMPLOYEE_NO_INLINE_DISTINCT_WHERE_2);
    }

    if (orderByComparator != null) {
        if (getDB().isSupportsInlineDistinct()) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true);
        } else {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true);
        }
    } else {
        if (getDB().isSupportsInlineDistinct()) {
            query.append(EmployeeModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(EmployeeModelImpl.ORDER_BY_SQL);
        }
    }

    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Employee.class.getName(),
            _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSQLQuery(sql);

        if (getDB().isSupportsInlineDistinct()) {
            q.addEntity(_FILTER_ENTITY_ALIAS, EmployeeImpl.class);
        } else {
            q.addEntity(_FILTER_ENTITY_TABLE, EmployeeImpl.class);
        }

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        if (fullNames != null) {
            qPos.add(fullNames);
        }

        qPos.add(workingUnitId);

        return (List<Employee>) QueryUtil.list(q, getDialect(), start, end);
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}

From source file:org.opencps.usermgt.service.persistence.EmployeePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the employees where groupId = &#63; and fullName LIKE any &#63; and workingUnitId = &#63;.
 *
 * <p>//from   w  w  w. j a  v a  2 s  . c om
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link org.opencps.usermgt.model.impl.EmployeeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param groupId the group ID
 * @param fullNames the full names
 * @param workingUnitId the working unit ID
 * @param start the lower bound of the range of employees
 * @param end the upper bound of the range of employees (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching employees
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Employee> findByG_N_W(long groupId, String[] fullNames, long workingUnitId, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    if ((fullNames != null) && (fullNames.length == 1)) {
        return findByG_N_W(groupId, fullNames[0], workingUnitId, start, end, orderByComparator);
    }

    boolean pagination = true;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderArgs = new Object[] { groupId, StringUtil.merge(fullNames), workingUnitId };
    } else {
        finderArgs = new Object[] { groupId, StringUtil.merge(fullNames), workingUnitId,

                start, end, orderByComparator };
    }

    List<Employee> list = (List<Employee>) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_W,
            finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Employee employee : list) {
            if ((groupId != employee.getGroupId()) || !ArrayUtil.contains(fullNames, employee.getFullName())
                    || (workingUnitId != employee.getWorkingUnitId())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = new StringBundler();

        query.append(_SQL_SELECT_EMPLOYEE_WHERE);

        boolean conjunctionable = false;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_N_W_GROUPID_5);

        conjunctionable = true;

        if ((fullNames == null) || (fullNames.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < fullNames.length; i++) {
                String fullName = fullNames[i];

                if (fullName == null) {
                    query.append(_FINDER_COLUMN_G_N_W_FULLNAME_4);
                } else if (fullName.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_G_N_W_FULLNAME_6);
                } else {
                    query.append(_FINDER_COLUMN_G_N_W_FULLNAME_5);
                }

                if ((i + 1) < fullNames.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_N_W_WORKINGUNITID_5);

        conjunctionable = true;

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(EmployeeModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

            if (fullNames != null) {
                qPos.add(fullNames);
            }

            qPos.add(workingUnitId);

            if (!pagination) {
                list = (List<Employee>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<Employee>(list);
            } else {
                list = (List<Employee>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_W, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_W, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}

From source file:org.opencps.usermgt.service.persistence.EmployeePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of employees where groupId = &#63; and fullName LIKE any &#63; and workingUnitId = &#63;.
 *
 * @param groupId the group ID//from  w  ww . j  av a 2s.  co m
 * @param fullNames the full names
 * @param workingUnitId the working unit ID
 * @return the number of matching employees
 * @throws SystemException if a system exception occurred
 */
@Override
public int countByG_N_W(long groupId, String[] fullNames, long workingUnitId) throws SystemException {
    Object[] finderArgs = new Object[] { groupId, StringUtil.merge(fullNames), workingUnitId };

    Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_N_W, finderArgs, this);

    if (count == null) {
        StringBundler query = new StringBundler();

        query.append(_SQL_COUNT_EMPLOYEE_WHERE);

        boolean conjunctionable = false;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_N_W_GROUPID_5);

        conjunctionable = true;

        if ((fullNames == null) || (fullNames.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < fullNames.length; i++) {
                String fullName = fullNames[i];

                if (fullName == null) {
                    query.append(_FINDER_COLUMN_G_N_W_FULLNAME_4);
                } else if (fullName.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_G_N_W_FULLNAME_6);
                } else {
                    query.append(_FINDER_COLUMN_G_N_W_FULLNAME_5);
                }

                if ((i + 1) < fullNames.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_N_W_WORKINGUNITID_5);

        conjunctionable = true;

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

            if (fullNames != null) {
                qPos.add(fullNames);
            }

            qPos.add(workingUnitId);

            count = (Long) q.uniqueResult();

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_N_W, finderArgs, count);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_N_W, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return count.intValue();
}

From source file:org.opencps.usermgt.service.persistence.EmployeePersistenceImpl.java

License:Open Source License

/**
 * Returns the number of employees that the user has permission to view where groupId = &#63; and fullName LIKE any &#63; and workingUnitId = &#63;.
 *
 * @param groupId the group ID//  w w  w.  j a v a 2 s  .c o  m
 * @param fullNames the full names
 * @param workingUnitId the working unit ID
 * @return the number of matching employees that the user has permission to view
 * @throws SystemException if a system exception occurred
 */
@Override
public int filterCountByG_N_W(long groupId, String[] fullNames, long workingUnitId) throws SystemException {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_N_W(groupId, fullNames, workingUnitId);
    }

    StringBundler query = new StringBundler();

    query.append(_FILTER_SQL_COUNT_EMPLOYEE_WHERE);

    boolean conjunctionable = false;

    if (conjunctionable) {
        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_N_W_GROUPID_5);

    conjunctionable = true;

    if ((fullNames == null) || (fullNames.length > 0)) {
        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(StringPool.OPEN_PARENTHESIS);

        for (int i = 0; i < fullNames.length; i++) {
            String fullName = fullNames[i];

            if (fullName == null) {
                query.append(_FINDER_COLUMN_G_N_W_FULLNAME_4);
            } else if (fullName.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_G_N_W_FULLNAME_6);
            } else {
                query.append(_FINDER_COLUMN_G_N_W_FULLNAME_5);
            }

            if ((i + 1) < fullNames.length) {
                query.append(WHERE_OR);
            }
        }

        query.append(StringPool.CLOSE_PARENTHESIS);

        conjunctionable = true;
    }

    if (conjunctionable) {
        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_N_W_WORKINGUNITID_5);

    conjunctionable = true;

    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Employee.class.getName(),
            _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSQLQuery(sql);

        q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        if (fullNames != null) {
            qPos.add(fullNames);
        }

        qPos.add(workingUnitId);

        Long count = (Long) q.uniqueResult();

        return count.intValue();
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}

From source file:org.opencps.usermgt.service.persistence.EmployeePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the employees that the user has permission to view where groupId = &#63; and fullName LIKE any &#63;.
 *
 * <p>//from  ww w .ja  v  a  2 s  . co  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link org.opencps.usermgt.model.impl.EmployeeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param groupId the group ID
 * @param fullNames the full names
 * @param start the lower bound of the range of employees
 * @param end the upper bound of the range of employees (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching employees that the user has permission to view
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Employee> filterFindByG_N(long groupId, String[] fullNames, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return findByG_N(groupId, fullNames, start, end, orderByComparator);
    }

    StringBundler query = new StringBundler();

    if (getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_EMPLOYEE_WHERE);
    } else {
        query.append(_FILTER_SQL_SELECT_EMPLOYEE_NO_INLINE_DISTINCT_WHERE_1);
    }

    boolean conjunctionable = false;

    if (conjunctionable) {
        query.append(WHERE_AND);
    }

    query.append(_FINDER_COLUMN_G_N_GROUPID_5);

    conjunctionable = true;

    if ((fullNames == null) || (fullNames.length > 0)) {
        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(StringPool.OPEN_PARENTHESIS);

        for (int i = 0; i < fullNames.length; i++) {
            String fullName = fullNames[i];

            if (fullName == null) {
                query.append(_FINDER_COLUMN_G_N_FULLNAME_4);
            } else if (fullName.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_G_N_FULLNAME_6);
            } else {
                query.append(_FINDER_COLUMN_G_N_FULLNAME_5);
            }

            if ((i + 1) < fullNames.length) {
                query.append(WHERE_OR);
            }
        }

        query.append(StringPool.CLOSE_PARENTHESIS);

        conjunctionable = true;
    }

    if (!getDB().isSupportsInlineDistinct()) {
        query.append(_FILTER_SQL_SELECT_EMPLOYEE_NO_INLINE_DISTINCT_WHERE_2);
    }

    if (orderByComparator != null) {
        if (getDB().isSupportsInlineDistinct()) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true);
        } else {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true);
        }
    } else {
        if (getDB().isSupportsInlineDistinct()) {
            query.append(EmployeeModelImpl.ORDER_BY_JPQL);
        } else {
            query.append(EmployeeModelImpl.ORDER_BY_SQL);
        }
    }

    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), Employee.class.getName(),
            _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSQLQuery(sql);

        if (getDB().isSupportsInlineDistinct()) {
            q.addEntity(_FILTER_ENTITY_ALIAS, EmployeeImpl.class);
        } else {
            q.addEntity(_FILTER_ENTITY_TABLE, EmployeeImpl.class);
        }

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        if (fullNames != null) {
            qPos.add(fullNames);
        }

        return (List<Employee>) QueryUtil.list(q, getDialect(), start, end);
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}

From source file:org.opencps.usermgt.service.persistence.EmployeePersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the employees where groupId = &#63; and fullName LIKE any &#63;.
 *
 * <p>// w w w . ja v a2s  .co  m
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link org.opencps.usermgt.model.impl.EmployeeModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param groupId the group ID
 * @param fullNames the full names
 * @param start the lower bound of the range of employees
 * @param end the upper bound of the range of employees (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching employees
 * @throws SystemException if a system exception occurred
 */
@Override
public List<Employee> findByG_N(long groupId, String[] fullNames, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
    if ((fullNames != null) && (fullNames.length == 1)) {
        return findByG_N(groupId, fullNames[0], start, end, orderByComparator);
    }

    boolean pagination = true;
    Object[] finderArgs = null;

    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderArgs = new Object[] { groupId, StringUtil.merge(fullNames) };
    } else {
        finderArgs = new Object[] { groupId, StringUtil.merge(fullNames),

                start, end, orderByComparator };
    }

    List<Employee> list = (List<Employee>) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N,
            finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (Employee employee : list) {
            if ((groupId != employee.getGroupId()) || !ArrayUtil.contains(fullNames, employee.getFullName())) {
                list = null;

                break;
            }
        }
    }

    if (list == null) {
        StringBundler query = new StringBundler();

        query.append(_SQL_SELECT_EMPLOYEE_WHERE);

        boolean conjunctionable = false;

        if (conjunctionable) {
            query.append(WHERE_AND);
        }

        query.append(_FINDER_COLUMN_G_N_GROUPID_5);

        conjunctionable = true;

        if ((fullNames == null) || (fullNames.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }

            query.append(StringPool.OPEN_PARENTHESIS);

            for (int i = 0; i < fullNames.length; i++) {
                String fullName = fullNames[i];

                if (fullName == null) {
                    query.append(_FINDER_COLUMN_G_N_FULLNAME_4);
                } else if (fullName.equals(StringPool.BLANK)) {
                    query.append(_FINDER_COLUMN_G_N_FULLNAME_6);
                } else {
                    query.append(_FINDER_COLUMN_G_N_FULLNAME_5);
                }

                if ((i + 1) < fullNames.length) {
                    query.append(WHERE_OR);
                }
            }

            query.append(StringPool.CLOSE_PARENTHESIS);

            conjunctionable = true;
        }

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(EmployeeModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

            if (fullNames != null) {
                qPos.add(fullNames);
            }

            if (!pagination) {
                list = (List<Employee>) QueryUtil.list(q, getDialect(), start, end, false);

                Collections.sort(list);

                list = new UnmodifiableList<Employee>(list);
            } else {
                list = (List<Employee>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N, finderArgs);

            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    return list;
}