001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.workflowtasks.notifications;
016    
017    import com.liferay.portal.kernel.json.JSONFactoryUtil;
018    import com.liferay.portal.kernel.json.JSONObject;
019    import com.liferay.portal.kernel.notifications.BaseUserNotificationHandler;
020    import com.liferay.portal.kernel.portlet.LiferayPortletURL;
021    import com.liferay.portal.kernel.util.HtmlUtil;
022    import com.liferay.portal.model.UserNotificationEvent;
023    import com.liferay.portal.service.ServiceContext;
024    import com.liferay.portal.util.PortalUtil;
025    import com.liferay.portal.util.PortletKeys;
026    import com.liferay.portlet.PortletURLFactoryUtil;
027    
028    import javax.portlet.PortletRequest;
029    import javax.portlet.WindowState;
030    
031    /**
032     * @author Jonathan Lee
033     */
034    public class WorkflowTasksUserNotificationHandler
035            extends BaseUserNotificationHandler {
036    
037            public WorkflowTasksUserNotificationHandler() {
038                    setPortletId(PortletKeys.MY_WORKFLOW_TASKS);
039            }
040    
041            @Override
042            protected String getBody(
043                            UserNotificationEvent userNotificationEvent,
044                            ServiceContext serviceContext)
045                    throws Exception {
046    
047                    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(
048                            userNotificationEvent.getPayload());
049    
050                    return HtmlUtil.escape(jsonObject.getString("notificationMessage"));
051            }
052    
053            @Override
054            protected String getLink(
055                            UserNotificationEvent userNotificationEvent,
056                            ServiceContext serviceContext)
057                    throws Exception {
058    
059                    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(
060                            userNotificationEvent.getPayload());
061    
062                    LiferayPortletURL portletURL = PortletURLFactoryUtil.create(
063                            serviceContext.getRequest(), PortletKeys.MY_WORKFLOW_TASKS,
064                            PortalUtil.getControlPanelPlid(serviceContext.getCompanyId()),
065                            PortletRequest.RENDER_PHASE);
066    
067                    portletURL.setControlPanelCategory("my");
068                    portletURL.setParameter(
069                            "struts_action", "/my_workflow_tasks/edit_workflow_task");
070                    portletURL.setParameter(
071                            "workflowTaskId", jsonObject.getString("workflowTaskId"));
072                    portletURL.setWindowState(WindowState.MAXIMIZED);
073    
074                    return portletURL.toString();
075            }
076    
077    }