Search in sources :

Example 11 with OAuthConsumer

use of com.liferay.opensocial.model.OAuthConsumer in project liferay-ide by liferay.

the class OAuthConsumerPersistenceImpl method findAll.

/**
 * Returns an ordered range of all the o auth consumers.
 *
 * <p>
 * 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.opensocial.model.impl.OAuthConsumerModelImpl}. 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 start the lower bound of the range of o auth consumers
 * @param end the upper bound of the range of o auth consumers (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of o auth consumers
 * @throws SystemException if a system exception occurred
 */
@Override
public List<OAuthConsumer> findAll(int start, int end, OrderByComparator orderByComparator) throws SystemException {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
        finderArgs = FINDER_ARGS_EMPTY;
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
        finderArgs = new Object[] { start, end, orderByComparator };
    }
    List<OAuthConsumer> list = (List<OAuthConsumer>) FinderCacheUtil.getResult(finderPath, finderArgs, this);
    if (list == null) {
        StringBundler query = null;
        String sql = null;
        if (orderByComparator != null) {
            query = new StringBundler(2 + (orderByComparator.getOrderByFields().length * 3));
            query.append(_SQL_SELECT_OAUTHCONSUMER);
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            sql = query.toString();
        } else {
            sql = _SQL_SELECT_OAUTHCONSUMER;
            if (pagination) {
                sql = sql.concat(OAuthConsumerModelImpl.ORDER_BY_JPQL);
            }
        }
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            if (!pagination) {
                list = (List<OAuthConsumer>) QueryUtil.list(q, getDialect(), start, end, false);
                Collections.sort(list);
                list = new UnmodifiableList<OAuthConsumer>(list);
            } else {
                list = (List<OAuthConsumer>) QueryUtil.list(q, getDialect(), start, end);
            }
            cacheResult(list);
            FinderCacheUtil.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return list;
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOAuthConsumerException(com.liferay.opensocial.NoSuchOAuthConsumerException) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) ArrayList(java.util.ArrayList) UnmodifiableList(com.liferay.portal.kernel.util.UnmodifiableList) List(java.util.List) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 12 with OAuthConsumer

use of com.liferay.opensocial.model.OAuthConsumer in project liferay-ide by liferay.

the class OAuthConsumerPersistenceImpl method getByGadgetKey_PrevAndNext.

protected OAuthConsumer getByGadgetKey_PrevAndNext(Session session, OAuthConsumer oAuthConsumer, String gadgetKey, OrderByComparator orderByComparator, boolean previous) {
    StringBundler query = null;
    if (orderByComparator != null) {
        query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
    } else {
        query = new StringBundler(3);
    }
    query.append(_SQL_SELECT_OAUTHCONSUMER_WHERE);
    boolean bindGadgetKey = false;
    if (gadgetKey == null) {
        query.append(_FINDER_COLUMN_GADGETKEY_GADGETKEY_1);
    } else if (gadgetKey.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_GADGETKEY_GADGETKEY_3);
    } else {
        bindGadgetKey = true;
        query.append(_FINDER_COLUMN_GADGETKEY_GADGETKEY_2);
    }
    if (orderByComparator != null) {
        String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
        if (orderByConditionFields.length > 0) {
            query.append(WHERE_AND);
        }
        for (int i = 0; i < orderByConditionFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByConditionFields[i]);
            if ((i + 1) < orderByConditionFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
                } else {
                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(WHERE_GREATER_THAN);
                } else {
                    query.append(WHERE_LESSER_THAN);
                }
            }
        }
        query.append(ORDER_BY_CLAUSE);
        String[] orderByFields = orderByComparator.getOrderByFields();
        for (int i = 0; i < orderByFields.length; i++) {
            query.append(_ORDER_BY_ENTITY_ALIAS);
            query.append(orderByFields[i]);
            if ((i + 1) < orderByFields.length) {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC_HAS_NEXT);
                } else {
                    query.append(ORDER_BY_DESC_HAS_NEXT);
                }
            } else {
                if (orderByComparator.isAscending() ^ previous) {
                    query.append(ORDER_BY_ASC);
                } else {
                    query.append(ORDER_BY_DESC);
                }
            }
        }
    } else {
        query.append(OAuthConsumerModelImpl.ORDER_BY_JPQL);
    }
    String sql = query.toString();
    Query q = session.createQuery(sql);
    q.setFirstResult(0);
    q.setMaxResults(2);
    QueryPos qPos = QueryPos.getInstance(q);
    if (bindGadgetKey) {
        qPos.add(gadgetKey);
    }
    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(oAuthConsumer);
        for (Object value : values) {
            qPos.add(value);
        }
    }
    List<OAuthConsumer> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 13 with OAuthConsumer

use of com.liferay.opensocial.model.OAuthConsumer in project liferay-ide by liferay.

the class OAuthConsumerPersistenceImpl method findByGadgetKey_First.

/**
 * Returns the first o auth consumer in the ordered set where gadgetKey = &#63;.
 *
 * @param gadgetKey the gadget key
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the first matching o auth consumer
 * @throws com.liferay.opensocial.NoSuchOAuthConsumerException if a matching o auth consumer could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public OAuthConsumer findByGadgetKey_First(String gadgetKey, OrderByComparator orderByComparator) throws NoSuchOAuthConsumerException, SystemException {
    OAuthConsumer oAuthConsumer = fetchByGadgetKey_First(gadgetKey, orderByComparator);
    if (oAuthConsumer != null) {
        return oAuthConsumer;
    }
    StringBundler msg = new StringBundler(4);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("gadgetKey=");
    msg.append(gadgetKey);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchOAuthConsumerException(msg.toString());
}
Also used : NoSuchOAuthConsumerException(com.liferay.opensocial.NoSuchOAuthConsumerException) OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 14 with OAuthConsumer

use of com.liferay.opensocial.model.OAuthConsumer in project liferay-ide by liferay.

the class OAuthConsumerPersistenceImpl method clearCache.

@Override
public void clearCache(List<OAuthConsumer> oAuthConsumers) {
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    for (OAuthConsumer oAuthConsumer : oAuthConsumers) {
        EntityCacheUtil.removeResult(OAuthConsumerModelImpl.ENTITY_CACHE_ENABLED, OAuthConsumerImpl.class, oAuthConsumer.getPrimaryKey());
        clearUniqueFindersCache(oAuthConsumer);
    }
}
Also used : OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer)

Example 15 with OAuthConsumer

use of com.liferay.opensocial.model.OAuthConsumer in project liferay-ide by liferay.

the class LiferayOAuthStore method getConsumerKeyAndSecret.

public ConsumerInfo getConsumerKeyAndSecret(SecurityToken securityToken, String serviceName, OAuthServiceProvider oAuthServiceProvider) throws GadgetException {
    OAuthConsumer oAuthConsumer = getOAuthConsumer(securityToken, serviceName);
    if (oAuthConsumer == null) {
        throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, "No key for gadget " + securityToken.getAppUrl() + " and service " + serviceName);
    }
    net.oauth.OAuthConsumer netOAuthConsumer = null;
    String keyType = oAuthConsumer.getKeyType();
    if (keyType.equals(OAuthConsumerConstants.KEY_TYPE_RSA_PRIVATE)) {
        netOAuthConsumer = new net.oauth.OAuthConsumer(null, oAuthConsumer.getConsumerKey(), null, oAuthServiceProvider);
        netOAuthConsumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.RSA_SHA1);
        netOAuthConsumer.setProperty(RSA_SHA1.PRIVATE_KEY, oAuthConsumer.getConsumerSecret());
    } else {
        netOAuthConsumer = new net.oauth.OAuthConsumer(null, oAuthConsumer.getConsumerKey(), oAuthConsumer.getConsumerSecret(), oAuthServiceProvider);
        netOAuthConsumer.setProperty(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1);
    }
    String keyName = oAuthConsumer.getKeyName();
    String callbackURL = ShindigUtil.transformURL(_callbackURL);
    return new ConsumerInfo(netOAuthConsumer, keyName, callbackURL);
}
Also used : OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer) GadgetException(org.apache.shindig.gadgets.GadgetException)

Aggregations

OAuthConsumer (com.liferay.opensocial.model.OAuthConsumer)17 NoSuchOAuthConsumerException (com.liferay.opensocial.NoSuchOAuthConsumerException)9 StringBundler (com.liferay.portal.kernel.util.StringBundler)7 Session (com.liferay.portal.kernel.dao.orm.Session)6 SystemException (com.liferay.portal.kernel.exception.SystemException)6 OAuthConsumerImpl (com.liferay.opensocial.model.impl.OAuthConsumerImpl)5 Query (com.liferay.portal.kernel.dao.orm.Query)4 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)3 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)2 Date (java.util.Date)1 GadgetException (org.apache.shindig.gadgets.GadgetException)1