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

migrate some fields to session to speed up ajax requests

parent 5391003c
......@@ -50,10 +50,6 @@ public class AuthorizationBean implements Serializable {
private List<ServiceEntity> unregisteredServiceList;
private List<RegistryEntity> userRegistryList;
private List<ServiceEntity> serviceApproverList;
private List<ServiceEntity> serviceAdminList;
private List<ServiceEntity> serviceHotlineList;
private List<ServiceEntity> serviceGroupAdminList;
@Inject
private Logger logger;
......@@ -89,24 +85,30 @@ public class AuthorizationBean implements Serializable {
long start, end;
start = System.currentTimeMillis();
UserEntity user = userService.findByIdWithStore(sessionManager.getUserId());
List<GroupEntity> groupList = groupService.findByUser(user);
String groupString = groupsToString(groupList);
List<ServiceEntity> unregisteredServiceList;
List<RegistryEntity> userRegistryList;
List<ServiceEntity> serviceApproverList;
List<ServiceEntity> serviceAdminList;
List<ServiceEntity> serviceHotlineList;
List<ServiceEntity> serviceGroupAdminList;
end = System.currentTimeMillis();
logger.debug("user find by id with store loading took {} ms", (end-start));
if (sessionManager.getRoleSetCreated() == null ||
(System.currentTimeMillis() - sessionManager.getRoleSetCreated()) > 5 * 60 * 1000L) {
start = System.currentTimeMillis();
List<GroupEntity> groupList = groupService.findByUser(user);
sessionManager.setGroupString(groupsToString(groupList));
for (GroupEntity g : groupList) {
sessionManager.getGroupList().add(g.getId());
}
end = System.currentTimeMillis();
logger.debug("groups loading took {} ms", (end-start));
}
start = System.currentTimeMillis();
userRegistryList = registryService.findByUserAndNotStatus(user, RegistryStatus.DELETED, RegistryStatus.DEPROVISIONED);
end = System.currentTimeMillis();
logger.debug("registered servs loading took {} ms", (end-start));
serviceApproverList = new ArrayList<ServiceEntity>();
serviceAdminList = new ArrayList<ServiceEntity>();
serviceHotlineList = new ArrayList<ServiceEntity>();
serviceGroupAdminList = new ArrayList<ServiceEntity>();
unregisteredServiceList = serviceService.findAllPublishedWithServiceProps();
for (RegistryEntity registry : userRegistryList) {
......@@ -127,7 +129,7 @@ public class AuthorizationBean implements Serializable {
if (s.getServiceProps().containsKey("group_filter")) {
String groupFilter = serviceProps.get("group_filter");
if (groupFilter != null &&
(! groupString.matches(groupFilter)))
(! sessionManager.getGroupString().matches(groupFilter)))
serviceToRemove.add(s);
}
......@@ -141,25 +143,34 @@ public class AuthorizationBean implements Serializable {
}
unregisteredServiceList.removeAll(serviceToRemove);
start = System.currentTimeMillis();
List<RoleEntity> roleList = roleService.findByUser(user);
for (RoleEntity role : roleList) {
sessionManager.addRole(role.getId());
if (role instanceof AdminRoleEntity) {
serviceAdminList.addAll(serviceService.findByAdminRole(role));
serviceHotlineList.addAll(serviceService.findByHotlineRole(role));
}
else if (role instanceof ApproverRoleEntity) {
serviceApproverList.addAll(serviceService.findByApproverRole(role));
}
else if (role instanceof GroupAdminRoleEntity) {
serviceGroupAdminList.addAll(serviceService.findByGroupAdminRole(role));
}
if (sessionManager.getRoleSetCreated() == null ||
(System.currentTimeMillis() - sessionManager.getRoleSetCreated()) > 5 * 60 * 1000L) {
start = System.currentTimeMillis();
List<RoleEntity> roleList = roleService.findByUser(user);
for (RoleEntity role : roleList) {
sessionManager.addRole(role.getId());
if (role instanceof AdminRoleEntity) {
for (ServiceEntity s : serviceService.findByAdminRole(role))
sessionManager.getServiceAdminList().add(s.getId());
for (ServiceEntity s : serviceService.findByHotlineRole(role))
sessionManager.getServiceHotlineList().add(s.getId());
}
else if (role instanceof ApproverRoleEntity) {
for (ServiceEntity s : serviceService.findByApproverRole(role))
sessionManager.getServiceApproverList().add(s.getId());
}
else if (role instanceof GroupAdminRoleEntity) {
for (ServiceEntity s : serviceService.findByGroupAdminRole(role))
sessionManager.getServiceGroupAdminList().add(s.getId());
}
}
end = System.currentTimeMillis();
logger.debug("Role loading took {} ms", (end-start));
sessionManager.setRoleSetCreated(System.currentTimeMillis());
}
end = System.currentTimeMillis();
logger.debug("Role loading took {} ms", (end-start));
}
public boolean isUserInRole(String roleName) {
......@@ -203,45 +214,25 @@ public class AuthorizationBean implements Serializable {
public boolean isUserServiceAdmin(Long id) {
if (id == null)
return false;
for (ServiceEntity service : getServiceAdminList()) {
if (id.equals(service.getId()))
return true;
}
return false;
return sessionManager.getServiceAdminList().contains(id);
}
public boolean isUserServiceApprover(Long id) {
if (id == null)
return false;
for (ServiceEntity service : getServiceApproverList()) {
if (id.equals(service.getId()))
return true;
}
return false;
return false;
return sessionManager.getServiceApproverList().contains(id);
}
public boolean isUserServiceHotline(Long id) {
if (id == null)
return false;
for (ServiceEntity service : getServiceHotlineList()) {
if (id.equals(service.getId()))
return true;
}
return false;
return sessionManager.getServiceHotlineList().contains(id);
}
public boolean isUserServiceGroupAdmin(Long id) {
if (id == null)
return false;
for (ServiceEntity service : getServiceGroupAdminList()) {
if (id.equals(service.getId()))
return true;
}
return false;
return sessionManager.getServiceGroupAdminList().contains(id);
}
public List<RegistryEntity> getUserRegistryList() {
......@@ -249,19 +240,20 @@ public class AuthorizationBean implements Serializable {
return userRegistryList;
}
public List<ServiceEntity> getServiceApproverList() {
if (serviceApproverList == null) init();
return serviceApproverList;
public List<Long> getServiceApproverList() {
return sessionManager.getServiceApproverList();
}
public List<ServiceEntity> getServiceAdminList() {
if (serviceAdminList == null) init();
return serviceAdminList;
public List<Long> getServiceAdminList() {
return sessionManager.getServiceAdminList();
}
public List<ServiceEntity> getServiceHotlineList() {
if (serviceHotlineList == null) init();
return serviceHotlineList;
public List<Long> getServiceHotlineList() {
return sessionManager.getServiceHotlineList();
}
public List<Long> getServiceGroupAdminList() {
return sessionManager.getServiceGroupAdminList();
}
public boolean isPasswordCapable(ServiceEntity serviceEntity) {
......@@ -292,10 +284,6 @@ public class AuthorizationBean implements Serializable {
return sb.toString();
}
public List<ServiceEntity> getServiceGroupAdminList() {
return serviceGroupAdminList;
}
public ApplicationConfig getAppConfig() {
return appConfig;
}
......
......@@ -6,6 +6,7 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.slf4j.Logger;
......@@ -19,6 +20,7 @@ import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.service.ServiceService;
@ApplicationScoped
@Named
public class ServiceCache {
@Inject
......
......@@ -11,11 +11,13 @@
package edu.kit.scc.webreg.util;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
......@@ -40,11 +42,28 @@ public class SessionManager implements Serializable {
private Set<Long> roles;
private Long roleSetCreated;
private List<Long> serviceApproverList;
private List<Long> serviceAdminList;
private List<Long> serviceHotlineList;
private List<Long> serviceGroupAdminList;
private List<Long> groupList;
private String groupString;
private String theme;
private String locale;
@PostConstruct
public void init() {
serviceApproverList = new ArrayList<Long>();
serviceAdminList = new ArrayList<Long>();
serviceHotlineList = new ArrayList<Long>();
serviceGroupAdminList = new ArrayList<Long>();
groupList = new ArrayList<Long>();
}
public Long getUserId() {
return userId;
}
......@@ -149,4 +168,51 @@ public class SessionManager implements Serializable {
this.roleSetCreated = roleSetCreated;
}
public List<Long> getServiceApproverList() {
return serviceApproverList;
}
public void setServiceApproverList(List<Long> serviceApproverList) {
this.serviceApproverList = serviceApproverList;
}
public List<Long> getServiceAdminList() {
return serviceAdminList;
}
public void setServiceAdminList(List<Long> serviceAdminList) {
this.serviceAdminList = serviceAdminList;
}
public List<Long> getServiceHotlineList() {
return serviceHotlineList;
}
public void setServiceHotlineList(List<Long> serviceHotlineList) {
this.serviceHotlineList = serviceHotlineList;
}
public List<Long> getServiceGroupAdminList() {
return serviceGroupAdminList;
}
public void setServiceGroupAdminList(List<Long> serviceGroupAdminList) {
this.serviceGroupAdminList = serviceGroupAdminList;
}
public List<Long> getGroupList() {
return groupList;
}
public void setGroupList(List<Long> groupList) {
this.groupList = groupList;
}
public String getGroupString() {
return groupString;
}
public void setGroupString(String groupString) {
this.groupString = groupString;
}
}
......@@ -82,30 +82,30 @@
</div>
</ui:repeat>
<ui:repeat var="service" value="#{authorizationBean.serviceAdminList}">
<ui:repeat var="serviceId" value="#{authorizationBean.serviceAdminList}">
<div class="submenu">
<div class="submenu-title">#{service.name} Admin</div>
<div class="submenu-title">#{serviceCache.getServiceFromId(serviceId).name} Admin</div>
<div class="submenu-content">
<div>
<ul>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-admin/index.xhtml" value="#{messages.service_props}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-admin/list-service-users.xhtml" value="#{messages.service_users}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-admin/list-service-users-for-depro.xhtml" value="#{messages.service_users_depro}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
<li><span class="ui-icon ui-icon-signal" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-admin/service-stats.xhtml" value="#{messages.statistics}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
</ul>
......@@ -114,15 +114,15 @@
</div>
</ui:repeat>
<ui:repeat var="service" value="#{authorizationBean.serviceHotlineList}">
<ui:repeat var="serviceId" value="#{authorizationBean.serviceHotlineList}">
<div class="submenu">
<div class="submenu-title">#{service.name} Hotline</div>
<div class="submenu-title">#{serviceCache.getServiceFromId(serviceId).name} Hotline</div>
<div class="submenu-content">
<div>
<ul>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-admin/list-service-users.xhtml" value="#{messages.service_users}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
</ul>
......@@ -131,15 +131,15 @@
</div>
</ui:repeat>
<ui:repeat var="service" value="#{authorizationBean.serviceApproverList}">
<ui:repeat var="serviceId" value="#{authorizationBean.serviceApproverList}">
<div class="submenu">
<div class="submenu-title">#{service.name} Approver</div>
<div class="submenu-title">#{serviceCache.getServiceFromId(serviceId).name} Approver</div>
<div class="submenu-content">
<div>
<ul>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-approver/index.xhtml" value="#{messages.new_approvals}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
</ul>
......@@ -148,15 +148,15 @@
</div>
</ui:repeat>
<ui:repeat var="service" value="#{authorizationBean.serviceGroupAdminList}">
<ui:repeat var="serviceId" value="#{authorizationBean.serviceGroupAdminList}">
<div class="submenu">
<div class="submenu-title">#{service.name} GroupAdmin</div>
<div class="submenu-title">#{serviceCache.getServiceFromId(serviceId).name} GroupAdmin</div>
<div class="submenu-content">
<div>
<ul>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-group-admin/index.xhtml" value="#{messages.groups}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
</ul>
......
......@@ -82,30 +82,30 @@
</div>
</ui:repeat>
<ui:repeat var="service" value="#{authorizationBean.serviceAdminList}">
<ui:repeat var="serviceId" value="#{authorizationBean.serviceAdminList}">
<div class="submenu">
<div class="submenu-title">#{service.name} Admin</div>
<div class="submenu-title">#{serviceCache.getServiceFromId(serviceId).name} Admin</div>
<div class="submenu-content">
<div>
<ul>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-admin/index.xhtml" value="#{messages.service_props}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-admin/list-service-users.xhtml" value="#{messages.service_users}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-admin/list-service-users-for-depro.xhtml" value="#{messages.service_users_depro}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
<li><span class="ui-icon ui-icon-signal" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-admin/service-stats.xhtml" value="#{messages.statistics}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
</ul>
......@@ -113,16 +113,16 @@
</div>
</div>
</ui:repeat>
<ui:repeat var="service" value="#{authorizationBean.serviceHotlineList}">
<ui:repeat var="serviceId" value="#{authorizationBean.serviceHotlineList}">
<div class="submenu">
<div class="submenu-title">#{service.name} Hotline</div>
<div class="submenu-title">#{serviceCache.getServiceFromId(serviceId).name} Hotline</div>
<div class="submenu-content">
<div>
<ul>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-admin/list-service-users.xhtml" value="#{messages.service_users}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
</ul>
......@@ -131,15 +131,15 @@
</div>
</ui:repeat>
<ui:repeat var="service" value="#{authorizationBean.serviceApproverList}">
<ui:repeat var="serviceId" value="#{authorizationBean.serviceApproverList}">
<div class="submenu">
<div class="submenu-title">#{service.name} Approver</div>
<div class="submenu-title">#{serviceCache.getServiceFromId(serviceId).name} Approver</div>
<div class="submenu-content">
<div>
<ul>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-approver/index.xhtml" value="#{messages.new_approvals}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
</ul>
......@@ -148,15 +148,15 @@
</div>
</ui:repeat>
<ui:repeat var="service" value="#{authorizationBean.serviceGroupAdminList}">
<ui:repeat var="serviceId" value="#{authorizationBean.serviceGroupAdminList}">
<div class="submenu">
<div class="submenu-title">#{service.name} GroupAdmin</div>
<div class="submenu-title">#{serviceCache.getServiceFromId(serviceId).name} GroupAdmin</div>
<div class="submenu-content">
<div>
<ul>
<li><span class="ui-icon ui-icon-carat-1-e" style="display:inline-block; vertical-align: bottom;" />
<h:link outcome="/service-group-admin/index.xhtml" value="#{messages.groups}">
<f:param name="serviceId" value="#{service.id}" />
<f:param name="serviceId" value="#{serviceId}" />
</h:link>
</li>
</ul>
......@@ -164,7 +164,7 @@
</div>
</div>
</ui:repeat>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup>
<h:form id="languageForm">
......
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