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);
}
}
});
}
Aggregations