Ejemplo n.º 1
0
  /**
   * Retrieves the current state of the collection from the server, and populates an the Collection
   * object with the returned set of entities. Executes synchronously.
   *
   * @return an ApiResponse object
   */
  public ApiResponse fetch() {
    if (this.cursor != null) {
      this.qs.put("cursor", this.cursor);
    }

    Query query =
        this.client.queryEntitiesRequest(
            "GET",
            this.qs,
            null,
            this.client.getOrganizationId(),
            this.client.getApplicationId(),
            this.type);
    ApiResponse response = query.getResponse();
    if (response.getError() != null) {
      this.client.writeLog("Error getting collection.");
    } else {
      String theCursor = response.getCursor();
      int count = response.getEntityCount();

      UUID nextUUID = response.getNext();
      if (nextUUID != null) {
        this.next = nextUUID.toString();
      } else {
        this.next = null;
      }
      this.cursor = theCursor;

      this.saveCursor(theCursor);
      if (count > 0) {
        this.resetEntityPointer();
        this.list = new ArrayList<Entity>();
        List<Entity> retrievedEntities = response.getEntities();

        for (Entity retrievedEntity : retrievedEntities) {
          if (retrievedEntity.getUuid() != null) {
            retrievedEntity.setType(this.type);
            this.list.add(retrievedEntity);
          }
        }
      }
    }

    return response;
  }
Ejemplo n.º 2
0
 /**
  * Retrieves an entity from the server.
  *
  * @param uuid the UUID of the entity to retrieve
  * @return an ApiResponse object
  */
 public ApiResponse getEntityByUuid(UUID uuid) {
   Entity entity = new Entity(this.client);
   entity.setType(this.type);
   entity.setUuid(uuid);
   return entity.fetch();
 }
Ejemplo n.º 3
0
 /**
  * Constructor for instantiating an Entity with a UGClient and entity type. Normally this is the
  * constructor that should be used to model an entity locally.
  *
  * @param UGClient a UGClient object
  * @param type the 'type' property of the entity
  */
 public Entity(UGClient client, String type) {
   this.client = client;
   setType(type);
 }