Search in sources :

Example 26 with Category

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

the class ACSCategoryDAOImpl method setParentID.

/**
	 * Set the parent ID of the passed category
	 * 
	 * Each category has a parent ID that can be evaluated by reading
	 * the name of the category.
	 * If the name does not contain ':' then the parent ID is the ROOT.
	 * Otherwise its parent is the category whose name is represented
	 * by the substring before the ':'
	 * 
	 * @param cat
	 */
private void setParentID(CategoryImpl cat) {
    if (cat.getPath().equals("ROOT")) {
        // ROOT has no parent
        cat.setParentId(null);
        return;
    }
    String name = cat.getPath();
    int pos = name.lastIndexOf(':');
    if (pos == -1) {
        // This category parent is ROOT
        Category root = getCategoryByPath("ROOT");
        cat.setParentId(root.getCategoryId());
        cat.setPath(cat.getPath());
        cat.setName(cat.getPath());
        return;
    }
    String parentID = name.substring(0, pos);
    CategoryImpl parent = (CategoryImpl) getCategoryByPath(parentID);
    if (parent == null) {
        logger.log(AcsLogLevel.WARNING, "Parent category of " + parentID + " NOT found");
        return;
    }
    cat.setParentId(parent.getCategoryId());
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl) Category(cern.laser.business.data.Category)

Example 27 with Category

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

the class ACSCategoryDAOImpl method assignDefaultCategory.

/**
	 * Assign the default category to the alarms not assigned to any category
	 * 
	 * Scans all the alarms to check for alarms without any category and assign the default
	 * category to them.
	 * 
	 * @param defCategory The default category
	 */
private void assignDefaultCategory(Category defCategory) {
    if (defCategory == null) {
        throw new IllegalArgumentException("Invalid null category");
    }
    String[] IDs = ((ACSAlarmDAOImpl) alarmDao).getAllAlarmIDs();
    for (String alarmID : IDs) {
        Alarm alarm = alarmDao.getAlarm(alarmID);
        if (alarm == null) {
            logger.log(AcsLogLevel.WARNING, "Got a null alarm for ID=" + alarmID);
            continue;
        }
        Collection<Category> categories = alarm.getCategories();
        if (categories == null) {
            categories = new HashSet<Category>();
        }
        if (categories.size() == 0) {
            categories.add(defCategory);
            alarm.setCategories(categories);
            StringBuilder str = new StringBuilder("Alarm ");
            str.append(alarm.getAlarmId());
            str.append(" assigned to default category ");
            str.append(defCategory.getPath());
            logger.log(AcsLogLevel.DEBUG, str.toString());
        }
    }
}
Also used : Category(cern.laser.business.data.Category) Alarm(cern.laser.business.data.Alarm)

Example 28 with Category

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

the class AlarmDefinitionServiceImpl method createAlarms.

public void createAlarms(String userId, Collection alarms) throws LaserDefinitionException {
    Set categories_to_update = new HashSet();
    if ((alarms == null) || (alarms.size() == 0)) {
        return;
    }
    LOGGER.info("creating " + alarms.size() + " alarms");
    Iterator iterator = alarms.iterator();
    while (iterator.hasNext()) {
        Alarm alarm = createAlarmInternal(userId, (AlarmDefinition) iterator.next());
        alarmDAO.saveAlarm(alarm);
        String category_path = SOURCE_CATEGORY_PATH_PREFIX + alarm.getSource().getName();
        Category category = categoryDAO.findCategoryByPath(category_path);
        category.addAlarm(alarm);
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("alarm added to default category " + category_path);
        categories_to_update.add(category);
    }
    for (Iterator iter = categories_to_update.iterator(); iter.hasNext(); ) {
        Category category_to_update = (Category) iter.next();
        categoryDAO.updateCategory(category_to_update);
    }
    LOGGER.info("alarms created");
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Category(cern.laser.business.data.Category) Alarm(cern.laser.business.data.Alarm) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 29 with Category

use of cern.laser.business.data.Category 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 30 with Category

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

the class AlarmPublisherImpl method publish.

public void publish(AlarmChange alarmChange) {
    if (alarmChange == null) {
        logger.log(AcsLogLevel.WARNING, "alarm change is null");
        return;
    }
    try {
        logger.log(AcsLogLevel.DEBUG, "publishing alarm change for " + alarmChange.getCurrent().getAlarmId() + ", active= " + alarmChange.getCurrent().getStatus().getActive());
        Alarm alarm = alarmChange.getCurrent();
        Alarm previous = alarmChange.getPrevious();
        Iterator iterator = alarm.getCategories().iterator();
        while (iterator.hasNext()) {
            Category category = (Category) iterator.next();
            String destination = categoryRootTopic + "." + category.getPath();
            Topic topic = getTopicSession().createTopic(destination);
            //ObjectMessage message = getTopicSession().createObjectMessage((AlarmImpl) alarm);
            TextMessage message = getTopicSession().createTextMessage();
            setMessageProperties(message, alarm);
            Status previous_alarm_status = previous.getStatus();
            Status current_alarm_status = alarm.getStatus();
            message.setObjectProperty("REDUCED_MASKED_SET", Boolean.FALSE);
            /**
         * change belongs to the reduced set if and only if the transition is from whatever to (ACTIVE, NOT REDUCED, NOT
         * MASKED) or from (ACTIVE, NOT REDUCED, NOT MASKED) to whatever else or if there was not a transition but a
         * change of something NOT REDUCED and NOT MASKED
         */
            if (current_alarm_status.getActive().booleanValue() && !(current_alarm_status.getMasked().booleanValue() || current_alarm_status.getReduced().booleanValue())) {
                // transition to (ACTIVE, NOT REDUCED, NOT MASKED) or change of
                // something NOT REDUCED and NOT MASKED
                message.setObjectProperty("REDUCED_MASKED_SET", Boolean.TRUE);
            } else {
                // else
                if (previous_alarm_status.getActive().booleanValue() && !(previous_alarm_status.getMasked().booleanValue() || previous_alarm_status.getReduced().booleanValue())) {
                    message.setObjectProperty("REDUCED_MASKED_SET", Boolean.TRUE);
                }
            }
            message.setObjectProperty("NOT_REDUCED_MASKED_SET", Boolean.FALSE);
            /**
         * change belongs to the not reduced set if an only if the transition was from ACTIVE to NOT ACTIVE or from NOT
         * ACTIVE to ACTIVE or if it was not triggered by reduction or mask flags
         */
            if (current_alarm_status.getActive().booleanValue() != previous_alarm_status.getActive().booleanValue()) {
                // transition from ACTIVE to NOT ACTIVE or from NOT ACTIVE to ACTIVE
                message.setObjectProperty("NOT_REDUCED_MASKED_SET", Boolean.TRUE);
            } else if (current_alarm_status.getActive().booleanValue() && (current_alarm_status.getMasked().booleanValue() == previous_alarm_status.getMasked().booleanValue()) && (current_alarm_status.getReduced().booleanValue() == previous_alarm_status.getReduced().booleanValue())) {
                // change not triggered by reduction or mask flags
                message.setObjectProperty("NOT_REDUCED_MASKED_SET", Boolean.TRUE);
            }
            // I insert the xml representation of this object
            // in the text field of the message
            String xml = AlarmMessageConversion.getXML((AlarmImpl) alarm);
            message.setText(xml);
            getTopicPublisher().publish(topic, message);
            logger.log(AcsLogLevel.DEBUG, "change published on : " + destination);
        }
    } catch (Exception e) {
        logger.log(AcsLogLevel.ERROR, "unable to publish", e);
        close();
    }
}
Also used : Status(cern.laser.business.data.Status) Category(cern.laser.business.data.Category) Alarm(cern.laser.business.data.Alarm) Iterator(java.util.Iterator) Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) NamingException(javax.naming.NamingException) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserCreateException(cern.laser.business.LaserCreateException) JMSException(javax.jms.JMSException)

Aggregations

Category (cern.laser.business.data.Category)47 Alarm (cern.laser.business.data.Alarm)16 CategoryImpl (cern.laser.business.data.CategoryImpl)14 HashSet (java.util.HashSet)9 AdminUser (cern.laser.business.data.AdminUser)8 LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)8 LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)7 LaserDefinitionNotAllowedException (cern.laser.business.definition.LaserDefinitionNotAllowedException)7 LaserDefinitionNotFoundException (cern.laser.business.definition.LaserDefinitionNotFoundException)7 CategoryDefinition (alma.alarmsystem.alarmmessage.generated.CategoryDefinition)6 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)6 AlarmCacheException (cern.laser.business.cache.AlarmCacheException)6 Source (cern.laser.business.data.Source)6 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)5 AlarmCategoryDefinitions (alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions)4 AlarmCategoryLinkDefinitionListType (alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkDefinitionListType)4 AlarmCategoryLinkType (alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType)4 AlarmDefinition (alma.alarmsystem.alarmmessage.generated.AlarmDefinition)4 AlarmImpl (cern.laser.business.data.AlarmImpl)4 LaserDefinitionException (cern.laser.business.definition.LaserDefinitionException)4