/**
  * Generates a ContentValues object to insert into the database with the given values for a
  * multipart upload record.
  *
  * @param bucket The name of the bucket to upload to.
  * @param key The key in the specified bucket by which to store the new object.
  * @param file The file to upload.
  * @param fileOffset The byte offset for the file to upload.
  * @param partNumber The part number of this part.
  * @param uploadId The multipart upload id of the upload.
  * @param bytesTotal The Total bytes of the file.
  * @param isLastPart Whether this part is the last part of the upload.
  * @return The ContentValues object generated.
  */
 public ContentValues generateContentValuesForMultiPartUpload(
     String bucket,
     String key,
     File file,
     long fileOffset,
     int partNumber,
     String uploadId,
     long bytesTotal,
     int isLastPart,
     ObjectMetadata metadata) {
   ContentValues values = new ContentValues();
   values.put(TransferTable.COLUMN_TYPE, TransferType.UPLOAD.toString());
   values.put(TransferTable.COLUMN_STATE, TransferState.WAITING.toString());
   values.put(TransferTable.COLUMN_BUCKET_NAME, bucket);
   values.put(TransferTable.COLUMN_KEY, key);
   values.put(TransferTable.COLUMN_FILE, file.getAbsolutePath());
   values.put(TransferTable.COLUMN_BYTES_CURRENT, 0l);
   values.put(TransferTable.COLUMN_BYTES_TOTAL, bytesTotal);
   values.put(TransferTable.COLUMN_IS_MULTIPART, 1);
   values.put(TransferTable.COLUMN_PART_NUM, partNumber);
   values.put(TransferTable.COLUMN_FILE_OFFSET, fileOffset);
   values.put(TransferTable.COLUMN_MULTIPART_ID, uploadId);
   values.put(TransferTable.COLUMN_IS_LAST_PART, isLastPart);
   values.put(TransferTable.COLUMN_IS_ENCRYPTED, 0);
   values.putAll(generateContentValuesForObjectMetadata(metadata));
   return values;
 }
Exemple #2
0
  /** Get a list of all field/value pairs merged across data sources */
  public ContentValues getMergedValues() {
    ContentValues mergedValues = new ContentValues();

    ContentValues defaultValues = getDefaultValues();
    if (defaultValues != null) {
      mergedValues.putAll(defaultValues);
    }
    if (values != null) {
      mergedValues.putAll(values);
    }
    if (setValues != null) {
      mergedValues.putAll(setValues);
    }

    return mergedValues;
  }
Exemple #3
0
 /**
  * Transfers all set values into values. This occurs when a task is saved - future saves will not
  * need to write all the data as before.
  */
 public void markSaved() {
   if (values == null) {
     values = setValues;
   } else if (setValues != null) {
     values.putAll(setValues);
   }
   setValues = null;
 }
 /**
  * Generates a ContentValues object to insert into the database with the given values for a single
  * chunk upload or download.
  *
  * @param type The type of the transfer, can be "upload" or "download".
  * @param bucket The name of the bucket to upload to.
  * @param key The key in the specified bucket by which to store the new object.
  * @param file The file to upload.
  * @param metadata The S3 ObjectMetadata to send along with the object
  * @return The ContentValues object generated.
  */
 private ContentValues generateContentValuesForSinglePartTransfer(
     TransferType type, String bucket, String key, File file, ObjectMetadata metadata) {
   ContentValues values = new ContentValues();
   values.put(TransferTable.COLUMN_TYPE, type.toString());
   values.put(TransferTable.COLUMN_STATE, TransferState.WAITING.toString());
   values.put(TransferTable.COLUMN_BUCKET_NAME, bucket);
   values.put(TransferTable.COLUMN_KEY, key);
   values.put(TransferTable.COLUMN_FILE, file.getAbsolutePath());
   values.put(TransferTable.COLUMN_BYTES_CURRENT, 0l);
   if (type.equals(TransferType.UPLOAD))
     values.put(TransferTable.COLUMN_BYTES_TOTAL, file == null ? 0l : file.length());
   values.put(TransferTable.COLUMN_IS_MULTIPART, 0);
   values.put(TransferTable.COLUMN_PART_NUM, 0);
   values.put(TransferTable.COLUMN_IS_ENCRYPTED, 0);
   values.putAll(generateContentValuesForObjectMetadata(metadata));
   return values;
 }
  /**
   * Given a JSON item and a sync map, create a ContentValues map to be inserted into the DB.
   *
   * @param context
   * @param localItem will be null if item is new to mobile. If it's been sync'd before, will point
   *     to local entry.
   * @param item incoming JSON item.
   * @param mySyncMap A mapping between the JSON object and the content values.
   * @return new ContentValues, ready to be inserted into the database.
   * @throws JSONException
   * @throws IOException
   * @throws NetworkProtocolException
   */
  public static final ContentValues fromJSON(
      Context context, Uri localItem, JSONObject item, SyncMap mySyncMap)
      throws JSONException, IOException, NetworkProtocolException {
    final ContentValues cv = new ContentValues();

    for (final String propName : mySyncMap.keySet()) {
      final SyncItem map = mySyncMap.get(propName);
      if (!map.isDirection(SyncItem.SYNC_FROM)) {
        continue;
      }
      if (map.isOptional() && (!item.has(map.remoteKey) || item.isNull(map.remoteKey))) {
        continue;
      }
      final ContentValues cv2 = map.fromJSON(context, localItem, item, propName);
      if (cv2 != null) {
        cv.putAll(cv2);
      }
    }
    return cv;
  }
  // Make sure we can still delete after adding/updating stuff
  //
  // Student: Uncomment this test after you have completed writing the insert functionality
  // in your provider.  It relies on insertions with testInsertReadProvider, so insert and
  // query functionality must also be complete before this test can be used.
  public void testInsertReadProvider() {
    ContentValues testValues = TestUtilities.createNorthPoleLocationValues();

    // Register a content observer for our insert.  This time, directly with the content resolver
    TestUtilities.TestContentObserver tco = TestUtilities.getTestContentObserver();
    mContext.getContentResolver().registerContentObserver(LocationEntry.CONTENT_URI, true, tco);
    Uri locationUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, testValues);

    // Did our content observer get called?  Students:  If this fails, your insert location
    // isn't calling getContext().getContentResolver().notifyChange(uri, null);
    tco.waitForNotificationOrFail();
    mContext.getContentResolver().unregisterContentObserver(tco);

    long locationRowId = ContentUris.parseId(locationUri);

    // Verify we got a row back.
    assertTrue(locationRowId != -1);

    // Data's inserted.  IN THEORY.  Now pull some out to stare at it and verify it made
    // the round trip.

    // A cursor is your primary interface to the query results.
    Cursor cursor =
        mContext
            .getContentResolver()
            .query(
                LocationEntry.CONTENT_URI,
                null, // leaving "columns" null just returns all the columns.
                null, // cols for "where" clause
                null, // values for "where" clause
                null // sort order
                );

    TestUtilities.validateCursor(
        "testInsertReadProvider. Error validating LocationEntry.", cursor, testValues);

    // Fantastic.  Now that we have a location, add some weather!
    ContentValues weatherValues = TestUtilities.createWeatherValues(locationRowId);
    // The TestContentObserver is a one-shot class
    tco = TestUtilities.getTestContentObserver();

    mContext.getContentResolver().registerContentObserver(WeatherEntry.CONTENT_URI, true, tco);

    Uri weatherInsertUri =
        mContext.getContentResolver().insert(WeatherEntry.CONTENT_URI, weatherValues);
    assertTrue(weatherInsertUri != null);

    // Did our content observer get called?  Students:  If this fails, your insert weather
    // in your ContentProvider isn't calling
    // getContext().getContentResolver().notifyChange(uri, null);
    tco.waitForNotificationOrFail();
    mContext.getContentResolver().unregisterContentObserver(tco);

    // A cursor is your primary interface to the query results.
    Cursor weatherCursor =
        mContext
            .getContentResolver()
            .query(
                WeatherEntry.CONTENT_URI, // Table to Query
                null, // leaving "columns" null just returns all the columns.
                null, // cols for "where" clause
                null, // values for "where" clause
                null // columns to group by
                );

    TestUtilities.validateCursor(
        "testInsertReadProvider. Error validating WeatherEntry insert.",
        weatherCursor,
        weatherValues);

    // Add the location values in with the weather data so that we can make
    // sure that the join worked and we actually get all the values back
    weatherValues.putAll(testValues);

    // Get the joined Weather and Location data
    weatherCursor =
        mContext
            .getContentResolver()
            .query(
                WeatherEntry.weatherWithLocationUri(TestUtilities.TEST_LOCATION),
                null, // leaving "columns" null just returns all the columns.
                null, // cols for "where" clause
                null, // values for "where" clause
                null // sort order
                );
    TestUtilities.validateCursor(
        "testInsertReadProvider.  Error validating joined Weather and Location Data.",
        weatherCursor,
        weatherValues);

    // Get the joined Weather and Location data with a start date
    //        weatherCursor = mContext.getContentResolver().query(
    //                WeatherEntry.buildWeatherLocationWithStartDate(
    //                        TestUtilities.TEST_LOCATION, TestUtilities.TEST_DATE),
    //                null, // leaving "columns" null just returns all the columns.
    //                null, // cols for "where" clause
    //                null, // values for "where" clause
    //                null  // sort order
    //        );
    TestUtilities.validateCursor(
        "testInsertReadProvider.  Error validating joined Weather and Location Data with start date.",
        weatherCursor,
        weatherValues);

    // Get the joined Weather data for a specific date
    //
    TestUtilities.validateCursor(
        "testInsertReadProvider.  Error validating joined Weather and Location data for a specific date.",
        weatherCursor,
        weatherValues);
  }
Exemple #7
0
 /** Merges content values with those coming from another source */
 public synchronized void mergeWith(ContentValues other) {
   if (setValues == null) {
     setValues = new ContentValues();
   }
   setValues.putAll(other);
 }
 @Override
 public void putAll(ContentValues other) {
   contentValues.putAll(other);
 }