001
014
015 package com.liferay.portlet.directory.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.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
036 public class UserWorkflowHandler extends BaseWorkflowHandler {
037
038 public String getClassName() {
039 return User.class.getName();
040 }
041
042 public String getType(Locale locale) {
043 return ResourceActionsUtil.getModelResource(locale, getClassName());
044 }
045
046 @Override
047 public boolean isScopeable() {
048 return false;
049 }
050
051 public Object updateStatus(
052 int status, Map<String, Serializable> workflowContext)
053 throws PortalException, SystemException {
054
055 long userId = GetterUtil.getLong(
056 (String)workflowContext.get(
057 WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));
058
059 User user = UserLocalServiceUtil.getUser(userId);
060
061 if (((user.getStatus() == WorkflowConstants.STATUS_DRAFT) ||
062 (user.getStatus() == WorkflowConstants.STATUS_PENDING)) &&
063 (status == WorkflowConstants.STATUS_APPROVED)) {
064
065 ServiceContext serviceContext = (ServiceContext)workflowContext.get(
066 WorkflowConstants.CONTEXT_SERVICE_CONTEXT);
067
068 UserLocalServiceUtil.completeUserRegistration(user, serviceContext);
069
070 serviceContext.setAttribute(
071 "passwordUnencrypted", user.getPasswordUnencrypted());
072 }
073
074 return UserLocalServiceUtil.updateStatus(userId, status);
075 }
076
077 @Override
078 protected String getIconPath(ThemeDisplay themeDisplay) {
079 return themeDisplay.getPathThemeImages() + "/common/user_icon.png";
080 }
081
082 }