Omit change JSON fields when data is missing

If the project has gone missing and the ChangeControl cannot be built
simply omit the optional fields from the JSON result object. This is
a signal to a client that the server cannot obtain the correct data.
Instead of lieing and returning an empty list or map, omit the field
and let clients detect this omission and handle it on their own.

Change-Id: I5a737a9dc53be889bf11bc71ded3db9099bdca6a
This commit is contained in:
Shawn Pearce
2013-03-08 17:15:36 -08:00
parent c09b4048fa
commit 42517be1d3

View File

@@ -248,7 +248,7 @@ public class ChangeJson {
out.reviewed = in.getStatus().isOpen() && isChangeReviewed(cd) ? true : null;
out.labels = labelsFor(cd, options.contains(LABELS),
options.contains(DETAILED_LABELS));
if (options.contains(DETAILED_LABELS)) {
if (out.labels != null && options.contains(DETAILED_LABELS)) {
out.permitted_labels = permittedLabels(cd);
out.removable_reviewers = removableReviewers(cd, out.labels.values());
}
@@ -257,10 +257,12 @@ public class ChangeJson {
if (options.contains(ALL_REVISIONS) || options.contains(CURRENT_REVISION)
|| cd.getLimitedPatchSets() != null) {
out.revisions = revisions(cd);
for (String commit : out.revisions.keySet()) {
if (out.revisions.get(commit).isCurrent) {
out.current_revision = commit;
break;
if (out.revisions != null) {
for (String commit : out.revisions.keySet()) {
if (out.revisions.get(commit).isCurrent) {
out.current_revision = commit;
break;
}
}
}
}
@@ -315,12 +317,12 @@ public class ChangeJson {
ChangeControl ctl = control(cd);
if (ctl == null) {
return Collections.emptyMap();
return null;
}
PatchSet ps = cd.currentPatchSet(db);
if (ps == null) {
return Collections.emptyMap();
return null;
}
if (cd.getChange().getStatus().isOpen()) {
@@ -553,7 +555,7 @@ public class ChangeJson {
throws OrmException {
ChangeControl ctl = control(cd);
if (ctl == null) {
return Collections.emptyMap();
return null;
}
ListMultimap<String, String> permitted = LinkedListMultimap.create();
@@ -592,7 +594,7 @@ public class ChangeJson {
Collection<LabelInfo> labels) throws OrmException {
ChangeControl ctl = control(cd);
if (ctl == null) {
return ImmutableList.of();
return null;
}
Set<Account.Id> fixed = Sets.newHashSetWithExpectedSize(labels.size());
@@ -656,7 +658,7 @@ public class ChangeJson {
private Map<String, RevisionInfo> revisions(ChangeData cd) throws OrmException {
ChangeControl ctl = control(cd);
if (ctl == null) {
return Collections.emptyMap();
return null;
}
Collection<PatchSet> src;