group = parent.addChildGroup(extension,displayExtension );
try{ group = parent.addChildGroup(extension,displayExtension ); }catch(GroupAddException e) { String name = parent.getName() + GrouperHelper.HIER_DELIM + extension; try { group = GroupFinder.findByName(grouperSession,name); }catch(GroupNotFoundException ge) { request.setAttribute("message", new Message( "groups.message.error.add-problem",new String[] {e.getMessage()}, true));  return mapping.findForward(FORWARD_CreateAgain); } }
	public ActionForward grouperExecute(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response,			HttpSession session, GrouperSession grouperSession)			throws Exception {		DynaActionForm groupForm = (DynaActionForm) form;		boolean groupExists = false;		String curNode = (String)groupForm.get("groupId");		if (curNode == null || "".equals(curNode)) {			//Need to find the stem in which new group wuill be created						curNode = getBrowseNode(session);		} else {			groupExists = true;		}		if (curNode == null || "".equals(curNode)) {			String defaultStem = getDefaultRootStemName(session);			Stem root = StemFinder.findByName(grouperSession, defaultStem);			curNode = root.getUuid();		}		//TODO: should be checked by the API and exception thrown?		String groupName = (String) groupForm.get("groupName");		if (!groupExists && !groupName.matches("[^ \"<>\\*]+")) {			request.setAttribute("message", new Message(					"groups.message.error.invalid-char", true));			if (groupExists) {				return mapping.findForward(FORWARD_EditAgain);			} else {				return mapping.findForward(FORWARD_CreateAgain);			}		}		if ("".equals(groupForm.get("groupDisplayName")))			groupForm.set("groupDisplayName", groupName);		Group group = null;				String extension = (String) groupForm.get("groupName");		String displayExtension = (String) groupForm.get("groupDisplayName");		if(isEmpty(displayExtension))displayExtension=extension;		//TODO: should be transactional - so add map or List of attributes		Map assignedPrivs=null;		Subject grouperAll = SubjectFinder.findById("GrouperAll");		if (groupExists) {			group = GroupFinder.findByUuid(grouperSession, curNode);			doTypes(group,request);			group.setDisplayExtension(displayExtension);			group.setExtension(extension);			Map selectedPrivs = GrouperHelper.getImmediateHas(grouperSession,GroupOrStem.findByGroup(grouperSession,group),MemberFinder.findBySubject(grouperSession,grouperAll));			assignedPrivs=new HashMap();			Map.Entry entry;			String key;			Iterator it = selectedPrivs.entrySet().iterator();			while(it.hasNext()) {				entry = (Map.Entry)it.next();				key = (String)entry.getKey();				assignedPrivs.put(key.toLowerCase(),entry.getValue());			}		} else {			GroupOrStem curGos = GroupOrStem.findByID(grouperSession,curNode);			Stem parent=null;			if(curGos.isStem()) {				parent = curGos.getStem();			}else{				parent = curGos.getGroup().getParentStem();			}			group = parent.addChildGroup(extension,displayExtension );			doTypes(group,request);			groupForm.set("groupId", group.getUuid());			assignedPrivs = GrouperHelper.getDefaultAccessPrivsForGrouperAPI();		}		String [] privileges = request.getParameterValues("privileges");				Map selectedPrivs = new HashMap();		if(privileges==null) privileges = new String[]{};							for(int i=0;i<privileges.length;i++) {			selectedPrivs.put(privileges[i],Boolean.TRUE);			//Check if priv was automatically assigned...			if(!Boolean.TRUE.equals(assignedPrivs.get(privileges[i]))){				group.grantPriv(grouperAll,Privilege.getInstance(privileges[i]));			}		}		Map.Entry entry = null;		Iterator it = assignedPrivs.entrySet().iterator();		while(it.hasNext()) {			entry = (Map.Entry)it.next();			if(!Boolean.TRUE.equals(selectedPrivs.get(entry.getKey()))) {				group.revokePriv(grouperAll,Privilege.getInstance((String)entry.getKey()));			}		}										//TODO: are both these necessary?		request.setAttribute("groupId", group.getUuid());		groupForm.set("groupId",group.getUuid());		try {			if("true".equals(getMediaResources(request).getString("put.in.session.updated.groups"))) {				addSavedSubject(session,group.toSubject());			}		}catch(Exception e){}		String val  =(String) groupForm.get("groupDescription");		if("".equals(val)) val=null;		if(val!=null)group.setDescription(val);			request.setAttribute("message", new Message(				"groups.message.group-saved", (String) groupForm						.get("groupDisplayName")));				//TODO: more sophistication in determining where to go?		String submit = request.getParameter("submit.save");		if (submit != null) {			return mapping.findForward(FORWARD_GroupSummary);		}		submit=request.getParameter("submit.saveAndAddComposite");		if (submit != null) {			return mapping.findForward(FORWARD_AddComposite);		}		session.setAttribute("findForNode", group.getUuid());		return mapping.findForward(FORWARD_FindMembers);	}