Created
December 7, 2014 16:04
-
-
Save thorwebdev/7d20d452f0890ef9b339 to your computer and use it in GitHub Desktop.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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