Created
December 7, 2014 16:03
-
-
Save thorwebdev/1b7b0ec5a987bdc697fe to your computer and use it in GitHub Desktop.
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.
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 = "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