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            @Override
043            public String getClassName() {
044                    return DDLRecord.class.getName();
045            }
046    
047            @Override
048            public String getType(Locale locale) {
049                    return ResourceActionsUtil.getModelResource(locale, getClassName());
050            }
051    
052            @Override
053            public WorkflowDefinitionLink getWorkflowDefinitionLink(
054                            long companyId, long groupId, long classPK)
055                    throws PortalException, SystemException {
056    
057                    DDLRecordVersion recordVersion =
058                            DDLRecordLocalServiceUtil.getRecordVersion(classPK);
059    
060                    DDLRecord record = recordVersion.getRecord();
061    
062                    return WorkflowDefinitionLinkLocalServiceUtil.
063                            fetchWorkflowDefinitionLink(
064                                    companyId, groupId, DDLRecordSet.class.getName(),
065                                    record.getRecordSetId(), 0);
066            }
067    
068            @Override
069            public boolean isVisible() {
070                    return false;
071            }
072    
073            @Override
074            public DDLRecord updateStatus(
075                            int status, Map<String, Serializable> workflowContext)
076                    throws PortalException, SystemException {
077    
078                    long userId = GetterUtil.getLong(
079                            (String)workflowContext.get(WorkflowConstants.CONTEXT_USER_ID));
080                    long classPK = GetterUtil.getLong(
081                            (String)workflowContext.get(
082                                    WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
083    
084                    ServiceContext serviceContext = (ServiceContext)workflowContext.get(
085                            "serviceContext");
086    
087                    return DDLRecordLocalServiceUtil.updateStatus(
088                            userId, classPK, status, serviceContext);
089            }
090    
091            @Override
092            protected String getIconPath(ThemeDisplay themeDisplay) {
093                    return themeDisplay.getPathThemeImages() + "/common/history.png";
094            }
095    
096    }