Search in sources :

Example 1 with ObjectPreconditions

use of com.google.api.services.storage.model.ComposeRequest.SourceObjects.ObjectPreconditions in project google-cloud-java by GoogleCloudPlatform.

the class HttpStorageRpc method compose.

@Override
public StorageObject compose(Iterable<StorageObject> sources, StorageObject target, Map<Option, ?> targetOptions) {
    ComposeRequest request = new ComposeRequest();
    request.setDestination(target);
    List<ComposeRequest.SourceObjects> sourceObjects = new ArrayList<>();
    for (StorageObject source : sources) {
        ComposeRequest.SourceObjects sourceObject = new ComposeRequest.SourceObjects();
        sourceObject.setName(source.getName());
        Long generation = source.getGeneration();
        if (generation != null) {
            sourceObject.setGeneration(generation);
            sourceObject.setObjectPreconditions(new ObjectPreconditions().setIfGenerationMatch(generation));
        }
        sourceObjects.add(sourceObject);
    }
    request.setSourceObjects(sourceObjects);
    try {
        return storage.objects().compose(target.getBucket(), target.getName(), request).setIfMetagenerationMatch(Option.IF_METAGENERATION_MATCH.getLong(targetOptions)).setIfGenerationMatch(Option.IF_GENERATION_MATCH.getLong(targetOptions)).execute();
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) ArrayList(java.util.ArrayList) ObjectPreconditions(com.google.api.services.storage.model.ComposeRequest.SourceObjects.ObjectPreconditions) IOException(java.io.IOException) ComposeRequest(com.google.api.services.storage.model.ComposeRequest)

Aggregations

ComposeRequest (com.google.api.services.storage.model.ComposeRequest)1 ObjectPreconditions (com.google.api.services.storage.model.ComposeRequest.SourceObjects.ObjectPreconditions)1 StorageObject (com.google.api.services.storage.model.StorageObject)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1