Search in sources :

Example 6 with LaserDefinitionNotFoundException

use of cern.laser.business.definition.LaserDefinitionNotFoundException 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);
    }
}
Also used : LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AdminUser(cern.laser.business.data.AdminUser) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException)

Example 7 with LaserDefinitionNotFoundException

use of cern.laser.business.definition.LaserDefinitionNotFoundException 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);
    }
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) Alarm(cern.laser.business.data.Alarm) AdminUser(cern.laser.business.data.AdminUser) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Example 8 with LaserDefinitionNotFoundException

use of cern.laser.business.definition.LaserDefinitionNotFoundException 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);
    }
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException) AdminUser(cern.laser.business.data.AdminUser) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Example 9 with LaserDefinitionNotFoundException

use of cern.laser.business.definition.LaserDefinitionNotFoundException in project ACS by ACS-Community.

the class CategoryDefinitionServiceImpl method removeCategoryLink.

public void removeCategoryLink(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 exist");
    }
    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 " + link.getAlarm().getAlarmId() + " does not exist");
    }
    if (!category.containsAlarm(alarm)) {
        throw new LaserDefinitionNotFoundException("category/alarm link not defined : " + link);
    }
    try {
        LOGGER.info("user " + admin_user.getName() + " removing category link : " + link);
        category.removeAlarm(alarm);
        categoryDAO.flushCategory();
        alarmCache.invalidate(alarm.getAlarmId());
    //      Alarm surveillance_alarm = alarmDAO.findAlarm(alarm.getSource().getSurveillanceAlarmId());
    //      if (!categoryDAO.hasAlarmsForSource(category.getCategoryId(), alarm.getSource().getSourceId())) {
    //        category.removeAlarm(surveillance_alarm);
    //        alarmCache.invalidate(surveillance_alarm.getAlarmId());
    //      }
    //      categoryDAO.updateCategory(category);
    } catch (AlarmCacheException e) {
        LOGGER.error("unable to propagate category/alarm link : " + link, e);
    }
    LOGGER.info("category/alarm link removed");
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) Alarm(cern.laser.business.data.Alarm) AdminUser(cern.laser.business.data.AdminUser) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Aggregations

LaserDefinitionNotFoundException (cern.laser.business.definition.LaserDefinitionNotFoundException)9 AdminUser (cern.laser.business.data.AdminUser)8 LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)7 LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)6 LaserDefinitionNotAllowedException (cern.laser.business.definition.LaserDefinitionNotAllowedException)6 Alarm (cern.laser.business.data.Alarm)5 AlarmCacheException (cern.laser.business.cache.AlarmCacheException)4 Category (cern.laser.business.data.Category)4 LaserDefinitionException (cern.laser.business.definition.LaserDefinitionException)3 LaserRuntimeException (cern.laser.business.LaserRuntimeException)1 AlarmImpl (cern.laser.business.data.AlarmImpl)1 Building (cern.laser.business.data.Building)1 CategoryImpl (cern.laser.business.data.CategoryImpl)1 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)1 Source (cern.laser.business.data.Source)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1