Search in sources :

Example 6 with CategoryImpl

use of cern.laser.business.data.CategoryImpl 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 7 with CategoryImpl

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

the class ACSCategoryDAOImpl method setParentID.

/**
	 * Set the parent ID of the passed category
	 * 
	 * Each category has a parent ID that can be evaluated by reading
	 * the name of the category.
	 * If the name does not contain ':' then the parent ID is the ROOT.
	 * Otherwise its parent is the category whose name is represented
	 * by the substring before the ':'
	 * 
	 * @param cat
	 */
private void setParentID(CategoryImpl cat) {
    if (cat.getPath().equals("ROOT")) {
        // ROOT has no parent
        cat.setParentId(null);
        return;
    }
    String name = cat.getPath();
    int pos = name.lastIndexOf(':');
    if (pos == -1) {
        // This category parent is ROOT
        Category root = getCategoryByPath("ROOT");
        cat.setParentId(root.getCategoryId());
        cat.setPath(cat.getPath());
        cat.setName(cat.getPath());
        return;
    }
    String parentID = name.substring(0, pos);
    CategoryImpl parent = (CategoryImpl) getCategoryByPath(parentID);
    if (parent == null) {
        logger.log(AcsLogLevel.WARNING, "Parent category of " + parentID + " NOT found");
        return;
    }
    cat.setParentId(parent.getCategoryId());
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl) Category(cern.laser.business.data.Category)

Example 8 with CategoryImpl

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

the class ACSCategoryDAOImpl method saveCategory.

public void saveCategory(Category category) {
    // actual save is done in flushCategory();
    CategoryImpl cimpl = (CategoryImpl) category;
    if (cimpl.getCategoryId() == null) {
        cimpl.setCategoryId(new Integer(nextCatID++));
    }
    categories.put(cimpl.getCategoryId(), cimpl);
    if (cimpl.getPath() != null)
        catPathToCategory.put(cimpl.getPath(), cimpl);
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl)

Example 9 with CategoryImpl

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

the class SourceDefinitionServiceImpl method createSource.

public void createSource(String userId, SourceDefinition sourceDefinition) throws LaserDefinitionException {
    if (sourceDefinition == null) {
        throw new LaserDefinitionNotValidException("source is null");
    }
    Source source = sourceDAO.getSource(sourceDefinition.getSourceId());
    if (source != null) {
        throw new LaserDefinitionDuplicationException("source " + sourceDefinition.getSourceId() + " already exist");
    }
    if (sourceDefinition.getResponsiblePersonId() == null) {
        throw new LaserDefinitionNotValidException("responsible id for the source definition is null");
    }
    ResponsiblePerson responsible = responsiblePersonDAO.getResponsiblePerson(sourceDefinition.getResponsiblePersonId());
    if (responsible == null) {
        throw new LaserDefinitionNotValidException("responsible with id " + sourceDefinition.getResponsiblePersonId() + " does not exist");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    AdminUser laser_user = adminUserDAO.findByLaserAdminUser();
    LOGGER.info("user " + admin_user.getName() + " creating source : " + sourceDefinition);
    // create the source
    source = new Source(sourceDefinition, responsible);
    CategoryDefinition category_definition = new CategoryDefinition(SOURCE_CATEGORY_PATH_PREFIX + sourceDefinition.getName(), "Category for source " + sourceDefinition.getName());
    Category parent_category = categoryDAO.findCategoryByPath(category_definition.getParentPath());
    Category category = new CategoryImpl(category_definition);
    parent_category.addChildCategory(category);
    categoryDAO.saveCategory(category);
    admin_user.addAdministeredCategory(category);
    laser_user.addAdministeredCategory(category);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("default category " + category_definition.getPath() + "created for source " + sourceDefinition.getName());
    source.setSurveillanceAlarmId(alarmDAO.findLaserSurveillanceAlarmId());
    sourceDAO.saveSource(source);
    // create the source surveillance alarm
    AlarmDefinition surveillance_alarm_definition = (AlarmDefinition) SOURCE_SURVEILLANCE_ALARM_DEFINITION.clone();
    surveillance_alarm_definition.setFaultMember(sourceDefinition.getName());
    surveillance_alarm_definition.setIdentifier(sourceDefinition.getName());
    Alarm surveillance_alarm = new AlarmImpl(surveillance_alarm_definition, source, responsible);
    Category surveillance_category = categoryDAO.findBySurveillanceCategory();
    surveillance_category.addAlarm(surveillance_alarm);
    category.addAlarm(surveillance_alarm);
    alarmDAO.saveAlarm(surveillance_alarm);
    categoryDAO.updateCategory(surveillance_category);
    categoryDAO.updateCategory(category);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("surveillance alarm created for source " + sourceDefinition.getName());
    source.setSurveillanceAlarmId(surveillance_alarm.getAlarmId());
    sourceDAO.updateSource(source);
    admin_user.addAdministeredSource(source);
    laser_user.addAdministeredSource(source);
    adminUserDAO.updateAdminUser(admin_user);
    adminUserDAO.updateAdminUser(laser_user);
    LOGGER.info("source created");
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) AlarmDefinition(cern.laser.business.definition.data.AlarmDefinition) Alarm(cern.laser.business.data.Alarm) AlarmImpl(cern.laser.business.data.AlarmImpl) AdminUser(cern.laser.business.data.AdminUser) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) Source(cern.laser.business.data.Source) CategoryDefinition(cern.laser.business.definition.data.CategoryDefinition)

Example 10 with CategoryImpl

use of cern.laser.business.data.CategoryImpl 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);
    }
}
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) CategoryImpl(cern.laser.business.data.CategoryImpl) StringWriter(java.io.StringWriter) Alarm(cern.laser.business.data.Alarm) AlarmCategoryLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkDefinitionListType) CategoryDefinitionListType(alma.alarmsystem.alarmmessage.generated.CategoryDefinitionListType) AlarmCategoryDefinitions(alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions) CategoryDefinition(alma.alarmsystem.alarmmessage.generated.CategoryDefinition)

Aggregations

CategoryImpl (cern.laser.business.data.CategoryImpl)24 Category (cern.laser.business.data.Category)14 HashSet (java.util.HashSet)8 CategoryDefinition (alma.alarmsystem.alarmmessage.generated.CategoryDefinition)6 LaserObjectNotFoundException (cern.laser.business.LaserObjectNotFoundException)6 Alarm (cern.laser.business.data.Alarm)5 StringReader (java.io.StringReader)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)3 ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)3 Source (cern.laser.business.data.Source)3 IOException (java.io.IOException)3 Categories (alma.acs.alarmsystem.generated.Categories)2 CategoryDefinitionListType (alma.alarmsystem.alarmmessage.generated.CategoryDefinitionListType)2 CategoryDefinitions (alma.alarmsystem.alarmmessage.generated.CategoryDefinitions)2 AdminUser (cern.laser.business.data.AdminUser)2 Building (cern.laser.business.data.Building)2