Search in sources :

Example 11 with LaserDefinitionNotValidException

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

the class AlarmDefinitionServiceImpl method updateAlarm.

public void updateAlarm(String userId, AlarmDefinition alarmDefinition) throws LaserDefinitionException {
    if (alarmDefinition == null) {
        throw new LaserDefinitionNotValidException("alarm is null");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    Alarm alarm = alarmDAO.findAlarm(alarmDefinition.getAlarmId());
    Source new_source = sourceDAO.findSource(alarmDefinition.getSourceName());
    Source old_source = alarm.getSource();
    if (!(admin_user.administersSource(new_source) && admin_user.administersSource(old_source))) {
        throw new LaserDefinitionNotAllowedException("not an administrator for the alarm : " + alarmDefinition);
    }
    if (!new_source.equals(old_source)) {
        //      old_source.removeAlarm(alarm);
        new_source.addAlarm(alarm);
        String old_category_path = SOURCE_CATEGORY_PATH_PREFIX + old_source.getName();
        Category old_category = categoryDAO.findCategory(new Integer(old_category_path.hashCode()));
        old_category.removeAlarm(alarm);
        String new_category_path = SOURCE_CATEGORY_PATH_PREFIX + alarmDefinition.getSourceName();
        Category new_category = categoryDAO.findCategory(new Integer(new_category_path.hashCode()));
        new_category.addAlarm(alarm);
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("alarm removed from category " + old_category_path + " and added to category " + new_category_path);
        sourceDAO.updateSource(old_source);
        sourceDAO.updateSource(new_source);
        categoryDAO.updateCategory(old_category);
        categoryDAO.updateCategory(new_category);
    }
    LOGGER.info("user " + admin_user.getName() + " updating alarm : " + alarmDefinition);
    if (!alarm.getResponsiblePerson().getResponsibleId().equals(alarmDefinition.getResponsiblePersonId())) {
        //        ResponsiblePerson old_responsible = alarm.getResponsiblePerson();
        //        old_responsible.getAlarmIds().remove(alarm.getAlarmId());
        ResponsiblePerson new_responsible = alarmDefinition.getResponsiblePersonId() == null ? new_source.getResponsiblePerson() : responsiblePersonDAO.getResponsiblePerson(alarmDefinition.getResponsiblePersonId());
        //        new_responsible.getAlarmIds().add(alarm.getAlarmId());
        alarm.setResponsiblePerson(new_responsible);
    //        session.update(old_responsible);
    //        session.update(new_responsible);
    }
    alarm.setDefinition(alarmDefinition);
    alarmDAO.updateAlarm(alarm);
    try {
        alarmCache.invalidate(alarmDefinition.getAlarmId());
    } catch (Exception e) {
        LOGGER.error("unable to propagate alarm update : " + alarmDefinition, e);
    }
    LOGGER.info("alarm updated");
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) Alarm(cern.laser.business.data.Alarm) AdminUser(cern.laser.business.data.AdminUser) Source(cern.laser.business.data.Source) 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)

Example 12 with LaserDefinitionNotValidException

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

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

Example 14 with LaserDefinitionNotValidException

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

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