use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class CategoryDefinitionServiceImpl method createCategoryLink.
public void createCategoryLink(String userId, CategoryLink link) throws LaserDefinitionException {
if (link == null) {
throw new LaserDefinitionNotValidException("category/alarm link is null");
}
if (link.getCategory() == null) {
throw new LaserDefinitionNotValidException("malformed category/alarm link: category is null");
}
if (link.getAlarm() == null) {
throw new LaserDefinitionNotValidException("malformed category/alarm link: alarm is null");
}
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
Category category = categoryDAO.getCategoryByPath(link.getCategory().getPath());
if (category == null) {
throw new LaserDefinitionNotFoundException("category with path " + link.getCategory().getPath() + " does not exists");
}
if (!admin_user.administersCategory(category.getCategoryId())) {
throw new LaserDefinitionNotAllowedException("not an administrators for the category : " + link.getCategory());
}
Alarm alarm = alarmDAO.getAlarm(link.getAlarm().getAlarmId());
if (alarm == null) {
throw new LaserDefinitionNotFoundException("alarm with id " + link.getAlarm().getAlarmId() + " does not exist");
}
Alarm surveillance_alarm = alarmDAO.findAlarm(alarm.getSource().getSurveillanceAlarmId());
if (category.containsAlarm(alarm)) {
throw new LaserDefinitionDuplicationException("alarm/category link already defined : " + link);
}
LOGGER.info("user " + admin_user.getName() + " creating alarm/category link : " + link);
category.addAlarm(alarm);
category.addAlarm(surveillance_alarm);
categoryDAO.updateCategory(category);
try {
alarmCache.invalidate(alarm.getAlarmId());
alarmCache.invalidate(surveillance_alarm.getAlarmId());
} catch (AlarmCacheException e) {
LOGGER.error("unable to propagate category link : " + link, e);
}
LOGGER.info("link created");
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class CategoryDefinitionServiceImpl method updateCategory.
public void updateCategory(String userId, CategoryDefinition categoryDefinition) throws LaserDefinitionException {
if (categoryDefinition == null) {
throw new LaserDefinitionNotValidException("category is null");
}
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
Category category = categoryDAO.findCategoryByPath(categoryDefinition.getPath());
if (!admin_user.administersCategory(category.getCategoryId())) {
throw new LaserDefinitionNotAllowedException("not in category administrators : " + categoryDefinition);
}
try {
LOGGER.info("user " + admin_user.getName() + " updating category : " + categoryDefinition);
Category old_parent_category = categoryDAO.findCategoryByPath(categoryDefinition.getParentPath());
if (!category.getParentId().equals(old_parent_category.getCategoryId())) {
if (!admin_user.administersCategory(old_parent_category.getCategoryId()) || !admin_user.administersCategory(category.getParentId())) {
throw new LaserDefinitionNotAllowedException("not in category parent administrators : " + categoryDefinition);
}
old_parent_category.removeChildCategory(category);
Category new_parent_category = categoryDAO.findCategoryByPath(categoryDefinition.getParentPath());
new_parent_category.addChildCategory(category);
}
category.setDefinition(categoryDefinition);
categoryDAO.updateCategory(category);
LOGGER.info("category updated");
} catch (Exception e) {
throw new LaserDefinitionException("unable to update category " + categoryDefinition + " : " + e.getMessage(), e);
}
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class CategoryDefinitionServiceImpl method createCategory.
public void createCategory(String userId, CategoryDefinition categoryDefinition) throws LaserDefinitionException {
if (categoryDefinition == null) {
throw new LaserDefinitionNotValidException("category is null");
}
Category category = categoryDAO.getCategoryByPath(categoryDefinition.getPath());
if (category != null) {
throw new LaserDefinitionDuplicationException("category with path " + categoryDefinition.getPath() + " already exist");
}
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
AdminUser laser_user = adminUserDAO.findByLaserAdminUser();
Category parent_category = categoryDAO.getCategoryByPath(categoryDefinition.getParentPath());
if (parent_category == null) {
throw new LaserDefinitionNotFoundException("parent category with path " + categoryDefinition.getParentPath() + " does not exist");
}
if (!admin_user.administersCategory(parent_category.getCategoryId())) {
throw new LaserDefinitionNotAllowedException(admin_user.getName() + " not an administrator for the parent of category : " + categoryDefinition);
}
LOGGER.info("user " + admin_user.getName() + " creating category : " + categoryDefinition);
category = new CategoryImpl(categoryDefinition);
parent_category.addChildCategory(category);
categoryDAO.saveCategory(category);
admin_user.addAdministeredCategory(category);
adminUserDAO.updateAdminUser(admin_user);
laser_user.addAdministeredCategory(category);
adminUserDAO.updateAdminUser(laser_user);
LOGGER.info("category created");
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class AlarmDefinitionServiceImpl method createAlarm.
public void createAlarm(String userId, AlarmDefinition alarmDefinition) throws LaserDefinitionException {
Alarm alarm = createAlarmInternal(userId, alarmDefinition);
alarmDAO.saveAlarm(alarm);
String category_path = SOURCE_CATEGORY_PATH_PREFIX + alarm.getSource().getName();
Category category = categoryDAO.findCategoryByPath(category_path);
category.addAlarm(alarm);
categoryDAO.updateCategory(category);
if (LOGGER.isDebugEnabled())
LOGGER.debug("alarm added to default category " + category_path);
LOGGER.info("alarm created");
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class ACSCategoryDAOTest method testFindAllCategories.
/**
* Test the find all categories
*/
public void testFindAllCategories() throws Exception {
Integer[] IDs = categoryDAO.getAllCategoryIDs();
assertNotNull(IDs);
Category[] categories = categoryDAO.findAllCategories();
assertNotNull(categories);
assertEquals(IDs.length, categories.length);
// Check if each ID is in the categories
int found = 0;
for (Integer ID : IDs) {
for (Category cat : categories) {
if (cat.getCategoryId() == ID) {
found++;
}
}
}
assertEquals(IDs.length, found);
}
Aggregations