Search in sources :

Example 1 with RemoteJsonException

use of com.google.gwtjsonrpc.client.RemoteJsonException in project gerrit by GerritCodeReview.

the class ProjectAccessScreen method onCommit.

@UiHandler("commit")
void onCommit(@SuppressWarnings("unused") ClickEvent event) {
    final ProjectAccess access = driver.flush();
    if (driver.hasErrors()) {
        Window.alert(AdminConstants.I.errorsMustBeFixed());
        return;
    }
    String message = commitMessage.getText().trim();
    if ("".equals(message)) {
        message = null;
    }
    enable(false);
    //
    Util.PROJECT_SVC.changeProjectAccess(//
    getProjectKey(), //
    access.getRevision(), //
    message, //
    access.getLocal(), //
    access.getInheritsFrom(), new GerritCallback<ProjectAccess>() {

        @Override
        public void onSuccess(ProjectAccess newAccess) {
            enable(true);
            commitMessage.setText("");
            error.clear();
            final Set<String> diffs = getDiffs(access, newAccess);
            if (diffs.isEmpty()) {
                displayReadOnly(newAccess);
            } else {
                error.add(new Label(Gerrit.C.projectAccessError()));
                for (final String diff : diffs) {
                    error.add(new Label(diff));
                }
                if (access.canUpload()) {
                    error.add(new Label(Gerrit.C.projectAccessProposeForReviewHint()));
                }
            }
        }

        private Set<String> getDiffs(ProjectAccess wantedAccess, ProjectAccess newAccess) {
            List<AccessSection> wantedSections = mergeSections(removeEmptyPermissionsAndSections(wantedAccess.getLocal()));
            List<AccessSection> newSections = removeEmptyPermissionsAndSections(newAccess.getLocal());
            HashSet<AccessSection> same = new HashSet<>(wantedSections);
            HashSet<AccessSection> different = new HashSet<>(wantedSections.size() + newSections.size());
            different.addAll(wantedSections);
            different.addAll(newSections);
            same.retainAll(newSections);
            different.removeAll(same);
            Set<String> differentNames = new HashSet<>();
            for (AccessSection s : different) {
                differentNames.add(s.getName());
            }
            return differentNames;
        }

        @Override
        public void onFailure(Throwable caught) {
            error.clear();
            enable(true);
            if (caught instanceof RemoteJsonException && caught.getMessage().startsWith(UpdateParentFailedException.MESSAGE)) {
                new ErrorDialog(Gerrit.M.parentUpdateFailed(caught.getMessage().substring(UpdateParentFailedException.MESSAGE.length() + 1))).center();
            } else {
                super.onFailure(caught);
            }
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Label(com.google.gwt.user.client.ui.Label) RemoteJsonException(com.google.gwtjsonrpc.client.RemoteJsonException) ErrorDialog(com.google.gerrit.client.ErrorDialog) ProjectAccess(com.google.gerrit.common.data.ProjectAccess) AccessSection(com.google.gerrit.common.data.AccessSection) List(java.util.List) HashSet(java.util.HashSet) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Aggregations

ErrorDialog (com.google.gerrit.client.ErrorDialog)1 AccessSection (com.google.gerrit.common.data.AccessSection)1 ProjectAccess (com.google.gerrit.common.data.ProjectAccess)1 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 Label (com.google.gwt.user.client.ui.Label)1 RemoteJsonException (com.google.gwtjsonrpc.client.RemoteJsonException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1