use of cz.metacentrum.perun.controller.model.ServiceState in project perun by CESNET.
the class PropagationStatsReaderImpl method getFacilityServicesState.
@Override
public List<ServiceState> getFacilityServicesState(PerunSession sess, Facility facility) throws ServiceNotExistsException, InternalErrorException, PrivilegeException {
if (!AuthzResolver.isAuthorized(sess, Role.FACILITYADMIN, facility)) {
throw new PrivilegeException("getFacilityServicesState");
}
Map<Service, ServiceState> serviceStates = new HashMap<Service, ServiceState>();
// fill states for all services which are currently on facility
for (Service service : perun.getServicesManagerBl().getAssignedServices(sess, facility)) {
serviceStates.put(service, new ServiceState(service, facility));
try {
// fill global allowance state based on existing exec services
List<ExecService> execs = getGeneralServiceManager().listExecServices(sess, service.getId());
for (ExecService ex : execs) {
if (!ex.isEnabled())
serviceStates.get(service).setBlockedGlobally(true);
// fill facility allowance state based on existing exec services
if (getGeneralServiceManager().isExecServiceDeniedOnFacility(ex, facility))
serviceStates.get(service).setBlockedOnFacility(true);
}
} catch (EmptyResultDataAccessException ex) {
// service has no exec services -> blocked globally
serviceStates.get(service).setBlockedGlobally(true);
}
// service has destination on facility
serviceStates.get(service).setHasDestinations(!perun.getServicesManagerBl().getDestinations(sess, service, facility).isEmpty());
}
// fill states for all tasks on facility
List<Task> tasks = taskDao.listAllTasksForFacility(facility.getId());
for (Task task : tasks) {
Service taskService = task.getExecService().getService();
ServiceState serviceState = serviceStates.get(taskService);
if (serviceState == null) {
serviceState = new ServiceState(taskService, facility);
serviceStates.put(taskService, serviceState);
// fill destinations if service was not assigned
serviceStates.get(taskService).setHasDestinations(!perun.getServicesManagerBl().getDestinations(sess, taskService, facility).isEmpty());
}
// fill service state
if (ExecService.ExecServiceType.GENERATE.equals(task.getExecService().getExecServiceType())) {
serviceState.setGenTask(task);
} else {
serviceState.setSendTask(task);
}
if (!task.getExecService().isEnabled()) {
serviceStates.get(taskService).setBlockedGlobally(true);
}
if (getGeneralServiceManager().isExecServiceDeniedOnFacility(task.getExecService(), facility))
serviceStates.get(taskService).setBlockedOnFacility(true);
}
return new ArrayList<ServiceState>(serviceStates.values());
}
Aggregations