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.portal.workflow;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
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.User;
023    import com.liferay.portal.security.permission.ResourceActionsUtil;
024    import com.liferay.portal.service.ServiceContext;
025    import com.liferay.portal.service.UserLocalServiceUtil;
026    import com.liferay.portal.theme.ThemeDisplay;
027    
028    import java.io.Serializable;
029    
030    import java.util.Locale;
031    import java.util.Map;
032    
033    /**
034     * @author Michael C. Han
035     */
036    @OSGiBeanProperties
037    public class UserWorkflowHandler extends BaseWorkflowHandler<User> {
038    
039            @Override
040            public String getClassName() {
041                    return User.class.getName();
042            }
043    
044            @Override
045            public String getType(Locale locale) {
046                    return ResourceActionsUtil.getModelResource(locale, getClassName());
047            }
048    
049            @Override
050            public boolean isScopeable() {
051                    return false;
052            }
053    
054            @Override
055            public User updateStatus(
056                            int status, Map<String, Serializable> workflowContext)
057                    throws PortalException {
058    
059                    long userId = GetterUtil.getLong(
060                            (String)workflowContext.get(
061                                    WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
062    
063                    User user = UserLocalServiceUtil.getUser(userId);
064    
065                    ServiceContext serviceContext = (ServiceContext)workflowContext.get(
066                            WorkflowConstants.CONTEXT_SERVICE_CONTEXT);
067    
068                    if (((user.getStatus() == WorkflowConstants.STATUS_DRAFT) ||
069                             (user.getStatus() == WorkflowConstants.STATUS_PENDING)) &&
070                            (status == WorkflowConstants.STATUS_APPROVED)) {
071    
072                            UserLocalServiceUtil.completeUserRegistration(user, serviceContext);
073                    }
074    
075                    return UserLocalServiceUtil.updateStatus(
076                            userId, status, serviceContext);
077            }
078    
079            @Override
080            protected String getIconPath(ThemeDisplay themeDisplay) {
081                    return themeDisplay.getPathThemeImages() + "/common/user_icon.png";
082            }
083    
084    }