Line data Source code
1 : // Copyright (C) 2016 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.entities.RobotComment; 18 : import com.google.gerrit.extensions.registration.DynamicMap; 19 : import com.google.gerrit.extensions.restapi.ChildCollection; 20 : import com.google.gerrit.extensions.restapi.IdString; 21 : import com.google.gerrit.extensions.restapi.ResourceNotFoundException; 22 : import com.google.gerrit.extensions.restapi.RestView; 23 : import com.google.gerrit.server.CommentsUtil; 24 : import com.google.gerrit.server.change.RevisionResource; 25 : import com.google.gerrit.server.change.RobotCommentResource; 26 : import com.google.gerrit.server.notedb.ChangeNotes; 27 : import com.google.inject.Inject; 28 : import com.google.inject.Singleton; 29 : 30 : @Singleton 31 : public class RobotComments implements ChildCollection<RevisionResource, RobotCommentResource> { 32 : private final DynamicMap<RestView<RobotCommentResource>> views; 33 : private final ListRobotComments list; 34 : private final CommentsUtil commentsUtil; 35 : 36 : @Inject 37 : RobotComments( 38 : DynamicMap<RestView<RobotCommentResource>> views, 39 : ListRobotComments list, 40 145 : CommentsUtil commentsUtil) { 41 145 : this.views = views; 42 145 : this.list = list; 43 145 : this.commentsUtil = commentsUtil; 44 145 : } 45 : 46 : @Override 47 : public DynamicMap<RestView<RobotCommentResource>> views() { 48 1 : return views; 49 : } 50 : 51 : @Override 52 : public ListRobotComments list() { 53 1 : return list; 54 : } 55 : 56 : @Override 57 : public RobotCommentResource parse(RevisionResource rev, IdString id) 58 : throws ResourceNotFoundException { 59 2 : String uuid = id.get(); 60 2 : ChangeNotes notes = rev.getNotes(); 61 : 62 2 : for (RobotComment c : commentsUtil.robotCommentsByPatchSet(notes, rev.getPatchSet().id())) { 63 2 : if (uuid.equals(c.key.uuid)) { 64 2 : return new RobotCommentResource(rev, c); 65 : } 66 0 : } 67 0 : throw new ResourceNotFoundException(id); 68 : } 69 : }