1 23 package org.infoglue.cms.applications.workflowtool.function; 24 25 import java.util.List ; 26 27 import org.apache.log4j.Logger; 28 import org.infoglue.cms.controllers.kernel.impl.simple.UserControllerProxy; 29 import org.infoglue.cms.entities.management.SystemUserVO; 30 import org.infoglue.cms.security.InfoGlueGroup; 31 import org.infoglue.cms.security.InfoGlueRole; 32 33 import com.opensymphony.workflow.WorkflowException; 34 35 public class UserCreator extends InfoglueFunction 36 { 37 private final static Logger logger = Logger.getLogger(UserCreator.class.getName()); 38 39 42 private static final String STATUS_OK = "status.user.ok"; 43 44 47 private static final String STATUS_NOK = "status.user.nok"; 48 49 52 private SystemUserVO systemUserVO; 53 54 57 private String [] roleNames; 58 59 62 private String [] groupNames; 63 64 67 public UserCreator() 68 { 69 super(); 70 } 71 72 73 78 protected void execute() throws WorkflowException 79 { 80 setFunctionStatus(STATUS_NOK); 81 if(systemUserVO.validate().isEmpty()) 82 { 83 try 84 { 85 final UserControllerProxy controller = UserControllerProxy.getController(getDatabase()); 86 controller.createUser(systemUserVO); 87 controller.updateUser(systemUserVO, roleNames, groupNames); 88 setFunctionStatus(STATUS_OK); 89 } 90 catch(Exception e) 91 { 92 throwException(e); 93 } 94 } 95 } 96 97 100 private String [] getRoleNames(final List roles) 101 { 102 final String [] names = new String [roles.size()]; 103 for(int i=0; i<roles.size(); ++i) 104 { 105 final InfoGlueRole role = (InfoGlueRole) roles.get(i); 106 names[i] = role.getName(); 107 logger.debug("Adding role [" + role.getName() + "]"); 108 } 109 return names; 110 } 111 112 115 private String [] getGroupNames(final List groups) 116 { 117 final String [] names = new String [groups.size()]; 118 for(int i=0; i<groups.size(); ++i) 119 { 120 final InfoGlueGroup group = (InfoGlueGroup) groups.get(i); 121 names[i] = group.getName(); 122 logger.debug("Adding group [" + group.getName() + "]"); 123 } 124 return names; 125 } 126 127 133 protected void initialize() throws WorkflowException 134 { 135 super.initialize(); 136 this.systemUserVO = (SystemUserVO) getParameter(UserProvider.USER_PARAMETER); 137 this.roleNames = getRoleNames((List ) getParameter(RolesProvider.ROLES_PARAMETER)); 138 this.groupNames = getGroupNames((List ) getParameter(GroupsProvider.GROUPS_PARAMETER)); 139 } 140 } 141 | Popular Tags |