Merge pull request #1145 from dralves/gce-base

Operation.targetId needs to be optional for some kinds of operations
This commit is contained in:
Adrian Cole 2013-01-06 07:32:23 -08:00
commit abfc3cf9ec
1 changed files with 15 additions and 8 deletions

View File

@ -51,7 +51,7 @@ public class Operation extends Resource {
} }
private final URI targetLink; private final URI targetLink;
private final String targetId; private final Optional<String> targetId;
private final Optional<String> clientOperationId; private final Optional<String> clientOperationId;
private final Status status; private final Status status;
private final Optional<String> statusMessage; private final Optional<String> statusMessage;
@ -72,7 +72,7 @@ public class Operation extends Resource {
super(Kind.OPERATION, checkNotNull(id, "id of %s", name), fromNullable(creationTimestamp), super(Kind.OPERATION, checkNotNull(id, "id of %s", name), fromNullable(creationTimestamp),
checkNotNull(selfLink, "selfLink of %s", name), checkNotNull(name, "name"), fromNullable(description)); checkNotNull(selfLink, "selfLink of %s", name), checkNotNull(name, "name"), fromNullable(description));
this.targetLink = checkNotNull(targetLink, "targetLink of %s", name); this.targetLink = checkNotNull(targetLink, "targetLink of %s", name);
this.targetId = checkNotNull(targetId, "targetId of %s", name); this.targetId = fromNullable(targetId);
this.clientOperationId = fromNullable(clientOperationId); this.clientOperationId = fromNullable(clientOperationId);
this.status = checkNotNull(status, "status of %s", name); this.status = checkNotNull(status, "status of %s", name);
this.statusMessage = fromNullable(statusMessage); this.statusMessage = fromNullable(statusMessage);
@ -101,7 +101,7 @@ public class Operation extends Resource {
/** /**
* @return unique target id which identifies a particular incarnation of the target. * @return unique target id which identifies a particular incarnation of the target.
*/ */
public String getTargetId() { public Optional<String> getTargetId() {
return targetId; return targetId;
} }
@ -192,7 +192,7 @@ public class Operation extends Resource {
return super.string() return super.string()
.omitNullValues() .omitNullValues()
.add("targetLink", targetLink) .add("targetLink", targetLink)
.add("targetId", targetId) .add("targetId", targetId.orNull())
.add("clientOperationId", clientOperationId.orNull()) .add("clientOperationId", clientOperationId.orNull())
.add("status", status) .add("status", status)
.add("statusMessage", statusMessage.orNull()) .add("statusMessage", statusMessage.orNull())
@ -373,10 +373,17 @@ public class Operation extends Resource {
} }
public Builder fromOperation(Operation in) { public Builder fromOperation(Operation in) {
return super.fromResource(in).targetLink(in.getTargetLink()).targetId(in.getTargetId()).clientOperationId(in return super.fromResource(in)
.getClientOperationId().orNull()).status(in.getStatus()).statusMessage(in.getStatusMessage().orNull()) .targetLink(in.getTargetLink())
.user(in.getUser()).progress(in.getProgress().get()).insertTime(in.getInsertTime()) .targetId(in.getTargetId().orNull())
.startTime(in.getStartTime().orNull()).endTime(in.getEndTime().orNull()) .clientOperationId(in.getClientOperationId().orNull())
.status(in.getStatus())
.statusMessage(in.getStatusMessage().orNull())
.user(in.getUser())
.progress(in.getProgress().get())
.insertTime(in.getInsertTime())
.startTime(in.getStartTime().orNull())
.endTime(in.getEndTime().orNull())
.httpErrorStatusCode(in.getHttpError().isPresent() ? in.getHttpError().get().getStatusCode() : null) .httpErrorStatusCode(in.getHttpError().isPresent() ? in.getHttpError().get().getStatusCode() : null)
.httpErrorMessage(in.getHttpError().isPresent() ? in.getHttpError().get().getMessage() : null) .httpErrorMessage(in.getHttpError().isPresent() ? in.getHttpError().get().getMessage() : null)
.operationType(in.getOperationType()).errors(in.getErrors()); .operationType(in.getOperationType()).errors(in.getErrors());