mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Added a null check to virtualfire-alarm
This commit is contained in:
parent
cf9daf083d
commit
0fee083c4b
@ -62,6 +62,7 @@ import java.util.*;
|
|||||||
public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
|
public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
|
||||||
|
|
||||||
private static final String XMPP_PROTOCOL = "XMPP";
|
private static final String XMPP_PROTOCOL = "XMPP";
|
||||||
|
private static final String MQTT_PROTOCOL = "MQTT";
|
||||||
private static final String KEY_TYPE = "PRODUCTION";
|
private static final String KEY_TYPE = "PRODUCTION";
|
||||||
private static ApiApplicationKey apiApplicationKey;
|
private static ApiApplicationKey apiApplicationKey;
|
||||||
private static Log log = LogFactory.getLog(VirtualFireAlarmServiceImpl.class);
|
private static Log log = LogFactory.getLog(VirtualFireAlarmServiceImpl.class);
|
||||||
@ -70,13 +71,24 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
|
|||||||
@Path("device/{deviceId}/buzz")
|
@Path("device/{deviceId}/buzz")
|
||||||
public Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
public Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
||||||
@FormParam("state") String state) {
|
@FormParam("state") String state) {
|
||||||
|
if (state == null || state.isEmpty()) {
|
||||||
|
log.error("State is not defined for the buzzer operation");
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
|
}
|
||||||
String switchToState = state.toUpperCase();
|
String switchToState = state.toUpperCase();
|
||||||
if (!switchToState.equals(VirtualFireAlarmConstants.STATE_ON) && !switchToState.equals(
|
if (!switchToState.equals(VirtualFireAlarmConstants.STATE_ON) && !switchToState.equals(
|
||||||
VirtualFireAlarmConstants.STATE_OFF)) {
|
VirtualFireAlarmConstants.STATE_OFF)) {
|
||||||
log.error("The requested state change shoud be either - 'ON' or 'OFF'");
|
log.error("The requested state change shoud be either - 'ON' or 'OFF'");
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
}
|
}
|
||||||
String protocolString = protocol.toUpperCase();
|
String protocolString;
|
||||||
|
|
||||||
|
if (protocol == null || protocol.isEmpty()) {
|
||||||
|
protocolString = MQTT_PROTOCOL;
|
||||||
|
} else {
|
||||||
|
protocolString = protocol.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Sending request to switch-bulb of device [" + deviceId + "] via " +
|
log.debug("Sending request to switch-bulb of device [" + deviceId + "] via " +
|
||||||
protocolString);
|
protocolString);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user