public static class SaveActionListener extends EventListener<UIGroupEditMembershipForm> {
public void execute(Event<UIGroupEditMembershipForm> event) throws Exception {
UIGroupEditMembershipForm uiForm = event.getSource();
UIApplication uiApp = event.getRequestContext().getUIApplication();
UIPopupWindow uiPopup = uiForm.getParent();
OrganizationService service = uiForm.getApplicationComponent(OrganizationService.class);
Membership formMembership = service.getMembershipHandler().findMembership(uiForm.membershipId);
if (formMembership == null) {
uiApp.addMessage(new ApplicationMessage("UIGroupEditMembershipForm.msg.membership-delete", null));
uiPopup.setUIComponent(null);
uiPopup.setShow(false);
return;
}
String userName = formMembership.getUserName();
Group group = service.getGroupHandler().findGroupById(uiForm.groupId);
User user = service.getUserHandler().findUserByName(userName);
MembershipHandler memberShipHandler = service.getMembershipHandler();
String memberShipTypeStr = uiForm.getUIFormSelectBox(MEMBER_SHIP).getValue();
MembershipType membershipType = service.getMembershipTypeHandler().findMembershipType(memberShipTypeStr);
Membership membership = memberShipHandler.findMembershipByUserGroupAndType(userName, group.getId(),
membershipType.getName());
if (membership != null) {
uiApp.addMessage(new ApplicationMessage("UIGroupEditMembershipForm.msg.membership-exist", null));
return;
}
memberShipHandler.removeMembership(uiForm.membershipId, true);
memberShipHandler.linkMembership(user, group, membershipType, true);
uiPopup.setUIComponent(null);
uiPopup.setShow(false);
}