Search in sources :

Example 46 with Category

use of cern.laser.business.data.Category 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);
    }
}
Also used : Category(cern.laser.business.data.Category) AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) AlarmCategoryLinkType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType) CategoryDefinitions(alma.alarmsystem.alarmmessage.generated.CategoryDefinitions) AlarmCategoryDefinitions(alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions) LaserObjectNotFoundException(cern.laser.business.LaserObjectNotFoundException) ValidationException(org.exolab.castor.xml.ValidationException) MarshalException(org.exolab.castor.xml.MarshalException) IOException(java.io.IOException) CategoryImpl(cern.laser.business.data.CategoryImpl) StringWriter(java.io.StringWriter) Alarm(cern.laser.business.data.Alarm) Iterator(java.util.Iterator) AlarmCategoryLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkDefinitionListType) CategoryDefinitionListType(alma.alarmsystem.alarmmessage.generated.CategoryDefinitionListType) AlarmCategoryDefinitions(alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions) CategoryDefinition(alma.alarmsystem.alarmmessage.generated.CategoryDefinition)

Example 47 with Category

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

the class ACSCategoryDAOImpl method getAlarms.

public String[] getAlarms(Integer categoryId) {
    Category c = getCategory(categoryId);
    if (c == null)
        return new String[0];
    Set ids = ((CategoryImpl) c).getAlarmIds();
    String[] result = new String[ids.size()];
    ids.toArray(result);
    return result;
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl) Category(cern.laser.business.data.Category) HashSet(java.util.HashSet) Set(java.util.Set)

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