Commit 2607536a authored by Elias Englmeier's avatar Elias Englmeier
Browse files

fixed some map related bugs

parent 312dc8e2
package MapModule.portlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.portlet.Portlet;
import javax.portlet.PortletException;
......@@ -10,10 +12,18 @@ 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
......@@ -38,48 +48,76 @@ 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());
// }
// 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());
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(removeUnimportantData(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.ADMINISTRATOR, user.getUserId(), projectId)));
break;
}
else if(role.getName().equals(RoleConstants.USER)){
result = JSONFactoryUtil.looseSerializeDeep(removeUnimportantData(IdeasLocalServiceUtil.getIdeasByUserRoleProjectId(RoleConstants.USER, user.getUserId(), projectId)));
break;
}
}
} catch (Exception e) {
//case guest user
result = JSONFactoryUtil.looseSerializeDeep(removeUnimportantData(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(removeUnimportantData(IdeasLocalServiceUtil.getAllAccpetedIdeas()));
}
renderRequest.setAttribute(ALL_IDEAS, result);
}
else if (IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()) != null){
List<Ideas> tmp = new ArrayList<Ideas>();
Ideas i = IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey());
tmp.add(i);
tmp = removeUnimportantData(tmp);
result = JSONFactoryUtil.looseSerializeDeep(tmp);
renderRequest.setAttribute(ALL_IDEAS,result);
}
else{
renderRequest.setAttribute(ALL_IDEAS,JSONFactoryUtil.looseSerializeDeep(removeUnimportantData(IdeasLocalServiceUtil.getAllAccpetedIdeas())));
}
renderRequest.setAttribute(ALL_IDEAS, result);
super.render(renderRequest, renderResponse);
}
}
\ No newline at end of file
private List<Ideas> removeUnimportantData(List<Ideas> ideas){
//some special chars are not properly escaped by the serialization so all unimportant information is set to null.
for(Ideas i : ideas){
i.setAdditionalPictureRefs(null);
i.setAdditionalPictures(null);
i.setTitleImgRef(null);
i.setVideoUrl(null);
i.setUuid(null);
i.setTags(null);
i.setGoal(null);
i.setImportance(null);
i.setPitch(null);
i.setUserUuid(null);
i.setSolution(null);
i.setReviewStatus(null);
i.setShortdescription(null);
i.setDescription(null);
i.setPitch(null);
i.setStatus(0);
i.setTargetAudience(null);
}
return ideas;
}
}
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