package org.opennaas.core.resources.alarms;
/*
* #%L
* OpenNaaS :: Core :: Resources
* %%
* Copyright (C) 2007 - 2014 FundaciĆ³ Privada i2CAT, Internet i InnovaciĆ³ a Catalunya
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
*/
import java.util.Map;
import javax.xml.bind.annotation.XmlRootElement;
import org.osgi.service.event.Event;
/**
* Defines a ResourceAlarm.
*
* Define which properties are common to ResourceAlarms, although any other property may be added.
*
* @author isart
*
*/
@XmlRootElement
public class ResourceAlarm extends Event {
public static final String TOPIC = "org/opennaas/core/resources/resource/alarms/RECEIVED";
public static final String RESOURCE_ID_PROPERTY = "resourceId";
public static final String ALARM_CODE_PROPERTY = "alarmCode";
public static final String DESCRIPTION_PROPERTY = "alarmDescription";
public static final String SEVERITY_PROPERTY = "alarmSeverity";
public static final String ARRIVAL_TIME_PROPERTY = "arrivalTime";
/* Optional property */
public static final String CAUSE_PROPERY = "cause";
private String resourceId;
private String alarmCode;
private String arrivalTime;
public enum Severity {
INFO, WARNING, MINOR, MAJOR, CRITICAL
}
public ResourceAlarm(Map<String, Object> properties) {
super(TOPIC, properties);
resourceId = properties.get(RESOURCE_ID_PROPERTY).toString();
alarmCode = properties.get(ALARM_CODE_PROPERTY).toString();
arrivalTime = properties.get(ARRIVAL_TIME_PROPERTY).toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((alarmCode == null) ? 0 : alarmCode.hashCode());
result = prime * result + ((arrivalTime == null) ? 0 : arrivalTime.hashCode());
result = prime * result + ((resourceId == null) ? 0 : resourceId.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
ResourceAlarm other = (ResourceAlarm) obj;
if (alarmCode == null) {
if (other.alarmCode != null)
return false;
} else if (!alarmCode.equals(other.alarmCode))
return false;
if (arrivalTime == null) {
if (other.arrivalTime != null)
return false;
} else if (!arrivalTime.equals(other.arrivalTime))
return false;
if (resourceId == null) {
if (other.resourceId != null)
return false;
} else if (!resourceId.equals(other.resourceId))
return false;
return true;
}
}