use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class ACSCategoryDAOTest method testLoadCategory.
// Checks the categories loaded from CDB
public void testLoadCategory() throws Exception {
Integer[] catIds = categoryDAO.getAllCategoryIDs();
assertEquals(3, catIds.length);
// Lokk for the ROOT to check the parent ID of the other categories
Integer rootID = null;
for (Integer val : catIds) {
Category cat = categoryDAO.getCategory(val);
if (cat.getName() == "ROOT") {
rootID = cat.getCategoryId();
break;
}
}
assertNotNull("ROOT ID not found", rootID);
// Found checks if both the categories are returned by getCategory
int found = 0;
for (Integer val : catIds) {
Category cat = categoryDAO.getCategory(val);
assertNotNull("Got a null category", cat);
assertEquals(cat.getPath(), cat.getName());
if (cat.getPath().equals("CATEGORY1")) {
assertEquals(cat.getDescription(), "Test category 1");
// Check that parentID is the ROOT ID
found++;
} else if (cat.getPath().equals("CATEGORY2")) {
assertEquals(cat.getDescription(), "Test category 2");
found++;
}
}
assertEquals(2, found);
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class ACSCategoryDAOTest method testGetCategoryByID.
/**
* Test the getting of categories by their IDs and PATHS
*/
public void testGetCategoryByID() throws Exception {
Integer[] IDs = categoryDAO.getAllCategoryIDs();
// to check if they are the same category
for (Integer ID : IDs) {
Category catID = categoryDAO.getCategory(ID);
Category catPath = categoryDAO.getCategoryByPath(catID.getPath());
assertEquals(catID, catPath);
}
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class ACSCategoryDAOTest method testGetChilds.
/**
* Test if getting children works
* @throws Exception
*/
public void testGetChilds() throws Exception {
// The root is the only one having childs
Category root = categoryDAO.getCategoryByPath("ROOT");
assertNotNull("Found a null ROOT category", root);
Integer[] childs = categoryDAO.getChildren(root.getCategoryId());
assertNotNull(childs);
assertEquals(categoryDAO.getAllCategoryIDs().length - 1, childs.length);
// Other categories have no children
Category cat = categoryDAO.getCategory(root.getCategoryId() + 1);
assertNotNull(cat);
childs = categoryDAO.getChildren(cat.getCategoryId());
assertNotNull(childs);
assertEquals(0, childs.length);
// The childs of a non existent ID are null
assertNull(categoryDAO.getChildren(Integer.valueOf(-1)));
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class ACSAlarmDAOImpl method generateAlarmsMap.
/**
* Generate the alarms from the definition of the fault families.
* The alarms will be added into the HashMap with their triplet as key.
* The default item has FM="*".
*
* The sources read from the families are also added to the HashMap of the sources
*
* @param families The FF read from the CDB
*/
public void generateAlarmsMap(Vector<FaultFamily> families) {
if (families == null) {
throw new IllegalArgumentException("Invalid null vector of FFs");
}
for (FaultFamily family : families) {
String FF = family.getName();
String helpUrl = family.getHelpUrl();
String source = family.getAlarmSource();
Contact contactPerson = family.getContact();
FaultMember[] FMs = family.getFaultMember();
FaultMemberDefault defaultFM = family.getFaultMemberDefault();
FaultCode[] FCs = family.getFaultCode();
// There should be at least one FC in the CDB
if (FCs == null || FCs.length == 0) {
logger.log(AcsLogLevel.WARNING, "No FC defined for family " + family.getName());
continue;
}
// There should be at least one FM or a default FM defined in the CDB
if (defaultFM == null && (FMs == null || FMs.length == 0)) {
logger.log(AcsLogLevel.WARNING, "No FM defined for family " + family.getName());
continue;
}
// Iterate over the FCs
for (FaultCode code : FCs) {
int FC = code.getValue();
int priority = code.getPriority();
String action = code.getAction();
String cause = code.getCause();
String consequence = code.getConsequence();
String problemDesc = code.getProblemDescription();
boolean instant = code.getInstant();
// Iterate over all the FMs
for (FaultMember member : FMs) {
alma.acs.alarmsystem.generated.Location loc = member.getLocation();
if (loc == null) {
loc = new alma.acs.alarmsystem.generated.Location();
}
if (loc.getBuilding() == null) {
loc.setBuilding("");
}
if (loc.getFloor() == null) {
loc.setFloor("");
}
if (loc.getMnemonic() == null) {
loc.setMnemonic("");
}
if (loc.getPosition() == null) {
loc.setPosition("");
}
if (loc.getRoom() == null) {
loc.setRoom("");
}
String FM = member.getName();
if (FM.equals(DEFAULT_FM)) {
logger.log(AcsLogLevel.ERROR, "In the CDB, FM=" + DEFAULT_FM + " in family " + FF + " is not allowed");
}
AlarmImpl alarm = new AlarmImpl();
alarm.setMultiplicityChildrenIds(new HashSet());
alarm.setMultiplicityParentIds(new HashSet());
alarm.setNodeChildrenIds(new HashSet());
alarm.setNodeParentIds(new HashSet());
alarm.setAction(action);
alarm.setTriplet(new Triplet(FF, FM, FC));
alarm.setCategories(new HashSet<Category>());
alarm.setCause(cause);
alarm.setConsequence(consequence);
alarm.setProblemDescription(problemDesc);
try {
alarm.setHelpURL(new URL(helpUrl));
} catch (MalformedURLException e) {
alarm.setHelpURL(null);
}
alarm.setInstant(instant);
Location location = new Location("0", loc.getFloor(), loc.getMnemonic(), loc.getPosition(), loc.getRoom());
alarm.setLocation(location);
if (contactPerson.getEmail() != null) {
alarm.setPiquetEmail(contactPerson.getEmail());
} else {
alarm.setPiquetEmail("");
}
if (contactPerson.getGsm() != null) {
alarm.setPiquetGSM(contactPerson.getGsm());
} else {
alarm.setPiquetGSM("");
}
alarm.setPriority(priority);
ResponsiblePerson responsible = new ResponsiblePerson(0, contactPerson.getName(), "", contactPerson.getEmail(), contactPerson.getGsm(), "");
alarm.setResponsiblePerson(responsible);
SourceDefinition srcDef = new SourceDefinition(source, "SOURCE", "", 15, 1);
Source src = new Source(srcDef, responsible);
alarm.setSource(src);
alarm.setIdentifier(alarm.getTriplet().toIdentifier());
alarmDefs.put(alarm.getAlarmId(), alarm);
if (!srcDefs.containsKey(source)) {
srcDefs.put(src.getSourceId(), src);
logger.log(AcsLogLevel.DEBUG, "Source " + src.getName() + " (id=" + src.getSourceId() + ") added");
}
logger.log(AcsLogLevel.DEBUG, "Alarm added " + alarm.getAlarmId());
}
// Add the default
if (defaultFM != null) {
alma.acs.alarmsystem.generated.Location loc = defaultFM.getLocation();
if (loc == null) {
loc = new alma.acs.alarmsystem.generated.Location();
}
if (loc.getBuilding() == null) {
loc.setBuilding("");
}
if (loc.getFloor() == null) {
loc.setFloor("");
}
if (loc.getMnemonic() == null) {
loc.setMnemonic("");
}
if (loc.getPosition() == null) {
loc.setPosition("");
}
if (loc.getRoom() == null) {
loc.setRoom("");
}
AlarmImpl defaultAlarm = new AlarmImpl();
defaultAlarm.setMultiplicityChildrenIds(new HashSet());
defaultAlarm.setMultiplicityParentIds(new HashSet());
defaultAlarm.setNodeChildrenIds(new HashSet());
defaultAlarm.setNodeParentIds(new HashSet());
defaultAlarm.setAction(action);
defaultAlarm.setCategories(new HashSet<Category>());
defaultAlarm.setCause(cause);
defaultAlarm.setConsequence(consequence);
defaultAlarm.setProblemDescription(problemDesc);
try {
defaultAlarm.setHelpURL(new URL(helpUrl));
} catch (MalformedURLException e) {
defaultAlarm.setHelpURL(null);
}
defaultAlarm.setInstant(instant);
Location location = new Location("0", loc.getFloor(), loc.getMnemonic(), loc.getPosition(), loc.getRoom());
defaultAlarm.setLocation(location);
defaultAlarm.setPiquetEmail(contactPerson.getEmail());
defaultAlarm.setPiquetGSM(contactPerson.getGsm());
defaultAlarm.setPriority(priority);
ResponsiblePerson responsible = new ResponsiblePerson(0, contactPerson.getName(), "", contactPerson.getEmail(), contactPerson.getGsm(), "");
defaultAlarm.setResponsiblePerson(responsible);
SourceDefinition srcDef = new SourceDefinition(source, "SOURCE", "", 15, 1);
Source src = new Source(srcDef, responsible);
defaultAlarm.setSource(src);
defaultAlarm.setIdentifier(defaultAlarm.getTriplet().toIdentifier());
Triplet triplet = new Triplet(FF, DEFAULT_FM, FC);
defaultAlarm.setTriplet(triplet);
defaultAlarm.setIdentifier(triplet.toIdentifier());
alarmDefs.put(defaultAlarm.getAlarmId(), defaultAlarm);
if (!srcDefs.containsKey(source)) {
srcDefs.put(src.getSourceId(), src);
logger.log(AcsLogLevel.DEBUG, "Source " + src.getName() + " (id=" + src.getSourceId() + ") added");
}
logger.log(AcsLogLevel.DEBUG, "Default alarm added " + defaultAlarm.getAlarmId());
}
}
}
}
use of cern.laser.business.data.Category in project ACS by ACS-Community.
the class ACSCategoryDAOImpl method linkWithAlarms.
public void linkWithAlarms() {
if (conf == null)
throw new IllegalStateException("null configuration accessor");
if (alarmDao == null)
throw new IllegalStateException("missing alarm DAO");
String path = ALARM_CATEGORY_DEFINITION_PATH;
String xml;
try {
xml = conf.getConfiguration(path);
} catch (Exception e) {
throw new RuntimeException("Failed to read " + path);
}
AlarmCategoryDefinitions acds;
try {
acds = (AlarmCategoryDefinitions) AlarmCategoryDefinitions.unmarshalAlarmCategoryDefinitions(new StringReader(xml));
} catch (Exception e) {
throw new RuntimeException("Failed to parse " + path);
}
AlarmCategoryLinkDefinitionListType cltc = acds.getCategoryLinksToCreate();
if (cltc == null)
throw new RuntimeException("Missing category-links-to-create in " + path);
AlarmCategoryLinkType[] links = cltc.getAlarmCategoryLink();
for (int a = 0; a < links.length; a++) {
AlarmCategoryLinkType l = links[a];
alma.alarmsystem.alarmmessage.generated.Alarm linkAlarm = l.getAlarm();
alma.alarmsystem.alarmmessage.generated.Category linkCat = l.getCategory();
if (linkAlarm == null || linkCat == null)
throw new RuntimeException("Missing alarm or category in a link in " + path);
AlarmDefinition ad = linkAlarm.getAlarmDefinition();
CategoryDefinition cd = linkCat.getCategoryDefinition();
if (ad == null || cd == null)
throw new RuntimeException("Missing alarm-definition or category-definition in " + path);
String lff = ad.getFaultFamily();
String lfm = ad.getFaultMember();
if (lff == null || lfm == null)
throw new RuntimeException("Missing fault-family or fault-member in " + path);
String alarmId = Triplet.toIdentifier(lff, lfm, new Integer(ad.getFaultCode()));
String catPath = cd.getPath();
if (catPath == null)
throw new RuntimeException("Missing category path in " + path);
Alarm alarm = alarmDao.getAlarm(alarmId);
Category cat = getCategoryByPath(catPath);
if (alarm == null)
throw new RuntimeException("Missing alarm with ID " + alarmId);
if (cat == null)
throw new RuntimeException("Missing category with path " + catPath);
cat.addAlarm(alarm);
}
Iterator i = catPathToCategory.values().iterator();
while (i.hasNext()) {
CategoryImpl ci = (CategoryImpl) i.next();
String cPath = ci.getPath();
int lastcolon = cPath.lastIndexOf(':');
if (lastcolon >= 0) {
String parentCPath = cPath.substring(0, lastcolon);
CategoryImpl cp = (CategoryImpl) catPathToCategory.get(parentCPath);
if (cp != null) {
cp.addChildCategory(ci);
}
}
}
}
Aggregations