Search in sources :

Example 6 with OAuthToken

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

the class OAuthTokenLocalServiceImpl method addOAuthToken.

public OAuthToken addOAuthToken(long userId, String gadgetKey, String serviceName, long moduleId, String accessToken, String tokenName, String tokenSecret, String sessionHandle, long expiration) throws PortalException, SystemException {
    User user = UserLocalServiceUtil.getUser(userId);
    Date now = new Date();
    long oAuthTokenId = counterLocalService.increment();
    OAuthToken oAuthToken = oAuthTokenPersistence.create(oAuthTokenId);
    oAuthToken.setCompanyId(user.getCompanyId());
    oAuthToken.setUserId(user.getUserId());
    oAuthToken.setUserName(user.getFullName());
    oAuthToken.setCreateDate(now);
    oAuthToken.setModifiedDate(now);
    oAuthToken.setGadgetKey(gadgetKey);
    oAuthToken.setServiceName(serviceName);
    oAuthToken.setModuleId(moduleId);
    oAuthToken.setAccessToken(accessToken);
    oAuthToken.setTokenName(tokenName);
    oAuthToken.setTokenSecret(tokenSecret);
    oAuthToken.setSessionHandle(sessionHandle);
    oAuthToken.setExpiration(expiration);
    oAuthTokenPersistence.update(oAuthToken);
    return oAuthToken;
}
Also used : OAuthToken(com.liferay.opensocial.model.OAuthToken) User(com.liferay.portal.model.User) Date(java.util.Date)

Example 7 with OAuthToken

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

the class OAuthTokenModelImpl method equals.

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof OAuthToken)) {
        return false;
    }
    OAuthToken oAuthToken = (OAuthToken) obj;
    long primaryKey = oAuthToken.getPrimaryKey();
    if (getPrimaryKey() == primaryKey) {
        return true;
    } else {
        return false;
    }
}
Also used : OAuthToken(com.liferay.opensocial.model.OAuthToken)

Example 8 with OAuthToken

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

the class OAuthTokenPersistenceImpl method getByG_S_PrevAndNext.

protected OAuthToken getByG_S_PrevAndNext(Session session, OAuthToken oAuthToken, String gadgetKey, String serviceName, 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_OAUTHTOKEN_WHERE);
    boolean bindGadgetKey = false;
    if (gadgetKey == null) {
        query.append(_FINDER_COLUMN_G_S_GADGETKEY_1);
    } else if (gadgetKey.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_G_S_GADGETKEY_3);
    } else {
        bindGadgetKey = true;
        query.append(_FINDER_COLUMN_G_S_GADGETKEY_2);
    }
    boolean bindServiceName = false;
    if (serviceName == null) {
        query.append(_FINDER_COLUMN_G_S_SERVICENAME_1);
    } else if (serviceName.equals(StringPool.BLANK)) {
        query.append(_FINDER_COLUMN_G_S_SERVICENAME_3);
    } else {
        bindServiceName = true;
        query.append(_FINDER_COLUMN_G_S_SERVICENAME_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(OAuthTokenModelImpl.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 (bindServiceName) {
        qPos.add(serviceName);
    }
    if (orderByComparator != null) {
        Object[] values = orderByComparator.getOrderByConditionValues(oAuthToken);
        for (Object value : values) {
            qPos.add(value);
        }
    }
    List<OAuthToken> list = q.list();
    if (list.size() == 2) {
        return list.get(1);
    } else {
        return null;
    }
}
Also used : OAuthToken(com.liferay.opensocial.model.OAuthToken) Query(com.liferay.portal.kernel.dao.orm.Query) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 9 with OAuthToken

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

the class OAuthTokenPersistenceImpl method findByG_S.

/**
 * Returns an ordered range of all the o auth tokens where gadgetKey = &#63; and serviceName = &#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.OAuthTokenModelImpl}. 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 serviceName the service name
 * @param start the lower bound of the range of o auth tokens
 * @param end the upper bound of the range of o auth tokens (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching o auth tokens
 * @throws SystemException if a system exception occurred
 */
@Override
public List<OAuthToken> findByG_S(String gadgetKey, String serviceName, 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_G_S;
        finderArgs = new Object[] { gadgetKey, serviceName };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
        finderArgs = new Object[] { gadgetKey, serviceName, start, end, orderByComparator };
    }
    List<OAuthToken> list = (List<OAuthToken>) FinderCacheUtil.getResult(finderPath, finderArgs, this);
    if ((list != null) && !list.isEmpty()) {
        for (OAuthToken oAuthToken : list) {
            if (!Validator.equals(gadgetKey, oAuthToken.getGadgetKey()) || !Validator.equals(serviceName, oAuthToken.getServiceName())) {
                list = null;
                break;
            }
        }
    }
    if (list == null) {
        StringBundler query = null;
        if (orderByComparator != null) {
            query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 3));
        } else {
            query = new StringBundler(4);
        }
        query.append(_SQL_SELECT_OAUTHTOKEN_WHERE);
        boolean bindGadgetKey = false;
        if (gadgetKey == null) {
            query.append(_FINDER_COLUMN_G_S_GADGETKEY_1);
        } else if (gadgetKey.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_G_S_GADGETKEY_3);
        } else {
            bindGadgetKey = true;
            query.append(_FINDER_COLUMN_G_S_GADGETKEY_2);
        }
        boolean bindServiceName = false;
        if (serviceName == null) {
            query.append(_FINDER_COLUMN_G_S_SERVICENAME_1);
        } else if (serviceName.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_G_S_SERVICENAME_3);
        } else {
            bindServiceName = true;
            query.append(_FINDER_COLUMN_G_S_SERVICENAME_2);
        }
        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(OAuthTokenModelImpl.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 (bindServiceName) {
                qPos.add(serviceName);
            }
            if (!pagination) {
                list = (List<OAuthToken>) QueryUtil.list(q, getDialect(), start, end, false);
                Collections.sort(list);
                list = new UnmodifiableList<OAuthToken>(list);
            } else {
                list = (List<OAuthToken>) 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) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOAuthTokenException(com.liferay.opensocial.NoSuchOAuthTokenException) OAuthToken(com.liferay.opensocial.model.OAuthToken) 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 10 with OAuthToken

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

the class OAuthTokenPersistenceImpl method findAll.

/**
 * Returns an ordered range of all the o auth tokens.
 *
 * <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.OAuthTokenModelImpl}. 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 tokens
 * @param end the upper bound of the range of o auth tokens (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of o auth tokens
 * @throws SystemException if a system exception occurred
 */
@Override
public List<OAuthToken> 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<OAuthToken> list = (List<OAuthToken>) 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_OAUTHTOKEN);
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
            sql = query.toString();
        } else {
            sql = _SQL_SELECT_OAUTHTOKEN;
            if (pagination) {
                sql = sql.concat(OAuthTokenModelImpl.ORDER_BY_JPQL);
            }
        }
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            if (!pagination) {
                list = (List<OAuthToken>) QueryUtil.list(q, getDialect(), start, end, false);
                Collections.sort(list);
                list = new UnmodifiableList<OAuthToken>(list);
            } else {
                list = (List<OAuthToken>) 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) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOAuthTokenException(com.liferay.opensocial.NoSuchOAuthTokenException) OAuthToken(com.liferay.opensocial.model.OAuthToken) 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)

Aggregations

OAuthToken (com.liferay.opensocial.model.OAuthToken)16 NoSuchOAuthTokenException (com.liferay.opensocial.NoSuchOAuthTokenException)9 SystemException (com.liferay.portal.kernel.exception.SystemException)7 StringBundler (com.liferay.portal.kernel.util.StringBundler)7 Session (com.liferay.portal.kernel.dao.orm.Session)6 OAuthTokenImpl (com.liferay.opensocial.model.impl.OAuthTokenImpl)4 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 User (com.liferay.portal.model.User)1 Date (java.util.Date)1 GadgetException (org.apache.shindig.gadgets.GadgetException)1