Commit a6a3b14c authored by michael.simon's avatar michael.simon
Browse files

Refactor LocalGroup interface

parent 98f49a95
......@@ -11,7 +11,6 @@ import org.slf4j.Logger;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.GroupDao;
import edu.kit.scc.webreg.dao.LocalGroupDao;
import edu.kit.scc.webreg.dao.SerialDao;
import edu.kit.scc.webreg.dao.ServiceDao;
import edu.kit.scc.webreg.dao.ServiceGroupFlagDao;
import edu.kit.scc.webreg.dao.UserDao;
......@@ -23,7 +22,6 @@ import edu.kit.scc.webreg.entity.EventType;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.GroupStatus;
import edu.kit.scc.webreg.entity.LocalGroupEntity;
import edu.kit.scc.webreg.entity.RoleEntity;
import edu.kit.scc.webreg.entity.ServiceBasedGroupEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.ServiceGroupFlagEntity;
......@@ -37,6 +35,7 @@ import edu.kit.scc.webreg.exc.NoServiceFoundException;
import edu.kit.scc.webreg.exc.NoUserFoundException;
import edu.kit.scc.webreg.exc.RestInterfaceException;
import edu.kit.scc.webreg.exc.UnauthorizedException;
import edu.kit.scc.webreg.service.group.LocalGroupCreator;
@Stateless
public class GroupDtoServiceImpl extends BaseDtoServiceImpl<GroupEntity, GroupEntityDto, Long> implements GroupDtoService {
......@@ -65,7 +64,8 @@ public class GroupDtoServiceImpl extends BaseDtoServiceImpl<GroupEntity, GroupEn
private LocalGroupDao localGroupDao;
@Inject
private SerialDao serialDao;
private LocalGroupCreator localGroupCreator;
@Inject
private ServiceGroupFlagDao groupFlagDao;
......@@ -184,21 +184,8 @@ public class GroupDtoServiceImpl extends BaseDtoServiceImpl<GroupEntity, GroupEn
if (! accessChecker.checkAccess(service, userId))
throw new UnauthorizedException("Not authorized");
entity = localGroupDao.createNew();
entity.setName(name);
entity.setAdminRoles(new HashSet<RoleEntity>());
entity.setParents(new HashSet<GroupEntity>());
entity.setChildren(new HashSet<GroupEntity>());
entity.getAdminRoles().add(service.getGroupAdminRole());
entity.setGidNumber(serialDao.next("gid-number-serial").intValue());
entity = localGroupDao.persist(entity);
ServiceGroupFlagEntity groupFlag = groupFlagDao.createNew();
groupFlag.setService(service);
groupFlag.setGroup(entity);
groupFlag.setStatus(ServiceGroupStatus.CLEAN);
groupFlag = groupFlagDao.persist(groupFlag);
entity = localGroupCreator.createNew(name, service);
entity = localGroupCreator.save(entity, service);
GroupEntityDto dto = createNewDto();
mapper.copyProperties(entity, dto);
......
......@@ -13,10 +13,15 @@ package edu.kit.scc.webreg.service;
import java.util.List;
import edu.kit.scc.webreg.entity.LocalGroupEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.UserEntity;
public interface LocalGroupService extends BaseService<LocalGroupEntity, Long> {
LocalGroupEntity save(LocalGroupEntity entity, ServiceEntity service);
LocalGroupEntity createNew(ServiceEntity service);
LocalGroupEntity findByName(String name);
List<LocalGroupEntity> findByUser(UserEntity user);
......
......@@ -8,7 +8,7 @@
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.service.impl;
package edu.kit.scc.webreg.service.group;
import java.io.Serializable;
import java.text.Normalizer;
......@@ -43,6 +43,8 @@ import edu.kit.scc.webreg.exc.EventSubmitException;
import edu.kit.scc.webreg.exc.UserUpdateException;
import edu.kit.scc.webreg.service.GroupServiceHook;
import edu.kit.scc.webreg.service.SerialService;
import edu.kit.scc.webreg.service.impl.AttributeMapHelper;
import edu.kit.scc.webreg.service.impl.HookManager;
import edu.kit.scc.webreg.service.saml.HomeIdResolver;
@ApplicationScoped
......
package edu.kit.scc.webreg.service.group;
import java.io.Serializable;
import java.util.HashSet;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.slf4j.Logger;
import edu.kit.scc.webreg.dao.LocalGroupDao;
import edu.kit.scc.webreg.dao.SerialDao;
import edu.kit.scc.webreg.dao.ServiceGroupFlagDao;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.GroupStatus;
import edu.kit.scc.webreg.entity.LocalGroupEntity;
import edu.kit.scc.webreg.entity.RoleEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.ServiceGroupFlagEntity;
import edu.kit.scc.webreg.entity.ServiceGroupStatus;
@ApplicationScoped
public class LocalGroupCreator implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private Logger logger;
@Inject
private LocalGroupDao localGroupDao;
@Inject
private ServiceGroupFlagDao groupFlagDao;
@Inject
private SerialDao serialDao;
public LocalGroupEntity createNew(ServiceEntity service) {
return createNew(null, service);
}
public LocalGroupEntity createNew(String name, ServiceEntity service) {
LocalGroupEntity entity = localGroupDao.createNew();
entity.setName(name);
entity.setAdminRoles(new HashSet<RoleEntity>());
entity.setParents(new HashSet<GroupEntity>());
entity.setChildren(new HashSet<GroupEntity>());
entity.getAdminRoles().add(service.getGroupAdminRole());
return entity;
}
public LocalGroupEntity save(LocalGroupEntity entity, ServiceEntity service) {
entity.setGidNumber(serialDao.next("gid-number-serial").intValue());
entity.setGroupStatus(GroupStatus.ACTIVE);
entity = localGroupDao.persist(entity);
ServiceGroupFlagEntity groupFlag = groupFlagDao.createNew();
groupFlag.setService(service);
groupFlag.setGroup(entity);
groupFlag.setStatus(ServiceGroupStatus.CLEAN);
groupFlag = groupFlagDao.persist(groupFlag);
return entity;
}
}
......@@ -18,8 +18,10 @@ import javax.inject.Inject;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.LocalGroupDao;
import edu.kit.scc.webreg.entity.LocalGroupEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.service.LocalGroupService;
import edu.kit.scc.webreg.service.group.LocalGroupCreator;
@Stateless
public class LocalGroupServiceImpl extends BaseServiceImpl<LocalGroupEntity, Long> implements LocalGroupService {
......@@ -29,6 +31,19 @@ public class LocalGroupServiceImpl extends BaseServiceImpl<LocalGroupEntity, Lon
@Inject
private LocalGroupDao dao;
@Inject
private LocalGroupCreator creator;
@Override
public LocalGroupEntity createNew(ServiceEntity service) {
return creator.createNew(service);
}
@Override
public LocalGroupEntity save(LocalGroupEntity entity, ServiceEntity service) {
return creator.save(entity, service);
}
@Override
public LocalGroupEntity findWithUsers(Long id) {
return dao.findWithUsers(id);
......
......@@ -45,6 +45,7 @@ import edu.kit.scc.webreg.event.UserEvent;
import edu.kit.scc.webreg.exc.EventSubmitException;
import edu.kit.scc.webreg.exc.UserUpdateException;
import edu.kit.scc.webreg.service.UserCreateService;
import edu.kit.scc.webreg.service.group.HomeOrgGroupUpdater;
@Stateless
public class UserCreateServiceImpl implements UserCreateService {
......
......@@ -62,6 +62,7 @@ import edu.kit.scc.webreg.exc.UserUpdateException;
import edu.kit.scc.webreg.service.SerialService;
import edu.kit.scc.webreg.service.ServiceService;
import edu.kit.scc.webreg.service.UserServiceHook;
import edu.kit.scc.webreg.service.group.HomeOrgGroupUpdater;
import edu.kit.scc.webreg.service.identity.IdentityUpdater;
import edu.kit.scc.webreg.service.reg.AttributeSourceQueryService;
import edu.kit.scc.webreg.service.reg.impl.Registrator;
......
......@@ -66,27 +66,14 @@ public class GroupAdminAddLocalGroupBean implements Serializable {
throw new NotAuthorizedException("Nicht autorisiert");
if (entity == null)
entity = service.createNew();
entity = service.createNew(serviceEntity);
}
public String save() {
entity.setGidNumber(serialService.next("gid-number-serial").intValue());
if (entity.getAdminRoles() == null)
entity.setAdminRoles(new HashSet<RoleEntity>());
entity.getAdminRoles().add(serviceEntity.getGroupAdminRole());
entity = service.save(entity);
entity = service.save(entity, serviceEntity);
ServiceGroupFlagEntity groupFlag = groupFlagService.createNew();
groupFlag.setService(serviceEntity);
groupFlag.setGroup(entity);
groupFlag.setStatus(ServiceGroupStatus.CLEAN);
groupFlag = groupFlagService.save(groupFlag);
return ViewIds.GROUP_ADMIN_INDEX + "?serviceId=" + serviceEntity.getId() + "&faces-redirect=true";
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment