Search in sources :

Example 1 with ListDatasetsRequest

use of com.amazonaws.services.cognitosync.model.ListDatasetsRequest in project amazon-cognito-android by aws.

the class CognitoSyncStorage method getDatasets.

/*
     * (non-Javadoc)
     * @see com.amazonaws.cognitov2.RemoteStorage#listDatasets()
     */
@Override
public List<DatasetMetadata> getDatasets() {
    List<DatasetMetadata> datasets = new ArrayList<DatasetMetadata>();
    String nextToken = null;
    do {
        ListDatasetsRequest request = new ListDatasetsRequest();
        appendUserAgent(request, userAgent);
        request.setIdentityPoolId(identityPoolId);
        // a large enough number to reduce # of requests
        request.setMaxResults("64");
        request.setNextToken(nextToken);
        ListDatasetsResult result = null;
        try {
            request.setIdentityId(getIdentityId());
            result = client.listDatasets(request);
        } catch (AmazonClientException ace) {
            throw handleException(ace, "Failed to list dataset metadata");
        }
        for (com.amazonaws.services.cognitosync.model.Dataset dataset : result.getDatasets()) {
            datasets.add(modelToDatasetMetadata(dataset));
        }
        nextToken = result.getNextToken();
    } while (nextToken != null);
    return datasets;
}
Also used : DatasetMetadata(com.amazonaws.mobileconnectors.cognito.DatasetMetadata) AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) ListDatasetsResult(com.amazonaws.services.cognitosync.model.ListDatasetsResult) ListDatasetsRequest(com.amazonaws.services.cognitosync.model.ListDatasetsRequest)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)1 DatasetMetadata (com.amazonaws.mobileconnectors.cognito.DatasetMetadata)1 ListDatasetsRequest (com.amazonaws.services.cognitosync.model.ListDatasetsRequest)1 ListDatasetsResult (com.amazonaws.services.cognitosync.model.ListDatasetsResult)1 ArrayList (java.util.ArrayList)1