Search in sources :

Example 1 with AdminUser

use of cern.laser.business.data.AdminUser in project ACS by ACS-Community.

the class SourceDefinitionServiceImpl method updateSource.

public void updateSource(String userId, SourceDefinition sourceDefinition) throws LaserDefinitionException {
    if (sourceDefinition == null) {
        throw new LaserDefinitionNotValidException("source is null");
    }
    Source source = null;
    source = sourceDAO.findSource(sourceDefinition.getSourceId());
    if (!sourceDefinition.getName().equals(source.getName())) {
        throw new LaserDefinitionNotValidException("source name cannot be changed");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    if (!admin_user.administersSource(source)) {
        throw new LaserDefinitionNotAllowedException("not an administrator for source : " + sourceDefinition);
    }
    try {
        LOGGER.info("user " + admin_user.getName() + " updating source : " + sourceDefinition);
        source.setDefinition(sourceDefinition);
        sourceDAO.updateSource(source);
        String[] alarms = sourceDAO.getAlarms(source.getSourceId());
        for (int i = 0; i < alarms.length; i++) {
            try {
                alarmCache.invalidate(alarms[i]);
            } catch (Exception e) {
                LOGGER.error("unable to propagate alarm source update", e);
            }
        }
        LOGGER.info("source updated");
    } catch (Exception e) {
        throw new LaserDefinitionException("unable to update source " + sourceDefinition + " : " + e.getMessage(), e);
    }
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) 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 2 with AdminUser

use of cern.laser.business.data.AdminUser in project ACS by ACS-Community.

the class SourceDefinitionServiceImpl method createSource.

public void createSource(String userId, SourceDefinition sourceDefinition) throws LaserDefinitionException {
    if (sourceDefinition == null) {
        throw new LaserDefinitionNotValidException("source is null");
    }
    Source source = sourceDAO.getSource(sourceDefinition.getSourceId());
    if (source != null) {
        throw new LaserDefinitionDuplicationException("source " + sourceDefinition.getSourceId() + " already exist");
    }
    if (sourceDefinition.getResponsiblePersonId() == null) {
        throw new LaserDefinitionNotValidException("responsible id for the source definition is null");
    }
    ResponsiblePerson responsible = responsiblePersonDAO.getResponsiblePerson(sourceDefinition.getResponsiblePersonId());
    if (responsible == null) {
        throw new LaserDefinitionNotValidException("responsible with id " + sourceDefinition.getResponsiblePersonId() + " does not exist");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    AdminUser laser_user = adminUserDAO.findByLaserAdminUser();
    LOGGER.info("user " + admin_user.getName() + " creating source : " + sourceDefinition);
    // create the source
    source = new Source(sourceDefinition, responsible);
    CategoryDefinition category_definition = new CategoryDefinition(SOURCE_CATEGORY_PATH_PREFIX + sourceDefinition.getName(), "Category for source " + sourceDefinition.getName());
    Category parent_category = categoryDAO.findCategoryByPath(category_definition.getParentPath());
    Category category = new CategoryImpl(category_definition);
    parent_category.addChildCategory(category);
    categoryDAO.saveCategory(category);
    admin_user.addAdministeredCategory(category);
    laser_user.addAdministeredCategory(category);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("default category " + category_definition.getPath() + "created for source " + sourceDefinition.getName());
    source.setSurveillanceAlarmId(alarmDAO.findLaserSurveillanceAlarmId());
    sourceDAO.saveSource(source);
    // create the source surveillance alarm
    AlarmDefinition surveillance_alarm_definition = (AlarmDefinition) SOURCE_SURVEILLANCE_ALARM_DEFINITION.clone();
    surveillance_alarm_definition.setFaultMember(sourceDefinition.getName());
    surveillance_alarm_definition.setIdentifier(sourceDefinition.getName());
    Alarm surveillance_alarm = new AlarmImpl(surveillance_alarm_definition, source, responsible);
    Category surveillance_category = categoryDAO.findBySurveillanceCategory();
    surveillance_category.addAlarm(surveillance_alarm);
    category.addAlarm(surveillance_alarm);
    alarmDAO.saveAlarm(surveillance_alarm);
    categoryDAO.updateCategory(surveillance_category);
    categoryDAO.updateCategory(category);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("surveillance alarm created for source " + sourceDefinition.getName());
    source.setSurveillanceAlarmId(surveillance_alarm.getAlarmId());
    sourceDAO.updateSource(source);
    admin_user.addAdministeredSource(source);
    laser_user.addAdministeredSource(source);
    adminUserDAO.updateAdminUser(admin_user);
    adminUserDAO.updateAdminUser(laser_user);
    LOGGER.info("source created");
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) AlarmDefinition(cern.laser.business.definition.data.AlarmDefinition) Alarm(cern.laser.business.data.Alarm) AlarmImpl(cern.laser.business.data.AlarmImpl) AdminUser(cern.laser.business.data.AdminUser) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) Source(cern.laser.business.data.Source) CategoryDefinition(cern.laser.business.definition.data.CategoryDefinition)

Example 3 with AdminUser

use of cern.laser.business.data.AdminUser 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");
}
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) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Example 4 with AdminUser

use of cern.laser.business.data.AdminUser in project ACS by ACS-Community.

the class CategoryDefinitionServiceImpl method getCategoryDefinitions.

public Collection getCategoryDefinitions(String userId) throws LaserDefinitionException {
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    LOGGER.info("getting administered categories for user : " + admin_user.getName());
    Integer[] administered_categories = adminUserDAO.getAdministeredCategories(userId);
    Collection result = new ArrayList(administered_categories.length);
    for (int i = 0; i < administered_categories.length; i++) {
        result.add(getCategoryDefinition(administered_categories[i]));
    }
    LOGGER.info("found " + result.size() + " administered categories");
    return result;
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) AdminUser(cern.laser.business.data.AdminUser)

Example 5 with AdminUser

use of cern.laser.business.data.AdminUser 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);
    }
}
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)

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