Search in sources :

Example 1 with ComputedAttributesHandler

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");
    }
}
Also used : Position(org.traccar.model.Position) ComputedAttributesHandler(org.traccar.processing.ComputedAttributesHandler) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Position (org.traccar.model.Position)1 ComputedAttributesHandler (org.traccar.processing.ComputedAttributesHandler)1