Commit 312dc8e2 authored by Elias Englmeier's avatar Elias Englmeier
Browse files

simplified the mapmodule for wdhid

parent e115dd60
package MapModule.portlet;
import java.io.IOException;
import java.util.ArrayList;
import javax.portlet.Portlet;
import javax.portlet.PortletException;
......@@ -11,18 +10,10 @@ import javax.portlet.RenderResponse;
import org.osgi.service.component.annotations.Component;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.model.Role;
import com.liferay.portal.kernel.model.RoleConstants;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.WebKeys;
import MapModule.constants.MapModulePortletKeys;
import ideaService.model.Ideas;
import ideaService.service.IdeasLocalServiceUtil;
import projectService.service.ProjectLocalServiceUtil;
/**
* @author englmeier
......@@ -47,49 +38,47 @@ public class MapModulePortlet extends MVCPortlet {
@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException{
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
// ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
String result = null;
User user;
if(ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()) != null){
long projectId = ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()).getPrimaryKey();
try {
user = PortalUtil.getUser(renderRequest);
for(Role role : user.getRoles()){
if(role.getName().equals(RoleConstants.ADMINISTRATOR) || role.getName().equals(RoleConstants.PORTAL_CONTENT_REVIEWER)){
//Admins and ContentRevs have same viewing rights.
result = JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.ADMINISTRATOR, user.getUserId(), projectId));
break;
}
else if(role.getName().equals(RoleConstants.USER)){
result = JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.USER, user.getUserId(), projectId));
break;
}
}
} catch (Exception e) {
//case guest user
result = JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.GUEST, -1, projectId));
}
if(result.equals(null) || result.equals("") || result.equals("[]")){
//at least return all accepted ideas in any case
result = JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getAllAccpetedIdeas());
}
// User user;
// if(ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()) != null){
// long projectId = ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()).getPrimaryKey();
// try {
// user = PortalUtil.getUser(renderRequest);
// for(Role role : user.getRoles()){
// if(role.getName().equals(RoleConstants.ADMINISTRATOR) || role.getName().equals(RoleConstants.PORTAL_CONTENT_REVIEWER)){
// //Admins and ContentRevs have same viewing rights.
// result = JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.ADMINISTRATOR, user.getUserId(), projectId));
// break;
// }
// else if(role.getName().equals(RoleConstants.USER)){
// result = JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.USER, user.getUserId(), projectId));
// break;
// }
//
// }
// } catch (Exception e) {
// //case guest user
// result = JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.GUEST, -1, projectId));
// }
// if(result.equals(null) || result.equals("") || result.equals("[]")){
// //at least return all accepted ideas in any case
// result = JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getAllAccpetedIdeas());
// }
// renderRequest.setAttribute(ALL_IDEAS, result);
//
// }
// else if (IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()) != null){
// ArrayList<Ideas> tmp = new ArrayList<Ideas>();
// Ideas i = IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey());
// tmp.add(i);
// renderRequest.setAttribute(ALL_IDEAS,JSONFactoryUtil.looseSerializeDeep(tmp));
// }
// else{
// renderRequest.setAttribute(ALL_IDEAS,JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getAllAccpetedIdeas()));
// }
result = JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getAllAccpetedIdeas());
renderRequest.setAttribute(ALL_IDEAS, result);
}
else if (IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()) != null){
ArrayList<Ideas> tmp = new ArrayList<Ideas>();
Ideas i = IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey());
tmp.add(i);
renderRequest.setAttribute(ALL_IDEAS,
JSONFactoryUtil.looseSerializeDeep(tmp));
}
else{
renderRequest.setAttribute(ALL_IDEAS,JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getAllAccpetedIdeas()));
}
super.render(renderRequest, renderResponse);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment