|
|
@ -134,40 +134,6 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
|
|
|
|
@Path("device/{deviceId}/policy")
|
|
|
|
|
|
|
|
public Response updatePolicy(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol,
|
|
|
|
|
|
|
|
@FormParam("policy") String policy) {
|
|
|
|
|
|
|
|
String protocolString = protocol.toUpperCase();
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Sending request to update-policy of device [" + deviceId + "] via " + protocolString);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (!APIUtil.getDeviceAccessAuthorizationService().isUserAuthorized(
|
|
|
|
|
|
|
|
new DeviceIdentifier(deviceId, VirtualFireAlarmConstants.DEVICE_TYPE),
|
|
|
|
|
|
|
|
DeviceGroupConstants.Permissions.DEFAULT_MANAGE_POLICIES_PERMISSIONS)) {
|
|
|
|
|
|
|
|
return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String actualMessage = VirtualFireAlarmConstants.POLICY_CONTEXT + ":" + policy;
|
|
|
|
|
|
|
|
Map<String, String> dynamicProperties = new HashMap<>();
|
|
|
|
|
|
|
|
String publishTopic = APIUtil.getTenantDomainOftheUser() + "/"
|
|
|
|
|
|
|
|
+ VirtualFireAlarmConstants.DEVICE_TYPE + "/" + deviceId;
|
|
|
|
|
|
|
|
dynamicProperties.put(VirtualFireAlarmConstants.ADAPTER_TOPIC_PROPERTY, publishTopic);
|
|
|
|
|
|
|
|
dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY,
|
|
|
|
|
|
|
|
deviceId + "@" + XmppConfig.getInstance().getServerName());
|
|
|
|
|
|
|
|
dynamicProperties.put(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "POLICTY-REQUEST");
|
|
|
|
|
|
|
|
dynamicProperties.put(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY,
|
|
|
|
|
|
|
|
VirtualFireAlarmConstants.CHAT_PROPERTY_KEY);
|
|
|
|
|
|
|
|
APIUtil.getOutputEventAdapterService().publish(VirtualFireAlarmConstants.XMPP_ADAPTER_NAME,
|
|
|
|
|
|
|
|
dynamicProperties, actualMessage);
|
|
|
|
|
|
|
|
return Response.ok().build();
|
|
|
|
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
|
|
|
|
log.error(e.getErrorMessage(), e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Path("device/stats/{deviceId}")
|
|
|
|
@Path("device/stats/{deviceId}")
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|