001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }