Search in sources :

Example 1 with GadgetURLException

use of com.liferay.opensocial.GadgetURLException in project liferay-ide by liferay.

the class GadgetLocalServiceImpl method addGadget.

public Gadget addGadget(long companyId, String url, String portletCategoryNames, ServiceContext serviceContext) throws PortalException, SystemException {
    Date now = new Date();
    validate(companyId, url, portletCategoryNames);
    long gadgetId = counterLocalService.increment();
    Gadget gadget = gadgetPersistence.create(gadgetId);
    gadget.setUuid(serviceContext.getUuid());
    gadget.setCompanyId(companyId);
    gadget.setCreateDate(now);
    gadget.setModifiedDate(now);
    GadgetSpec gadgetSpec = null;
    try {
        gadgetSpec = ShindigUtil.getGadgetSpec(url);
    } catch (Exception e) {
        throw new GadgetURLException(e);
    }
    ModulePrefs modulePrefs = gadgetSpec.getModulePrefs();
    gadget.setName(modulePrefs.getTitle());
    gadget.setUrl(url);
    gadget.setPortletCategoryNames(portletCategoryNames);
    gadgetPersistence.update(gadget);
    gadgetLocalService.initGadget(gadget.getUuid(), companyId, gadgetId, gadget.getName(), gadget.getPortletCategoryNames());
    return gadget;
}
Also used : GadgetSpec(org.apache.shindig.gadgets.spec.GadgetSpec) Gadget(com.liferay.opensocial.model.Gadget) ModulePrefs(org.apache.shindig.gadgets.spec.ModulePrefs) DuplicateGadgetURLException(com.liferay.opensocial.DuplicateGadgetURLException) GadgetURLException(com.liferay.opensocial.GadgetURLException) Date(java.util.Date) DuplicateGadgetURLException(com.liferay.opensocial.DuplicateGadgetURLException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) GadgetPortletCategoryNamesException(com.liferay.opensocial.GadgetPortletCategoryNamesException) NoSuchGadgetException(com.liferay.opensocial.NoSuchGadgetException) GadgetURLException(com.liferay.opensocial.GadgetURLException)

Example 2 with GadgetURLException

use of com.liferay.opensocial.GadgetURLException in project liferay-ide by liferay.

the class ShindigUtil method getGadgetSpec.

public static GadgetSpec getGadgetSpec(String url, boolean debug, boolean ignoreCache) throws Exception {
    if (Validator.isNull(url)) {
        throw new GadgetURLException();
    }
    JSONObject gadgetContextJSONObject = new JSONObject();
    gadgetContextJSONObject.put("debug", debug);
    if (!ignoreCache && _ignoreGadgetSpecCache.contains(url)) {
        ignoreCache = true;
    }
    gadgetContextJSONObject.put("ignoreCache", ignoreCache);
    JSONObject gadgetRequestJSONObject = new JSONObject();
    gadgetRequestJSONObject.put("url", url);
    JsonRpcGadgetContext jsonRpcGadgetContext = new JsonRpcGadgetContext(gadgetContextJSONObject, gadgetRequestJSONObject);
    Gadget gadget = null;
    try {
        gadget = _processor.process(jsonRpcGadgetContext);
        _ignoreGadgetSpecCache.remove(url);
    } catch (ProcessingException pe) {
        _ignoreGadgetSpecCache.add(url);
        throw new GadgetURLException(pe);
    }
    return gadget.getSpec();
}
Also used : Gadget(org.apache.shindig.gadgets.Gadget) JSONObject(org.json.JSONObject) JsonRpcGadgetContext(org.apache.shindig.gadgets.servlet.JsonRpcGadgetContext) GadgetURLException(com.liferay.opensocial.GadgetURLException) ProcessingException(org.apache.shindig.gadgets.process.ProcessingException)

Example 3 with GadgetURLException

use of com.liferay.opensocial.GadgetURLException in project liferay-ide by liferay.

the class ShindigUtil method getGadget.

public static com.liferay.opensocial.model.Gadget getGadget(PortletPreferences portletPreferences) throws Exception {
    String url = portletPreferences.getValue("url", StringPool.BLANK);
    if (Validator.isNull(url)) {
        return null;
    }
    com.liferay.opensocial.model.Gadget gadget = new GadgetImpl();
    GadgetSpec gadgetSpec = null;
    try {
        gadgetSpec = ShindigUtil.getGadgetSpec(url);
    } catch (Exception e) {
        throw new GadgetURLException(e);
    }
    ModulePrefs modulePrefs = gadgetSpec.getModulePrefs();
    gadget.setName(modulePrefs.getTitle());
    gadget.setUrl(url);
    return gadget;
}
Also used : GadgetSpec(org.apache.shindig.gadgets.spec.GadgetSpec) ModulePrefs(org.apache.shindig.gadgets.spec.ModulePrefs) GadgetURLException(com.liferay.opensocial.GadgetURLException) GadgetImpl(com.liferay.opensocial.model.impl.GadgetImpl) ProcessingException(org.apache.shindig.gadgets.process.ProcessingException) PortalException(com.liferay.portal.kernel.exception.PortalException) SystemException(com.liferay.portal.kernel.exception.SystemException) GadgetURLException(com.liferay.opensocial.GadgetURLException)

Aggregations

GadgetURLException (com.liferay.opensocial.GadgetURLException)3 PortalException (com.liferay.portal.kernel.exception.PortalException)2 SystemException (com.liferay.portal.kernel.exception.SystemException)2 ProcessingException (org.apache.shindig.gadgets.process.ProcessingException)2 GadgetSpec (org.apache.shindig.gadgets.spec.GadgetSpec)2 ModulePrefs (org.apache.shindig.gadgets.spec.ModulePrefs)2 DuplicateGadgetURLException (com.liferay.opensocial.DuplicateGadgetURLException)1 GadgetPortletCategoryNamesException (com.liferay.opensocial.GadgetPortletCategoryNamesException)1 NoSuchGadgetException (com.liferay.opensocial.NoSuchGadgetException)1 Gadget (com.liferay.opensocial.model.Gadget)1 GadgetImpl (com.liferay.opensocial.model.impl.GadgetImpl)1 Date (java.util.Date)1 Gadget (org.apache.shindig.gadgets.Gadget)1 JsonRpcGadgetContext (org.apache.shindig.gadgets.servlet.JsonRpcGadgetContext)1 JSONObject (org.json.JSONObject)1