Search in sources :

Example 11 with Gadget

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

the class GadgetPersistenceImpl method findByUuid_C_PrevAndNext.

/**
 * Returns the gadgets before and after the current gadget in the ordered set where uuid = ? and companyId = ?.
 *
 * @param gadgetId the primary key of the current gadget
 * @param uuid the uuid
 * @param companyId the company ID
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next gadget
 * @throws com.liferay.opensocial.NoSuchGadgetException if a gadget with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public Gadget[] findByUuid_C_PrevAndNext(long gadgetId, String uuid, long companyId, OrderByComparator orderByComparator) throws NoSuchGadgetException, SystemException {
    Gadget gadget = findByPrimaryKey(gadgetId);
    Session session = null;
    try {
        session = openSession();
        Gadget[] array = new GadgetImpl[3];
        array[0] = getByUuid_C_PrevAndNext(session, gadget, uuid, companyId, orderByComparator, true);
        array[1] = gadget;
        array[2] = getByUuid_C_PrevAndNext(session, gadget, uuid, companyId, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : Gadget(com.liferay.opensocial.model.Gadget) GadgetImpl(com.liferay.opensocial.model.impl.GadgetImpl) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchGadgetException(com.liferay.opensocial.NoSuchGadgetException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 12 with Gadget

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

the class GadgetPersistenceImpl method fetchByC_U.

/**
 * Returns the gadget where companyId = &#63; and url = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param companyId the company ID
 * @param url the url
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching gadget, or <code>null</code> if a matching gadget could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public Gadget fetchByC_U(long companyId, String url, boolean retrieveFromCache) throws SystemException {
    Object[] finderArgs = new Object[] { companyId, url };
    Object result = null;
    if (retrieveFromCache) {
        result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U, finderArgs, this);
    }
    if (result instanceof Gadget) {
        Gadget gadget = (Gadget) result;
        if ((companyId != gadget.getCompanyId()) || !Validator.equals(url, gadget.getUrl())) {
            result = null;
        }
    }
    if (result == null) {
        StringBundler query = new StringBundler(4);
        query.append(_SQL_SELECT_GADGET_WHERE);
        query.append(_FINDER_COLUMN_C_U_COMPANYID_2);
        boolean bindUrl = false;
        if (url == null) {
            query.append(_FINDER_COLUMN_C_U_URL_1);
        } else if (url.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_C_U_URL_3);
        } else {
            bindUrl = true;
            query.append(_FINDER_COLUMN_C_U_URL_2);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(companyId);
            if (bindUrl) {
                qPos.add(url);
            }
            List<Gadget> list = q.list();
            if (list.isEmpty()) {
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U, finderArgs, list);
            } else {
                Gadget gadget = list.get(0);
                result = gadget;
                cacheResult(gadget);
                if ((gadget.getCompanyId() != companyId) || (gadget.getUrl() == null) || !gadget.getUrl().equals(url)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U, finderArgs, gadget);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    if (result instanceof List<?>) {
        return null;
    } else {
        return (Gadget) result;
    }
}
Also used : Gadget(com.liferay.opensocial.model.Gadget) SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) ArrayList(java.util.ArrayList) UnmodifiableList(com.liferay.portal.kernel.util.UnmodifiableList) List(java.util.List) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchGadgetException(com.liferay.opensocial.NoSuchGadgetException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 13 with Gadget

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

the class GadgetPersistenceImpl method filterFindByUuid_PrevAndNext.

/**
 * Returns the gadgets before and after the current gadget in the ordered set of gadgets that the user has permission to view where uuid = &#63;.
 *
 * @param gadgetId the primary key of the current gadget
 * @param uuid the uuid
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next gadget
 * @throws com.liferay.opensocial.NoSuchGadgetException if a gadget with the primary key could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public Gadget[] filterFindByUuid_PrevAndNext(long gadgetId, String uuid, OrderByComparator orderByComparator) throws NoSuchGadgetException, SystemException {
    if (!InlineSQLHelperUtil.isEnabled()) {
        return findByUuid_PrevAndNext(gadgetId, uuid, orderByComparator);
    }
    Gadget gadget = findByPrimaryKey(gadgetId);
    Session session = null;
    try {
        session = openSession();
        Gadget[] array = new GadgetImpl[3];
        array[0] = filterGetByUuid_PrevAndNext(session, gadget, uuid, orderByComparator, true);
        array[1] = gadget;
        array[2] = filterGetByUuid_PrevAndNext(session, gadget, uuid, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : Gadget(com.liferay.opensocial.model.Gadget) GadgetImpl(com.liferay.opensocial.model.impl.GadgetImpl) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchGadgetException(com.liferay.opensocial.NoSuchGadgetException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 14 with Gadget

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

the class GadgetPersistenceImpl method findByC_U.

/**
 * Returns the gadget where companyId = &#63; and url = &#63; or throws a {@link com.liferay.opensocial.NoSuchGadgetException} if it could not be found.
 *
 * @param companyId the company ID
 * @param url the url
 * @return the matching gadget
 * @throws com.liferay.opensocial.NoSuchGadgetException if a matching gadget could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public Gadget findByC_U(long companyId, String url) throws NoSuchGadgetException, SystemException {
    Gadget gadget = fetchByC_U(companyId, url);
    if (gadget == null) {
        StringBundler msg = new StringBundler(6);
        msg.append(_NO_SUCH_ENTITY_WITH_KEY);
        msg.append("companyId=");
        msg.append(companyId);
        msg.append(", url=");
        msg.append(url);
        msg.append(StringPool.CLOSE_CURLY_BRACE);
        if (_log.isWarnEnabled()) {
            _log.warn(msg.toString());
        }
        throw new NoSuchGadgetException(msg.toString());
    }
    return gadget;
}
Also used : Gadget(com.liferay.opensocial.model.Gadget) NoSuchGadgetException(com.liferay.opensocial.NoSuchGadgetException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 15 with Gadget

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

the class GadgetStagedModelDataHandler method deleteStagedModel.

@Override
public void deleteStagedModel(String uuid, long groupId, String className, String extraData) throws PortalException, SystemException {
    Group group = GroupLocalServiceUtil.getGroup(groupId);
    Gadget gadget = GadgetLocalServiceUtil.fetchGadgetByUuidAndCompanyId(uuid, group.getCompanyId());
    if (gadget != null) {
        GadgetLocalServiceUtil.deleteGadget(gadget);
    }
}
Also used : Group(com.liferay.portal.model.Group) Gadget(com.liferay.opensocial.model.Gadget)

Aggregations

Gadget (com.liferay.opensocial.model.Gadget)48 NoSuchGadgetException (com.liferay.opensocial.NoSuchGadgetException)24 StringBundler (com.liferay.portal.kernel.util.StringBundler)21 SystemException (com.liferay.portal.kernel.exception.SystemException)18 Session (com.liferay.portal.kernel.dao.orm.Session)16 SQLQuery (com.liferay.portal.kernel.dao.orm.SQLQuery)14 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)13 GadgetImpl (com.liferay.opensocial.model.impl.GadgetImpl)9 Query (com.liferay.portal.kernel.dao.orm.Query)8 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)4 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)4 GadgetSpec (org.apache.shindig.gadgets.spec.GadgetSpec)3 DuplicateGadgetURLException (com.liferay.opensocial.DuplicateGadgetURLException)2 PermissionChecker (com.liferay.portal.security.permission.PermissionChecker)2 ServiceContext (com.liferay.portal.service.ServiceContext)2 GadgetPortletCategoryNamesException (com.liferay.opensocial.GadgetPortletCategoryNamesException)1 GadgetURLException (com.liferay.opensocial.GadgetURLException)1