com.google.api.server.spi.response.CollectionResponse Java Examples

The following examples show how to use com.google.api.server.spi.response.CollectionResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageEndpoint.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 6 votes vote down vote up
/**
 * This accepts a message and persists it in the AppEngine datastore, it 
 * will also broadcast the message to upto 10 registered android devices
 * via Google Cloud Messaging
 *  
 * @param message
 *            the entity to be inserted.
 * @return 
 * @throws IOException
 */
@ApiMethod(name = "sendMessage")
public void sendMessage(@Named("message") String message)
    throws IOException {
  Sender sender = new Sender(API_KEY);
  // create a MessageData entity with a timestamp of when it was
  // received, and persist it
  MessageData messageObj = new MessageData();
  messageObj.setMessage(message);
  messageObj.setTimestamp(System.currentTimeMillis());
  EntityManager mgr = getEntityManager();
  try {
    mgr.persist(messageObj);
  } finally {
    mgr.close();
  }
  // ping a max of 10 registered devices
  CollectionResponse<DeviceInfo> response = endpoint.listDeviceInfo(null,
      10);
  for (DeviceInfo deviceInfo : response.getItems()) {
    doSendViaGcm(message, sender, deviceInfo);
  }
}
 
Example #2
Source File: PlaceEndpoint.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 5 votes vote down vote up
/**
 * This method lists all the entities inserted in datastore.
 * It uses HTTP GET method and paging support.
 *
 * @return A CollectionResponse class containing the list of all entities
 * persisted and a cursor to the next page.
 */
@SuppressWarnings({"unchecked", "unused"})
@ApiMethod(name = "listPlace")
public CollectionResponse<Place> listPlace(
    @Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) {

  EntityManager mgr = null;
  Cursor cursor = null;
  List<Place> execute = null;

  try {
    mgr = getEntityManager();
    Query query = mgr.createQuery("select from Place as Place");
    if (cursorString != null && cursorString != "") {
      cursor = Cursor.fromWebSafeString(cursorString);
      query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
    }

    if (limit != null) {
      query.setFirstResult(0);
      query.setMaxResults(limit);
    }

    execute = (List<Place>) query.getResultList();
    cursor = JPACursorHelper.getCursor(execute);
    if (cursor != null) cursorString = cursor.toWebSafeString();

    // Tight loop for fetching all entities from datastore and accomodate
    // for lazy fetch.
    for (Place obj : execute);
  } finally {
    mgr.close();
  }

  return CollectionResponse.<Place>builder()
      .setItems(execute).setNextPageToken(cursorString).build();
}
 
Example #3
Source File: DeviceInfoEndpoint.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 5 votes vote down vote up
/**
 * This method lists all the entities inserted in datastore.
 * It uses HTTP GET method and paging support.
 *
 * @return A CollectionResponse class containing the list of all entities
 * persisted and a cursor to the next page.
 */
@SuppressWarnings({"unchecked", "unused"})
@ApiMethod(name = "listDeviceInfo")
public CollectionResponse<DeviceInfo> listDeviceInfo(
    @Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) {

  EntityManager mgr = null;
  Cursor cursor = null;
  List<DeviceInfo> execute = null;

  try {
    mgr = getEntityManager();
    Query query = mgr.createQuery("select from DeviceInfo as DeviceInfo");
    if (cursorString != null && cursorString != "") {
      cursor = Cursor.fromWebSafeString(cursorString);
      query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
    }

    if (limit != null) {
      query.setFirstResult(0);
      query.setMaxResults(limit);
    }

    execute = (List<DeviceInfo>) query.getResultList();
    cursor = JPACursorHelper.getCursor(execute);
    if (cursor != null) cursorString = cursor.toWebSafeString();

    // Tight loop for fetching all entities from datastore and accomodate
    // for lazy fetch.
    for (DeviceInfo obj : execute);
  } finally {
    mgr.close();
  }

  return CollectionResponse.<DeviceInfo>builder()
      .setItems(execute).setNextPageToken(cursorString).build();
}
 
Example #4
Source File: CheckInEndpoint.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 5 votes vote down vote up
/**
 * This method lists all the entities inserted in datastore.
 * It uses HTTP GET method and paging support.
 *
 * @return A CollectionResponse class containing the list of all entities
 * persisted and a cursor to the next page.
 */
@SuppressWarnings({"unchecked", "unused"})
@ApiMethod(name = "listCheckIn")
public CollectionResponse<CheckIn> listCheckIn(
    @Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) {

  EntityManager mgr = null;
  Cursor cursor = null;
  List<CheckIn> execute = null;

  try {
    mgr = getEntityManager();
    Query query = mgr.createQuery("select from CheckIn as CheckIn");
    if (cursorString != null && cursorString != "") {
      cursor = Cursor.fromWebSafeString(cursorString);
      query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
    }

    if (limit != null) {
      query.setFirstResult(0);
      query.setMaxResults(limit);
    }

    execute = (List<CheckIn>) query.getResultList();
    cursor = JPACursorHelper.getCursor(execute);
    if (cursor != null) cursorString = cursor.toWebSafeString();

    // Tight loop for fetching all entities from datastore and accomodate
    // for lazy fetch.
    for (CheckIn obj : execute);
  } finally {
    mgr.close();
  }

  return CollectionResponse.<CheckIn>builder()
      .setItems(execute).setNextPageToken(cursorString).build();
}
 
Example #5
Source File: RecommendationEndpoint.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 5 votes vote down vote up
/**
 * This method lists all the entities inserted in datastore.
 * It uses HTTP GET method and paging support.
 *
 * @return A CollectionResponse class containing the list of all entities
 * persisted and a cursor to the next page.
 */
@SuppressWarnings({"unchecked", "unused"})
@ApiMethod(name = "listRecommendation")
public CollectionResponse<Recommendation> listRecommendation(
    @Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) {

  EntityManager mgr = null;
  Cursor cursor = null;
  List<Recommendation> execute = null;

  try {
    mgr = getEntityManager();
    Query query = mgr.createQuery("select from Recommendation as Recommendation");
    if (cursorString != null && cursorString != "") {
      cursor = Cursor.fromWebSafeString(cursorString);
      query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
    }

    if (limit != null) {
      query.setFirstResult(0);
      query.setMaxResults(limit);
    }

    execute = (List<Recommendation>) query.getResultList();
    cursor = JPACursorHelper.getCursor(execute);
    if (cursor != null) cursorString = cursor.toWebSafeString();

    // Tight loop for fetching all entities from datastore and accomodate
    // for lazy fetch.
    for (Recommendation obj : execute);
  } finally {
    mgr.close();
  }

  return CollectionResponse.<Recommendation>builder()
      .setItems(execute).setNextPageToken(cursorString).build();
}
 
Example #6
Source File: OfferEndpoint.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 5 votes vote down vote up
/**
 * This method lists all the entities inserted in datastore.
 * It uses HTTP GET method and paging support.
 *
 * @return A CollectionResponse class containing the list of all entities
 * persisted and a cursor to the next page.
 */
@SuppressWarnings({"unchecked", "unused"})
@ApiMethod(name = "listOffer")
public CollectionResponse<Offer> listOffer(
    @Nullable @Named("cursor") String cursorString, @Nullable @Named("limit") Integer limit) {

  EntityManager mgr = null;
  Cursor cursor = null;
  List<Offer> execute = null;

  try {
    mgr = getEntityManager();
    Query query = mgr.createQuery("select from Offer as Offer");
    if (cursorString != null && cursorString != "") {
      cursor = Cursor.fromWebSafeString(cursorString);
      query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
    }

    if (limit != null) {
      query.setFirstResult(0);
      query.setMaxResults(limit);
    }

    execute = (List<Offer>) query.getResultList();
    cursor = JPACursorHelper.getCursor(execute);
    if (cursor != null) cursorString = cursor.toWebSafeString();

    // Tight loop for fetching all entities from datastore and accomodate
    // for lazy fetch.
    for (Offer obj : execute);
  } finally {
    mgr.close();
  }

  return CollectionResponse.<Offer>builder()
      .setItems(execute).setNextPageToken(cursorString).build();
}
 
Example #7
Source File: RegistrationEndpoint.java    From MobileShoppingAssistant-sample with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a collection of registered devices.
 * @param count The number of devices to list
 * @param user the user listing registered devices.*
 * @return a list of Google Cloud Messaging registration Ids
 * @throws com.google.api.server.spi.response.UnauthorizedException if
 * user is unauthorized
 */
@ApiMethod(httpMethod = "GET")
public final CollectionResponse<Registration> listDevices(
        @Named("count") final int count,
        final User user) throws UnauthorizedException {
    EndpointUtil.throwIfNotAdmin(user);
    List<Registration> records = ofy().load()
            .type(Registration.class).limit(count)
            .list();
    return CollectionResponse.<Registration>builder()
            .setItems(records).build();
}
 
Example #8
Source File: TypesTest.java    From endpoints-java with Apache License 2.0 5 votes vote down vote up
@Test
public void isCollectionResponseType() {
  final class MyResponse extends CollectionResponse {
    protected MyResponse(Collection items, String nextPageToken) {
      super(items, nextPageToken);
    }
  }
  assertThat(Types.isCollectionResponseType(TypeToken.of(CollectionResponse.class))).isTrue();
  assertThat(Types.isCollectionResponseType(TypeToken.of(MyResponse.class))).isTrue();
  assertThat(Types.isCollectionResponseType(TypeToken.of(Collection.class))).isFalse();
}
 
Example #9
Source File: SchemaRepositoryTest.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
public CollectionResponse<Integer> getIntegerCollection() {
  return null;
}
 
Example #10
Source File: MessageEndpoint.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 4 votes vote down vote up
/**
 * This function returns a list of messages starting with the newest message
 * first and in descending order from there
 * 
 * @param cursorString 
 *          for paging, empty for the first request, subsequent requests can
 *          use the returned information from an earlier request to fill this
 *          parameter
 * @param limit
 *          number of results returned for this query
 * @return
 *          A collection of MessageData items
 */
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "listMessages")
public CollectionResponse<MessageData> listMessages(
    @Nullable @Named("cursor") String cursorString,
    @Nullable @Named("limit") Integer limit) {

  EntityManager mgr = null;  
  Cursor cursor = null;
  List<MessageData> execute = null;
  
  try {
    mgr = getEntityManager();
    // query for messages, newest message first
    Query query = mgr
        .createQuery("select from MessageData as MessageData order by timestamp desc");
    if (cursorString != null && cursorString != "") {
      cursor = Cursor.fromWebSafeString(cursorString);
      query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
    }

    if (limit != null) {
      query.setFirstResult(0);
      query.setMaxResults(limit);
    }

    execute = (List<MessageData>) query.getResultList();
    cursor = JPACursorHelper.getCursor(execute);
    if (cursor != null)
      cursorString = cursor.toWebSafeString();

    // Tight loop for fetching all entities from datastore and accomodate
    // for lazy fetch.
    for (MessageData obj : execute) {
      ;
    }
  } finally {
    mgr.close();
  }

  return CollectionResponse.<MessageData> builder().setItems(execute)
      .setNextPageToken(cursorString).build();
}
 
Example #11
Source File: AnnotationApiConfigGeneratorTest.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
public CollectionResponse<Baz> listWithPagination() {
  return null;
}
 
Example #12
Source File: JsonConfigWriterTest.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
public CollectionResponse<Baz> listWithPagination() {
  return null;
}
 
Example #13
Source File: ArrayEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
public CollectionResponse<Foo> getFoosResponse() {
  return null;
}
 
Example #14
Source File: Types.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
public static boolean isCollectionResponseType(TypeToken<?> type) {
  return type.isSubtypeOf(CollectionResponse.class);
}
 
Example #15
Source File: NonDiscoverableEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "toplevel", path = "foos", httpMethod = HttpMethod.POST)
public CollectionResponse<Foo> toplevel() {
  return null;
}
 
Example #16
Source File: NonDiscoverableEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "foo.list", description = "list desc", path = "foos",
    httpMethod = HttpMethod.GET)
public CollectionResponse<Foo> listFoos(@Named("n") Integer n) {
  return null;
}
 
Example #17
Source File: FooEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "toplevel", path = "foos", httpMethod = HttpMethod.POST)
public CollectionResponse<Foo> toplevel() {
  return null;
}
 
Example #18
Source File: FooEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "foo.list", description = "list desc", path = "foos",
    httpMethod = HttpMethod.GET)
public CollectionResponse<Foo> listFoos(@Named("n") Integer n) {
  return null;
}
 
Example #19
Source File: FooDescriptionEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "toplevel", path = "foos", httpMethod = HttpMethod.POST)
public CollectionResponse<FooDescription> toplevel() {
  return null;
}
 
Example #20
Source File: FooDescriptionEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(name = "foo.list", description = "list desc", path = "foos",
    httpMethod = HttpMethod.GET)
public CollectionResponse<FooDescription> listFoos(@Named("n") Integer n, @Nullable @Named("enum") @Description("enum desc") TestEnumDescription testEnum) {
  return null;
}
 
Example #21
Source File: ArrayEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(path = "getIntegersResponse")
public CollectionResponse<Integer> getIntegersResponse() {
  return null;
}
 
Example #22
Source File: ArrayEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(path = "getAllNestedFoosResponse")
public CollectionResponse<Collection<Collection<Foo>>> getAllNestedFoosResponse() {
  return null;
}
 
Example #23
Source File: ArrayEndpoint.java    From endpoints-java with Apache License 2.0 4 votes vote down vote up
@ApiMethod(path = "getAllFoosResponse")
public CollectionResponse<Collection<Foo>> getAllFoosResponse() {
  return null;
}