Fix issue in service ep

charithag 9 years ago
parent 5f8a94f4c6
commit 9e7e0aa845

@ -31,4 +31,5 @@ public class VirtualFireAlarmConstants {
public static final String TEMPERATURE_CONTEXT = "/TEMPERATURE/"; public static final String TEMPERATURE_CONTEXT = "/TEMPERATURE/";
public static final String SENSOR_TEMP = "temperature"; public static final String SENSOR_TEMP = "temperature";
public static final String SENSOR_HUMIDITY = "humidity";
} }

@ -648,7 +648,6 @@ public class VirtualFireAlarmService {
/** /**
*
* @param owner * @param owner
* @param deviceId * @param deviceId
* @param protocol * @param protocol
@ -657,25 +656,23 @@ public class VirtualFireAlarmService {
*/ */
@Path("controller/readhumidity") @Path("controller/readhumidity")
@GET @GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Feature(code = "readhumidity", name = "Humidity", type = "monitor", @Feature(code = "readhumidity", name = "Humidity", type = "monitor",
description = "Read Humidity Readings from Virtual Fire Alarm") description = "Read Humidity Readings from Virtual Fire Alarm")
public String requestHumidity(@HeaderParam("owner") String owner, public SensorRecord requestHumidity(@HeaderParam("owner") String owner,
@HeaderParam("deviceId") String deviceId, @HeaderParam("deviceId") String deviceId,
@HeaderParam("protocol") String protocol, @HeaderParam("protocol") String protocol,
@Context HttpServletResponse response) { @Context HttpServletResponse response) {
String replyMsg = ""; SensorRecord sensorRecord = null;
DeviceValidator deviceValidator = new DeviceValidator(); DeviceValidator deviceValidator = new DeviceValidator();
try { try {
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier( if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(
deviceId, VirtualFireAlarmConstants.DEVICE_TYPE))) { deviceId, VirtualFireAlarmConstants.DEVICE_TYPE))) {
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode()); response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
return "Unauthorized Access Attempt";
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
replyMsg = e.getErrorMessage();
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return replyMsg;
} }
String protocolString = protocol.toUpperCase(); String protocolString = protocol.toUpperCase();
@ -689,14 +686,16 @@ public class VirtualFireAlarmService {
case HTTP_PROTOCOL: case HTTP_PROTOCOL:
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId); String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
if (deviceHTTPEndpoint == null) { if (deviceHTTPEndpoint == null) {
replyMsg = "IP not registered for device: " + deviceId + " of owner: " + owner;
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
return replyMsg;
} }
replyMsg = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, String humidityValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint,
VirtualFireAlarmConstants.HUMIDITY_CONTEXT, VirtualFireAlarmConstants.HUMIDITY_CONTEXT,
false); false);
SensorDataManager.getInstance().setSensorRecord(deviceId,
VirtualFireAlarmConstants.SENSOR_TEMP,
humidityValue,
Calendar.getInstance().getTimeInMillis());
break; break;
case MQTT_PROTOCOL: case MQTT_PROTOCOL:
@ -710,22 +709,18 @@ public class VirtualFireAlarmService {
break; break;
default: default:
replyMsg = "Requested protocol '" + protocolString + "' is not supported";
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode()); response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
return replyMsg;
} }
} catch (DeviceManagementException | TransportHandlerException e) { sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId,
replyMsg = e.getMessage(); VirtualFireAlarmConstants.SENSOR_HUMIDITY);
} catch (DeviceManagementException | DeviceControllerException | TransportHandlerException e) {
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()); response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
return replyMsg;
} }
response.setStatus(Response.Status.OK.getStatusCode()); response.setStatus(Response.Status.OK.getStatusCode());
replyMsg = "The current humidity reading of the device is " + replyMsg; return sensorRecord;
return replyMsg;
} }
/** /**
* *
* @param owner * @param owner

Loading…
Cancel
Save