Skip to content

Commit 4b62b6d

Browse files
committed
Merge pull request #47 from aozarov/master
storage work in progress
2 parents 59bc707 + a1c6fa1 commit 4b62b6d

File tree

11 files changed

+82
-38
lines changed

11 files changed

+82
-38
lines changed

src/main/java/com/google/gcloud/datastore/DatastoreServiceFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package com.google.gcloud.datastore;
1818

1919

20-
20+
/**
21+
* A base class for DatasoreService factories.
22+
*/
2123
public abstract class DatastoreServiceFactory {
2224

2325
private static final DatastoreServiceFactory INSTANCE = new DatastoreServiceFactory() {

src/main/java/com/google/gcloud/examples/DatastoreExample.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* <li>compile using maven - {@code mvn compile}</li>
4747
* <li>run using maven - {@code mvn exec:java
4848
* -Dexec.mainClass="com.google.gcloud.examples.DatastoreExample"
49-
* -Dexec.args="projectId [user] [delete|display|add comment]"}</li>
49+
* -Dexec.args="[projectId] [user] [delete|display|add comment]"}</li>
5050
* </ol>
5151
*/
5252
public class DatastoreExample {
@@ -174,25 +174,23 @@ public static void main(String... args) {
174174
DatastoreAction action = null;
175175
DatastoreService datastore = null;
176176
Key key = null;
177-
if (args.length > 0) {
178-
String projectId = args[0];
179-
// If you want to access a local Datastore running via the gcd sdk, do
180-
// DatastoreServiceOptions options = DatastoreServiceOptions.builder()
181-
// .projectId(projectId)
182-
// .namespace(NAMESPACE)
183-
// .host("http://localhost:8080")
184-
// .build();
185-
DatastoreServiceOptions options = DatastoreServiceOptions.builder()
186-
.projectId(projectId)
187-
.namespace(NAMESPACE)
188-
.build();
189-
String name = args.length > 1 ? args[1] : System.getProperty("user.name");
190-
datastore = DatastoreServiceFactory.instance().get(options);
191-
KeyFactory keyFactory = datastore.newKeyFactory().kind(USER_KIND);
192-
key = keyFactory.newKey(name);
193-
String actionName = args.length > 2 ? args[2].toLowerCase() : DEFAULT_ACTION;
194-
action = ACTIONS.get(actionName);
195-
}
177+
String projectId = args.length > 0 ? args[0] : null;
178+
// If you want to access a local Datastore running via the gcd sdk, do
179+
// DatastoreServiceOptions options = DatastoreServiceOptions.builder()
180+
// .projectId(projectId)
181+
// .namespace(NAMESPACE)
182+
// .host("http://localhost:8080")
183+
// .build();
184+
DatastoreServiceOptions options = DatastoreServiceOptions.builder()
185+
.projectId(projectId)
186+
.namespace(NAMESPACE)
187+
.build();
188+
String name = args.length > 1 ? args[1] : System.getProperty("user.name");
189+
datastore = DatastoreServiceFactory.instance().get(options);
190+
KeyFactory keyFactory = datastore.newKeyFactory().kind(USER_KIND);
191+
key = keyFactory.newKey(name);
192+
String actionName = args.length > 2 ? args[2].toLowerCase() : DEFAULT_ACTION;
193+
action = ACTIONS.get(actionName);
196194
if (action == null) {
197195
StringBuilder actionAndParams = new StringBuilder();
198196
for (Map.Entry<String, DatastoreAction> entry : ACTIONS.entrySet()) {
@@ -204,7 +202,7 @@ public static void main(String... args) {
204202
actionAndParams.append('|');
205203
}
206204
actionAndParams.setLength(actionAndParams.length() - 1);
207-
System.out.printf("Usage: %s projectId [user] [%s]%n",
205+
System.out.printf("Usage: %s [projectId] [user] [%s]%n",
208206
DatastoreExample.class.getSimpleName(), actionAndParams);
209207
return;
210208
}

src/main/java/com/google/gcloud/examples/StorageExample.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,15 @@ Tuple<Blob, Path> parse(String... args) {
270270
if (args.length < 2 || args.length > 3) {
271271
throw new IllegalArgumentException();
272272
}
273-
Path path = null;
273+
Path path;
274274
if (args.length > 2) {
275275
path = Paths.get(args[2]);
276276
if (Files.isDirectory(path)) {
277277
path = path.resolve(Paths.get(args[1]).getFileName());
278278
}
279+
} else {
280+
path = null;
279281
}
280-
String blob = args.length < 3 ? path.getFileName().toString() : args[2];
281282
return Tuple.of(Blob.of(args[0], args[1]), path);
282283
}
283284

src/main/java/com/google/gcloud/spi/DefaultStorageRpc.java

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/main/java/com/google/gcloud/storage/Acl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
import java.io.Serializable;
2323

24+
/**
25+
* Access Control List on for buckets or blobs.
26+
*/
2427
public final class Acl implements Serializable {
2528

2629
private static final long serialVersionUID = 6435575339887912222L;

src/main/java/com/google/gcloud/storage/BatchRequest.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,23 @@ public static class Builder {
4343

4444
private Builder() {}
4545

46+
/**
47+
* Delete the given blob.
48+
*/
4649
public void delete(Blob blob, BlobSourceOption... options) {
4750
toDelete.put(blob, options);
4851
}
4952

53+
/**
54+
* Update the given blob.
55+
*/
5056
public void update(Blob blob, BlobTargetOption... options) {
5157
toUpdate.put(blob, options);
5258
}
5359

60+
/**
61+
* Retrieve metadata for the given blob.
62+
*/
5463
public void get(Blob blob, BlobSourceOption... options) {
5564
toGet.put(blob, options);
5665
}
@@ -66,15 +75,15 @@ private BatchRequest(Builder builder) {
6675
toGet = ImmutableMap.copyOf(builder.toGet);
6776
}
6877

69-
public Map<Blob, BlobSourceOption[]> toDelete() {
78+
Map<Blob, BlobSourceOption[]> toDelete() {
7079
return toDelete;
7180
}
7281

73-
public Map<Blob, BlobTargetOption[]> toUpdate() {
82+
Map<Blob, BlobTargetOption[]> toUpdate() {
7483
return toUpdate;
7584
}
7685

77-
public Map<Blob, BlobSourceOption[]> toGet() {
86+
Map<Blob, BlobSourceOption[]> toGet() {
7887
return toGet;
7988
}
8089

src/main/java/com/google/gcloud/storage/Blob.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
import java.util.List;
3434
import java.util.Map;
3535

36+
/**
37+
* A Google Storage object.
38+
*
39+
* @see <a href="https://cloud.google.com/storage/docs/concepts-techniques#concepts">Concepts and Terminology</a>
40+
*/
3641
public class Blob implements Serializable {
3742

3843
private static final long serialVersionUID = 2228487739943277159L;
@@ -148,7 +153,7 @@ public Builder cacheControl(String cacheControl) {
148153
}
149154

150155
public Builder acl(List<Acl> acl) {
151-
this.acl = ImmutableList.copyOf(acl);
156+
this.acl = acl != null ? ImmutableList.copyOf(acl) : null;
152157
return this;
153158
}
154159

@@ -188,7 +193,7 @@ public Builder mediaLink(String mediaLink) {
188193
}
189194

190195
public Builder metadata(Map<String, String> metadata) {
191-
this.metadata = ImmutableMap.copyOf(metadata);
196+
this.metadata = metadata != null ? ImmutableMap.copyOf(metadata) : null;
192197
return this;
193198
}
194199

src/main/java/com/google/gcloud/storage/Bucket.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
import java.io.Serializable;
4141
import java.util.List;
4242

43+
/**
44+
* A Google Storage bucket.
45+
*
46+
* @see <a href="https://cloud.google.com/storage/docs/concepts-techniques#concepts">Concepts and Terminology</a>
47+
*/
4348
public final class Bucket implements Serializable {
4449

4550
private static final long serialVersionUID = -3946094202176916586L;
@@ -431,17 +436,17 @@ Builder metageneration(Long metageneration) {
431436
}
432437

433438
public Builder cors(Iterable<Cors> cors) {
434-
this.cors = ImmutableList.copyOf(cors);
439+
this.cors = cors != null ? ImmutableList.copyOf(cors) : null;
435440
return this;
436441
}
437442

438443
public Builder acl(Iterable<Acl> acl) {
439-
this.acl = ImmutableList.copyOf(acl);
444+
this.acl = acl != null ? ImmutableList.copyOf(acl) : null;
440445
return this;
441446
}
442447

443448
public Builder defaultAcl(Iterable<Acl> acl) {
444-
this.defaultAcl = ImmutableList.copyOf(acl);
449+
this.defaultAcl = acl != null ? ImmutableList.copyOf(acl) : null;
445450
return this;
446451
}
447452

src/main/java/com/google/gcloud/storage/Cors.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import java.net.URISyntaxException;
3131
import java.util.List;
3232

33+
/**
34+
* Cross-Origin Resource Sharing (CORS) configuration for a bucket.
35+
*/
3336
public final class Cors implements Serializable {
3437

3538
private static final long serialVersionUID = -8637770919343335655L;

src/main/java/com/google/gcloud/storage/StorageService.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@
3030
import java.util.List;
3131
import java.util.Set;
3232

33+
/**
34+
* An interface for Google Cloud Storage.
35+
*
36+
* @see <a href="https://cloud.google.com/storage/docs">Google Cloud Storage</a>
37+
*/
3338
public interface StorageService extends Service<StorageServiceOptions> {
3439

35-
// todo: provide way for construct signed URLs -
36-
// https://cloud.google.com/storage/docs/access-control#Signed-URLs
37-
3840
enum PredefinedAcl {
3941
AUTHENTICATED_READ("authenticatedRead"),
4042
ALL_AUTHENTICATED_USERS("allAuthenticatedUsers"),
@@ -347,17 +349,26 @@ public static Builder builder() {
347349
}
348350
}
349351

352+
350353
/**
354+
* Create a new bucket.
355+
*
356+
* @return a complete bucket information.
351357
* @throws StorageServiceException upon failure
352358
*/
353359
Bucket create(Bucket bucket, BucketTargetOption... options);
354360

355361
/**
362+
* Create a new blob.
363+
*
364+
* @return a complete blob information.
356365
* @throws StorageServiceException upon failure
357366
*/
358367
Blob create(Blob blob, byte[] content, BlobTargetOption... options);
359368

360369
/**
370+
* Returns a complete bucket information.
371+
*
361372
* @throws StorageServiceException upon failure
362373
*/
363374
Bucket get(Bucket bucket, BucketSourceOption... options);
@@ -426,5 +437,4 @@ public static Builder builder() {
426437
*/
427438
BlobWriteChannel writer(Blob blob, BlobTargetOption... options);
428439

429-
430440
}

src/main/java/com/google/gcloud/storage/StorageServiceFactory.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
package com.google.gcloud.storage;
1818

1919

20-
20+
/**
21+
* A base class for StorageService factories.
22+
*/
2123
public abstract class StorageServiceFactory {
2224

2325
private static final StorageServiceFactory INSTANCE = new StorageServiceFactory() {
@@ -27,9 +29,15 @@ public StorageService get(StorageServiceOptions options) {
2729
}
2830
};
2931

32+
/**
33+
* Returns the default factory instance.
34+
*/
3035
public static StorageServiceFactory instance() {
3136
return INSTANCE;
3237
}
3338

39+
/**
40+
* Returns a {@code StorageService} for the given options.
41+
*/
3442
public abstract StorageService get(StorageServiceOptions options);
3543
}

0 commit comments

Comments
 (0)