public static class SaveActionListener extends EventListener<UIGroupForm> {
public void execute(Event<UIGroupForm> event) throws Exception {
UIGroupForm uiGroupForm = event.getSource();
UIGroupDetail uiGroupDetail = uiGroupForm.getParent();
UIGroupManagement uiGroupManagement = uiGroupDetail.getParent();
OrganizationService service = uiGroupForm.getApplicationComponent(OrganizationService.class);
UIGroupExplorer uiGroupExplorer = uiGroupManagement.getChild(UIGroupExplorer.class);
String currentGroupId = uiGroupForm.getGroupId();
if (currentGroupId != null) {
Group currentGroup = service.getGroupHandler().findGroupById(currentGroupId);
if (currentGroup == null) {
Object[] args = { uiGroupForm.getUIStringInput(GROUP_NAME).getValue() };
UIApplication uiApp = event.getRequestContext().getUIApplication();
uiApp.addMessage(new ApplicationMessage("UIGroupForm.msg.group-not-exist", args));
uiGroupExplorer.changeGroup(null);
uiGroupDetail.getChild(UIGroupForm.class).setGroup(null);
uiGroupDetail.setRenderedChild(UIGroupInfo.class);
return;
}
uiGroupForm.invokeSetBindingBean(currentGroup);
if (currentGroup.getLabel() == null || currentGroup.getLabel().trim().length() == 0) {
currentGroup.setLabel(currentGroup.getGroupName());
}
service.getGroupHandler().saveGroup(currentGroup, true);
uiGroupForm.reset();
uiGroupForm.setGroup(null);
uiGroupExplorer.changeGroup(currentGroup.getId());
uiGroupForm.setRenderSibling(UIGroupInfo.class);
return;
}
// UIGroupExplorer uiGroupExplorer = uiGroupManagement.getChild(UIGroupExplorer.class) ;
Group currentGroup = uiGroupExplorer.getCurrentGroup();
if (currentGroup != null) {
currentGroupId = currentGroup.getId();
} else {
currentGroupId = null;
}
String groupName = "/" + uiGroupForm.getUIStringInput(GROUP_NAME).getValue();
GroupHandler groupHandler = service.getGroupHandler();
if (currentGroupId != null) {
groupName = currentGroupId + groupName;
}
Group newGroup = groupHandler.findGroupById(groupName);
if (newGroup != null) {
Object[] args = { groupName };
UIApplication uiApp = event.getRequestContext().getUIApplication();
uiApp.addMessage(new ApplicationMessage("UIGroupForm.msg.group-exist", args));
return;
}
newGroup = groupHandler.createGroupInstance();
uiGroupForm.invokeSetBindingBean(newGroup);
if (newGroup.getLabel() == null || newGroup.getLabel().trim().length() == 0) {
newGroup.setLabel(newGroup.getGroupName());
}
String changeGroupId;
if (currentGroupId == null) {
groupHandler.addChild(null, newGroup, true);
// uiGroupExplorer.changeGroup(groupName) ;
changeGroupId = groupName;
} else {
Group parrentGroup = groupHandler.findGroupById(currentGroupId);
groupHandler.addChild(parrentGroup, newGroup, true);
// uiGroupExplorer.changeGroup(currentGroupId) ;
changeGroupId = currentGroupId;
}
// change group
String username = org.exoplatform.portal.webui.util.Util.getPortalRequestContext().getRemoteUser();
User user = service.getUserHandler().findUserByName(username);
MembershipType membershipType = service.getMembershipTypeHandler().findMembershipType(
GroupManagement.getUserACL().getAdminMSType());
if (membershipType != null) {
service.getMembershipHandler().linkMembership(user, newGroup, membershipType, true);
}
uiGroupExplorer.changeGroup(changeGroupId);
uiGroupForm.reset();
uiGroupForm.setGroup(null);