Search in sources :

Example 1 with LaserDefinitionNotValidException

use of cern.laser.business.definition.LaserDefinitionNotValidException 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 2 with LaserDefinitionNotValidException

use of cern.laser.business.definition.LaserDefinitionNotValidException 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)

Example 3 with LaserDefinitionNotValidException

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

the class CategoryDefinitionServiceImpl method createCategory.

public void createCategory(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 LaserDefinitionDuplicationException("category with path " + categoryDefinition.getPath() + " already exist");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    AdminUser laser_user = adminUserDAO.findByLaserAdminUser();
    Category parent_category = categoryDAO.getCategoryByPath(categoryDefinition.getParentPath());
    if (parent_category == null) {
        throw new LaserDefinitionNotFoundException("parent category with path " + categoryDefinition.getParentPath() + " does not exist");
    }
    if (!admin_user.administersCategory(parent_category.getCategoryId())) {
        throw new LaserDefinitionNotAllowedException(admin_user.getName() + " not an administrator for the parent of category : " + categoryDefinition);
    }
    LOGGER.info("user " + admin_user.getName() + " creating category : " + categoryDefinition);
    category = new CategoryImpl(categoryDefinition);
    parent_category.addChildCategory(category);
    categoryDAO.saveCategory(category);
    admin_user.addAdministeredCategory(category);
    adminUserDAO.updateAdminUser(admin_user);
    laser_user.addAdministeredCategory(category);
    adminUserDAO.updateAdminUser(laser_user);
    LOGGER.info("category created");
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) AdminUser(cern.laser.business.data.AdminUser) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Example 4 with LaserDefinitionNotValidException

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

the class AlarmDefinitionServiceImpl method createAlarmInternal.

//
// -- PRIVATE METHODS ----------------------------------------------
//
private Alarm createAlarmInternal(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 LaserDefinitionDuplicationException("alarm " + alarmDefinition.getAlarmId() + " does already exist");
    }
    if (alarmDefinition.getSourceName() == null) {
        throw new LaserDefinitionNotValidException("source name for the alarm definition is null");
    }
    Source source = sourceDAO.getSource(alarmDefinition.getSourceName());
    if (source == null) {
        throw new LaserDefinitionNotFoundException("source " + alarmDefinition.getSourceName() + " does not exist");
    }
    if (alarmDefinition.getResponsiblePersonId() == null) {
        throw new LaserDefinitionNotValidException("responsible id for the alarm definition is null");
    }
    ResponsiblePerson responsible = responsiblePersonDAO.getResponsiblePerson(alarmDefinition.getResponsiblePersonId());
    if (responsible == null) {
        throw new LaserDefinitionNotFoundException("responsible with id " + alarmDefinition.getResponsiblePersonId() + " does not exist");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    if (!admin_user.administersSource(source)) {
        throw new LaserDefinitionNotAllowedException("not an administrator for the alarm : " + alarmDefinition);
    }
    LOGGER.info("user " + admin_user.getName() + " creating alarm : " + alarmDefinition);
    alarm = new AlarmImpl(alarmDefinition, source, responsible);
    String building_number = alarmDefinition.getBuilding();
    if (building_number != null && !building_number.equals("")) {
        Building building = alarmDAO.findBuilding(building_number);
        alarm.getLocation().setBuilding(building);
    }
    return alarm;
}
Also used : Building(cern.laser.business.data.Building) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) 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) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Example 5 with LaserDefinitionNotValidException

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

the class AlarmDefinitionServiceImpl method setMultiplicityThresholdEJB.

private void setMultiplicityThresholdEJB(String userId, MultiplicityThreshold threshold) throws LaserDefinitionException {
    if ((threshold == null) || (threshold.getParent() == null) || (threshold.getThreshold() == null) || (threshold.getThreshold().intValue() <= 0))
        throw new LaserDefinitionNotValidException("null parameter or negative threshold");
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    LOGGER.info("user " + admin_user.getName() + " setting multiplicity threshold : " + threshold);
    Alarm parent = alarmDAO.findAlarm(threshold.getParent().getAlarmId());
    parent.setMultiplicityThreshold(threshold.getThreshold());
    alarmDAO.updateAlarm(parent);
    LOGGER.info("multiplicity threshold set");
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Alarm(cern.laser.business.data.Alarm) AdminUser(cern.laser.business.data.AdminUser)

Aggregations

LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)14 AdminUser (cern.laser.business.data.AdminUser)13 LaserDefinitionNotFoundException (cern.laser.business.definition.LaserDefinitionNotFoundException)11 LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)10 LaserDefinitionNotAllowedException (cern.laser.business.definition.LaserDefinitionNotAllowedException)10 Alarm (cern.laser.business.data.Alarm)8 Category (cern.laser.business.data.Category)8 AlarmCacheException (cern.laser.business.cache.AlarmCacheException)6 Source (cern.laser.business.data.Source)6 LaserDefinitionException (cern.laser.business.definition.LaserDefinitionException)6 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)3 LaserRuntimeException (cern.laser.business.LaserRuntimeException)2 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 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1