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:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns an ordered range of all the tasks entries where groupId = ? and assigneeUserId = ? and status = any ?.
 *
 * <p>/*ww w  .  ja  va  2  s.  com*/
 * 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 com.liferay.tasks.model.impl.TasksEntryModelImpl}. 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 assigneeUserId the assignee user ID
 * @param statuses the statuses
 * @param start the lower bound of the range of tasks entries
 * @param end the upper bound of the range of tasks entries (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching tasks entries
 */
@Override
public List<TasksEntry> findByG_A_S(long groupId, long assigneeUserId, int[] statuses, int start, int end,
        OrderByComparator<TasksEntry> orderByComparator) {
    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    if (statuses.length == 1) {
        return findByG_A_S(groupId, assigneeUserId, statuses[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, assigneeUserId, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { groupId, assigneeUserId, StringUtil.merge(statuses),

                start, end, orderByComparator };
    }

    List<TasksEntry> list = (List<TasksEntry>) FinderCacheUtil
            .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_S, finderArgs, this);

    if ((list != null) && !list.isEmpty()) {
        for (TasksEntry tasksEntry : list) {
            if ((groupId != tasksEntry.getGroupId()) || (assigneeUserId != tasksEntry.getAssigneeUserId())
                    || !ArrayUtil.contains(statuses, tasksEntry.getStatus())) {
                list = null;

                break;
            }
        }
    }

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

        query.append(_SQL_SELECT_TASKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_G_A_S_GROUPID_2);

        query.append(_FINDER_COLUMN_G_A_S_ASSIGNEEUSERID_2);

        if (statuses.length > 0) {
            query.append(StringPool.OPEN_PARENTHESIS);

            query.append(_FINDER_COLUMN_G_A_S_STATUS_7);

            query.append(StringUtil.merge(statuses));

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);
        }

        query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1);

        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(TasksEntryModelImpl.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);

            qPos.add(assigneeUserId);

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

                Collections.sort(list);

                list = Collections.unmodifiableList(list);
            } else {
                list = (List<TasksEntry>) QueryUtil.list(q, getDialect(), start, end);
            }

            cacheResult(list);

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

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

    return list;
}

From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of tasks entries where groupId = &#63; and assigneeUserId = &#63; and status = any &#63;.
 *
 * @param groupId the group ID/*  w ww  .j a  v  a  2  s  .c  om*/
 * @param assigneeUserId the assignee user ID
 * @param statuses the statuses
 * @return the number of matching tasks entries
 */
@Override
public int countByG_A_S(long groupId, long assigneeUserId, int[] statuses) {
    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    Object[] finderArgs = new Object[] { groupId, assigneeUserId, StringUtil.merge(statuses) };

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

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

        query.append(_SQL_COUNT_TASKSENTRY_WHERE);

        query.append(_FINDER_COLUMN_G_A_S_GROUPID_2);

        query.append(_FINDER_COLUMN_G_A_S_ASSIGNEEUSERID_2);

        if (statuses.length > 0) {
            query.append(StringPool.OPEN_PARENTHESIS);

            query.append(_FINDER_COLUMN_G_A_S_STATUS_7);

            query.append(StringUtil.merge(statuses));

            query.append(StringPool.CLOSE_PARENTHESIS);

            query.append(StringPool.CLOSE_PARENTHESIS);
        }

        query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1);

        String sql = query.toString();

        Session session = null;

        try {
            session = openSession();

            Query q = session.createQuery(sql);

            QueryPos qPos = QueryPos.getInstance(q);

            qPos.add(groupId);

            qPos.add(assigneeUserId);

            count = (Long) q.uniqueResult();

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

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

    return count.intValue();
}

From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java

License:Open Source License

/**
 * Returns the number of tasks entries that the user has permission to view where groupId = &#63; and assigneeUserId = &#63; and status = any &#63;.
 *
 * @param groupId the group ID/*from  w w w.  java  2 s  .  co m*/
 * @param assigneeUserId the assignee user ID
 * @param statuses the statuses
 * @return the number of matching tasks entries that the user has permission to view
 */
@Override
public int filterCountByG_A_S(long groupId, long assigneeUserId, int[] statuses) {
    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
        return countByG_A_S(groupId, assigneeUserId, statuses);
    }

    if (statuses == null) {
        statuses = new int[0];
    } else {
        statuses = ArrayUtil.unique(statuses);
    }

    StringBundler query = new StringBundler();

    query.append(_FILTER_SQL_COUNT_TASKSENTRY_WHERE);

    query.append(_FINDER_COLUMN_G_A_S_GROUPID_2);

    query.append(_FINDER_COLUMN_G_A_S_ASSIGNEEUSERID_2);

    if (statuses.length > 0) {
        query.append(StringPool.OPEN_PARENTHESIS);

        query.append(_FINDER_COLUMN_G_A_S_STATUS_7);

        query.append(StringUtil.merge(statuses));

        query.append(StringPool.CLOSE_PARENTHESIS);

        query.append(StringPool.CLOSE_PARENTHESIS);
    }

    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1);

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

    Session session = null;

    try {
        session = openSession();

        SQLQuery q = session.createSynchronizedSQLQuery(sql);

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

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(groupId);

        qPos.add(assigneeUserId);

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

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

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected void checkIfClauseParentheses(String ifClause, String fileName, int lineCount) {

    int quoteCount = StringUtil.count(ifClause, StringPool.QUOTE);

    if ((quoteCount % 2) == 1) {
        return;/*from w  ww . j  a v  a2s .c o m*/
    }

    ifClause = stripQuotes(ifClause, CharPool.QUOTE);

    ifClause = stripQuotes(ifClause, CharPool.APOSTROPHE);

    if (ifClause.contains(StringPool.DOUBLE_SLASH) || ifClause.contains("/*") || ifClause.contains("*/")) {

        return;
    }

    if (hasRedundantParentheses(ifClause, "||", "&&") || hasRedundantParentheses(ifClause, "&&", "||")) {

        processErrorMessage(fileName, "redundant parentheses: " + fileName + " " + lineCount);
    }

    ifClause = stripRedundantParentheses(ifClause);

    int level = 0;
    int max = StringUtil.count(ifClause, StringPool.OPEN_PARENTHESIS);
    int previousParenthesisPos = -1;

    int[] levels = new int[max];

    for (int i = 0; i < ifClause.length(); i++) {
        char c = ifClause.charAt(i);

        if ((c == CharPool.OPEN_PARENTHESIS) || (c == CharPool.CLOSE_PARENTHESIS)) {

            if (previousParenthesisPos != -1) {
                String s = ifClause.substring(previousParenthesisPos + 1, i);

                if (hasMissingParentheses(s)) {
                    processErrorMessage(fileName, "missing parentheses: " + fileName + " " + lineCount);
                }
            }

            previousParenthesisPos = i;

            if (c == CharPool.OPEN_PARENTHESIS) {
                levels[level] = i;

                level += 1;
            } else {
                int posOpenParenthesis = levels[level - 1];

                if (level > 1) {
                    char nextChar = ifClause.charAt(i + 1);
                    char previousChar = ifClause.charAt(posOpenParenthesis - 1);

                    if (!Character.isLetterOrDigit(nextChar) && (nextChar != CharPool.PERIOD)
                            && !Character.isLetterOrDigit(previousChar)) {

                        String s = ifClause.substring(posOpenParenthesis + 1, i);

                        if (hasRedundantParentheses(s)) {
                            processErrorMessage(fileName,
                                    "redundant parentheses: " + fileName + " " + lineCount);
                        }
                    }

                    if ((previousChar == CharPool.OPEN_PARENTHESIS)
                            && (nextChar == CharPool.CLOSE_PARENTHESIS)) {

                        processErrorMessage(fileName, "redundant parentheses: " + fileName + " " + lineCount);
                    }
                }

                level -= 1;
            }
        }
    }
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected void checkStringBundler(String line, String fileName, int lineCount) {

    if ((!line.startsWith("sb.append(") && !line.contains("SB.append(")) || !line.endsWith(");")) {

        return;/*w  w  w.  j  a  v a2 s .  com*/
    }

    int pos = line.indexOf(".append(");

    line = line.substring(pos + 8, line.length() - 2);

    line = stripQuotes(line, CharPool.QUOTE);

    if (!line.contains(" + ")) {
        return;
    }

    String[] lineParts = StringUtil.split(line, " + ");

    for (String linePart : lineParts) {
        int closeParenthesesCount = StringUtil.count(linePart, StringPool.CLOSE_PARENTHESIS);
        int openParenthesesCount = StringUtil.count(linePart, StringPool.OPEN_PARENTHESIS);

        if (closeParenthesesCount != openParenthesesCount) {
            return;
        }

        if (Validator.isNumber(linePart)) {
            return;
        }
    }

    processErrorMessage(fileName, "plus: " + fileName + " " + lineCount);
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected boolean hasRedundantParentheses(String s) {
    if (!s.contains("&&") && !s.contains("||")) {
        for (int x = 0;;) {
            x = s.indexOf(StringPool.CLOSE_PARENTHESIS);

            if (x == -1) {
                break;
            }//from   www . j a va 2 s. c om

            int y = s.substring(0, x).lastIndexOf(StringPool.OPEN_PARENTHESIS);

            if (y == -1) {
                break;
            }

            s = s.substring(0, y) + s.substring(x + 1);
        }
    }

    if (Validator.isNotNull(s) && !s.contains(StringPool.SPACE)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected boolean hasRedundantParentheses(String s, String operator1, String operator2) {

    String[] parts = StringUtil.split(s, operator1);

    if (parts.length < 3) {
        return false;
    }//w  w w.  j  a va  2s  .  c om

    for (int i = 1; i < (parts.length - 1); i++) {
        String part = parts[i];

        if (part.contains(operator2) || part.contains("!(")) {
            continue;
        }

        int closeParenthesesCount = StringUtil.count(part, StringPool.CLOSE_PARENTHESIS);
        int openParenthesesCount = StringUtil.count(part, StringPool.OPEN_PARENTHESIS);

        if (Math.abs(closeParenthesesCount - openParenthesesCount) == 1) {
            return true;
        }
    }

    return false;
}

From source file:com.liferay.tools.sourceformatter.BaseSourceProcessor.java

License:Open Source License

protected String stripRedundantParentheses(String s) {
    for (int x = 0;;) {
        x = s.indexOf(StringPool.OPEN_PARENTHESIS, x + 1);
        int y = s.indexOf(StringPool.CLOSE_PARENTHESIS, x);

        if ((x == -1) || (y == -1)) {
            return s;
        }/*from  w  w  w .  j  a v a  2  s .c  om*/

        String linePart = s.substring(x + 1, y);

        linePart = StringUtil.replace(linePart, StringPool.COMMA, StringPool.BLANK);

        if (Validator.isAlphanumericName(linePart) || Validator.isNull(linePart)) {

            s = s.substring(0, x) + s.substring(y + 1);
        }
    }
}

From source file:com.liferay.tools.sourceformatter.JavaClass.java

License:Open Source License

protected void checkAnnotationForMethod(JavaTerm javaTerm, String annotation, String requiredMethodNameRegex,
        int requiredMethodType, String fileName) {

    String methodContent = javaTerm.getContent();
    String methodName = javaTerm.getName();

    Pattern pattern = Pattern.compile(requiredMethodNameRegex);

    Matcher matcher = pattern.matcher(methodName);

    if (methodContent.contains(_indent + StringPool.AT + annotation + "\n")
            || methodContent.contains(_indent + StringPool.AT + annotation + StringPool.OPEN_PARENTHESIS)) {

        if (!matcher.find()) {
            BaseSourceProcessor.processErrorMessage(fileName,
                    "LPS-36303: Incorrect method name: " + methodName + " " + fileName);
        } else if (javaTerm.getType() != requiredMethodType) {
            BaseSourceProcessor.processErrorMessage(fileName,
                    "LPS-36303: Incorrect method type for " + methodName + " " + fileName);
        }/*from   ww  w . ja v a 2 s. c  o m*/
    } else if (matcher.find() && !methodContent.contains(_indent + "@Override")) {

        BaseSourceProcessor.processErrorMessage(fileName,
                "Annotation @" + annotation + " required for " + methodName + " " + fileName);
    }
}

From source file:com.liferay.tools.sourceformatter.JavaClass.java

License:Open Source License

protected void fixTabsAndIncorrectEmptyLines(JavaTerm javaTerm) {
    if (!javaTerm.isConstructor() && !javaTerm.isMethod()) {
        return;//from   w w w  .java2  s  .  c  o  m
    }

    String javaTermContent = "\n" + javaTerm.getContent();

    Pattern methodNameAndParametersPattern = Pattern
            .compile("\n" + _indent + "(private |protected |public )(.|\n)*?(\\{|;)\n");

    Matcher matcher = methodNameAndParametersPattern.matcher(javaTermContent);

    if (!matcher.find()) {
        return;
    }

    String methodNameAndParameters = matcher.group();

    String[] lines = StringUtil.splitLines(methodNameAndParameters);

    if (lines.length == 1) {
        if (methodNameAndParameters.endsWith("{\n") && javaTermContent.contains(methodNameAndParameters + "\n")
                && !javaTermContent.contains(methodNameAndParameters + "\n" + _indent + StringPool.TAB + "/*")
                && !javaTermContent
                        .contains(methodNameAndParameters + "\n" + _indent + StringPool.TAB + "// ")) {

            String trimmedJavaTermContent = StringUtil.trimTrailing(javaTermContent);

            if (!trimmedJavaTermContent.endsWith("\n\n" + _indent + StringPool.CLOSE_CURLY_BRACE)) {

                _content = StringUtil.replace(_content, methodNameAndParameters + "\n",
                        methodNameAndParameters);
            }
        }

        return;
    }

    if (methodNameAndParameters.endsWith("{\n") && !javaTermContent.contains(methodNameAndParameters + "\n")
            && !javaTermContent.contains(methodNameAndParameters + _indent + StringPool.CLOSE_CURLY_BRACE)) {

        _content = StringUtil.replace(_content, methodNameAndParameters, methodNameAndParameters + "\n");
    }

    boolean throwsException = methodNameAndParameters.contains(_indent + "throws ");

    String newMethodNameAndParameters = methodNameAndParameters;

    int expectedTabCount = -1;

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

        if (line.contains(_indent + "throws ")) {
            newMethodNameAndParameters = fixLeadingTabs(newMethodNameAndParameters, line, _indent.length() + 1);

            break;
        }

        if (expectedTabCount == -1) {
            if (line.endsWith(StringPool.OPEN_PARENTHESIS)) {
                expectedTabCount = Math.max(JavaSourceProcessor.getLeadingTabCount(line), _indent.length()) + 1;

                if (throwsException && (expectedTabCount == (_indent.length() + 1))) {

                    expectedTabCount += 1;
                }
            }
        } else {
            String previousLine = lines[i - 1];

            if (previousLine.endsWith(StringPool.COMMA) || previousLine.endsWith(StringPool.OPEN_PARENTHESIS)) {

                newMethodNameAndParameters = fixLeadingTabs(newMethodNameAndParameters, line, expectedTabCount);
            } else {
                newMethodNameAndParameters = fixLeadingTabs(newMethodNameAndParameters, line,
                        JavaSourceProcessor.getLeadingTabCount(previousLine) + 1);
            }
        }
    }

    _content = StringUtil.replace(_content, methodNameAndParameters, newMethodNameAndParameters);
}