use of alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType 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);
}
}
}
}
use of alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType in project ACS by ACS-Community.
the class ACSCategoryDAOImpl method flushCategory.
public void flushCategory() {
if (conf == null || !conf.isWriteable())
throw new IllegalStateException("no writable configuration accessor");
CategoryDefinitions acds = new CategoryDefinitions();
CategoryDefinitionListType ctc = new CategoryDefinitionListType();
acds.setCategoriesToCreate(ctc);
AlarmCategoryDefinitions linksTop = new AlarmCategoryDefinitions();
AlarmCategoryLinkDefinitionListType cltc = new AlarmCategoryLinkDefinitionListType();
linksTop.setCategoryLinksToCreate(cltc);
Iterator<Category> i = catPathToCategory.values().iterator();
while (i.hasNext()) {
CategoryDefinition cd = new CategoryDefinition();
CategoryImpl ci = (CategoryImpl) i.next();
cd.setDescription(ci.getDescription());
cd.setPath(ci.getPath());
ctc.addCategoryDefinition(cd);
Iterator<?> aidsi = ci.getAlarmIds().iterator();
while (aidsi.hasNext()) {
String aid = (String) aidsi.next();
Alarm a = alarmDao.getAlarm(aid);
if (a == null)
throw new RuntimeException("Category has a link to a non-existent alarm");
AlarmCategoryLinkType link = new AlarmCategoryLinkType();
alma.alarmsystem.alarmmessage.generated.Alarm linkAlarm = new alma.alarmsystem.alarmmessage.generated.Alarm();
alma.alarmsystem.alarmmessage.generated.Category linkCat = new alma.alarmsystem.alarmmessage.generated.Category();
link.setAlarm(linkAlarm);
link.setCategory(linkCat);
AlarmDefinition linkAlarmDef = new AlarmDefinition();
CategoryDefinition linkCatDef = new CategoryDefinition();
linkAlarm.setAlarmDefinition(linkAlarmDef);
linkCat.setCategoryDefinition(linkCatDef);
linkAlarmDef.setFaultCode(a.getTriplet().getFaultCode().intValue());
linkAlarmDef.setFaultFamily(a.getTriplet().getFaultFamily());
linkAlarmDef.setFaultMember(a.getTriplet().getFaultMember());
linkCatDef.setPath(ci.getPath());
cltc.addAlarmCategoryLink(link);
}
}
StringWriter catList = new StringWriter();
try {
acds.marshal(catList);
} catch (Exception e) {
throw new RuntimeException("Failed to encode categories", e);
}
StringWriter linkList = new StringWriter();
try {
acds.marshal(linkList);
} catch (Exception e) {
throw new RuntimeException("Failed to encode link", e);
}
try {
conf.setConfiguration(CATEGORY_DEFINITION_PATH, catList.toString());
conf.setConfiguration(ALARM_CATEGORY_DEFINITION_PATH, linkList.toString());
} catch (Exception e) {
throw new RuntimeException("Failed to store configuration", e);
}
}
use of alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType 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<Category> i = catPathToCategory.values().iterator();
while (i.hasNext()) {
Category ci = 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);
}
}
}
}
use of alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType in project ACS by ACS-Community.
the class ACSCategoryDAOImpl method flushCategory.
public void flushCategory() {
if (conf == null || !conf.isWriteable())
throw new IllegalStateException("no writable configuration accessor");
CategoryDefinitions acds = new CategoryDefinitions();
CategoryDefinitionListType ctc = new CategoryDefinitionListType();
acds.setCategoriesToCreate(ctc);
AlarmCategoryDefinitions linksTop = new AlarmCategoryDefinitions();
AlarmCategoryLinkDefinitionListType cltc = new AlarmCategoryLinkDefinitionListType();
linksTop.setCategoryLinksToCreate(cltc);
Iterator<Category> i = catPathToCategory.values().iterator();
while (i.hasNext()) {
CategoryDefinition cd = new CategoryDefinition();
CategoryImpl ci = (CategoryImpl) i.next();
cd.setDescription(ci.getDescription());
cd.setPath(ci.getPath());
ctc.addCategoryDefinition(cd);
Iterator aidsi = ci.getAlarmIds().iterator();
while (aidsi.hasNext()) {
String aid = (String) aidsi.next();
Alarm a = alarmDao.getAlarm(aid);
if (a == null)
throw new RuntimeException("Category has a link to a non-existent alarm");
AlarmCategoryLinkType link = new AlarmCategoryLinkType();
alma.alarmsystem.alarmmessage.generated.Alarm linkAlarm = new alma.alarmsystem.alarmmessage.generated.Alarm();
alma.alarmsystem.alarmmessage.generated.Category linkCat = new alma.alarmsystem.alarmmessage.generated.Category();
link.setAlarm(linkAlarm);
link.setCategory(linkCat);
AlarmDefinition linkAlarmDef = new AlarmDefinition();
CategoryDefinition linkCatDef = new CategoryDefinition();
linkAlarm.setAlarmDefinition(linkAlarmDef);
linkCat.setCategoryDefinition(linkCatDef);
linkAlarmDef.setFaultCode(a.getTriplet().getFaultCode().intValue());
linkAlarmDef.setFaultFamily(a.getTriplet().getFaultFamily());
linkAlarmDef.setFaultMember(a.getTriplet().getFaultMember());
linkCatDef.setPath(ci.getPath());
cltc.addAlarmCategoryLink(link);
}
}
StringWriter catList = new StringWriter();
try {
acds.marshal(catList);
} catch (Exception e) {
throw new RuntimeException("Failed to encode categories", e);
}
StringWriter linkList = new StringWriter();
try {
acds.marshal(linkList);
} catch (Exception e) {
throw new RuntimeException("Failed to encode link", e);
}
try {
conf.setConfiguration(CATEGORY_DEFINITION_PATH, catList.toString().replaceFirst("xsi:type=\".*\"", ""));
conf.setConfiguration(ALARM_CATEGORY_DEFINITION_PATH, linkList.toString().replaceFirst("xsi:type=\".*\"", ""));
} catch (Exception e) {
throw new RuntimeException("Failed to store configuration", e);
}
}
Aggregations