Search in sources :

Example 11 with LaserDefinitionException

use of cern.laser.business.definition.LaserDefinitionException 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);
    }
}
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) Source(cern.laser.business.data.Source) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException)

Aggregations

LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)11 LaserDefinitionException (cern.laser.business.definition.LaserDefinitionException)11 LaserDefinitionNotFoundException (cern.laser.business.definition.LaserDefinitionNotFoundException)11 LaserDefinitionNotAllowedException (cern.laser.business.definition.LaserDefinitionNotAllowedException)10 LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)10 AlarmCacheException (cern.laser.business.cache.AlarmCacheException)8 AdminUser (cern.laser.business.data.AdminUser)8 LaserRuntimeException (cern.laser.business.LaserRuntimeException)6 Alarm (cern.laser.business.data.Alarm)5 Category (cern.laser.business.data.Category)4 Source (cern.laser.business.data.Source)3 Iterator (java.util.Iterator)2 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)1 AlarmDefinition (cern.laser.business.definition.data.AlarmDefinition)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1