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.journal.workflow;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.kernel.workflow.BaseWorkflowHandler;
021    import com.liferay.portal.kernel.workflow.WorkflowConstants;
022    import com.liferay.portal.security.permission.ResourceActionsUtil;
023    import com.liferay.portal.service.ServiceContext;
024    import com.liferay.portal.theme.ThemeDisplay;
025    import com.liferay.portal.util.PortalUtil;
026    import com.liferay.portal.util.PortletKeys;
027    import com.liferay.portlet.journal.model.JournalArticle;
028    import com.liferay.portlet.journal.service.JournalArticleLocalServiceUtil;
029    
030    import java.io.Serializable;
031    
032    import java.util.Locale;
033    import java.util.Map;
034    
035    /**
036     * @author Bruno Farache
037     * @author Marcellus Tavares
038     * @author Juan Fern??ndez
039     * @author Julio Camarero
040     */
041    public class JournalArticleWorkflowHandler extends BaseWorkflowHandler {
042    
043            @Override
044            public String getClassName() {
045                    return JournalArticle.class.getName();
046            }
047    
048            @Override
049            public String getType(Locale locale) {
050                    return ResourceActionsUtil.getModelResource(locale, getClassName());
051            }
052    
053            @Override
054            public JournalArticle updateStatus(
055                            int status, Map<String, Serializable> workflowContext)
056                    throws PortalException, SystemException {
057    
058                    long userId = GetterUtil.getLong(
059                            (String)workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
060                    long classPK = GetterUtil.getLong(
061                            (String)workflowContext.get(
062                                    WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
063    
064                    JournalArticle article = JournalArticleLocalServiceUtil.getArticle(
065                            classPK);
066    
067                    ServiceContext serviceContext = (ServiceContext)workflowContext.get(
068                            "serviceContext");
069    
070                    String articleURL = PortalUtil.getControlPanelFullURL(
071                            serviceContext.getScopeGroupId(), PortletKeys.JOURNAL, null);
072    
073                    return JournalArticleLocalServiceUtil.updateStatus(
074                            userId, article, status, articleURL, workflowContext,
075                            serviceContext);
076            }
077    
078            @Override
079            protected String getIconPath(ThemeDisplay themeDisplay) {
080                    return themeDisplay.getPathThemeImages() + "/common/history.png";
081            }
082    
083    }