use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.
the class StorageImpl method update.
@Override
public Blob update(BlobInfo blobInfo, BlobTargetOption... options) {
final StorageObject storageObject = blobInfo.toPb();
final Map<StorageRpc.Option, ?> optionsMap = optionMap(blobInfo, options);
try {
return Blob.fromPb(this, runWithRetries(new Callable<StorageObject>() {
@Override
public StorageObject call() {
return storageRpc.patch(storageObject, optionsMap);
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()));
} catch (RetryHelperException e) {
throw StorageException.translateAndThrow(e);
}
}
use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.
the class BlobId method toPb.
StorageObject toPb() {
StorageObject storageObject = new StorageObject();
storageObject.setBucket(bucket);
storageObject.setName(name);
storageObject.setGeneration(generation);
return storageObject;
}
use of com.google.api.services.storage.model.StorageObject 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);
}
}
use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.
the class StorageImplTest method testUpdateAllIterable.
@Test
public void testUpdateAllIterable() {
RpcBatch batchMock = EasyMock.createMock(RpcBatch.class);
Capture<RpcBatch.Callback<StorageObject>> callback1 = Capture.newInstance();
Capture<RpcBatch.Callback<StorageObject>> callback2 = Capture.newInstance();
batchMock.addPatch(EasyMock.eq(BLOB_INFO1.toPb()), EasyMock.capture(callback1), EasyMock.eq(ImmutableMap.<StorageRpc.Option, Object>of()));
batchMock.addPatch(EasyMock.eq(BLOB_INFO2.toPb()), EasyMock.capture(callback2), EasyMock.eq(ImmutableMap.<StorageRpc.Option, Object>of()));
EasyMock.expect(storageRpcMock.createBatch()).andReturn(batchMock);
batchMock.submit();
EasyMock.replay(storageRpcMock, batchMock);
initializeService();
List<Blob> resultBlobs = storage.update(ImmutableList.of(BLOB_INFO1, BLOB_INFO2));
callback1.getValue().onSuccess(BLOB_INFO1.toPb());
callback2.getValue().onFailure(new GoogleJsonError());
assertEquals(2, resultBlobs.size());
assertEquals(new Blob(storage, new BlobInfo.BuilderImpl(BLOB_INFO1)), resultBlobs.get(0));
assertNull(resultBlobs.get(1));
EasyMock.verify(batchMock);
}
use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.
the class BlobInfoTest method testToPbAndFromPb.
@Test
public void testToPbAndFromPb() {
compareCustomerEncryptions(CUSTOMER_ENCRYPTION, CustomerEncryption.fromPb(CUSTOMER_ENCRYPTION.toPb()));
compareBlobs(BLOB_INFO, BlobInfo.fromPb(BLOB_INFO.toPb()));
BlobInfo blobInfo = BlobInfo.newBuilder(BlobId.of("b", "n")).build();
compareBlobs(blobInfo, BlobInfo.fromPb(blobInfo.toPb()));
StorageObject object = new StorageObject().setName("n/").setBucket("b").setSize(BigInteger.ZERO).set("isDirectory", true);
blobInfo = BlobInfo.fromPb(object);
assertEquals("b", blobInfo.getBucket());
assertEquals("n/", blobInfo.getName());
assertNull(blobInfo.getAcl());
assertNull(blobInfo.getComponentCount());
assertNull(blobInfo.getContentType());
assertNull(blobInfo.getCacheControl());
assertNull(blobInfo.getContentDisposition());
assertNull(blobInfo.getContentEncoding());
assertNull(blobInfo.getContentLanguage());
assertNull(blobInfo.getCustomerEncryption());
assertNull(blobInfo.getCrc32c());
assertNull(blobInfo.getCreateTime());
assertNull(blobInfo.getDeleteTime());
assertNull(blobInfo.getEtag());
assertNull(blobInfo.getGeneration());
assertNull(blobInfo.getGeneratedId());
assertNull(blobInfo.getMd5());
assertNull(blobInfo.getMediaLink());
assertNull(blobInfo.getMetadata());
assertNull(blobInfo.getMetageneration());
assertNull(blobInfo.getOwner());
assertNull(blobInfo.getSelfLink());
assertEquals(0L, (long) blobInfo.getSize());
assertNull(blobInfo.getUpdateTime());
assertNull(blobInfo.getStorageClass());
assertTrue(blobInfo.isDirectory());
}
Aggregations