use of cern.laser.business.data.AdminUser in project ACS by ACS-Community.
the class SourceDefinitionServiceImpl method removeSource.
public void removeSource(String userId, SourceDefinition sourceDefinition) throws LaserDefinitionException {
if (sourceDefinition == null) {
throw new LaserDefinitionNotValidException("source is null");
}
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
AdminUser laser_user = adminUserDAO.findByLaserAdminUser();
Source source = sourceDAO.findSource(sourceDefinition.getSourceId());
if (!admin_user.administersSource(source)) {
throw new LaserDefinitionNotAllowedException("not in source administrators");
}
if (sourceDAO.getAlarms(sourceDefinition.getSourceId()).length > 1) {
throw new LaserDefinitionNotAllowedException("source has attached alarms");
}
try {
LOGGER.info("user " + admin_user.getName() + " removing source : " + sourceDefinition);
alarmDefinitionService.removeAlarm(adminUserDAO.findByLaserAdminUser().getUserId(), alarmDAO.findAlarm(source.getSurveillanceAlarmId()).getDefinition());
admin_user.removeAdministeredSource(source);
laser_user.removeAdministeredSource(source);
sourceDAO.deleteSource(source);
source = null;
String category_path = new String(SOURCE_CATEGORY_PATH_PREFIX + sourceDefinition.getName());
Category parent_category = categoryDAO.findCategoryByPath(SOURCES_CATEGORY_ROOT_PATH);
Category category = categoryDAO.findCategoryByPath(category_path);
parent_category.removeChildCategory(category);
admin_user.removeAdministeredCategory(category);
laser_user.removeAdministeredCategory(category);
categoryDAO.deleteCategory(category);
if (LOGGER.isDebugEnabled())
LOGGER.debug("removed default category " + category_path + " for source " + sourceDefinition.getName());
adminUserDAO.updateAdminUser(admin_user);
adminUserDAO.updateAdminUser(laser_user);
LOGGER.info("removed source " + sourceDefinition.getName());
} catch (Exception e) {
throw new LaserDefinitionException("unable to remove source " + sourceDefinition + " : " + e.getMessage(), e);
}
}
use of cern.laser.business.data.AdminUser in project ACS by ACS-Community.
the class SourceDefinitionServiceImpl method getSourceDefinitions.
public Collection getSourceDefinitions(String userId) throws LaserDefinitionException {
LOGGER.info("getting administered sources for user : " + userId);
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
String[] sources = adminUserDAO.getAdministeredSources(userId);
Collection result = new ArrayList(sources.length);
for (int i = 0; i < sources.length; i++) {
result.add(getSourceDefinition(sources[i]));
}
LOGGER.info("found " + result.size() + " administered sources");
return result;
}
Aggregations