use of org.traccar.processing.ComputedAttributesHandler in project traccar by traccar.
the class AttributeResource method test.
@POST
@Path("test")
public Response test(@QueryParam("deviceId") long deviceId, Attribute entity) throws SQLException {
Context.getPermissionsManager().checkReadonly(getUserId());
Context.getPermissionsManager().checkDevice(getUserId(), deviceId);
Position last = Context.getIdentityManager().getLastPosition(deviceId);
if (last != null) {
Object result = new ComputedAttributesHandler().computeAttribute(entity, last);
if (result != null) {
switch(entity.getType()) {
case "number":
Number numberValue = (Number) result;
return Response.ok(numberValue).build();
case "boolean":
Boolean booleanValue = (Boolean) result;
return Response.ok(booleanValue).build();
default:
return Response.ok(result.toString()).build();
}
} else {
return Response.noContent().build();
}
} else {
throw new IllegalArgumentException("Device has no last position");
}
}
Aggregations