Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
For some use cases it makes sense to fetch all the fences at once in the beginning, so we want to have an endpoint to list all fences from a certain group.
@ApiMethod(name = "list", httpMethod = "get", path = "list")
public ArrayList < MyFence > listFences(@Named("group") String group) {
ArrayList < MyFence > fences = new ArrayList < MyFence > ();
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Key fenceKey = KeyFactory.createKey("Geofence", group);
Query query = new Query("Fence", fenceKey).addSort("id", Query.SortDirection.DESCENDING);
List < Entity > fencesFromStore = datastore.prepare(query).asList(FetchOptions.Builder.withDefaults());
if (fencesFromStore.isEmpty()) {
return fences;
} else {
for (Entity fenceFromStore: fencesFromStore) {
long id = (long) fenceFromStore.getProperty("id");
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.