Search in sources :

Example 36 with Category

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

the class ACSCategoryDAOImpl method getChildren.

public Integer[] getChildren(Integer parentId) {
    int pid = parentId.intValue();
    CategoryImpl cat = (CategoryImpl) getCategory(parentId);
    if (cat == null)
        return null;
    ArrayList<Integer> result = new ArrayList<Integer>();
    Iterator<Category> i = categories.values().iterator();
    while (i.hasNext()) {
        Category c = i.next();
        // root categories have null parentId
        if (c.getParentId() != null && c.getParentId().intValue() == pid)
            result.add(c.getCategoryId());
    }
    Integer[] out = new Integer[result.size()];
    result.toArray(out);
    return out;
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl) Category(cern.laser.business.data.Category) ArrayList(java.util.ArrayList)

Example 37 with Category

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

the class CoreServiceImpl method select.

//
// -- PRIVATE METHODS ---------------------------------------------
//
/*
   * (non-Javadoc)
   * 
   * @see cern.laser.business.ejb.CoreServiceSessionEJB#select(java.lang.Integer, java.lang.String)
   */
private void select(Integer categoryId, String clientId) throws LaserProcessingException {
    System.out.println("*** CoreServiceImpl::select: selecting category " + categoryId.toString() + " for client " + clientId);
    ProcessingController processingController = ProcessingController.getInstance();
    if (!processingController.isProcessing()) {
        throw new LaserProcessingException("server not initialized");
    }
    try {
        if (LOGGER.isInfoEnabled()) {
            Category category = categoryDAO.findCategory(categoryId);
            String category_path = category.getPath();
            LOGGER.info("requested category : " + category_path);
        }
        String destination = getClientRootTopic() + "." + clientId;
        CategoryActiveList active_list = alarmCache.getActiveListReference(categoryId);
        String[] active_alarms = active_list.getActiveAlarms();
        if (active_alarms.length > 0) {
            Collection init_alarms = new HashSet(active_alarms.length);
            for (int i = 0; i < active_alarms.length; i++) {
                Alarm alarm = alarmCache.getReference(active_alarms[i]);
                init_alarms.add(alarm);
            }
            LOGGER.info("found " + init_alarms.size() + " matching alarm(s)");
            alarmPublisher.sendInit(init_alarms, destination);
        }
    } catch (AlarmCacheException e) {
        System.err.println("*** Got an exception! " + e.getMessage());
        e.printStackTrace(System.out);
        System.err.println("*** Exception masked");
    //throw new EJBException("unable to select alarms", e);
    }
}
Also used : LaserProcessingException(cern.laser.business.LaserProcessingException) Category(cern.laser.business.data.Category) ProcessingController(cern.laser.business.ProcessingController) CategoryActiveList(cern.laser.business.data.CategoryActiveList) Alarm(cern.laser.business.data.Alarm) Collection(java.util.Collection) AlarmCacheException(cern.laser.business.cache.AlarmCacheException) HashSet(java.util.HashSet)

Example 38 with Category

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

the class ACSCategoryDAOImpl method updateCategory.

public void updateCategory(Category category) {
    Integer id = category.getCategoryId();
    if (id == null)
        throw new IllegalStateException();
    Category previous = categories.get(id);
    // path may have changed
    catPathToCategory.values().remove(previous);
    categories.put(id, category);
    if (category.getPath() != null)
        catPathToCategory.put(category.getPath(), category);
}
Also used : Category(cern.laser.business.data.Category)

Example 39 with Category

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

the class ACSCategoryDAOImpl method assignCategoryToAlarms.

/**
	 * Assign the category to the all the alarms of a given FaultFamily.
	 * 
	 * In the CDB each category has a list (eventually empty) of FaultFamily.
	 * If a FaultFamily appear in the definition of a Category then add
	 * such category to all the alarms of such FF.
	 *   
	 *  @param category The category to assign to the alarms
	 *  @param FF The fault family of the alarms to assign the category to
	 */
private void assignCategoryToAlarms(Category category, String FF) {
    if (category == null) {
        throw new IllegalArgumentException("Invalid null category");
    }
    if (FF == null) {
        throw new IllegalArgumentException("Invalid null fault family");
    }
    String[] alarmIDs = ((ACSAlarmDAOImpl) alarmDao).getAllAlarmIDs();
    for (String id : alarmIDs) {
        Alarm alarm = alarmDao.getAlarm(id);
        if (alarm == null) {
            logger.log(AcsLogLevel.WARNING, "Got a null alarm for ID=" + id);
            continue;
        }
        if (alarm.getTriplet().getFaultFamily().equals(FF)) {
            Collection<Category> alarmCategories = alarm.getCategories();
            if (!alarmCategories.contains(category)) {
                alarmCategories.add(category);
                logger.log(AcsLogLevel.DEBUG, "Category " + category.getName() + " assigned to alarm " + alarm.getAlarmId());
            }
        }
    }
}
Also used : Category(cern.laser.business.data.Category) Alarm(cern.laser.business.data.Alarm)

Example 40 with Category

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

the class ACSCategoryDAOTest method testRootChilds.

/**
	 * Check that all the categories are child of ROOT
	 */
public void testRootChilds() throws Exception {
    Category root = categoryDAO.getCategoryByPath("ROOT");
    assertNotNull("Found a null ROOT category", root);
    Integer[] IDs = categoryDAO.getAllCategoryIDs();
    for (Integer ID : IDs) {
        Category cat = categoryDAO.getCategory(ID);
        // Skip the ROOT
        if (cat == root) {
            continue;
        }
        assertEquals("The category is not child of ROOT", root.getCategoryId(), cat.getParentId());
        assertTrue("The category should be a leaf", cat.isLeaf());
    }
}
Also used : Category(cern.laser.business.data.Category)

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