Line data Source code
1 : // Copyright (C) 2013 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.restapi.change; 16 : 17 : import com.google.gerrit.extensions.common.Input; 18 : import com.google.gerrit.extensions.restapi.Response; 19 : import com.google.gerrit.extensions.restapi.RestModifyView; 20 : import com.google.gerrit.server.change.AccountPatchReviewStore; 21 : import com.google.gerrit.server.change.FileResource; 22 : import com.google.gerrit.server.plugincontext.PluginItemContext; 23 : import com.google.inject.Inject; 24 : import com.google.inject.Singleton; 25 : 26 : public class Reviewed { 27 : 28 : @Singleton 29 : public static class PutReviewed implements RestModifyView<FileResource, Input> { 30 : private final PluginItemContext<AccountPatchReviewStore> accountPatchReviewStore; 31 : 32 : @Inject 33 142 : PutReviewed(PluginItemContext<AccountPatchReviewStore> accountPatchReviewStore) { 34 142 : this.accountPatchReviewStore = accountPatchReviewStore; 35 142 : } 36 : 37 : @Override 38 : public Response<String> apply(FileResource resource, Input input) { 39 2 : boolean reviewFlagUpdated = 40 2 : accountPatchReviewStore.call( 41 : s -> 42 2 : s.markReviewed( 43 2 : resource.getPatchKey().patchSetId(), 44 2 : resource.getAccountId(), 45 2 : resource.getPatchKey().fileName())); 46 2 : return reviewFlagUpdated ? Response.created() : Response.ok(); 47 : } 48 : } 49 : 50 : @Singleton 51 : public static class DeleteReviewed implements RestModifyView<FileResource, Input> { 52 : private final PluginItemContext<AccountPatchReviewStore> accountPatchReviewStore; 53 : 54 : @Inject 55 142 : DeleteReviewed(PluginItemContext<AccountPatchReviewStore> accountPatchReviewStore) { 56 142 : this.accountPatchReviewStore = accountPatchReviewStore; 57 142 : } 58 : 59 : @Override 60 : public Response<?> apply(FileResource resource, Input input) { 61 2 : accountPatchReviewStore.run( 62 : s -> 63 2 : s.clearReviewed( 64 2 : resource.getPatchKey().patchSetId(), 65 2 : resource.getAccountId(), 66 2 : resource.getPatchKey().fileName())); 67 2 : return Response.none(); 68 : } 69 : } 70 : 71 : private Reviewed() {} 72 : }