001
014
015 package com.liferay.portlet.communities.action;
016
017 import com.liferay.portal.kernel.util.ParamUtil;
018 import com.liferay.portal.model.Group;
019 import com.liferay.portal.model.Layout;
020 import com.liferay.portal.model.LayoutTypePortlet;
021 import com.liferay.portal.model.MembershipRequest;
022 import com.liferay.portal.model.PortletPreferencesIds;
023 import com.liferay.portal.model.Team;
024 import com.liferay.portal.service.GroupLocalServiceUtil;
025 import com.liferay.portal.service.MembershipRequestLocalServiceUtil;
026 import com.liferay.portal.service.PortletPreferencesLocalServiceUtil;
027 import com.liferay.portal.service.TeamLocalServiceUtil;
028 import com.liferay.portal.util.PortalUtil;
029 import com.liferay.portal.util.PortletKeys;
030 import com.liferay.portal.util.WebKeys;
031 import com.liferay.portlet.PortletPreferencesFactoryUtil;
032
033 import java.util.List;
034
035 import javax.portlet.PortletPreferences;
036 import javax.portlet.PortletRequest;
037
038 import javax.servlet.http.HttpServletRequest;
039
040
043 public class ActionUtil
044 extends com.liferay.portlet.enterpriseadmin.action.ActionUtil {
045
046 public static void copyPreferences(
047 HttpServletRequest request, Layout targetLayout,
048 Layout sourceLayout)
049 throws Exception {
050
051 long companyId = targetLayout.getCompanyId();
052
053 LayoutTypePortlet sourceLayoutTypePortlet =
054 (LayoutTypePortlet)sourceLayout.getLayoutType();
055
056 List<String> sourcePortletIds = sourceLayoutTypePortlet.getPortletIds();
057
058 for (String sourcePortletId : sourcePortletIds) {
059
060
061
062 PortletPreferencesIds portletPreferencesIds =
063 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
064 request, targetLayout, sourcePortletId);
065
066 PortletPreferencesLocalServiceUtil.getPreferences(
067 portletPreferencesIds);
068
069 PortletPreferencesIds sourcePortletPreferencesIds =
070 PortletPreferencesFactoryUtil.getPortletPreferencesIds(
071 request, sourceLayout, sourcePortletId);
072
073 PortletPreferences sourcePreferences =
074 PortletPreferencesLocalServiceUtil.getPreferences(
075 sourcePortletPreferencesIds);
076
077 PortletPreferencesLocalServiceUtil.updatePreferences(
078 portletPreferencesIds.getOwnerId(),
079 portletPreferencesIds.getOwnerType(),
080 portletPreferencesIds.getPlid(),
081 portletPreferencesIds.getPortletId(), sourcePreferences);
082
083
084
085 PortletPreferencesLocalServiceUtil.getPreferences(
086 companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
087 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, targetLayout.getPlid(),
088 sourcePortletId);
089
090 sourcePreferences =
091 PortletPreferencesLocalServiceUtil.getPreferences(
092 companyId, PortletKeys.PREFS_OWNER_ID_DEFAULT,
093 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, sourceLayout.getPlid(),
094 sourcePortletId);
095
096 PortletPreferencesLocalServiceUtil.updatePreferences(
097 PortletKeys.PREFS_OWNER_ID_DEFAULT,
098 PortletKeys.PREFS_OWNER_TYPE_LAYOUT, targetLayout.getPlid(),
099 sourcePortletId, sourcePreferences);
100 }
101 }
102
103 public static void copyPreferences(
104 PortletRequest portletRequest, Layout targetLayout,
105 Layout sourceLayout)
106 throws Exception {
107
108 HttpServletRequest request = PortalUtil.getHttpServletRequest(
109 portletRequest);
110
111 copyPreferences(request, targetLayout, sourceLayout);
112 }
113
114 public static Group getGroup(HttpServletRequest request) throws Exception {
115 long groupId = ParamUtil.getLong(request, "groupId");
116
117 Group group = null;
118
119 if (groupId > 0) {
120 group = GroupLocalServiceUtil.getGroup(groupId);
121 }
122
123 request.setAttribute(WebKeys.GROUP, group);
124
125 return group;
126 }
127
128 public static Group getGroup(PortletRequest portletRequest)
129 throws Exception {
130
131 HttpServletRequest request = PortalUtil.getHttpServletRequest(
132 portletRequest);
133
134 return getGroup(request);
135 }
136
137 public static void getMembershipRequest(HttpServletRequest request)
138 throws Exception {
139
140 long membershipRequestId = ParamUtil.getLong(
141 request, "membershipRequestId");
142
143 MembershipRequest membershipRequest = null;
144
145 if (membershipRequestId > 0) {
146 membershipRequest =
147 MembershipRequestLocalServiceUtil.getMembershipRequest(
148 membershipRequestId);
149 }
150
151 request.setAttribute(WebKeys.MEMBERSHIP_REQUEST, membershipRequest);
152 }
153
154 public static void getMembershipRequest(PortletRequest portletRequest)
155 throws Exception {
156
157 HttpServletRequest request = PortalUtil.getHttpServletRequest(
158 portletRequest);
159
160 getMembershipRequest(request);
161 }
162
163 public static void getTeam(HttpServletRequest request)
164 throws Exception {
165
166 long teamId = ParamUtil.getLong(request, "teamId");
167
168 Team team = null;
169
170 if (teamId > 0) {
171 team = TeamLocalServiceUtil.getTeam(teamId);
172 }
173
174 request.setAttribute(WebKeys.TEAM, team);
175 }
176
177 public static void getTeam(PortletRequest portletRequest)
178 throws Exception {
179
180 HttpServletRequest request = PortalUtil.getHttpServletRequest(
181 portletRequest);
182
183 getTeam(request);
184 }
185
186 }