Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
When we query our fences we only return the ids of the fences that were returned, therefore we need an endpoint to retrieve the metadata that corresponds to a fence id. This endpoint simply accepts an id, queries the Datastore and returns the metadata of the fence with the corresponding id.
@ApiMethod(name = "getById", httpMethod = "get", path = "getById")
public ArrayList < MyFence > getFenceById(@Named("group") String group, @Named("id") long id) {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key fenceKey = KeyFactory.createKey("Geofence", group);
Filter propertyFilter = new FilterPredicate("id", FilterOperator.EQUAL, id);
Query query = new Query("Fence", fenceKey).setFilter(propertyFilter);
Entity fenceFromStore = datastore.prepare(query).asSingleEntity();
ArrayList < MyFence > fences = new ArrayList < MyFence > ();
if (fenceFromStore != null) {
String name = (String) fenceFromStore.getProperty("name");
String description = (String) fenceFromStore.getProperty("description");
Gson gson = new Gson();
Text vText = (Text) fenceFromStore.getProperty("vertices");
String vString = vText.getValue();
double[][] vertices = gson.fromJson(vString, double[][].class);
MyFence tempFence = new MyFence(id, name, group, description, vertices);
fences.add(tempFence);
}
return fences;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.