Line data Source code
1 : // Copyright (C) 2018 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.ChangeMessageApi; 20 : import com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput; 21 : import com.google.gerrit.extensions.common.ChangeMessageInfo; 22 : import com.google.gerrit.extensions.restapi.RestApiException; 23 : import com.google.gerrit.server.change.ChangeMessageResource; 24 : import com.google.gerrit.server.restapi.change.DeleteChangeMessage; 25 : import com.google.gerrit.server.restapi.change.GetChangeMessage; 26 : import com.google.inject.Inject; 27 : import com.google.inject.assistedinject.Assisted; 28 : 29 : class ChangeMessageApiImpl implements ChangeMessageApi { 30 : interface Factory { 31 : ChangeMessageApiImpl create(ChangeMessageResource changeMessageResource); 32 : } 33 : 34 : private final GetChangeMessage getChangeMessage; 35 : private final DeleteChangeMessage deleteChangeMessage; 36 : private final ChangeMessageResource changeMessageResource; 37 : 38 : @Inject 39 : ChangeMessageApiImpl( 40 : GetChangeMessage getChangeMessage, 41 : DeleteChangeMessage deleteChangeMessage, 42 2 : @Assisted ChangeMessageResource changeMessageResource) { 43 2 : this.getChangeMessage = getChangeMessage; 44 2 : this.deleteChangeMessage = deleteChangeMessage; 45 2 : this.changeMessageResource = changeMessageResource; 46 2 : } 47 : 48 : @Override 49 : public ChangeMessageInfo get() throws RestApiException { 50 : try { 51 2 : return getChangeMessage.apply(changeMessageResource).value(); 52 0 : } catch (Exception e) { 53 0 : throw asRestApiException("Cannot retrieve change message", e); 54 : } 55 : } 56 : 57 : @Override 58 : public ChangeMessageInfo delete(DeleteChangeMessageInput input) throws RestApiException { 59 : try { 60 1 : return deleteChangeMessage.apply(changeMessageResource, input).value(); 61 1 : } catch (Exception e) { 62 1 : throw asRestApiException("Cannot delete change message", e); 63 : } 64 : } 65 : }