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.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            public String getClassName() {
044                    return JournalArticle.class.getName();
045            }
046    
047            public String getType(Locale locale) {
048                    return ResourceActionsUtil.getModelResource(locale, getClassName());
049            }
050    
051            public JournalArticle updateStatus(
052                            int status, Map<String, Serializable> workflowContext)
053                    throws PortalException, SystemException {
054    
055                    long userId = GetterUtil.getLong(
056                            (String)workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
057                    long classPK = GetterUtil.getLong(
058                            (String)workflowContext.get(
059                                    WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
060    
061                    JournalArticle article = JournalArticleLocalServiceUtil.getArticle(
062                            classPK);
063    
064                    ServiceContext serviceContext = (ServiceContext)workflowContext.get(
065                            "serviceContext");
066    
067                    String articleURL = PortalUtil.getControlPanelFullURL(
068                            serviceContext.getScopeGroupId(), PortletKeys.JOURNAL, null);
069    
070                    return JournalArticleLocalServiceUtil.updateStatus(
071                            userId, article, status, articleURL, workflowContext,
072                            serviceContext);
073            }
074    
075            @Override
076            protected String getIconPath(ThemeDisplay themeDisplay) {
077                    return themeDisplay.getPathThemeImages() + "/common/history.png";
078            }
079    
080    }