Search in sources :

Example 1 with OAuthConsumer

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

the class OAuthConsumerLocalServiceImpl method addOAuthConsumer.

public OAuthConsumer addOAuthConsumer(long companyId, String gadgetKey, String serviceName, String consumerKey, String consumerSecret, String keyType) throws SystemException {
    if (keyType.equals(OAuthConsumerConstants.KEY_TYPE_RSA_PRIVATE)) {
        consumerSecret = StringPool.BLANK;
    }
    Date now = new Date();
    long oAuthConsumerId = counterLocalService.increment();
    OAuthConsumer oAuthConsumer = oAuthConsumerPersistence.create(oAuthConsumerId);
    oAuthConsumer.setCompanyId(companyId);
    oAuthConsumer.setCreateDate(now);
    oAuthConsumer.setModifiedDate(now);
    oAuthConsumer.setGadgetKey(gadgetKey);
    oAuthConsumer.setServiceName(serviceName);
    oAuthConsumer.setConsumerKey(consumerKey);
    oAuthConsumer.setConsumerSecret(consumerSecret);
    oAuthConsumer.setKeyType(keyType);
    oAuthConsumerPersistence.update(oAuthConsumer);
    return oAuthConsumer;
}
Also used : OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer) Date(java.util.Date)

Example 2 with OAuthConsumer

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

the class OAuthConsumerPersistenceImpl method findByGadgetKey_PrevAndNext.

/**
 * Returns the o auth consumers before and after the current o auth consumer in the ordered set where gadgetKey = ?.
 *
 * @param oAuthConsumerId the primary key of the current o auth consumer
 * @param gadgetKey the gadget key
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next o auth consumer
 * @throws com.liferay.opensocial.NoSuchOAuthConsumerException if a o auth consumer with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public OAuthConsumer[] findByGadgetKey_PrevAndNext(long oAuthConsumerId, String gadgetKey, OrderByComparator orderByComparator) throws NoSuchOAuthConsumerException, SystemException {
    OAuthConsumer oAuthConsumer = findByPrimaryKey(oAuthConsumerId);
    Session session = null;
    try {
        session = openSession();
        OAuthConsumer[] array = new OAuthConsumerImpl[3];
        array[0] = getByGadgetKey_PrevAndNext(session, oAuthConsumer, gadgetKey, orderByComparator, true);
        array[1] = oAuthConsumer;
        array[2] = getByGadgetKey_PrevAndNext(session, oAuthConsumer, gadgetKey, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : OAuthConsumerImpl(com.liferay.opensocial.model.impl.OAuthConsumerImpl) OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOAuthConsumerException(com.liferay.opensocial.NoSuchOAuthConsumerException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 3 with OAuthConsumer

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

the class OAuthConsumerPersistenceImpl method findByGadgetKey.

/**
 * Returns an ordered range of all the o auth consumers where gadgetKey = &#63;.
 *
 * <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 gadgetKey the gadget key
 * @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 matching o auth consumers
 * @throws SystemException if a system exception occurred
 */
@Override
public List<OAuthConsumer> findByGadgetKey(String gadgetKey, 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_BY_GADGETKEY;
        finderArgs = new Object[] { gadgetKey };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GADGETKEY;
        finderArgs = new Object[] { gadgetKey, start, end, orderByComparator };
    }
    List<OAuthConsumer> list = (List<OAuthConsumer>) FinderCacheUtil.getResult(finderPath, finderArgs, this);
    if ((list != null) && !list.isEmpty()) {
        for (OAuthConsumer oAuthConsumer : list) {
            if (!Validator.equals(gadgetKey, oAuthConsumer.getGadgetKey())) {
                list = null;
                break;
            }
        }
    }
    if (list == null) {
        StringBundler query = null;
        if (orderByComparator != null) {
            query = new StringBundler(3 + (orderByComparator.getOrderByFields().length * 3));
        } 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) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OAuthConsumerModelImpl.ORDER_BY_JPQL);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            if (bindGadgetKey) {
                qPos.add(gadgetKey);
            }
            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) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 4 with OAuthConsumer

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

the class OAuthConsumerPersistenceImpl method create.

/**
 * Creates a new o auth consumer with the primary key. Does not add the o auth consumer to the database.
 *
 * @param oAuthConsumerId the primary key for the new o auth consumer
 * @return the new o auth consumer
 */
@Override
public OAuthConsumer create(long oAuthConsumerId) {
    OAuthConsumer oAuthConsumer = new OAuthConsumerImpl();
    oAuthConsumer.setNew(true);
    oAuthConsumer.setPrimaryKey(oAuthConsumerId);
    return oAuthConsumer;
}
Also used : OAuthConsumerImpl(com.liferay.opensocial.model.impl.OAuthConsumerImpl) OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer)

Example 5 with OAuthConsumer

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

the class OAuthConsumerPersistenceImpl method findByGadgetKey_Last.

/**
 * Returns the last 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 last 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_Last(String gadgetKey, OrderByComparator orderByComparator) throws NoSuchOAuthConsumerException, SystemException {
    OAuthConsumer oAuthConsumer = fetchByGadgetKey_Last(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)

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