Search in sources :

Example 6 with OAuthConsumer

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

the class OAuthConsumerPersistenceImpl method findByG_S.

/**
 * Returns the o auth consumer where gadgetKey = ? and serviceName = ? or throws a {@link com.liferay.opensocial.NoSuchOAuthConsumerException} if it could not be found.
 *
 * @param gadgetKey the gadget key
 * @param serviceName the service name
 * @return the 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 findByG_S(String gadgetKey, String serviceName) throws NoSuchOAuthConsumerException, SystemException {
    OAuthConsumer oAuthConsumer = fetchByG_S(gadgetKey, serviceName);
    if (oAuthConsumer == null) {
        StringBundler msg = new StringBundler(6);
        msg.append(_NO_SUCH_ENTITY_WITH_KEY);
        msg.append("gadgetKey=");
        msg.append(gadgetKey);
        msg.append(", serviceName=");
        msg.append(serviceName);
        msg.append(StringPool.CLOSE_CURLY_BRACE);
        if (_log.isWarnEnabled()) {
            _log.warn(msg.toString());
        }
        throw new NoSuchOAuthConsumerException(msg.toString());
    }
    return oAuthConsumer;
}
Also used : NoSuchOAuthConsumerException(com.liferay.opensocial.NoSuchOAuthConsumerException) OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 7 with OAuthConsumer

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

the class OAuthConsumerPersistenceImpl method remove.

/**
 * Removes the o auth consumer with the primary key from the database. Also notifies the appropriate model listeners.
 *
 * @param primaryKey the primary key of the o auth consumer
 * @return the o auth consumer that was removed
 * @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 remove(Serializable primaryKey) throws NoSuchOAuthConsumerException, SystemException {
    Session session = null;
    try {
        session = openSession();
        OAuthConsumer oAuthConsumer = (OAuthConsumer) session.get(OAuthConsumerImpl.class, primaryKey);
        if (oAuthConsumer == null) {
            if (_log.isWarnEnabled()) {
                _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
            }
            throw new NoSuchOAuthConsumerException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
        }
        return remove(oAuthConsumer);
    } catch (NoSuchOAuthConsumerException nsee) {
        throw nsee;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : OAuthConsumerImpl(com.liferay.opensocial.model.impl.OAuthConsumerImpl) NoSuchOAuthConsumerException(com.liferay.opensocial.NoSuchOAuthConsumerException) 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 8 with OAuthConsumer

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

the class OAuthConsumerLocalServiceImpl method updateOAuthConsumer.

public OAuthConsumer updateOAuthConsumer(long oAuthConsumerId, String consumerKey, String consumerSecret, String keyType, String keyName, String callbackURL) throws PortalException, SystemException {
    if (keyType.equals(OAuthConsumerConstants.KEY_TYPE_RSA_PRIVATE)) {
        consumerSecret = StringPool.BLANK;
    }
    OAuthConsumer oAuthConsumer = oAuthConsumerPersistence.findByPrimaryKey(oAuthConsumerId);
    oAuthConsumer.setConsumerKey(consumerKey);
    oAuthConsumer.setConsumerSecret(consumerSecret);
    oAuthConsumer.setKeyType(keyType);
    oAuthConsumerPersistence.update(oAuthConsumer);
    return oAuthConsumer;
}
Also used : OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer)

Example 9 with OAuthConsumer

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

the class OAuthConsumerPersistenceImpl method fetchByG_S.

/**
 * Returns the o auth consumer where gadgetKey = &#63; and serviceName = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param gadgetKey the gadget key
 * @param serviceName the service name
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching o auth consumer, or <code>null</code> if a matching o auth consumer could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public OAuthConsumer fetchByG_S(String gadgetKey, String serviceName, boolean retrieveFromCache) throws SystemException {
    Object[] finderArgs = new Object[] { gadgetKey, serviceName };
    Object result = null;
    if (retrieveFromCache) {
        result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_S, finderArgs, this);
    }
    if (result instanceof OAuthConsumer) {
        OAuthConsumer oAuthConsumer = (OAuthConsumer) result;
        if (!Validator.equals(gadgetKey, oAuthConsumer.getGadgetKey()) || !Validator.equals(serviceName, oAuthConsumer.getServiceName())) {
            result = null;
        }
    }
    if (result == null) {
        StringBundler query = new StringBundler(4);
        query.append(_SQL_SELECT_OAUTHCONSUMER_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);
        }
        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);
            }
            List<OAuthConsumer> list = q.list();
            if (list.isEmpty()) {
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S, finderArgs, list);
            } else {
                if ((list.size() > 1) && _log.isWarnEnabled()) {
                    _log.warn("OAuthConsumerPersistenceImpl.fetchByG_S(String, String, boolean) with parameters (" + StringUtil.merge(finderArgs) + ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
                }
                OAuthConsumer oAuthConsumer = list.get(0);
                result = oAuthConsumer;
                cacheResult(oAuthConsumer);
                if ((oAuthConsumer.getGadgetKey() == null) || !oAuthConsumer.getGadgetKey().equals(gadgetKey) || (oAuthConsumer.getServiceName() == null) || !oAuthConsumer.getServiceName().equals(serviceName)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_S, finderArgs, oAuthConsumer);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_S, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    if (result instanceof List<?>) {
        return null;
    } else {
        return (OAuthConsumer) result;
    }
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) ArrayList(java.util.ArrayList) UnmodifiableList(com.liferay.portal.kernel.util.UnmodifiableList) List(java.util.List) OAuthConsumer(com.liferay.opensocial.model.OAuthConsumer) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchOAuthConsumerException(com.liferay.opensocial.NoSuchOAuthConsumerException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 10 with OAuthConsumer

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

the class OAuthConsumerPersistenceImpl method fetchByPrimaryKey.

/**
 * Returns the o auth consumer with the primary key or returns <code>null</code> if it could not be found.
 *
 * @param primaryKey the primary key of the o auth consumer
 * @return the o auth consumer, or <code>null</code> if a o auth consumer with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public OAuthConsumer fetchByPrimaryKey(Serializable primaryKey) throws SystemException {
    OAuthConsumer oAuthConsumer = (OAuthConsumer) EntityCacheUtil.getResult(OAuthConsumerModelImpl.ENTITY_CACHE_ENABLED, OAuthConsumerImpl.class, primaryKey);
    if (oAuthConsumer == _nullOAuthConsumer) {
        return null;
    }
    if (oAuthConsumer == null) {
        Session session = null;
        try {
            session = openSession();
            oAuthConsumer = (OAuthConsumer) session.get(OAuthConsumerImpl.class, primaryKey);
            if (oAuthConsumer != null) {
                cacheResult(oAuthConsumer);
            } else {
                EntityCacheUtil.putResult(OAuthConsumerModelImpl.ENTITY_CACHE_ENABLED, OAuthConsumerImpl.class, primaryKey, _nullOAuthConsumer);
            }
        } catch (Exception e) {
            EntityCacheUtil.removeResult(OAuthConsumerModelImpl.ENTITY_CACHE_ENABLED, OAuthConsumerImpl.class, primaryKey);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return oAuthConsumer;
}
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)

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