Example usage for com.liferay.portal.kernel.service PortletPreferencesLocalServiceUtil updatePortletPreferences

List of usage examples for com.liferay.portal.kernel.service PortletPreferencesLocalServiceUtil updatePortletPreferences

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service PortletPreferencesLocalServiceUtil updatePortletPreferences.

Prototype

public static com.liferay.portal.kernel.model.PortletPreferences updatePortletPreferences(
        com.liferay.portal.kernel.model.PortletPreferences portletPreferences) 

Source Link

Document

Updates the portlet preferences in the database or adds it if it does not yet exist.

Usage

From source file:at.graz.meduni.bibbox.liferay.portlet.service.impl.ApplicationInstanceServiceImpl.java

License:Open Source License

@JSONWebService(value = "/set-portlet-configuration")
public JSONObject setPortletConfiguration(long companyId, long plid, String portletId, String preferences) {
    JSONObject returnobject = JSONFactoryUtil.createJSONObject();
    System.out.println("-------------------------");
    System.out.println("PortletConfiguration");
    System.out.println("companyId:" + companyId + " plid:" + plid + " portletId:" + portletId + " preferences:"
            + preferences);//w w w.j av  a  2  s  .  c  o m
    returnobject.put("companyId", companyId);
    returnobject.put("plid", plid);
    returnobject.put("portletId", portletId);
    returnobject.put("preferences", preferences);
    Layout layout;
    try {
        layout = LayoutLocalServiceUtil.getLayout(plid);
        System.out.println("ModelClassName" + layout.getModelClassName());
    } catch (PortalException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    List<PortletPreferences> portletpreferences = PortletPreferencesLocalServiceUtil.getPortletPreferences(plid,
            portletId);
    System.out.println(portletpreferences.size());
    if (portletpreferences.size() == 0) {
        long ownerId = 0;
        Portlet portlet = PortletLocalServiceUtil.getPortletById(portletId);
        PortletPreferencesLocalServiceUtil.addPortletPreferences(companyId, ownerId,
                PortletKeys.PREFS_OWNER_TYPE_LAYOUT, plid, portletId, portlet, preferences);
    } else {
        for (PortletPreferences portletpreference : portletpreferences) {
            portletpreference.setPreferences(preferences);
            PortletPreferencesLocalServiceUtil.updatePortletPreferences(portletpreference);

        }
    }
    System.out.println("PortletConfiguration ... end");
    return returnobject;
}