Search in sources :

Example 6 with ResponsiblePerson

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

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

the class AlarmDefinitionServiceImpl method updateAlarm.

public void updateAlarm(String userId, AlarmDefinition alarmDefinition) throws LaserDefinitionException {
    if (alarmDefinition == null) {
        throw new LaserDefinitionNotValidException("alarm is null");
    }
    AdminUser admin_user = adminUserDAO.findAdminUser(userId);
    Alarm alarm = alarmDAO.findAlarm(alarmDefinition.getAlarmId());
    Source new_source = sourceDAO.findSource(alarmDefinition.getSourceName());
    Source old_source = alarm.getSource();
    if (!(admin_user.administersSource(new_source) && admin_user.administersSource(old_source))) {
        throw new LaserDefinitionNotAllowedException("not an administrator for the alarm : " + alarmDefinition);
    }
    if (!new_source.equals(old_source)) {
        //      old_source.removeAlarm(alarm);
        new_source.addAlarm(alarm);
        String old_category_path = SOURCE_CATEGORY_PATH_PREFIX + old_source.getName();
        Category old_category = categoryDAO.findCategory(new Integer(old_category_path.hashCode()));
        old_category.removeAlarm(alarm);
        String new_category_path = SOURCE_CATEGORY_PATH_PREFIX + alarmDefinition.getSourceName();
        Category new_category = categoryDAO.findCategory(new Integer(new_category_path.hashCode()));
        new_category.addAlarm(alarm);
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("alarm removed from category " + old_category_path + " and added to category " + new_category_path);
        sourceDAO.updateSource(old_source);
        sourceDAO.updateSource(new_source);
        categoryDAO.updateCategory(old_category);
        categoryDAO.updateCategory(new_category);
    }
    LOGGER.info("user " + admin_user.getName() + " updating alarm : " + alarmDefinition);
    if (!alarm.getResponsiblePerson().getResponsibleId().equals(alarmDefinition.getResponsiblePersonId())) {
        //        ResponsiblePerson old_responsible = alarm.getResponsiblePerson();
        //        old_responsible.getAlarmIds().remove(alarm.getAlarmId());
        ResponsiblePerson new_responsible = alarmDefinition.getResponsiblePersonId() == null ? new_source.getResponsiblePerson() : responsiblePersonDAO.getResponsiblePerson(alarmDefinition.getResponsiblePersonId());
        //        new_responsible.getAlarmIds().add(alarm.getAlarmId());
        alarm.setResponsiblePerson(new_responsible);
    //        session.update(old_responsible);
    //        session.update(new_responsible);
    }
    alarm.setDefinition(alarmDefinition);
    alarmDAO.updateAlarm(alarm);
    try {
        alarmCache.invalidate(alarmDefinition.getAlarmId());
    } catch (Exception e) {
        LOGGER.error("unable to propagate alarm update : " + alarmDefinition, e);
    }
    LOGGER.info("alarm updated");
}
Also used : LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) Category(cern.laser.business.data.Category) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) Alarm(cern.laser.business.data.Alarm) AdminUser(cern.laser.business.data.AdminUser) Source(cern.laser.business.data.Source) LaserDefinitionNotFoundException(cern.laser.business.definition.LaserDefinitionNotFoundException) LaserDefinitionNotAllowedException(cern.laser.business.definition.LaserDefinitionNotAllowedException) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserDefinitionDuplicationException(cern.laser.business.definition.LaserDefinitionDuplicationException) LaserDefinitionException(cern.laser.business.definition.LaserDefinitionException) LaserDefinitionNotValidException(cern.laser.business.definition.LaserDefinitionNotValidException) AlarmCacheException(cern.laser.business.cache.AlarmCacheException)

Example 8 with ResponsiblePerson

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

the class ACSAlarmCacheImpl method buildUnconfiguredAlarm.

/**
	 * Build a unconfigured alarm from the passed ID.
	 * 
	 * A unconfigured alarm has no data but the triplet generated
	 * from the identifier.
	 * I associate the lowest priority and a user property
	 * to be recognized by clients as being generated by the AS instead
	 * of being retrieved from the configuration database.
	 * <P>
	 * The property identifying this alarm as generated by the AS is:
	 * <Name="AlarmServerProp", Value="UnconfiguredAlarm">
	 * <P>
	 * The alarm is associated to the ROOT category.
	 * 
	 * @param alarmID The ID of the alarm
	 * @return The default alarm
	 */
private Alarm buildUnconfiguredAlarm(String alarmID) {
    if (alarmID == null || alarmID.isEmpty()) {
        throw new IllegalArgumentException("Invalid null or empty alarm ID!");
    }
    String[] parts = alarmID.split(":");
    if (parts.length != 3) {
        throw new IllegalArgumentException("Invalid alarm ID: " + alarmID);
    }
    String FF = parts[0];
    String FM = parts[1];
    Integer FC;
    try {
        FC = Integer.valueOf(parts[2]);
    } catch (NumberFormatException nfe) {
        throw new IllegalArgumentException("Invalid FC in alarm ID: " + alarmID, nfe);
    }
    AlarmImpl alarm = new AlarmImpl();
    alarm.setMultiplicityChildrenIds(new HashSet());
    alarm.setMultiplicityParentIds(new HashSet());
    alarm.setNodeChildrenIds(new HashSet());
    alarm.setNodeParentIds(new HashSet());
    alarm.setAction(EMPTY_STRING);
    alarm.setTriplet(new Triplet(FF, FM, FC));
    alarm.setCategories(new HashSet<Category>());
    alarm.setCause(EMPTY_STRING);
    alarm.setConsequence(EMPTY_STRING);
    alarm.setProblemDescription(EMPTY_STRING);
    alarm.setHelpURL(null);
    alarm.setInstant(false);
    Location location = new Location("0", EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING);
    alarm.setLocation(location);
    alarm.setPiquetEmail(EMPTY_STRING);
    alarm.setPiquetGSM(EMPTY_STRING);
    alarm.setPriority(3);
    ResponsiblePerson responsible = new ResponsiblePerson(1, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING, EMPTY_STRING);
    alarm.setResponsiblePerson(responsible);
    SourceDefinition srcDef = new SourceDefinition("ALARM_SYSTEM_SOURCES", "SOURCE", EMPTY_STRING, 15, 1);
    Source src = new Source(srcDef, responsible);
    alarm.setSource(src);
    alarm.setIdentifier(alarm.getTriplet().toIdentifier());
    // Build the status in order to associate the property
    Properties userProps = new Properties();
    userProps.put(alarmServerPropkey, undocumentedAlarmProp);
    StatusImpl status = new StatusImpl(false, false, false, false, false, EMPTY_STRING, new Timestamp(0), new Timestamp(0), new Timestamp(0), userProps);
    alarm.setStatus(status);
    // Category association
    //
    // A category for this FF can be already set (this is the case when a new FC/FM is found
    // but the FF has already been associated to a category)
    // In practice a new category has to be defined only if the FF is unknown.
    Category[] categories = categoryDAO.findAllCategories();
    Set<Category> categoriesSet = new HashSet<Category>();
    for (Category cat : categories) {
        if (cat.containsAlarm(alarm)) {
            categoriesSet.add(cat);
        }
    }
    if (!categoriesSet.isEmpty()) {
        System.out.println("Alarm " + alarm.getAlarmId() + " already associated to categories");
    } else {
        System.out.println("Alarm " + alarm.getAlarmId() + " has no associated category");
        Category root = categoryDAO.findCategoryByPath("ROOT");
        categoriesSet.add(root);
        alarm.setCategories(categoriesSet);
        root.addAlarm(alarm);
    }
    return alarm;
}
Also used : SourceDefinition(cern.laser.business.definition.data.SourceDefinition) Category(cern.laser.business.data.Category) 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) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) AlarmImpl(cern.laser.business.data.AlarmImpl) HashSet(java.util.HashSet) Location(cern.laser.business.data.Location)

Example 9 with ResponsiblePerson

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

the class ACSAlarmDAOImpl method encodeToXML.

static String encodeToXML(StringBuffer result, Alarm alarm) {
    result.append("<alarm-definition");
    Triplet t = alarm.getTriplet();
    if (t == null || t.getFaultCode() == null || t.getFaultFamily() == null || t.getFaultMember() == null)
        throw new IllegalArgumentException("Incomplete alarm");
    DAOUtil.encodeAttr(result, "fault-family", t.getFaultFamily());
    DAOUtil.encodeAttr(result, "fault-member", t.getFaultMember());
    DAOUtil.encodeAttr(result, "fault-code", t.getFaultCode().toString());
    result.append(">\n");
    {
        String sn = alarm.getSystemName();
        String si = alarm.getIdentifier();
        String pd = alarm.getProblemDescription();
        if (sn != null || si != null || pd != null) {
            result.append("\t<visual-fields>\n");
            if (sn != null)
                DAOUtil.encodeElem(result, "system-name", sn, 2);
            if (si != null)
                DAOUtil.encodeElem(result, "identifier", si, 2);
            if (pd != null)
                DAOUtil.encodeElem(result, "problem-description", pd, 2);
            result.append("\t</visual-fields>\n");
        }
    }
    DAOUtil.encodeElemIf(result, "instant", alarm.getInstant(), 1);
    DAOUtil.encodeElemIf(result, "cause", alarm.getCause(), 1);
    DAOUtil.encodeElemIf(result, "action", alarm.getAction(), 1);
    DAOUtil.encodeElemIf(result, "consequence", alarm.getConsequence(), 1);
    DAOUtil.encodeElemIf(result, "priority", alarm.getPriority(), 1);
    ResponsiblePerson rp = alarm.getResponsiblePerson();
    if (rp != null)
        DAOUtil.encodeElemIf(result, "responsible-id", rp.getResponsibleId(), 1);
    DAOUtil.encodeElemIf(result, "piquetGSM", alarm.getPiquetGSM(), 1);
    DAOUtil.encodeElemIf(result, "help-url", alarm.getHelpURL(), 1);
    Source s = alarm.getSource();
    if (s != null)
        DAOUtil.encodeElemIf(result, "source-name", s.getName(), 1);
    Location l = alarm.getLocation();
    if (l != null) {
        result.append("\t<location>\n");
        Building b = l.getBuilding();
        if (b != null)
            DAOUtil.encodeElemIf(result, "building", b.getBuildingNumber(), 2);
        DAOUtil.encodeElemIf(result, "floor", l.getFloor(), 2);
        DAOUtil.encodeElemIf(result, "room", l.getRoom(), 2);
        DAOUtil.encodeElemIf(result, "mnemonic", l.getMnemonic(), 2);
        DAOUtil.encodeElemIf(result, "position", l.getPosition(), 2);
        result.append("\t</location>\n");
    }
    DAOUtil.encodeElemIf(result, "piquetEmail", alarm.getPiquetEmail(), 1);
    result.append("</alarm-definition>\n");
    return result.toString();
}
Also used : Building(cern.laser.business.data.Building) ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) Triplet(cern.laser.business.data.Triplet) Source(cern.laser.business.data.Source) InputSource(org.xml.sax.InputSource) Location(cern.laser.business.data.Location)

Example 10 with ResponsiblePerson

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

the class CoreServiceImpl method getResponsiblePersons.

/*
   * (non-Javadoc)
   * 
   * @see cern.laser.business.ejb.CoreServiceSessionEJB#getResponsiblePersons()
   */
public Collection getResponsiblePersons() {
    Collection result = null;
    try {
        ResponsiblePerson[] responsibles_ejb = responsiblePersonDAO.findAllResponsiblePersons();
        result = new ArrayList(responsibles_ejb.length);
        for (int i = 0; i < responsibles_ejb.length; i++) {
            result.add(responsibles_ejb[i]);
        }
    } catch (Exception e) {
        LOGGER.error("unable to get alarm responsibles", e);
    //throw new EJBException("unable to get alarm responsibles", e);
    }
    return result;
}
Also used : ResponsiblePerson(cern.laser.business.data.ResponsiblePerson) ArrayList(java.util.ArrayList) Collection(java.util.Collection) LaserRuntimeException(cern.laser.business.LaserRuntimeException) LaserProcessingException(cern.laser.business.LaserProcessingException) AlarmCacheException(cern.laser.business.cache.AlarmCacheException)

Aggregations

ResponsiblePerson (cern.laser.business.data.ResponsiblePerson)10 Source (cern.laser.business.data.Source)9 AlarmImpl (cern.laser.business.data.AlarmImpl)7 Location (cern.laser.business.data.Location)6 Triplet (cern.laser.business.data.Triplet)6 Category (cern.laser.business.data.Category)5 HashSet (java.util.HashSet)5 Building (cern.laser.business.data.Building)4 AdminUser (cern.laser.business.data.AdminUser)3 Alarm (cern.laser.business.data.Alarm)3 CategoryImpl (cern.laser.business.data.CategoryImpl)3 StatusImpl (cern.laser.business.data.StatusImpl)3 LaserDefinitionDuplicationException (cern.laser.business.definition.LaserDefinitionDuplicationException)3 LaserDefinitionNotValidException (cern.laser.business.definition.LaserDefinitionNotValidException)3 SourceDefinition (cern.laser.business.definition.data.SourceDefinition)3 Timestamp (java.sql.Timestamp)3 Properties (java.util.Properties)3 InputSource (org.xml.sax.InputSource)3 Contact (alma.acs.alarmsystem.generated.Contact)2 FaultCode (alma.acs.alarmsystem.generated.FaultCode)2