Search in sources :

Example 6 with LaserDefinitionNotValidException

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

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

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

the class AlarmDefinitionServiceImpl method getAlarmDefinitions.

public Collection getAlarmDefinitions(String userId) throws LaserDefinitionException {
    if (userId == null) {
        throw new LaserDefinitionNotValidException("user id is null");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    LOGGER.info("getting administered alarms for user : " + admin_user.getName());
    Collection result = new ArrayList();
    String[] administered_sources = adminUserDAO.getAdministeredSources(userId);
    for (int i = 0; i < administered_sources.length; i++) {
        Source source = sourceDAO.findSource(administered_sources[i]);
        String[] alarms = sourceDAO.getAlarms(source.getSourceId());
        for (int j = 0; j < alarms.length; j++) {
            result.add(getAlarmDefinition(alarms[j]));
        }
    }
    LOGGER.info("found " + result.size() + " administered alarms");
    return result;
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) ArrayList(java.util.ArrayList) Collection(java.util.Collection) AdminUser(cern.laser.business.data.AdminUser) Source(cern.laser.business.data.Source)

Example 9 with LaserDefinitionNotValidException

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

the class AlarmDefinitionServiceImpl method validateReductionLink.

private Alarm[] validateReductionLink(ReductionLink link) throws LaserDefinitionException {
    if (link == null) {
        throw new LaserDefinitionNotValidException("reduction link is null");
    }
    if (link.getParent() == null) {
        throw new LaserDefinitionNotValidException("malformed reduction link: parent is null");
    }
    if (link.getChild() == null) {
        throw new LaserDefinitionNotValidException("malformed reduction link: child is null");
    }
    Alarm parent = alarmDAO.getAlarm(link.getParent().getAlarmId());
    if (parent == null) {
        throw new LaserDefinitionNotFoundException("reduction parent " + link.getParent().getAlarmId() + " does not exist");
    }
    Alarm child = alarmDAO.getAlarm(link.getChild().getAlarmId());
    if (child == null) {
        throw new LaserDefinitionNotFoundException("reduction child " + link.getChild().getAlarmId() + " does not exist");
    }
    return new Alarm[] { parent, child };
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Alarm(cern.laser.business.data.Alarm) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

Example 10 with LaserDefinitionNotValidException

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

the class AlarmDefinitionServiceImpl method removeAlarmInternal.

private void removeAlarmInternal(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 LaserDefinitionNotFoundException("alarm " + alarmDefinition.getAlarmId() + " does not exist");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    if (!admin_user.administersSource(alarm.getSource())) {
        throw new LaserDefinitionNotAllowedException("not in source administrators");
    }
    try {
        LOGGER.info("user " + admin_user.getName() + " removing alarm : " + alarmDefinition.getAlarmId());
        alarmDAO.deleteAlarm(alarm);
        LOGGER.info("alarm removed");
    } catch (Exception e) {
        throw new LaserRuntimeException("unable to remove alarm " + alarmDefinition.getAlarmId() + " : " + e.getMessage(), e);
    }
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) Alarm(cern.laser.business.data.Alarm) AdminUser(cern.laser.business.data.AdminUser) 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) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException)

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