diff options
Diffstat (limited to 'gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetPublishDetailFactory.java')
-rw-r--r-- | gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetPublishDetailFactory.java | 87 |
1 files changed, 8 insertions, 79 deletions
diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetPublishDetailFactory.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetPublishDetailFactory.java index 50baf970da..d0101a688e 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetPublishDetailFactory.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/changedetail/PatchSetPublishDetailFactory.java @@ -14,18 +14,14 @@ package com.google.gerrit.httpd.rpc.changedetail; -import com.google.gerrit.common.data.ApprovalDetail; -import com.google.gerrit.common.data.ApprovalType; -import com.google.gerrit.common.data.ApprovalTypes; +import com.google.gerrit.common.data.LabelType; import com.google.gerrit.common.data.PatchSetPublishDetail; import com.google.gerrit.common.data.PermissionRange; import com.google.gerrit.common.data.SubmitRecord; import com.google.gerrit.httpd.rpc.Handler; -import com.google.gerrit.reviewdb.client.Account; import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.PatchLineComment; import com.google.gerrit.reviewdb.client.PatchSet; -import com.google.gerrit.reviewdb.client.PatchSetApproval; import com.google.gerrit.reviewdb.client.PatchSetInfo; import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.server.IdentifiedUser; @@ -34,14 +30,10 @@ import com.google.gerrit.server.patch.PatchSetInfoFactory; import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException; import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.NoSuchChangeException; -import com.google.gerrit.server.workflow.CategoryFunction; -import com.google.gerrit.server.workflow.FunctionState; import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -53,9 +45,7 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail> private final PatchSetInfoFactory infoFactory; private final ReviewDb db; - private final FunctionState.Factory functionState; private final ChangeControl.Factory changeControlFactory; - private final ApprovalTypes approvalTypes; private final AccountInfoCacheFactory aic; private final IdentifiedUser user; @@ -69,15 +59,11 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail> PatchSetPublishDetailFactory(final PatchSetInfoFactory infoFactory, final ReviewDb db, final AccountInfoCacheFactory.Factory accountInfoCacheFactory, - final FunctionState.Factory functionState, final ChangeControl.Factory changeControlFactory, - final ApprovalTypes approvalTypes, final IdentifiedUser user, @Assisted final PatchSet.Id patchSetId) { this.infoFactory = infoFactory; this.db = db; - this.functionState = functionState; this.changeControlFactory = changeControlFactory; - this.approvalTypes = approvalTypes; this.aic = accountInfoCacheFactory.create(); this.user = user; @@ -101,9 +87,6 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail> detail.setChange(change); detail.setDrafts(drafts); - List<PermissionRange> allowed = Collections.emptyList(); - List<PatchSetApproval> given = Collections.emptyList(); - if (change.getStatus().isOpen() && patchSetId.equals(change.currentPatchSetId())) { // TODO Push this selection of labels down into the Prolog interpreter. @@ -120,11 +103,6 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail> rangeByName.put(r.getLabel(), r); } } - allowed = new ArrayList<PermissionRange>(); - - given = db.patchSetApprovals() // - .byPatchSetUser(patchSetId, user.getAccountId()) // - .toList(); boolean couldSubmit = false; List<SubmitRecord> submitRecords = control.canSubmit(db, patchSet); @@ -142,12 +120,8 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail> boolean canMakeOk = false; PermissionRange range = rangeByName.get(lbl.label); if (range != null) { - if (!allowed.contains(range)) { - allowed.add(range); - } - - ApprovalType at = approvalTypes.byLabel(lbl.label); - if (at == null || at.getMax().getValue() == range.getMax()) { + LabelType lt = control.getLabelTypes().byLabel(lbl.label); + if (lt != null && lt.getMax().getValue() == range.getMax()) { canMakeOk = true; } } @@ -163,6 +137,10 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail> ok++; } break; + + case IMPOSSIBLE: + case REJECT: + break; } } @@ -176,60 +154,11 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail> if (couldSubmit && control.getRefControl().canSubmit()) { detail.setCanSubmit(true); } - - detail.setSubmitRecords(submitRecords); } - detail.setLabels(allowed); - detail.setGiven(given); - loadApprovals(detail, control); - + detail.setSubmitTypeRecord(control.getSubmitTypeRecord(db, patchSet)); detail.setAccounts(aic.create()); return detail; } - - private void loadApprovals(final PatchSetPublishDetail detail, - final ChangeControl control) throws OrmException { - final PatchSet.Id psId = detail.getChange().currentPatchSetId(); - final Change.Id changeId = patchSetId.getParentKey(); - final List<PatchSetApproval> allApprovals = - db.patchSetApprovals().byChange(changeId).toList(); - - if (detail.getChange().getStatus().isOpen()) { - final FunctionState fs = functionState.create(control, psId, allApprovals); - - for (final ApprovalType at : approvalTypes.getApprovalTypes()) { - CategoryFunction.forCategory(at.getCategory()).run(at, fs); - } - } - - final boolean canRemoveReviewers = detail.getChange().getStatus().isOpen() // - && control.getCurrentUser() instanceof IdentifiedUser; - final HashMap<Account.Id, ApprovalDetail> ad = - new HashMap<Account.Id, ApprovalDetail>(); - for (PatchSetApproval ca : allApprovals) { - ApprovalDetail d = ad.get(ca.getAccountId()); - if (d == null) { - d = new ApprovalDetail(ca.getAccountId()); - d.setCanRemove(canRemoveReviewers); - ad.put(d.getAccount(), d); - } - if (d.canRemove()) { - d.setCanRemove(control.canRemoveReviewer(ca)); - } - if (ca.getPatchSetId().equals(psId)) { - d.add(ca); - } - } - - final Account.Id owner = detail.getChange().getOwner(); - if (ad.containsKey(owner)) { - // Ensure the owner always sorts to the top of the table - ad.get(owner).sortFirst(); - } - - aic.want(ad.keySet()); - detail.setApprovals(ad.values()); - } } |