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;
}
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();
}
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;
}
Aggregations