001    /**
002     * Copyright (c) 2000-present 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.wiki.workflow;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.util.GetterUtil;
019    import com.liferay.portal.kernel.workflow.BaseWorkflowHandler;
020    import com.liferay.portal.kernel.workflow.WorkflowConstants;
021    import com.liferay.portal.security.permission.ResourceActionsUtil;
022    import com.liferay.portal.service.ServiceContext;
023    import com.liferay.portal.theme.ThemeDisplay;
024    import com.liferay.portlet.wiki.model.WikiPage;
025    import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil;
026    
027    import java.io.Serializable;
028    
029    import java.util.Locale;
030    import java.util.Map;
031    
032    /**
033     * @author Jorge Ferrer
034     * @author Julio Camarero
035     */
036    public class WikiPageWorkflowHandler extends BaseWorkflowHandler<WikiPage> {
037    
038            @Override
039            public String getClassName() {
040                    return WikiPage.class.getName();
041            }
042    
043            @Override
044            public String getType(Locale locale) {
045                    return ResourceActionsUtil.getModelResource(locale, getClassName());
046            }
047    
048            @Override
049            public WikiPage updateStatus(
050                            int status, Map<String, Serializable> workflowContext)
051                    throws PortalException {
052    
053                    long userId = GetterUtil.getLong(
054                            (String)workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
055                    long classPK = GetterUtil.getLong(
056                            (String)workflowContext.get(
057                                    WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
058    
059                    ServiceContext serviceContext = (ServiceContext)workflowContext.get(
060                            "serviceContext");
061    
062                    WikiPage page = WikiPageLocalServiceUtil.getPageByPageId(classPK);
063    
064                    return WikiPageLocalServiceUtil.updateStatus(
065                            userId, page, status, serviceContext, workflowContext);
066            }
067    
068            @Override
069            protected String getIconPath(ThemeDisplay themeDisplay) {
070                    return themeDisplay.getPathThemeImages() + "/common/pages.png";
071            }
072    
073    }