use of cern.laser.business.data.Building in project ACS by ACS-Community.
the class CategoryClient method convertAlarmType.
/**
* Convert a CORBA alarm into a client alarm.
*
* @param alarm The CORBA alarm
* @return the client alarm
*/
private Alarm convertAlarmType(alma.alarmsystem.Alarm alarm) {
Source source = new Source();
Building building = new Building(alarm.alarmLocation.buildingNb, alarm.alarmLocation.site, alarm.alarmLocation.zone, alarm.alarmLocation.map);
Location location = new Location(alarm.alarmLocation.locationId, alarm.alarmLocation.floor, alarm.alarmLocation.mnemonic, alarm.alarmLocation.position, alarm.alarmLocation.room);
location.setBuilding(building);
ResponsiblePerson responsiblePerson = new ResponsiblePerson(alarm.alarmResponsiblePerson.responsibleId, alarm.alarmResponsiblePerson.familyName, alarm.alarmResponsiblePerson.firstName, alarm.alarmResponsiblePerson.eMail, alarm.alarmResponsiblePerson.gsmNumber, alarm.alarmResponsiblePerson.phoneNumber);
Properties userProperties = new Properties();
for (org.omg.CosPropertyService.Property prop : alarm.alarmStatus.userProperties) {
userProperties.put(prop.property_name, prop.property_value);
}
Status status = new StatusImpl(Boolean.valueOf(alarm.alarmStatus.active), Boolean.valueOf(alarm.alarmStatus.masked), Boolean.valueOf(alarm.alarmStatus.reduced), Boolean.FALSE, Boolean.FALSE, alarm.alarmStatus.sourceHostname, new Timestamp(alarm.alarmStatus.sourceTimestamp.miliseconds), new Timestamp(alarm.alarmStatus.userTimestamp.miliseconds), new Timestamp(alarm.alarmStatus.systemTimestamp.miliseconds), userProperties);
Triplet triplet = new Triplet(alarm.alarmTriplet.faultFamily, alarm.alarmTriplet.faultMember, alarm.alarmTriplet.faultCode);
Set<cern.laser.business.data.Category> categories = new HashSet<cern.laser.business.data.Category>();
for (Category cat : alarm.categories) {
CategoryImpl catImpl = new CategoryImpl(cat.categoryId, cat.name, cat.description, cat.path, cat.leaf);
categories.add(catImpl);
}
cern.laser.business.data.Alarm businessAlarm = new AlarmImpl(alarm.alarmId, alarm.systemName, alarm.identifier, alarm.problemDescription, Integer.valueOf(alarm.priority), alarm.cause, alarm.action, alarm.consequence, alarm.piquetGSM, alarm.piquetEmail, alarm.helpURL, Boolean.valueOf(alarm.instant), source, location, responsiblePerson, categories, status, triplet, alarm.nodeParent, alarm.multiplicityParent, alarm.nodeChild, alarm.multiplicityChild);
Alarm ret = new cern.laser.client.impl.data.AlarmImpl(businessAlarm);
return ret;
}
use of cern.laser.business.data.Building in project ACS by ACS-Community.
the class AlarmDefinitionServiceImpl method createAlarmInternal.
//
// -- PRIVATE METHODS ----------------------------------------------
//
private Alarm createAlarmInternal(String userId, AlarmDefinition alarmDefinition) throws LaserDefinitionException {
if (alarmDefinition == null) {
throw new LaserDefinitionNotValidException("alarm is null");
}
Alarm alarm = alarmDAO.getAlarm(alarmDefinition.getAlarmId());
if (alarm != null) {
throw new LaserDefinitionDuplicationException("alarm " + alarmDefinition.getAlarmId() + " does already exist");
}
if (alarmDefinition.getSourceName() == null) {
throw new LaserDefinitionNotValidException("source name for the alarm definition is null");
}
Source source = sourceDAO.getSource(alarmDefinition.getSourceName());
if (source == null) {
throw new LaserDefinitionNotFoundException("source " + alarmDefinition.getSourceName() + " does not exist");
}
if (alarmDefinition.getResponsiblePersonId() == null) {
throw new LaserDefinitionNotValidException("responsible id for the alarm definition is null");
}
ResponsiblePerson responsible = responsiblePersonDAO.getResponsiblePerson(alarmDefinition.getResponsiblePersonId());
if (responsible == null) {
throw new LaserDefinitionNotFoundException("responsible with id " + alarmDefinition.getResponsiblePersonId() + " does not exist");
}
AdminUser admin_user = adminUserDAO.findAdminUser(userId);
if (!admin_user.administersSource(source)) {
throw new LaserDefinitionNotAllowedException("not an administrator for the alarm : " + alarmDefinition);
}
LOGGER.info("user " + admin_user.getName() + " creating alarm : " + alarmDefinition);
alarm = new AlarmImpl(alarmDefinition, source, responsible);
String building_number = alarmDefinition.getBuilding();
if (building_number != null && !building_number.equals("")) {
Building building = alarmDAO.findBuilding(building_number);
alarm.getLocation().setBuilding(building);
}
return alarm;
}
use of cern.laser.business.data.Building 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;
}
use of cern.laser.business.data.Building 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();
}
use of cern.laser.business.data.Building in project ACS by ACS-Community.
the class LaserComponent method fromBusinessAlarm.
/**
* Helper method which converts EJB business Alarm to CORBA Alarm structure.
* @param alarm
* @return
*/
private Alarm fromBusinessAlarm(cern.laser.business.data.Alarm alarm) {
cern.laser.business.data.Triplet bt = alarm.getTriplet();
cern.laser.business.data.Location bl = alarm.getLocation();
if (bl.getBuilding() == null) {
bl.setBuilding(new Building("", "", 1, ""));
}
cern.laser.business.data.Status bs = alarm.getStatus();
// Build the properties
Property[] props;
if (alarm.getStatus().getProperties() != null) {
props = new Property[alarm.getStatus().getProperties().size()];
Set keys = alarm.getStatus().getProperties().keySet();
int t = 0;
for (Object key : keys) {
String name = (String) key;
String value = alarm.getStatus().getProperties().getProperty(name);
Any any = corbaServer.getORB().create_any();
any.insert_string(value);
props[t++] = new Property(name, any);
}
} else {
props = new Property[0];
}
Alarm newAlarm = new Alarm(alarm.getAlarmId(), new Triplet(bt.getFaultFamily(), bt.getFaultMember(), bt.getFaultCode().intValue()), getString(alarm.getSystemName()), getString(alarm.getIdentifier()), getString(alarm.getProblemDescription()), alarm.getPriority().intValue(), getString(alarm.getCause()), getString(alarm.getAction()), getString(alarm.getConsequence()), fromBusinessSource(alarm.getSource()), getString(alarm.getHelpURL().toExternalForm()), getString(alarm.getPiquetGSM()), getString(alarm.getPiquetEmail()), fromBusinessResponsiblePerson(alarm.getResponsiblePerson()), new Location(bl.getLocationId(), bl.getFloor(), bl.getRoom(), bl.getPosition(), bl.getMnemonic(), bl.getBuilding().getBuildingNumber(), bl.getBuilding().getSite(), bl.getBuilding().getZone().intValue(), bl.getBuilding().getMap()), fromBusinessCategoryCollection(alarm.getCategories()), new Status(bs.getActive().booleanValue(), bs.getMasked().booleanValue(), bs.getReduced().booleanValue(), new Timestamp(bs.getSourceTimestamp().getTime(), bs.getSourceTimestamp().getNanos()), bs.getSourceHostname(), new Timestamp(bs.getUserTimestamp().getTime(), bs.getUserTimestamp().getNanos()), new Timestamp(bs.getSystemTimestamp().getTime(), bs.getSystemTimestamp().getNanos()), props), alarm.getInstant().booleanValue(), alarm.hasNodeParents(), alarm.hasMultiplicityParents(), alarm.hasNodeChildren(), alarm.hasMultiplicityChildren());
return newAlarm;
}
Aggregations