Commit 2f1df7f5 authored by michael.simon's avatar michael.simon
Browse files

creating groups, group events missing yet

parent f1b5c022
......@@ -11,10 +11,13 @@
package edu.kit.scc.webreg.dao;
import java.util.List;
import java.util.Set;
import edu.kit.scc.webreg.dao.as.AttributeSourceGroupDao;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.LocalGroupEntity;
import edu.kit.scc.webreg.entity.ServiceBasedGroupEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserGroupEntity;
......@@ -48,4 +51,12 @@ public interface GroupDao extends BaseDao<GroupEntity, Long> {
AttributeSourceGroupDao getAttributeSourceGroupDao();
Long getNextGID();
ServiceBasedGroupEntity persistWithServiceFlags(
ServiceBasedGroupEntity entity);
ServiceBasedGroupEntity persistWithServiceFlags(
ServiceBasedGroupEntity entity, Set<ServiceEntity> services);
}
......@@ -29,6 +29,4 @@ public interface HomeOrgGroupDao extends BaseDao<HomeOrgGroupEntity, Long> {
List<HomeOrgGroupEntity> findByNameListAndPrefix(List<String> nameList,
String prefix);
HomeOrgGroupEntity persistWithServiceFlags(HomeOrgGroupEntity entity);
}
......@@ -16,4 +16,6 @@ public interface SerialDao extends BaseDao<SerialEntity, Long> {
SerialEntity findByName(String name);
Long next(String name);
}
......@@ -11,6 +11,7 @@
package edu.kit.scc.webreg.dao.jpa;
import java.util.List;
import java.util.Set;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
......@@ -24,9 +25,16 @@ import javax.persistence.criteria.Root;
import edu.kit.scc.webreg.dao.GroupDao;
import edu.kit.scc.webreg.dao.HomeOrgGroupDao;
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.as.AttributeSourceGroupDao;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.LocalGroupEntity;
import edu.kit.scc.webreg.entity.ServiceBasedGroupEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.ServiceGroupFlagEntity;
import edu.kit.scc.webreg.entity.ServiceGroupStatus;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserGroupEntity;
......@@ -43,6 +51,48 @@ public class JpaGroupDao extends JpaBaseDao<GroupEntity, Long> implements GroupD
@Inject
private AttributeSourceGroupDao attributeSourceGroupDao;
@Inject
private SerialDao serialDao;
@Inject
private ServiceGroupFlagDao groupFlagDao;
@Inject
private ServiceDao serviceDao;
@Override
public ServiceBasedGroupEntity persistWithServiceFlags(ServiceBasedGroupEntity entity) {
entity = (ServiceBasedGroupEntity) persist(entity);
List<ServiceEntity> serviceList = serviceDao.findByGroupCapability(true);
for (ServiceEntity service : serviceList) {
List<ServiceGroupFlagEntity> flagList = groupFlagDao.findByGroupAndService(entity, service);
if (flagList.size() == 0) {
ServiceGroupFlagEntity groupFlag = groupFlagDao.createNew();
groupFlag.setGroup(entity);
groupFlag.setService(service);
groupFlag.setStatus(ServiceGroupStatus.DIRTY);
groupFlagDao.persist(groupFlag);
}
}
return entity;
}
@Override
public ServiceBasedGroupEntity persistWithServiceFlags(ServiceBasedGroupEntity entity, Set<ServiceEntity> services) {
entity = (ServiceBasedGroupEntity) persist(entity);
for (ServiceEntity service : services) {
List<ServiceGroupFlagEntity> flagList = groupFlagDao.findByGroupAndService(entity, service);
if (flagList.size() == 0) {
ServiceGroupFlagEntity groupFlag = groupFlagDao.createNew();
groupFlag.setGroup(entity);
groupFlag.setService(service);
groupFlag.setStatus(ServiceGroupStatus.DIRTY);
groupFlagDao.persist(groupFlag);
}
}
return entity;
}
@Override
public void addUserToGroup(UserEntity user, GroupEntity group) {
UserGroupEntity userGroup = createNewUserGroup();
......@@ -163,6 +213,11 @@ public class JpaGroupDao extends JpaBaseDao<GroupEntity, Long> implements GroupD
}
}
@Override
public Long getNextGID() {
return serialDao.next("gid-number-serial");
}
@Override
public Class<GroupEntity> getEntityClass() {
return GroupEntity.class;
......
......@@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
......@@ -25,41 +24,13 @@ import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Root;
import edu.kit.scc.webreg.dao.HomeOrgGroupDao;
import edu.kit.scc.webreg.dao.ServiceDao;
import edu.kit.scc.webreg.dao.ServiceGroupFlagDao;
import edu.kit.scc.webreg.entity.HomeOrgGroupEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.ServiceGroupFlagEntity;
import edu.kit.scc.webreg.entity.ServiceGroupStatus;
import edu.kit.scc.webreg.entity.UserEntity;
@Named
@ApplicationScoped
public class JpaHomeOrgGroupDao extends JpaBaseDao<HomeOrgGroupEntity, Long> implements HomeOrgGroupDao {
@Inject
private ServiceDao serviceDao;
@Inject
private ServiceGroupFlagDao groupFlagDao;
@Override
public HomeOrgGroupEntity persistWithServiceFlags(HomeOrgGroupEntity entity) {
entity = persist(entity);
List<ServiceEntity> serviceList = serviceDao.findByGroupCapability(true);
for (ServiceEntity service : serviceList) {
List<ServiceGroupFlagEntity> flagList = groupFlagDao.findByGroupAndService(entity, service);
if (flagList.size() == 0) {
ServiceGroupFlagEntity groupFlag = groupFlagDao.createNew();
groupFlag.setGroup(entity);
groupFlag.setService(service);
groupFlag.setStatus(ServiceGroupStatus.DIRTY);
groupFlagDao.persist(groupFlag);
}
}
return entity;
}
@Override
public List<HomeOrgGroupEntity> findByUser(UserEntity user) {
CriteriaBuilder builder = em.getCriteriaBuilder();
......
......@@ -33,6 +33,15 @@ public class JpaSerialDao extends JpaBaseDao<SerialEntity, Long> implements Seri
}
}
@Override
public Long next(String name) {
SerialEntity serial = findByName(name);
Long value = serial.getActual();
value++;
serial.setActual(value);
return value;
}
@Override
public Class<SerialEntity> getEntityClass() {
return SerialEntity.class;
......
......@@ -16,12 +16,14 @@ import edu.kit.scc.webreg.dao.GroupDao;
import edu.kit.scc.webreg.dao.as.ASUserAttrValueDao;
import edu.kit.scc.webreg.dao.as.AttributeSourceGroupDao;
import edu.kit.scc.webreg.entity.AuditStatus;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.as.ASUserAttrEntity;
import edu.kit.scc.webreg.entity.as.ASUserAttrValueEntity;
import edu.kit.scc.webreg.entity.as.ASUserAttrValueStringEntity;
import edu.kit.scc.webreg.entity.as.AttributeSourceEntity;
import edu.kit.scc.webreg.entity.as.AttributeSourceGroupEntity;
import edu.kit.scc.webreg.entity.as.AttributeSourceServiceEntity;
import edu.kit.scc.webreg.exc.PropertyReaderException;
import edu.kit.scc.webreg.exc.UserUpdateException;
import edu.kit.scc.webreg.service.reg.ldap.PropertyReader;
......@@ -194,7 +196,7 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource
changed = true;
}
else {
String[] groupsString = asValue.getValueString().split(groupSeparator);
String[] groupsString = asValue.getValueString().toLowerCase().split(groupSeparator);
Set<String> newGroups = new HashSet<String>(Arrays.asList(groupsString));
Map<String, AttributeSourceGroupEntity> oldGroupsMap = new HashMap<String, AttributeSourceGroupEntity>();
......@@ -220,8 +222,15 @@ public abstract class AbstractAttributeSourceWorkflow implements AttributeSource
group = attributeSourceGroupDao.createNew();
group.setName(s);
group.setAttributeSource(attributeSource);
group.setGidNumber(groupDao.getNextGID().intValue());
Set<ServiceEntity> services = new HashSet<ServiceEntity>();
for (AttributeSourceServiceEntity asse : attributeSource.getAttributeSourceServices())
services.add(asse.getService());
group = (AttributeSourceGroupEntity) groupDao.persistWithServiceFlags(group, services);
}
logger.debug("Adding {} to group {}", user.getEppn(), s);
groupDao.addUserToGroup(user, group);
}
}
......
......@@ -113,7 +113,7 @@ public class LdapUidNumberGroupHook implements GroupServiceHook {
group.setName("noname_" + gid);
group.setPrefix("ka");
group.setIdp(user.getIdp());
group = dao.persistWithServiceFlags(group);
group = (HomeOrgGroupEntity) groupDao.persistWithServiceFlags(group);
auditor.logAction(group.getName(), "SET FIELD (LDAP)", "idpEntityId", "" + user.getIdp().getEntityId(), AuditStatus.SUCCESS);
auditor.logAction(group.getName(), "SET FIELD (LDAP)", "name", group.getName(), AuditStatus.SUCCESS);
auditor.logAction(group.getName(), "SET FIELD (LDAP)", "prefix", group.getPrefix(), AuditStatus.SUCCESS);
......@@ -131,7 +131,7 @@ public class LdapUidNumberGroupHook implements GroupServiceHook {
group.setName(groupNameFromLdap);
group.setPrefix("ka");
group.setIdp(user.getIdp());
group = dao.persistWithServiceFlags(group);
group = (HomeOrgGroupEntity) groupDao.persistWithServiceFlags(group);
auditor.logAction(group.getName(), "SET FIELD (LDAP)", "idpEntityId", "" + user.getIdp().getEntityId(), AuditStatus.SUCCESS);
auditor.logAction(group.getName(), "SET FIELD (LDAP)", "name", group.getName(), AuditStatus.SUCCESS);
auditor.logAction(group.getName(), "SET FIELD (LDAP)", "prefix", group.getPrefix(), AuditStatus.SUCCESS);
......@@ -240,7 +240,7 @@ public class LdapUidNumberGroupHook implements GroupServiceHook {
groupEntity.setPrefix("ka");
groupEntity.setGidNumber(gidNumber);
groupEntity.setIdp(user.getIdp());
groupEntity = dao.persistWithServiceFlags(groupEntity);
groupEntity = (HomeOrgGroupEntity) groupDao.persistWithServiceFlags(groupEntity);
auditor.logAction(groupEntity.getName(), "SET FIELD (LDAP)", "idpEntityId", "" + user.getIdp().getEntityId(), AuditStatus.SUCCESS);
auditor.logAction(groupEntity.getName(), "SET FIELD (LDAP)", "name", groupEntity.getName(), AuditStatus.SUCCESS);
auditor.logAction(groupEntity.getName(), "SET FIELD (LDAP)", "prefix", groupEntity.getPrefix(), AuditStatus.SUCCESS);
......
......@@ -16,8 +16,6 @@ public interface SerialService extends BaseService<SerialEntity, Long> {
SerialEntity findByName(String name);
void createIfNotExistant(String name, Long initalValue);
Long next(String name);
}
......@@ -16,6 +16,7 @@ import javax.ejb.Stateless;
import javax.inject.Inject;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.GroupDao;
import edu.kit.scc.webreg.dao.HomeOrgGroupDao;
import edu.kit.scc.webreg.entity.HomeOrgGroupEntity;
import edu.kit.scc.webreg.entity.UserEntity;
......@@ -28,7 +29,10 @@ public class HomeOrgGroupServiceImpl extends BaseServiceImpl<HomeOrgGroupEntity,
@Inject
private HomeOrgGroupDao dao;
@Inject
private GroupDao groupDao;
@Override
public HomeOrgGroupEntity findWithUsers(Long id) {
return dao.findWithUsers(id);
......@@ -46,7 +50,7 @@ public class HomeOrgGroupServiceImpl extends BaseServiceImpl<HomeOrgGroupEntity,
@Override
public HomeOrgGroupEntity persistWithServiceFlags(HomeOrgGroupEntity entity) {
return dao.persistWithServiceFlags(entity);
return (HomeOrgGroupEntity) groupDao.persistWithServiceFlags(entity);
}
@Override
......
......@@ -169,7 +169,7 @@ public class HomeOrgGroupUpdater implements Serializable {
auditor.logAction(group.getName(), "SET FIELD", "gidNumber", "" + group.getGidNumber(), AuditStatus.SUCCESS);
group.setIdp(user.getIdp());
auditor.logAction(group.getName(), "SET FIELD", "idpEntityId", "" + user.getIdp().getEntityId(), AuditStatus.SUCCESS);
group = dao.persistWithServiceFlags(group);
group = (HomeOrgGroupEntity) groupDao.persistWithServiceFlags(group);
auditor.logAction(group.getName(), "CREATE GROUP", null, "Group created", AuditStatus.SUCCESS);
changedGroups.add(group);
......@@ -294,7 +294,7 @@ public class HomeOrgGroupUpdater implements Serializable {
auditor.logAction(groupEntity.getName(), "SET FIELD", "gidNumber", "" + groupEntity.getGidNumber(), AuditStatus.SUCCESS);
groupEntity.setIdp(user.getIdp());
auditor.logAction(groupEntity.getName(), "SET FIELD", "idpEntityId", "" + user.getIdp().getEntityId(), AuditStatus.SUCCESS);
groupEntity = dao.persistWithServiceFlags(groupEntity);
groupEntity = (HomeOrgGroupEntity) groupDao.persistWithServiceFlags(groupEntity);
auditor.logAction(groupEntity.getName(), "CREATE GROUP", null, "Group created", AuditStatus.SUCCESS);
changedGroups.add(groupEntity);
......
......@@ -12,7 +12,6 @@ package edu.kit.scc.webreg.service.impl;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.persistence.NoResultException;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.SerialDao;
......@@ -34,27 +33,9 @@ public class SerialServiceImpl extends BaseServiceImpl<SerialEntity, Long> imple
@Override
public Long next(String name) {
SerialEntity serial = dao.findByName(name);
Long value = serial.getActual();
value++;
serial.setActual(value);
dao.persist(serial);
return value;
return dao.next(name);
}
@Override
public void createIfNotExistant(String name, Long initalValue) {
try {
dao.findByName(name);
} catch (NoResultException nre) {
SerialEntity serial = dao.createNew();
serial.setName(name);
serial.setActual(initalValue);
dao.persist(serial);
}
}
@Override
protected BaseDao<SerialEntity, Long> getDao() {
return dao;
......
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