class SecurityServiceImpl extends RemoteServiceServlet implements SecurityService {

	@Override
	public GUIGroup saveGroup(GUIGroup group) throws ServerException {
		Session session = ServiceUtil.checkMenu(getThreadLocalRequest(), Menu.ADMINISTRATION);

		try {
			GroupDAO groupDao = (GroupDAO) Context.get().getBean(GroupDAO.class);
			Group grp;
			if (group.getId() != 0) {
				grp = groupDao.findById(group.getId());
				groupDao.initialize(grp);

				grp.setName(group.getName());
				grp.setDescription(group.getDescription());
				boolean stored = false;
				if (group.getInheritGroupId() == null || group.getInheritGroupId().longValue() == 0) {
					stored = groupDao.store(grp);
				} else {
					stored = groupDao.insert(grp, group.getInheritGroupId().longValue());
				}
				if (!stored)
					throw new Exception("Group has not been updated");
			} else {
				grp = new Group();
				grp.setTenantId(session.getTenantId());
				grp.setName(group.getName());
				grp.setDescription(group.getDescription());
				boolean stored = groupDao.store(grp);
				if (!stored)
					throw new Exception("Group has not been stored");

				if (group.getInheritGroupId() != null && group.getInheritGroupId().longValue() != 0)
					groupDao.inheritACLs(grp, group.getInheritGroupId().longValue());
			}

			group.setId(grp.getId());
			return group;
		} catch (Throwable t) {
			return (GUIGroup) ServiceUtil.throwServerException(session, log, t);
		}
	}

}