Search in sources :

Example 21 with AdminUser

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);
    }
}
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)

Example 22 with AdminUser

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

Aggregations

AdminUser (cern.laser.business.data.AdminUser)22 LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)14 LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)14 LaserDefinitionNotFoundException (cern.laser.business.definition.LaserDefinitionNotFoundException)13 Alarm (cern.laser.business.data.Alarm)11 LaserDefinitionNotAllowedException (cern.laser.business.definition.LaserDefinitionNotAllowedException)11 Category (cern.laser.business.data.Category)8 LaserDefinitionException (cern.laser.business.definition.LaserDefinitionException)8 AlarmCacheException (cern.laser.business.cache.AlarmCacheException)7 Source (cern.laser.business.data.Source)6 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 LaserRuntimeException (cern.laser.business.LaserRuntimeException)3 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)3 AlarmImpl (cern.laser.business.data.AlarmImpl)2 CategoryImpl (cern.laser.business.data.CategoryImpl)2 Building (cern.laser.business.data.Building)1 AlarmDefinition (cern.laser.business.definition.data.AlarmDefinition)1 CategoryDefinition (cern.laser.business.definition.data.CategoryDefinition)1