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.project; 16 : 17 : import com.google.gerrit.extensions.registration.DynamicMap; 18 : import com.google.gerrit.extensions.restapi.ChildCollection; 19 : import com.google.gerrit.extensions.restapi.IdString; 20 : import com.google.gerrit.extensions.restapi.ResourceNotFoundException; 21 : import com.google.gerrit.extensions.restapi.RestView; 22 : import com.google.gerrit.server.git.GitRepositoryManager; 23 : import com.google.gerrit.server.project.BranchResource; 24 : import com.google.gerrit.server.project.FileResource; 25 : import com.google.inject.Inject; 26 : import com.google.inject.Singleton; 27 : import java.io.IOException; 28 : import org.eclipse.jgit.lib.ObjectId; 29 : 30 : @Singleton 31 : public class FilesCollection implements ChildCollection<BranchResource, FileResource> { 32 : private final DynamicMap<RestView<FileResource>> views; 33 : private final GitRepositoryManager repoManager; 34 : 35 : @Inject 36 138 : FilesCollection(DynamicMap<RestView<FileResource>> views, GitRepositoryManager repoManager) { 37 138 : this.views = views; 38 138 : this.repoManager = repoManager; 39 138 : } 40 : 41 : @Override 42 : public RestView<BranchResource> list() throws ResourceNotFoundException { 43 1 : throw new ResourceNotFoundException(); 44 : } 45 : 46 : @Override 47 : public FileResource parse(BranchResource parent, IdString id) 48 : throws ResourceNotFoundException, IOException { 49 5 : if (parent.getRevision().isEmpty()) { 50 1 : throw new ResourceNotFoundException(id); 51 : } 52 5 : return FileResource.create( 53 : repoManager, 54 5 : parent.getProjectState(), 55 5 : ObjectId.fromString(parent.getRevision().get()), 56 5 : id.get()); 57 : } 58 : 59 : @Override 60 : public DynamicMap<RestView<FileResource>> views() { 61 1 : return views; 62 : } 63 : }