Line data Source code
1 : // Copyright (C) 2020 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.api.changes; 16 : 17 : import static com.google.gerrit.server.api.ApiUtil.asRestApiException; 18 : 19 : import com.google.gerrit.extensions.api.changes.AttentionSetApi; 20 : import com.google.gerrit.extensions.api.changes.AttentionSetInput; 21 : import com.google.gerrit.extensions.restapi.RestApiException; 22 : import com.google.gerrit.server.change.AttentionSetEntryResource; 23 : import com.google.gerrit.server.restapi.change.RemoveFromAttentionSet; 24 : import com.google.inject.Inject; 25 : import com.google.inject.assistedinject.Assisted; 26 : 27 : public class AttentionSetApiImpl implements AttentionSetApi { 28 : interface Factory { 29 : AttentionSetApiImpl create(AttentionSetEntryResource attentionSetEntryResource); 30 : } 31 : 32 : private final RemoveFromAttentionSet removeFromAttentionSet; 33 : private final AttentionSetEntryResource attentionSetEntryResource; 34 : 35 : @Inject 36 : AttentionSetApiImpl( 37 : RemoveFromAttentionSet removeFromAttentionSet, 38 13 : @Assisted AttentionSetEntryResource attentionSetEntryResource) { 39 13 : this.removeFromAttentionSet = removeFromAttentionSet; 40 13 : this.attentionSetEntryResource = attentionSetEntryResource; 41 13 : } 42 : 43 : @Override 44 : public void remove(AttentionSetInput input) throws RestApiException { 45 : try { 46 13 : removeFromAttentionSet.apply(attentionSetEntryResource, input); 47 1 : } catch (Exception e) { 48 1 : throw asRestApiException("Cannot remove from attention set", e); 49 13 : } 50 13 : } 51 : }