Search in sources :

Example 16 with Category

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);
}
Also used : Category(cern.laser.business.data.Category)

Example 17 with Category

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);
    }
}
Also used : Category(cern.laser.business.data.Category)

Example 18 with Category

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)));
}
Also used : Category(cern.laser.business.data.Category)

Example 19 with Category

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());
            }
        }
    }
}
Also used : FaultCode(alma.acs.alarmsystem.generated.FaultCode) MalformedURLException(java.net.MalformedURLException) SourceDefinition(cern.laser.business.definition.data.SourceDefinition) Category(cern.laser.business.data.Category) URL(java.net.URL) Source(cern.laser.business.data.Source) InputSource(org.xml.sax.InputSource) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) HashSet(java.util.HashSet) FaultMember(alma.acs.alarmsystem.generated.FaultMember) Triplet(cern.laser.business.data.Triplet) Contact(alma.acs.alarmsystem.generated.Contact) FaultMemberDefault(alma.acs.alarmsystem.generated.FaultMemberDefault) FaultFamily(alma.acs.alarmsystem.generated.FaultFamily) AlarmImpl(cern.laser.business.data.AlarmImpl) Location(cern.laser.business.data.Location)

Example 20 with Category

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);
            }
        }
    }
}
Also used : Category(cern.laser.business.data.Category) AlarmDefinition(alma.alarmsystem.alarmmessage.generated.AlarmDefinition) AlarmCategoryLinkType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkType) 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) Alarm(cern.laser.business.data.Alarm) StringReader(java.io.StringReader) Iterator(java.util.Iterator) AlarmCategoryLinkDefinitionListType(alma.alarmsystem.alarmmessage.generated.AlarmCategoryLinkDefinitionListType) AlarmCategoryDefinitions(alma.alarmsystem.alarmmessage.generated.AlarmCategoryDefinitions) CategoryDefinition(alma.alarmsystem.alarmmessage.generated.CategoryDefinition)

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