REST endpoints for managing the attention set

Attention set is returned by default in change details.

Background:
https://www.gerritcodereview.com/design-docs/attention-set.html

Upcoming further changes:
- Add to index
- Extend ReviewInput API to add reviewers
- Add invariants (e.g. user must be reviewer)
- Send notifications in *Attention*Op#postUpdate()
- Consider adding NotificationHandling in AttentionInput
- Consider adding validation listeners

Change-Id: I52ae870a94852ac98f731fef63f65cd2a7064742
This commit is contained in:
Joerg Zieren
2020-03-06 13:44:25 +01:00
parent d4550a1e0b
commit fdbea383d6
38 changed files with 1111 additions and 148 deletions

View File

@@ -0,0 +1,51 @@
// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.api.changes;
import static com.google.gerrit.server.api.ApiUtil.asRestApiException;
import com.google.gerrit.extensions.api.changes.AttentionSetApi;
import com.google.gerrit.extensions.api.changes.RemoveFromAttentionSetInput;
import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.change.AttentionSetEntryResource;
import com.google.gerrit.server.restapi.change.RemoveFromAttentionSet;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
public class AttentionSetApiImpl implements AttentionSetApi {
interface Factory {
AttentionSetApiImpl create(AttentionSetEntryResource attentionSetEntryResource);
}
private final RemoveFromAttentionSet removeFromAttentionSet;
private final AttentionSetEntryResource attentionSetEntryResource;
@Inject
AttentionSetApiImpl(
RemoveFromAttentionSet removeFromAttentionSet,
@Assisted AttentionSetEntryResource attentionSetEntryResource) {
this.removeFromAttentionSet = removeFromAttentionSet;
this.attentionSetEntryResource = attentionSetEntryResource;
}
@Override
public void remove(RemoveFromAttentionSetInput input) throws RestApiException {
try {
removeFromAttentionSet.apply(attentionSetEntryResource, input);
} catch (Exception e) {
throw asRestApiException("Cannot remove from attention set", e);
}
}
}

View File

@@ -23,7 +23,9 @@ import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.extensions.api.changes.AbandonInput;
import com.google.gerrit.extensions.api.changes.AddReviewerInput;
import com.google.gerrit.extensions.api.changes.AddReviewerResult;
import com.google.gerrit.extensions.api.changes.AddToAttentionSetInput;
import com.google.gerrit.extensions.api.changes.AssigneeInput;
import com.google.gerrit.extensions.api.changes.AttentionSetApi;
import com.google.gerrit.extensions.api.changes.ChangeApi;
import com.google.gerrit.extensions.api.changes.ChangeEditApi;
import com.google.gerrit.extensions.api.changes.ChangeMessageApi;
@@ -66,6 +68,8 @@ import com.google.gerrit.server.change.ChangeMessageResource;
import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.change.WorkInProgressOp;
import com.google.gerrit.server.restapi.change.Abandon;
import com.google.gerrit.server.restapi.change.AddToAttentionSet;
import com.google.gerrit.server.restapi.change.AttentionSet;
import com.google.gerrit.server.restapi.change.ChangeIncludedIn;
import com.google.gerrit.server.restapi.change.ChangeMessages;
import com.google.gerrit.server.restapi.change.Check;
@@ -147,6 +151,9 @@ class ChangeApiImpl implements ChangeApi {
private final Provider<GetChange> getChangeProvider;
private final PostHashtags postHashtags;
private final GetHashtags getHashtags;
private final AttentionSet attentionSet;
private final AttentionSetApiImpl.Factory attentionSetApi;
private final AddToAttentionSet addToAttentionSet;
private final PutAssignee putAssignee;
private final GetAssignee getAssignee;
private final GetPastAssignees getPastAssignees;
@@ -197,6 +204,9 @@ class ChangeApiImpl implements ChangeApi {
Provider<GetChange> getChangeProvider,
PostHashtags postHashtags,
GetHashtags getHashtags,
AttentionSet attentionSet,
AttentionSetApiImpl.Factory attentionSetApi,
AddToAttentionSet addToAttentionSet,
PutAssignee putAssignee,
GetAssignee getAssignee,
GetPastAssignees getPastAssignees,
@@ -245,6 +255,9 @@ class ChangeApiImpl implements ChangeApi {
this.getChangeProvider = getChangeProvider;
this.postHashtags = postHashtags;
this.getHashtags = getHashtags;
this.attentionSet = attentionSet;
this.attentionSetApi = attentionSetApi;
this.addToAttentionSet = addToAttentionSet;
this.putAssignee = putAssignee;
this.getAssignee = getAssignee;
this.getPastAssignees = getPastAssignees;
@@ -529,6 +542,24 @@ class ChangeApiImpl implements ChangeApi {
}
}
@Override
public AccountInfo addToAttentionSet(AddToAttentionSetInput input) throws RestApiException {
try {
return addToAttentionSet.apply(change, input).value();
} catch (Exception e) {
throw asRestApiException("Cannot add to attention set", e);
}
}
@Override
public AttentionSetApi attention(String id) throws RestApiException {
try {
return attentionSetApi.create(attentionSet.parse(change, IdString.fromDecoded(id)));
} catch (Exception e) {
throw asRestApiException("Cannot parse account", e);
}
}
@Override
public AccountInfo setAssignee(AssigneeInput input) throws RestApiException {
try {

View File

@@ -32,5 +32,6 @@ public class Module extends FactoryModule {
factory(RevisionReviewerApiImpl.Factory.class);
factory(ChangeEditApiImpl.Factory.class);
factory(ChangeMessageApiImpl.Factory.class);
factory(AttentionSetApiImpl.Factory.class);
}
}