Commit b04bb521 authored by Elias Englmeier's avatar Elias Englmeier
Browse files

updated MapModule

parent 371373e2
package MapModule.portlet;
import MapModule.constants.MapModulePortletKeys;
import ideaService.model.Ideas;
import ideaService.service.IdeasLocalServiceUtil;
import projectService.service.ProjectLocalServiceUtil;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.WebKeys;
import java.io.IOException;
import java.util.ArrayList;
import javax.portlet.Portlet;
import javax.portlet.PortletException;
......@@ -20,6 +9,19 @@ 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.service.IdeasLocalServiceUtil;
import projectService.service.ProjectLocalServiceUtil;
/**
* @author englmeier
*/
......@@ -42,18 +44,29 @@ public class MapModulePortlet extends MVCPortlet {
@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException{
ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
if(ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()) != null){
renderRequest.setAttribute("allIdeas",
JSONFactoryUtil.looseSerializeDeep(IdeasLocalServiceUtil.getAllIdeasForProject
(ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()).getPrimaryKey())));
}
else{
ArrayList<Ideas> tmp = new ArrayList<Ideas>();
Ideas i = IdeasLocalServiceUtil.getIdeasByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey());
tmp.add(i);
renderRequest.setAttribute("allIdeas",
JSONFactoryUtil.looseSerializeDeep(tmp));
long projectId = ProjectLocalServiceUtil.getProjectByLayoutIdRef(themeDisplay.getLayout().getPrimaryKey()).getPrimaryKey();
String result = null;
User user;
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));
}
renderRequest.setAttribute("allIdeas", result);
super.render(renderRequest, renderResponse);
}
......
......@@ -413,8 +413,6 @@ public interface IdeasLocalService extends BaseLocalService,
public void addVideoToExistingIdea(long ideasId, long videoId,
java.lang.String videoRef);
public void approveIdea(long ideasId);
/**
* persists the new Idea and performs some checks e.g. if the entry is a duplicate it won't be inserted.
*
......@@ -423,5 +421,5 @@ public interface IdeasLocalService extends BaseLocalService,
@Indexable(type = IndexableType.REINDEX)
public void persistIdeasAndPerformTypeChecks(Ideas idea);
public void rejectIdea(long ideasId);
public void setIdeaReviewStatus(long ideasId, ReviewStatus status);
}
\ No newline at end of file
......@@ -489,10 +489,6 @@ public class IdeasLocalServiceUtil {
getService().addVideoToExistingIdea(ideasId, videoId, videoRef);
}
public static void approveIdea(long ideasId) {
getService().approveIdea(ideasId);
}
/**
* persists the new Idea and performs some checks e.g. if the entry is a duplicate it won't be inserted.
*
......@@ -503,8 +499,9 @@ public class IdeasLocalServiceUtil {
getService().persistIdeasAndPerformTypeChecks(idea);
}
public static void rejectIdea(long ideasId) {
getService().rejectIdea(ideasId);
public static void setIdeaReviewStatus(long ideasId,
ideasService.service.enums.ReviewStatus status) {
getService().setIdeaReviewStatus(ideasId, status);
}
public static IdeasLocalService getService() {
......
......@@ -518,11 +518,6 @@ public class IdeasLocalServiceWrapper implements IdeasLocalService,
_ideasLocalService.addVideoToExistingIdea(ideasId, videoId, videoRef);
}
@Override
public void approveIdea(long ideasId) {
_ideasLocalService.approveIdea(ideasId);
}
/**
* persists the new Idea and performs some checks e.g. if the entry is a duplicate it won't be inserted.
*
......@@ -534,8 +529,9 @@ public class IdeasLocalServiceWrapper implements IdeasLocalService,
}
@Override
public void rejectIdea(long ideasId) {
_ideasLocalService.rejectIdea(ideasId);
public void setIdeaReviewStatus(long ideasId,
ideasService.service.enums.ReviewStatus status) {
_ideasLocalService.setIdeaReviewStatus(ideasId, status);
}
@Override
......
......@@ -22,6 +22,7 @@ import com.liferay.asset.kernel.model.AssetLinkConstants;
import com.liferay.counter.kernel.service.CounterLocalServiceUtil;
import com.liferay.document.library.kernel.service.DLAppLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.model.Layout;
import com.liferay.portal.kernel.model.LayoutFriendlyURL;
import com.liferay.portal.kernel.model.RoleConstants;
import com.liferay.portal.kernel.model.User;
......@@ -91,24 +92,25 @@ public class IdeasLocalServiceImpl extends IdeasLocalServiceBaseImpl {
return result;
}
public void approveIdea(long ideasId){
public void setIdeaReviewStatus(long ideasId, ReviewStatus status){
try {
Ideas i = IdeasUtil.findByPrimaryKey(ideasId);
i.setReviewStatus(ReviewStatus.ACCEPTED.getReviewStatusDescription());
i.persist();
} catch (NoSuchIdeasException e) {
e.printStackTrace();
}
}
i.setReviewStatus(status.getReviewStatusDescription());
if(status.equals(ReviewStatus.ACCEPTED)){
//Makes the layout visible to everyone.
Layout layout = LayoutLocalServiceUtil.getLayout(i.getLayoutRef());
layout.setHidden(false);
layout.persist();
}
public void rejectIdea(long ideasId){
try {
Ideas i = IdeasUtil.findByPrimaryKey(ideasId);
i.setReviewStatus(ReviewStatus.REJECTED.getReviewStatusDescription());
i.persist();
} catch (NoSuchIdeasException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (PortalException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
......
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