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