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;
}
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);
}
}
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);
}
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());
}
}
}
}
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());
}
}
Aggregations