}
}
public void save(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
WorkflowAPI wapi = APILocator.getWorkflowAPI();
String actionName = request.getParameter("actionName");
String actionId = request.getParameter("actionId");
String whoCanUseTmp = request.getParameter("whoCanUse");
List<String> whoCanUse = Arrays.asList(whoCanUseTmp.split(","));
String actionIcon = request.getParameter("actionIconSelect");
boolean actionAssignable = (request.getParameter("actionAssignable") != null);
boolean actionCommentable = (request.getParameter("actionCommentable") != null);
boolean requiresCheckout = (request.getParameter("actionRequiresCheckout") != null);
boolean roleHierarchyForAssign = false;
if(actionAssignable){
roleHierarchyForAssign = (request.getParameter("actionRoleHierarchyForAssign") != null);
}
String actionNextAssign = request.getParameter("actionAssignToSelect");
String actionNextStep = request.getParameter("actionNextStep");
if (actionNextAssign != null && actionNextAssign.startsWith("role-")) {
actionNextAssign = actionNextAssign.replaceAll("role-", "");
}
String actionCondition = request.getParameter("actionCondition");
String stepId = request.getParameter("stepId");
WorkflowAction newAction = new WorkflowAction();
boolean isNew = true;
try {
WorkflowAction origAction = APILocator.getWorkflowAPI().findAction(actionId, APILocator.getUserAPI().getSystemUser());
BeanUtils.copyProperties(newAction, origAction);
if(origAction !=null || !origAction.isNew()){
isNew=false;
}
} catch (Exception e) {
Logger.debug(this.getClass(), "Unable to find action" + actionId);
}
newAction.setName(actionName);
newAction.setAssignable(actionAssignable);
newAction.setCommentable(actionCommentable);
newAction.setIcon(actionIcon);
newAction.setNextStep(actionNextStep);
newAction.setStepId(stepId);
newAction.setCondition(actionCondition);
newAction.setRequiresCheckout(requiresCheckout);
newAction.setRoleHierarchyForAssign(roleHierarchyForAssign);
try {
newAction.setNextAssign(resolveRole(actionNextAssign).getId());
if(!UtilMethods.isSet(newAction.getNextAssign())){
newAction.setNextAssign(null);
}
List<Permission> permissions = new ArrayList<Permission>();
for ( String perm : whoCanUse ) {
if ( !UtilMethods.isSet( perm ) ) {
continue;
}
Role role = resolveRole( perm );
Permission p = new Permission( newAction.getId(), role.getId(), PermissionAPI.PERMISSION_USE );
boolean exists = false;
for ( Permission curr : permissions ) {
exists = exists || curr.getRoleId().equals( p.getRoleId() );
}
if ( !exists ) {
permissions.add( p );
}
}
wapi.saveAction(newAction, permissions);
if(isNew){
WorkflowActionClass wac = new WorkflowActionClass();
wac.setActionId(newAction.getId());
wac.setClazz(NotifyAssigneeActionlet.class.getName());
wac.setName(NotifyAssigneeActionlet.class.newInstance().getName());
wac.setOrder(0);
wapi.saveActionClass(wac);
}
response.getWriter().println("SUCCESS:" + newAction.getId());