Commit 61a6ad3e authored by michael.simon's avatar michael.simon
Browse files

check and update parent service registries

parent 47e53ef7
......@@ -60,4 +60,8 @@ public interface RegistryDao extends BaseDao<RegistryEntity, Long> {
List<RegistryEntity> findByUserAndNotStatusAndNotHidden(UserEntity user,
RegistryStatus... status);
List<RegistryEntity> findByServiceAndNotStatus(ServiceEntity service,
RegistryStatus... status);
}
......@@ -40,4 +40,6 @@ public interface ServiceDao extends BaseDao<ServiceEntity, Long> {
List<ServiceEntity> findByGroupAdminRole(RoleEntity role);
List<ServiceEntity> findByParentService(ServiceEntity service);
}
......@@ -125,6 +125,23 @@ public class JpaRegistryDao extends JpaBaseDao<RegistryEntity, Long> implements
return em.createQuery(criteria).getResultList();
}
@Override
public List<RegistryEntity> findByServiceAndNotStatus(ServiceEntity service, RegistryStatus... status) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<RegistryEntity> criteria = builder.createQuery(RegistryEntity.class);
Root<RegistryEntity> root = criteria.from(RegistryEntity.class);
List<Predicate> predList = new ArrayList<Predicate>();
predList.add(builder.equal(root.get("service"), service));
for (RegistryStatus s : status)
predList.add(builder.notEqual(root.get("registryStatus"), s));
criteria.where(builder.and(predList.toArray(new Predicate[]{})));
criteria.select(root);
return em.createQuery(criteria).getResultList();
}
@Override
public List<RegistryEntity> findByServiceAndStatusPaging(ServiceEntity service, RegistryStatus status,
int first, int pageSize, String sortField,
......
......@@ -53,6 +53,13 @@ public class JpaServiceDao extends JpaBaseDao<ServiceEntity, Long> implements Se
return em.createQuery(criteria).getResultList();
}
@Override
@SuppressWarnings({"unchecked"})
public List<ServiceEntity> findByParentService(ServiceEntity service) {
return em.createQuery("select e from ServiceEntity e where e.parentService = :service")
.setParameter("service", service).getResultList();
}
@Override
@SuppressWarnings({"unchecked"})
public List<ServiceEntity> findByAdminRole(RoleEntity role) {
......
......@@ -58,4 +58,7 @@ public interface RegistryService extends BaseService<RegistryEntity, Long> {
RegistryStatus... status);
List<RegistryEntity> findRegistriesForDepro(String serviceShortName);
List<RegistryEntity> findByServiceAndNotStatus(ServiceEntity service,
RegistryStatus... status);
}
......@@ -40,4 +40,6 @@ public interface ServiceService extends BaseService<ServiceEntity, Long> {
List<ServiceEntity> findByGroupAdminRole(RoleEntity role);
List<ServiceEntity> findByParentService(ServiceEntity service);
}
......@@ -59,6 +59,11 @@ public class RegistryServiceImpl extends BaseServiceImpl<RegistryEntity, Long> i
return dao.findByServiceAndStatus(service, status);
}
@Override
public List<RegistryEntity> findByServiceAndNotStatus(ServiceEntity service, RegistryStatus... status) {
return dao.findByServiceAndNotStatus(service, status);
}
@Override
public List<RegistryEntity> findByServiceAndStatusPaging(ServiceEntity service, RegistryStatus status,
int first, int pageSize, String sortField,
......
......@@ -69,6 +69,11 @@ public class ServiceServiceImpl extends BaseServiceImpl<ServiceEntity, Long> imp
return dao.findByAdminRole(role);
}
@Override
public List<ServiceEntity> findByParentService(ServiceEntity service) {
return dao.findByParentService(service);
}
@Override
public List<ServiceEntity> findByHotlineRole(RoleEntity role) {
return dao.findByHotlineRole(role);
......
......@@ -21,5 +21,8 @@ public interface ApprovalService {
void denyApproval(RegistryEntity registry, String executor)
throws RegisterException;
void approve(RegistryEntity registry, String executor,
Boolean sendGroupUpdate) throws RegisterException;
}
......@@ -55,5 +55,8 @@ public interface RegisterUserService {
void reconGroupsForRegistry(RegistryEntity registry, String executor)
throws RegisterException;
void registerUser(UserEntity user, ServiceEntity service, String executor,
Boolean sendGroupUpdate) throws RegisterException;
}
......@@ -111,10 +111,16 @@ public class ApprovalServiceImpl implements ApprovalService {
logger.warn("Exeption", e);
}
}
@Override
public void approve(RegistryEntity registry, String executor)
throws RegisterException {
approve(registry, executor, true);
}
@Override
public void approve(RegistryEntity registry, String executor, Boolean sendGroupUpdate)
throws RegisterException {
logger.info("Finally approving registry {} for user {} and service {}", registry.getId(),
registry.getUser().getEppn(), registry.getService().getName());
......@@ -155,11 +161,13 @@ public class ApprovalServiceImpl implements ApprovalService {
}
}
MultipleGroupEvent mge = new MultipleGroupEvent(userGroups);
try {
eventSubmitter.submit(mge, EventType.GROUP_UPDATE, auditor.getActualExecutor());
} catch (EventSubmitException e) {
logger.warn("Exeption", e);
if (sendGroupUpdate) {
MultipleGroupEvent mge = new MultipleGroupEvent(userGroups);
try {
eventSubmitter.submit(mge, EventType.GROUP_UPDATE, auditor.getActualExecutor());
} catch (EventSubmitException e) {
logger.warn("Exeption", e);
}
}
ServiceRegisterEvent serviceRegisterEvent = new ServiceRegisterEvent(registry);
......
......@@ -55,6 +55,7 @@ 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;
import edu.kit.scc.webreg.entity.UserStatus;
import edu.kit.scc.webreg.event.EventSubmitter;
import edu.kit.scc.webreg.event.MultipleGroupEvent;
import edu.kit.scc.webreg.event.ServiceRegisterEvent;
......@@ -119,6 +120,17 @@ public class RegisterUserServiceImpl implements RegisterUserService {
@Override
public void registerUser(UserEntity user, ServiceEntity service, String executor)
throws RegisterException {
registerUser(user, service, executor, true);
}
@Override
public void registerUser(UserEntity user, ServiceEntity service, String executor, Boolean sendGroupUpdate)
throws RegisterException {
if (! UserStatus.ACTIVE.equals(user.getUserStatus())) {
logger.warn("Only Users in status ACTIVE can register with a service. User {} is {}", user.getEppn(), user.getUserStatus());
throw new RegisterException("Only Users in status ACTIVE can register with a service");
}
service = serviceDao.findById(service.getId());
......
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.bean.admin.service;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import org.slf4j.Logger;
import edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.entity.RegistryStatus;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserStatus;
import edu.kit.scc.webreg.exc.RegisterException;
import edu.kit.scc.webreg.service.RegistryService;
import edu.kit.scc.webreg.service.ServiceService;
import edu.kit.scc.webreg.service.reg.RegisterUserService;
import edu.kit.scc.webreg.session.SessionManager;
@ManagedBean
@ViewScoped
public class CompareChildRegistriesBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private Logger logger;
@Inject
private SessionManager sessionManager;
@Inject
private ServiceService service;
@Inject
private RegistryService registryService;
@Inject
private RegisterUserService registerUserService;
private ServiceEntity entity;
private List<RegistryEntity> registryList;
private List<ServiceEntity> childServiceList;
private Map<ServiceEntity, List<RegistryEntity>> registriesMap;
private Long id;
private Boolean initialized = false;
public void preRenderView(ComponentSystemEvent ev) {
if (! initialized) {
logger.debug("Load service for id {}", id);
entity = service.findById(id);
logger.debug("Loading active registries for service {}", entity.getName());
registryList = registryService.findByServiceAndNotStatus(entity,
RegistryStatus.DELETED, RegistryStatus.DEPROVISIONED);
childServiceList = service.findByParentService(entity);
registriesMap = new HashMap<ServiceEntity, List<RegistryEntity>>(childServiceList.size());
initialized = true;
}
}
public void loadRegistries(ServiceEntity service) {
logger.debug("Loading active registries for child service {}", service.getName());
registriesMap.put(service,
registryService.findByServiceAndNotStatus(service,
RegistryStatus.DELETED, RegistryStatus.DEPROVISIONED)
);
logger.debug("Done Loading active registries for child service {}", service.getName());
}
public List<RegistryEntity> compareMissing(ServiceEntity service) {
Set<UserEntity> userList = new HashSet<UserEntity>();
for (RegistryEntity registry : registryList) {
userList.add(registry.getUser());
}
List<RegistryEntity> missingList = new ArrayList<RegistryEntity>();
for (RegistryEntity registry : registriesMap.get(service)) {
if (! userList.contains(registry.getUser())) {
missingList.add(registry);
}
}
return missingList;
}
public void registerMissing(ServiceEntity service) {
List<RegistryEntity> missingList = compareMissing(service);
logger.info("Will register {} missing users for service {}", missingList.size(), entity.getName());
for (RegistryEntity registry : missingList) {
if (! UserStatus.ACTIVE.equals(registry.getUser().getUserStatus())) {
logger.debug("Skipping registration of user {} to service {}, user is {}", registry.getUser().getEppn(), entity.getName(), registry.getUser().getUserStatus());
}
else {
logger.debug("Starting registration of user {} to service {}", registry.getUser().getEppn(), entity.getName());
List<RegistryEntity> tempRegistryList = registryService.findByServiceAndUserAndNotStatus(entity,
registry.getUser(), RegistryStatus.DELETED, RegistryStatus.DEPROVISIONED);
if (tempRegistryList.size() == 0) {
try {
registerUserService.registerUser(registry.getUser(), entity, "admin-" + sessionManager.getUserId(), false);
} catch (RegisterException e) {
logger.warn("Registration failed", e);
}
}
else {
logger.info("User {} is seems already to be registered with service {}", registry.getUser().getEppn(), entity);
}
}
}
}
public List<RegistryEntity> getRegistries(ServiceEntity service) {
return registriesMap.get(service);
}
public ServiceEntity getEntity() {
return entity;
}
public void setEntity(ServiceEntity entity) {
this.entity = entity;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<ServiceEntity> getChildServiceList() {
return childServiceList;
}
public void setChildServiceList(List<ServiceEntity> childServiceList) {
this.childServiceList = childServiceList;
}
public List<RegistryEntity> getRegistryList() {
return registryList;
}
public void setRegistryList(List<RegistryEntity> registryList) {
this.registryList = registryList;
}
public Map<ServiceEntity, List<RegistryEntity>> getRegistriesMap() {
return registriesMap;
}
public void setRegistriesMap(Map<ServiceEntity, List<RegistryEntity>> registriesMap) {
this.registriesMap = registriesMap;
}
}
......@@ -362,4 +362,5 @@ remove_all_members=Alle Mitglieder entfernen
uid=Lokale User ID
bwidm_org_id=Organisationsk\u00FCrzel
affiliation=Zugeh\u00F6rigkeit
compare_child_registries=Child Registries abgleichen
......@@ -362,4 +362,4 @@ remove_all_members=Remove all members
uid=Local user ID
bwidm_org_id=Org short name
affiliation=Affiliation
compare_child_registries=Compare child registries
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:bw="http://www.scc.kit.edu/bwfacelets"
xmlns:p="http://primefaces.org/ui">
<head>
<title></title>
</head>
<body>
<f:view>
<f:metadata>
<f:viewParam name="id" value="#{compareChildRegistriesBean.id}"/>
<f:event type="javax.faces.event.PreRenderViewEvent"
listener="#{compareChildRegistriesBean.preRenderView}" />
</f:metadata>
<ui:composition template="/template/default-admin.xhtml">
<ui:param name="title" value="#{messages.title}"/>
<ui:define name="content">
<h:form id="form">
<h2><h:outputText value="#{messages.compare_child_registries}: #{compareChildRegistriesBean.entity.name}"/></h2>
<div id="panelInline">
Active registries: <h:outputText value="#{compareChildRegistriesBean.registryList.size()}"/>
</div>
<div id="panelInline">
<p:panel id="childPanel">
<p:dataList var="child" value="#{compareChildRegistriesBean.childServiceList}">
<div><h:outputText value="#{child.name}" /></div>
<div>
<h:panelGroup rendered="#{compareChildRegistriesBean.getRegistries(child) == null}">
<p:commandButton action="#{compareChildRegistriesBean.loadRegistries(child)}"
value="Load" update=":form:childPanel" />
</h:panelGroup>
<h:panelGroup rendered="#{compareChildRegistriesBean.getRegistries(child) != null}">
Active registries: <h:outputText value="#{compareChildRegistriesBean.getRegistries(child).size()}"/><br/>
Missing registries: <h:outputText value="#{compareChildRegistriesBean.compareMissing(child).size()}"/><br/>
<p:commandButton action="#{compareChildRegistriesBean.registerMissing(child)}"
value="Register Missing" update=":form:childPanel" />
</h:panelGroup>
</div>
</p:dataList>
</p:panel>
</div>
</h:form>
</ui:define>
</ui:composition>
</f:view>
</body>
</html>
......@@ -180,7 +180,12 @@
<p:commandButton id="recon2" action="#{showServiceBean.startRecon(true, false)}" value="#{messages.full_reconsiliation}"
ajax="false"/>
<p:commandButton id="recon3" action="#{showServiceBean.startRecon(true, true)}" value="#{messages.full_reconsiliation_with_groups}"
ajax="false"/>
ajax="false"/>
<h:link outcome="compare-child-registries.xhtml" value="#{messages.compare_child_registries}">
<f:param name="id" value="#{showServiceBean.entity.id}" />
</h:link>
</p:panel>
</div>
</h:form>
......
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