use of cern.laser.business.definition.LaserDefinitionException in project ACS by ACS-Community.
the class AlarmDefinitionServiceImpl method removeAlarms.
public void removeAlarms(String userId, Collection alarms) throws LaserDefinitionException {
if ((alarms == null) || (alarms.size() == 0)) {
return;
}
removeAlarmsInternal(userId, alarms);
Iterator iterator = alarms.iterator();
Alarm alarm_obj = null;
while (iterator.hasNext()) {
try {
alarm_obj = alarmCache.getCopy(((AlarmDefinition) iterator.next()).getAlarmId());
invalidateAlarm(alarm_obj);
propagateRemovedAlarm(alarm_obj);
} catch (Exception e) {
LOGGER.warn("unable to handle removed alarm " + alarm_obj.getTriplet() + " : " + e.getMessage());
}
}
}
use of cern.laser.business.definition.LaserDefinitionException in project ACS by ACS-Community.
the class AdminUserDefinitionServiceImpl method getAdminUsers.
// public AdminUser findAdminUser(Integer userId) throws LaserDefinitionException {
// if (userId == null) throw new LaserDefinitionNotAllowedException("userId is null");
//
// AdminUser admin_user = adminUserDAO.getAdminUser(userId);
// if (admin_user == null) {
// throw new LaserDefinitionNotFoundException("unable to find admin user "+userId);
// }
//
// return admin_user;
// }
public Collection getAdminUsers() throws LaserDefinitionException {
try {
AdminUser[] users = adminUserDAO.findAllAdminUsers();
Collection result = new ArrayList(users.length);
for (int i = 0; i < users.length; i++) {
result.add(users[i].getUserId());
}
return result;
} catch (Exception e) {
throw new LaserDefinitionException("unable to get admin users", e);
}
}
use of cern.laser.business.definition.LaserDefinitionException in project ACS by ACS-Community.
the class AlarmDefinitionServiceImpl method removeAlarmInternal.
private void removeAlarmInternal(String userId, AlarmDefinition alarmDefinition) throws LaserDefinitionException {
if (alarmDefinition == null) {
throw new LaserDefinitionNotValidException("alarm is null");
}
Alarm alarm = alarmDAO.getAlarm(alarmDefinition.getAlarmId());
if (alarm == null) {
throw new LaserDefinitionNotFoundException("alarm " + alarmDefinition.getAlarmId() + " does not exist");
}
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
if (!admin_user.administersSource(alarm.getSource())) {
throw new LaserDefinitionNotAllowedException("not in source administrators");
}
try {
LOGGER.info("user " + admin_user.getName() + " removing alarm : " + alarmDefinition.getAlarmId());
alarmDAO.deleteAlarm(alarm);
LOGGER.info("alarm removed");
} catch (Exception e) {
throw new LaserRuntimeException("unable to remove alarm " + alarmDefinition.getAlarmId() + " : " + e.getMessage(), e);
}
}
use of cern.laser.business.definition.LaserDefinitionException in project ACS by ACS-Community.
the class AlarmDefinitionServiceImpl method updateAlarm.
public void updateAlarm(String userId, AlarmDefinition alarmDefinition) throws LaserDefinitionException {
if (alarmDefinition == null) {
throw new LaserDefinitionNotValidException("alarm is null");
}
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
Alarm alarm = alarmDAO.findAlarm(alarmDefinition.getAlarmId());
Source new_source = sourceDAO.findSource(alarmDefinition.getSourceName());
Source old_source = alarm.getSource();
if (!(admin_user.administersSource(new_source) && admin_user.administersSource(old_source))) {
throw new LaserDefinitionNotAllowedException("not an administrator for the alarm : " + alarmDefinition);
}
if (!new_source.equals(old_source)) {
// old_source.removeAlarm(alarm);
new_source.addAlarm(alarm);
String old_category_path = SOURCE_CATEGORY_PATH_PREFIX + old_source.getName();
Category old_category = categoryDAO.findCategory(new Integer(old_category_path.hashCode()));
old_category.removeAlarm(alarm);
String new_category_path = SOURCE_CATEGORY_PATH_PREFIX + alarmDefinition.getSourceName();
Category new_category = categoryDAO.findCategory(new Integer(new_category_path.hashCode()));
new_category.addAlarm(alarm);
if (LOGGER.isDebugEnabled())
LOGGER.debug("alarm removed from category " + old_category_path + " and added to category " + new_category_path);
sourceDAO.updateSource(old_source);
sourceDAO.updateSource(new_source);
categoryDAO.updateCategory(old_category);
categoryDAO.updateCategory(new_category);
}
LOGGER.info("user " + admin_user.getName() + " updating alarm : " + alarmDefinition);
if (!alarm.getResponsiblePerson().getResponsibleId().equals(alarmDefinition.getResponsiblePersonId())) {
// ResponsiblePerson old_responsible = alarm.getResponsiblePerson();
// old_responsible.getAlarmIds().remove(alarm.getAlarmId());
ResponsiblePerson new_responsible = alarmDefinition.getResponsiblePersonId() == null ? new_source.getResponsiblePerson() : responsiblePersonDAO.getResponsiblePerson(alarmDefinition.getResponsiblePersonId());
// new_responsible.getAlarmIds().add(alarm.getAlarmId());
alarm.setResponsiblePerson(new_responsible);
// session.update(old_responsible);
// session.update(new_responsible);
}
alarm.setDefinition(alarmDefinition);
alarmDAO.updateAlarm(alarm);
try {
alarmCache.invalidate(alarmDefinition.getAlarmId());
} catch (Exception e) {
LOGGER.error("unable to propagate alarm update : " + alarmDefinition, e);
}
LOGGER.info("alarm updated");
}
use of cern.laser.business.definition.LaserDefinitionException in project ACS by ACS-Community.
the class CategoryDefinitionServiceImpl method removeCategory.
public void removeCategory(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 LaserDefinitionNotFoundException("category with path " + categoryDefinition.getPath() + " does not exist");
}
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
AdminUser laser_user = adminUserDAO.findByLaserAdminUser();
if (!admin_user.administersCategory(category.getCategoryId())) {
throw new LaserDefinitionNotAllowedException("not in category administrators : " + categoryDefinition);
}
if (categoryDAO.getAlarms(category.getCategoryId()).length != 0) {
throw new LaserDefinitionNotAllowedException("category has attached alarms");
}
try {
LOGGER.info("user " + admin_user.getName() + " removing category : " + categoryDefinition);
admin_user.removeAdministeredCategory(category);
laser_user.removeAdministeredCategory(category);
categoryDAO.deleteCategory(category);
adminUserDAO.updateAdminUser(admin_user);
adminUserDAO.updateAdminUser(laser_user);
LOGGER.info("category removed");
} catch (Exception e) {
throw new LaserDefinitionException("unable to remove category " + categoryDefinition + " : " + e.getMessage(), e);
}
}
Aggregations