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.change; 16 : 17 : import com.google.gerrit.entities.Change; 18 : import com.google.gerrit.extensions.common.ChangeMessageInfo; 19 : import com.google.gerrit.extensions.restapi.RestResource; 20 : import com.google.gerrit.extensions.restapi.RestView; 21 : import com.google.inject.TypeLiteral; 22 : 23 : /** A change message resource. */ 24 : public class ChangeMessageResource implements RestResource { 25 152 : public static final TypeLiteral<RestView<ChangeMessageResource>> CHANGE_MESSAGE_KIND = 26 152 : new TypeLiteral<>() {}; 27 : 28 : private final ChangeResource changeResource; 29 : private final ChangeMessageInfo changeMessage; 30 : private final int changeMessageIndex; 31 : 32 : public ChangeMessageResource( 33 3 : ChangeResource changeResource, ChangeMessageInfo changeMessage, int changeMessageIndex) { 34 3 : this.changeResource = changeResource; 35 3 : this.changeMessage = changeMessage; 36 3 : this.changeMessageIndex = changeMessageIndex; 37 3 : } 38 : 39 : public ChangeResource getChangeResource() { 40 1 : return changeResource; 41 : } 42 : 43 : public ChangeMessageInfo getChangeMessage() { 44 3 : return changeMessage; 45 : } 46 : 47 : public Change.Id getChangeId() { 48 1 : return changeResource.getId(); 49 : } 50 : 51 : public String getChangeMessageId() { 52 1 : return changeMessage.id; 53 : } 54 : 55 : /** 56 : * Gets the index of the change message among all messages of the change sorted by creation time. 57 : * 58 : * @return the index of the change message. 59 : */ 60 : public int getChangeMessageIndex() { 61 1 : return changeMessageIndex; 62 : } 63 : }