Search in sources :

Example 16 with CategoryImpl

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

the class AlarmMessageConversion method getAlarm.

public static synchronized AlarmImpl getAlarm(String xml) throws ValidationException, MarshalException, ParseException {
    if (xml == null) {
        throw new IllegalArgumentException();
    }
    StringReader strReader = new StringReader(xml);
    ACSAlarmMessage alarm = ACSAlarmMessage.unmarshalACSAlarmMessage(strReader);
    // Primitive field
    String alarmId = alarm.getAlarmId();
    String systemName = alarm.getSystemName();
    String identifier = alarm.getIdent();
    String problemDescription = alarm.getProblemDescription();
    Integer priority = new Integer(alarm.getPriority());
    String cause = alarm.getCause();
    String action = alarm.getAction();
    String consequence = alarm.getConsequence();
    String piquetGSM = alarm.getPiquetGSM();
    String piquetEmail = alarm.getPiquetEmail();
    String helpURLString = alarm.getHelpURLString();
    Boolean instant = new Boolean(alarm.getInstant());
    boolean nodeParent = alarm.getNodeParent();
    boolean multiplicityParent = alarm.getMultiplicityParent();
    boolean nodeChild = alarm.getNodeChild();
    boolean multiplicityChild = alarm.getMultiplicityChild();
    // The Triplet
    Triplet triplet = new Triplet(alarm.getTriplet().getFaultFamily(), alarm.getTriplet().getFaultMember(), new Integer(alarm.getTriplet().getFaultCode()));
    // The Building
    Building building;
    if (alarm.getLocation() != null) {
        if (alarm.getLocation().getBuilding() != null) {
            building = new Building(alarm.getLocation().getBuilding().getBuildingNumber(), alarm.getLocation().getBuilding().getSite(), new Integer(alarm.getLocation().getBuilding().getZone()), alarm.getLocation().getBuilding().getMap());
        } else {
            building = new Building("N/A", ",N/A", 0, "N/A");
        }
    } else {
        building = new Building("N/A", ",N/A", 0, "N/A");
    }
    // The Location
    Location location;
    if (alarm.getLocation() != null) {
        location = new Location(alarm.getLocation().getLocationId(), alarm.getLocation().getFloor(), alarm.getLocation().getMnemonic(), alarm.getLocation().getPosition(), alarm.getLocation().getRoom());
    } else {
        location = new Location("N/A", "N/A", "N/A", "N/A", "N/A");
    }
    location.setBuilding(building);
    // The ResponsiblePerson
    ResponsiblePerson responsiblePerson = null;
    if (alarm.getResponsiblePerson() != null) {
        responsiblePerson = new ResponsiblePerson(new Integer(alarm.getResponsiblePerson().getResponsibleId()), alarm.getResponsiblePerson().getFirstName(), alarm.getResponsiblePerson().getFamilyName(), alarm.getResponsiblePerson().getEMail(), alarm.getResponsiblePerson().getGsmNumber(), alarm.getResponsiblePerson().getPhoneNumber());
    }
    // The Source
    Source source = new Source();
    source.setSourceId(alarm.getSource().getSourceId());
    source.setDescription(alarm.getSource().getDescription());
    source.setConnectionTimeout(new Integer(alarm.getSource().getConnectionTimeout()));
    source.setSurveillanceAlarmId(alarm.getSource().getSurveillanceAlarmId());
    source.setHostName(alarm.getSource().getHostName());
    ResponsiblePerson responsiblePersonSrc = new ResponsiblePerson(new Integer(alarm.getSource().getResponsiblePerson().getResponsibleId()), alarm.getSource().getResponsiblePerson().getFirstName(), alarm.getSource().getResponsiblePerson().getFamilyName(), alarm.getSource().getResponsiblePerson().getEMail(), alarm.getSource().getResponsiblePerson().getGsmNumber(), alarm.getSource().getResponsiblePerson().getPhoneNumber());
    source.setResponsiblePerson(responsiblePersonSrc);
    HashSet set = new HashSet();
    for (int pos = 0; pos < alarm.getSource().getAlarmIds().length; pos++) {
        set.add(alarm.getSource().getAlarmIds()[pos]);
    }
    source.setAlarmIds(set);
    Timestamp lastContact = null;
    if (alarm.getSource().getSourceStatus().getLastContact() != null) {
        Date date = IsoDateFormat.parseIsoTimestamp(alarm.getSource().getSourceStatus().getLastContact());
        lastContact = new Timestamp(date.getTime());
    }
    SourceStatus sourceStatus = new SourceStatus(new Boolean(alarm.getSource().getSourceStatus().getConnected()), new Boolean(alarm.getSource().getSourceStatus().getEnabled()), lastContact);
    source.setStatus(sourceStatus);
    // The Status
    Timestamp sourceTimestamp = new Timestamp(IsoDateFormat.parseIsoTimestamp(alarm.getStatus().getSourceTimestamp()).getTime());
    Timestamp userTimestamp = new Timestamp(IsoDateFormat.parseIsoTimestamp(alarm.getStatus().getUserTimestamp()).getTime());
    Timestamp systemTimestamp = new Timestamp(IsoDateFormat.parseIsoTimestamp(alarm.getStatus().getSystemTimestamp()).getTime());
    // The properties
    ACSProperty[] props = alarm.getStatus().getPersistentUserProperties();
    Properties properties = new Properties();
    for (int pos = 0; pos < props.length; pos++) {
        properties.put(props[pos].getKey(), props[pos].getValue());
    }
    StatusImpl status = new StatusImpl(new Boolean(alarm.getStatus().getActive()), new Boolean(alarm.getStatus().getMasked()), new Boolean(alarm.getStatus().getReduced()), new Boolean(alarm.getStatus().getActivatedByBackup()), new Boolean(alarm.getStatus().getTerminatedByBackup()), alarm.getStatus().getSourceHostname(), sourceTimestamp, userTimestamp, systemTimestamp, properties);
    // The Categories
    HashSet categories = new HashSet();
    for (int pos = 0; pos < alarm.getCategoriesCount(); pos++) {
        ACSCategory cat = alarm.getCategories(pos);
        CategoryImpl catImpl = new CategoryImpl(new Integer(cat.getCategoryId()), cat.getName(), cat.getDescription(), cat.getPath(), cat.getIsLeaf());
        catImpl.setParentId(new Integer(cat.getParentId()));
        HashSet alarmIds = new HashSet();
        if (cat.getAlarmIdsCount() > 0) {
            for (pos = 0; pos < cat.getAlarmIdsCount(); pos++) {
                alarmIds.add(cat.getAlarmIds(pos));
            }
            catImpl.setAlarmIds(alarmIds);
        }
        HashSet childrenIds = new HashSet();
        if (cat.getChildrenIdsCount() > 0) {
            for (pos = 0; pos < cat.getChildrenIdsCount(); pos++) {
                childrenIds.add(cat.getChildrenIds(pos));
            }
            catImpl.setChildrenIds(childrenIds);
        }
        categories.add(catImpl);
    }
    // MutiplicityChildIds (added later to alarmImpl)
    HashSet MultiplicityChildIds = new HashSet();
    if (alarm.getMultiplicityChildrenIdsCount() > 0) {
        for (int pos = 0; pos < alarm.getMultiplicityChildrenIdsCount(); pos++) {
            MultiplicityChildIds.add(alarm.getMultiplicityChildrenIds(pos));
        }
    }
    // MutiplicityParentIds (added later to alarmImpl)
    HashSet MultiplicityParentIds = new HashSet();
    if (alarm.getMultiplicityParentIdsCount() > 0) {
        for (int pos = 0; pos < alarm.getMultiplicityParentIdsCount(); pos++) {
            MultiplicityParentIds.add(alarm.getMultiplicityParentIds(pos));
        }
    }
    // NodeChildIds (added later to alarmImpl)
    HashSet NodeChildIds = new HashSet();
    if (alarm.getNodeChildrenIdsCount() > 0) {
        for (int pos = 0; pos < alarm.getNodeChildrenIdsCount(); pos++) {
            NodeChildIds.add(alarm.getNodeChildrenIds(pos));
        }
    }
    // NodeParentIds (added later to alarmImpl)
    HashSet NodeParentIds = new HashSet();
    if (alarm.getNodeParentIdsCount() > 0) {
        for (int pos = 0; pos < alarm.getNodeParentIdsCount(); pos++) {
            NodeParentIds.add(alarm.getNodeParentIds(pos));
        }
    }
    // The multiplicity threshold (added later to alarmImpl)
    int multiplityThreshold = alarm.getMultiplicityThreshold();
    AlarmImpl alarmImpl = new AlarmImpl(alarmId, systemName, identifier, problemDescription, priority, cause, action, consequence, piquetGSM, piquetEmail, helpURLString, instant, source, location, responsiblePerson, categories, status, triplet, nodeParent, multiplicityParent, nodeChild, multiplicityChild);
    alarmImpl.setNodeParentIds(NodeParentIds);
    alarmImpl.setNodeChildrenIds(NodeChildIds);
    alarmImpl.setMultiplicityChildrenIds(MultiplicityChildIds);
    alarmImpl.setMultiplicityParentIds(MultiplicityParentIds);
    alarmImpl.setMultiplicityThreshold(new Integer(multiplityThreshold));
    return alarmImpl;
}
Also used : Building(cern.laser.business.data.Building) SourceStatus(cern.laser.business.data.SourceStatus) Triplet(cern.laser.business.data.Triplet) StatusImpl(cern.laser.business.data.StatusImpl) Properties(java.util.Properties) Timestamp(java.sql.Timestamp) Source(cern.laser.business.data.Source) Date(java.util.Date) CategoryImpl(cern.laser.business.data.CategoryImpl) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) AlarmImpl(cern.laser.business.data.AlarmImpl) StringReader(java.io.StringReader) Location(cern.laser.business.data.Location) HashSet(java.util.HashSet)

Example 17 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 18 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 19 with CategoryImpl

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

the class ACSCategoryDAOImpl method dumpCategories.

/**
	 * Dumps the category.
	 * 
	 */
private void dumpCategories() {
    Set<Integer> keys = categories.keySet();
    if (keys == null || keys.size() == 0) {
        System.out.println("No categories");
    }
    for (Integer i : keys) {
        CategoryImpl cat = (CategoryImpl) getCategory(i);
        if (cat == null) {
            System.out.println("Null categor for ID " + i);
        }
        System.out.println("Category ID=" + cat.getCategoryId());
        System.out.println("\tName: " + cat.getName());
        System.out.println("\tPath: " + cat.getPath());
        System.out.println("\tDesc: " + cat.getDescription());
        System.out.println("\tParentID: " + cat.getParentId());
        System.out.println("\tChildren: ");
        Set<Integer> childs = cat.getChildrenIds();
        if (childs == null || childs.size() == 0) {
            System.out.println("\t\tNo childs");
        } else {
            for (Integer child : childs) {
                System.out.println("\t\t" + child);
            }
        }
    }
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl)

Example 20 with CategoryImpl

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

the class ACSCategoryDAOImpl method addRootCategory.

/**
	 * Add the ROOT category
	 * 
	 * This avoid the user to add this entry in the CDB
	 */
private void addRootCategory() {
    CategoryImpl ci = new CategoryImpl();
    // will get filled in later
    ci.setAlarmIds(new HashSet());
    ci.setCategoryId(new Integer(nextCatID++));
    ci.setChildrenIds(new HashSet());
    ci.setDescription("ROOT category");
    ci.setName("ROOT");
    ci.setParentId(null);
    ci.setPath("ROOT");
    ci.setAlarmIds(new HashSet());
    // Stores the categories
    categories.put(ci.getCategoryId(), ci);
    catPathToCategory.put(ci.getPath(), ci);
}
Also used : CategoryImpl(cern.laser.business.data.CategoryImpl) HashSet(java.util.HashSet)

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