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.dynamicdatalists.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.model.WorkflowDefinitionLink;
023    import com.liferay.portal.security.permission.ResourceActionsUtil;
024    import com.liferay.portal.service.ServiceContext;
025    import com.liferay.portal.service.WorkflowDefinitionLinkLocalServiceUtil;
026    import com.liferay.portal.theme.ThemeDisplay;
027    import com.liferay.portlet.dynamicdatalists.model.DDLRecord;
028    import com.liferay.portlet.dynamicdatalists.model.DDLRecordSet;
029    import com.liferay.portlet.dynamicdatalists.model.DDLRecordVersion;
030    import com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalServiceUtil;
031    
032    import java.io.Serializable;
033    
034    import java.util.Locale;
035    import java.util.Map;
036    
037    /**
038     * @author Marcellus Tavares
039     */
040    public class DDLRecordWorkflowHandler extends BaseWorkflowHandler {
041    
042            public String getClassName() {
043                    return DDLRecord.class.getName();
044            }
045    
046            public String getType(Locale locale) {
047                    return ResourceActionsUtil.getModelResource(locale, getClassName());
048            }
049    
050            @Override
051            public WorkflowDefinitionLink getWorkflowDefinitionLink(
052                            long companyId, long groupId, long classPK)
053                    throws PortalException, SystemException {
054    
055                    DDLRecordVersion recordVersion =
056                            DDLRecordLocalServiceUtil.getRecordVersion(classPK);
057    
058                    DDLRecord record = recordVersion.getRecord();
059    
060                    return WorkflowDefinitionLinkLocalServiceUtil.getWorkflowDefinitionLink(
061                            companyId, groupId, DDLRecordSet.class.getName(),
062                            record.getRecordSetId(), 0);
063            }
064    
065            @Override
066            public boolean isVisible() {
067                    return false;
068            }
069    
070            public DDLRecord updateStatus(
071                            int status, Map<String, Serializable> workflowContext)
072                    throws PortalException, SystemException {
073    
074                    long userId = GetterUtil.getLong(
075                            (String)workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
076                    long classPK = GetterUtil.getLong(
077                            (String)workflowContext.get(
078                                    WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
079    
080                    ServiceContext serviceContext = (ServiceContext)workflowContext.get(
081                            "serviceContext");
082    
083                    return DDLRecordLocalServiceUtil.updateStatus(
084                            userId, classPK, status, serviceContext);
085            }
086    
087            @Override
088            protected String getIconPath(ThemeDisplay themeDisplay) {
089                    return themeDisplay.getPathThemeImages() + "/common/history.png";
090            }
091    
092    }