Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. @ApiMethod(name = "getAllUnclaimedLeftovers")
  2. public Collection<Leftover> getAllUnclaimedLeftovers() {
  3. Collection<Leftover> unclaimedLeftoverOffers = new ArrayList<Leftover>();
  4.  
  5. for(Leftover leftover : ofy().load().type(Leftover.class)) {
  6. if (!leftover.isClaimed() && leftover.isValid()) {
  7. unclaimedLeftoverOffers.add(leftover);
  8. }
  9. }
  10.  
  11. return unclaimedLeftoverOffers;
  12. }
  13.  
  14. public static Collection<Leftover> getAllUnclaimedLeftovers() throws IOException {
  15. try {
  16. return Proxy.getEndpoint().getAllUnclaimedLeftovers().execute().getItems();
  17. } catch (IOException e) {
  18. Log.d("DataStore_UnclaimedLeftovers_Error", e.getMessage());
  19. throw e;
  20. }
  21. }
  22.  
  23. private class UnclaimedLeftoversTask extends AsyncTask<Void, Void, Void> {
  24.  
  25. @Override
  26. protected Void doInBackground(Void... params) {
  27. try {
  28. setUnclaimedLeftovers(LeftoverProxy.getAllUnclaimedLeftovers());
  29. setIsUnclaimedLeftoversSucceeded(true);
  30. return null;
  31. } catch (IOException e) {
  32. setIsUnclaimedLeftoversSucceeded(false);
  33. return null;
  34. } catch (NullPointerException e) {
  35. setIsUnclaimedLeftoversSucceeded(false);
  36. return null;
  37. }
  38. }
  39. }
  40.  
  41. public GetAllUnclaimedLeftovers getAllUnclaimedLeftovers() throws java.io.IOException {
  42. GetAllUnclaimedLeftovers result = new GetAllUnclaimedLeftovers();
  43. initialize(result);
  44. return result;
  45. }
  46.  
  47. public class GetAllUnclaimedLeftovers extends EndpointRequest<com.frigoshare.endpoint.model.LeftoverCollection> {
  48.  
  49. private static final String REST_PATH = "leftovercollection";
  50.  
  51.  
  52. protected GetAllUnclaimedLeftovers() {
  53. super(Endpoint.this, "GET", REST_PATH, null, com.frigoshare.endpoint.model.LeftoverCollection.class);
  54. }
  55.  
  56. ...
  57. }
  58.  
  59. public EndpointRequest(
  60. Endpoint client, String method, String uriTemplate, Object content, Class<T> responseClass) {
  61. super(
  62. client,
  63. method,
  64. uriTemplate,
  65. content,
  66. responseClass);
  67. }
  68.  
  69. /**
  70. * Sends the metadata request to the server and returns the parsed metadata response.
  71. *
  72. * <p>
  73. * Subclasses may override by calling the super implementation.
  74. * </p>
  75. *
  76. * @return parsed HTTP response
  77. */
  78. public T execute() throws IOException {
  79. HttpResponse response = executeUnparsed();
  80. if (Void.class.equals(responseClass)) {
  81. response.ignore();
  82. return null;
  83. }
  84. return response.parseAs(responseClass);
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement