Package com.google.gerrit.common.data

Examples of com.google.gerrit.common.data.ReviewResult


  @Override
  public ChangeDetail call() throws OrmException, NoSuchEntityException,
      IllegalStateException, PatchSetInfoNotAvailableException,
      NoSuchChangeException, RepositoryNotFoundException, IOException {
    final ReviewResult result = publishFactory.create(patchSetId).call();
    if (result.getErrors().size() > 0) {
      throw new IllegalStateException("Cannot publish patchset");
    }
    return changeDetailFactory.create(result.getChangeId()).call();
  }
View Full Code Here


      PatchSetInfoNotAvailableException, RepositoryNotFoundException,
      IOException {
    final RestoreChange restoreChange = restoreChangeProvider.get();
    restoreChange.setChangeId(patchSetId.getParentKey());
    restoreChange.setMessage(message);
    final ReviewResult result = restoreChange.call();
    if (result.getErrors().size() > 0) {
      throw new NoSuchChangeException(result.getChangeId());
    }
    return changeDetailFactory.create(result.getChangeId()).call();
  }
View Full Code Here

  public void deleteDraftPatchSet(final PatchSet.Id psid,
      final AsyncCallback<ChangeDetail> callback) {
    run(callback, new Action<ChangeDetail>() {
      public ChangeDetail run(ReviewDb db) throws OrmException, Failure {
        ReviewResult result = null;
        try {
          result = deleteDraftPatchSetFactory.create(psid).call();
          if (result.getErrors().size() > 0) {
            throw new Failure(new NoSuchEntityException());
          }
          if (result.getChangeId() == null) {
            // the change was deleted because the draft patch set that was
            // deleted was the only patch set in the change
            return null;
          }
          return changeDetailFactory.create(result.getChangeId()).call();
        } catch (NoSuchChangeException e) {
          throw new Failure(new NoSuchChangeException(result.getChangeId()));
        } catch (NoSuchEntityException e) {
          throw new Failure(e);
        } catch (PatchSetInfoNotAvailableException e) {
          throw new Failure(e);
        } catch (RepositoryNotFoundException e) {
View Full Code Here

  @Override
  public ChangeDetail call() throws OrmException, NoSuchEntityException,
      IllegalStateException, InvalidChangeOperationException,
      PatchSetInfoNotAvailableException, NoSuchChangeException,
      RepositoryNotFoundException, IOException {
    final ReviewResult result =
        submitFactory.create(patchSetId).call();
    if (result.getErrors().size() > 0) {
      throw new IllegalStateException(
          "Cannot submit " + result.getErrors().get(0).getMessageOrType());
    }
    return changeDetailFactory.create(result.getChangeId()).call();
  }
View Full Code Here

      PatchSetInfoNotAvailableException, RepositoryNotFoundException,
      IOException {
    final AbandonChange abandonChange = abandonChangeProvider.get();
    abandonChange.setChangeId(patchSetId.getParentKey());
    abandonChange.setMessage(message);
    final ReviewResult result = abandonChange.call();
    if (result.getErrors().size() > 0) {
      throw new NoSuchChangeException(result.getChangeId());
    }
    return changeDetailFactory.create(result.getChangeId()).call();
  }
View Full Code Here

      if (abandonChange) {
        final AbandonChange abandonChange = abandonChangeProvider.get();
        abandonChange.setChangeId(patchSetId.getParentKey());
        abandonChange.setMessage(changeComment);
        final ReviewResult result = abandonChange.call();
        handleReviewResultErrors(result);
      } else if (restoreChange) {
        final RestoreChange restoreChange = restoreChangeProvider.get();
        restoreChange.setChangeId(patchSetId.getParentKey());
        restoreChange.setMessage(changeComment);
        final ReviewResult result = restoreChange.call();
        handleReviewResultErrors(result);
      }
      if (submitChange) {
        final ReviewResult result = submitFactory.create(patchSetId).call();
        handleReviewResultErrors(result);
      }
    } catch (InvalidChangeOperationException e) {
      throw error(e.getMessage());
    } catch (IllegalStateException e) {
      throw error(e.getMessage());
    }

    if (publishPatchSet) {
      final ReviewResult result = publishDraftFactory.create(patchSetId).call();
      handleReviewResultErrors(result);
    } else if (deleteDraftPatchSet) {
      final ReviewResult result =
          deleteDraftPatchSetFactory.create(patchSetId).call();
      handleReviewResultErrors(result);
    }
  }
View Full Code Here

    this.patchSetId = patchSetId;
  }

  @Override
  public ReviewResult call() throws NoSuchChangeException, OrmException {
    final ReviewResult result = new ReviewResult();

    final Change.Id changeId = patchSetId.getParentKey();
    result.setChangeId(changeId);
    final ChangeControl control = changeControlFactory.validateFor(changeId);
    final PatchSet patch = db.patchSets().get(patchSetId);
    if (patch == null) {
      throw new NoSuchChangeException(changeId);
    }
    if (!patch.isDraft()) {
      result.addError(new ReviewResult.Error(
          ReviewResult.Error.Type.NOT_A_DRAFT));
      return result;
    }

    if (!control.canPublish(db)) {
      result.addError(new ReviewResult.Error(
          ReviewResult.Error.Type.PUBLISH_NOT_PERMITTED));
    } else {
      boolean published = false;
      final PatchSet updatedPatch = db.patchSets().atomicUpdate(patchSetId,
          new AtomicUpdate<PatchSet>() {
View Full Code Here

      InvalidChangeOperationException, NoSuchChangeException, OrmException {
    if (changeId == null) {
      throw new InvalidChangeOperationException("changeId is required");
    }

    final ReviewResult result = new ReviewResult();
    result.setChangeId(changeId);

    final ChangeControl control = changeControlFactory.validateFor(changeId);
    final Change change = db.changes().get(changeId);
    final PatchSet.Id patchSetId = change.currentPatchSetId();
    final PatchSet patch = db.patchSets().get(patchSetId);
    if (!control.canAbandon()) {
      result.addError(new ReviewResult.Error(
          ReviewResult.Error.Type.ABANDON_NOT_PERMITTED));
    } else if (patch == null) {
      throw new NoSuchChangeException(changeId);
    } else {

      // Create a message to accompany the abandoned change
      final ChangeMessage cmsg = new ChangeMessage(
          new ChangeMessage.Key(changeId, ChangeUtil.messageUUID(db)),
          currentUser.getAccountId(), patchSetId);
      final StringBuilder msgBuf =
          new StringBuilder("Patch Set " + patchSetId.get() + ": Abandoned");
      if (message != null && message.length() > 0) {
        msgBuf.append("\n\n");
        msgBuf.append(message);
      }
      cmsg.setMessage(msgBuf.toString());

      // Abandon the change
      final Change updatedChange = db.changes().atomicUpdate(changeId,
          new AtomicUpdate<Change>() {
        @Override
        public Change update(Change change) {
          if (change.getStatus().isOpen()) {
            change.setStatus(Change.Status.ABANDONED);
            ChangeUtil.updated(change);
            return change;
          } else {
            return null;
          }
        }
      });

      if (updatedChange == null) {
        result.addError(new ReviewResult.Error(
            ReviewResult.Error.Type.CHANGE_IS_CLOSED));
        return result;
      }

      ChangeUtil.updatedChange(db, currentUser, updatedChange, cmsg,
View Full Code Here

  @Override
  public ReviewResult call() throws IllegalStateException,
      InvalidChangeOperationException, NoSuchChangeException, OrmException,
      IOException {
    final ReviewResult result = new ReviewResult();

    final PatchSet patch = db.patchSets().get(patchSetId);
    final Change.Id changeId = patchSetId.getParentKey();
    final ChangeControl control = changeControlFactory.validateFor(changeId);
    result.setChangeId(changeId);
    if (patch == null) {
      throw new NoSuchChangeException(changeId);
    }

    List<SubmitRecord> submitResult = control.canSubmit(db, patch);
    if (submitResult.isEmpty()) {
      throw new IllegalStateException(
          "ChangeControl.canSubmit returned empty list");
    }

    for (SubmitRecord submitRecord : submitResult) {
      switch (submitRecord.status) {
        case OK:
          if (!control.getRefControl().canSubmit()) {
            result.addError(new ReviewResult.Error(
              ReviewResult.Error.Type.SUBMIT_NOT_PERMITTED));
          }
          break;

        case NOT_READY:
          StringBuilder errMsg = new StringBuilder();
          for (SubmitRecord.Label lbl : submitRecord.labels) {
            switch (lbl.status) {
              case OK:
                break;

              case REJECT:
                if (errMsg.length() > 0) errMsg.append("; ");
                errMsg.append("change " + changeId + ": blocked by "
                              + lbl.label);
                break;

              case NEED:
                if (errMsg.length() > 0) errMsg.append("; ");
                errMsg.append("change " + changeId + ": needs " + lbl.label);
                break;

              case MAY:
                // The MAY label didn't cause the NOT_READY status
                break;

              case IMPOSSIBLE:
                if (errMsg.length() > 0) errMsg.append("; ");
                errMsg.append("change " + changeId + ": needs " + lbl.label
                    + " (check project access)");
                break;

              default:
                throw new IllegalArgumentException(
                    "Unsupported SubmitRecord.Label.status (" + lbl.status
                    + ")");
            }
          }
          result.addError(new ReviewResult.Error(
            ReviewResult.Error.Type.SUBMIT_NOT_READY, errMsg.toString()));
          break;

        case CLOSED:
          result.addError(new ReviewResult.Error(
            ReviewResult.Error.Type.CHANGE_IS_CLOSED));
          break;

        case RULE_ERROR:
          result.addError(new ReviewResult.Error(
            ReviewResult.Error.Type.RULE_ERROR,
            submitResult.get(0).errorMessage));
          break;

        default:
          throw new IllegalStateException(
              "Unsupported SubmitRecord.status + (" + submitRecord.status
              + ")");
      }
    }

    if (!ProjectUtil.branchExists(repoManager, control.getChange().getDest())) {
      result.addError(new ReviewResult.Error(
          ReviewResult.Error.Type.DEST_BRANCH_NOT_FOUND,
          "Destination branch \"" + control.getChange().getDest().get()
              + "\" not found."));
      return result;
    }

    // Submit the change if we can
    if (result.getErrors().isEmpty()) {
      final List<PatchSetApproval> allApprovals =
          new ArrayList<PatchSetApproval>(db.patchSetApprovals().byPatchSet(
              patchSetId).toList());

      final PatchSetApproval.Key akey =
View Full Code Here

      RepositoryNotFoundException, IOException {
    if (changeId == null) {
      throw new InvalidChangeOperationException("changeId is required");
    }

    final ReviewResult result = new ReviewResult();
    result.setChangeId(changeId);

    final ChangeControl control = changeControlFactory.validateFor(changeId);
    final Change change = db.changes().get(changeId);
    final PatchSet.Id patchSetId = change.currentPatchSetId();
    if (!control.canRestore()) {
      result.addError(new ReviewResult.Error(
          ReviewResult.Error.Type.RESTORE_NOT_PERMITTED));
      return result;
    }

    final PatchSet patch = db.patchSets().get(patchSetId);
    if (patch == null) {
      throw new NoSuchChangeException(changeId);
    }

    final Branch.NameKey destBranch = control.getChange().getDest();
    if (!ProjectUtil.branchExists(repoManager, destBranch)) {
      result.addError(new ReviewResult.Error(
          ReviewResult.Error.Type.DEST_BRANCH_NOT_FOUND, destBranch.get()));
      return result;
    }

    // Create a message to accompany the restored change
    final ChangeMessage cmsg =
        new ChangeMessage(new ChangeMessage.Key(changeId, ChangeUtil
            .messageUUID(db)), currentUser.getAccountId(), patchSetId);
    final StringBuilder msgBuf =
        new StringBuilder("Patch Set " + patchSetId.get() + ": Restored");
    if (message != null && message.length() > 0) {
      msgBuf.append("\n\n");
      msgBuf.append(message);
    }
    cmsg.setMessage(msgBuf.toString());

    // Restore the change
    final Change updatedChange = db.changes().atomicUpdate(changeId,
        new AtomicUpdate<Change>() {
          @Override
          public Change update(Change change) {
            if (change.getStatus() == Change.Status.ABANDONED) {
              change.setStatus(Change.Status.NEW);
              ChangeUtil.updated(change);
              return change;
            } else {
              return null;
            }
          }
        });

    if (updatedChange == null) {
      result.addError(new ReviewResult.Error(
          ReviewResult.Error.Type.CHANGE_NOT_ABANDONED));
      return result;
    }

    ChangeUtil.updatedChange(db, currentUser, updatedChange, cmsg,
View Full Code Here

TOP

Related Classes of com.google.gerrit.common.data.ReviewResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.