Line data Source code
1 : // Copyright (C) 2012 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 static com.google.gerrit.server.project.BranchResource.BRANCH_KIND; 18 : import static com.google.gerrit.server.project.ChildProjectResource.CHILD_PROJECT_KIND; 19 : import static com.google.gerrit.server.project.CommitResource.COMMIT_KIND; 20 : import static com.google.gerrit.server.project.DashboardResource.DASHBOARD_KIND; 21 : import static com.google.gerrit.server.project.FileResource.FILE_KIND; 22 : import static com.google.gerrit.server.project.LabelResource.LABEL_KIND; 23 : import static com.google.gerrit.server.project.ProjectResource.PROJECT_KIND; 24 : import static com.google.gerrit.server.project.SubmitRequirementResource.SUBMIT_REQUIREMENT_KIND; 25 : import static com.google.gerrit.server.project.TagResource.TAG_KIND; 26 : 27 : import com.google.gerrit.extensions.registration.DynamicMap; 28 : import com.google.gerrit.extensions.registration.DynamicSet; 29 : import com.google.gerrit.extensions.restapi.RestApiModule; 30 : import com.google.gerrit.server.config.GerritConfigListener; 31 : import com.google.gerrit.server.project.RefValidationHelper; 32 : import com.google.gerrit.server.restapi.change.CherryPickCommit; 33 : import com.google.gerrit.server.validators.ProjectCreationValidationListener; 34 : 35 152 : public class ProjectRestApiModule extends RestApiModule { 36 : 37 : @Override 38 : protected void configure() { 39 152 : bind(ProjectsCollection.class); 40 152 : bind(DashboardsCollection.class); 41 : 42 152 : DynamicMap.mapOf(binder(), PROJECT_KIND); 43 152 : DynamicMap.mapOf(binder(), CHILD_PROJECT_KIND); 44 152 : DynamicMap.mapOf(binder(), BRANCH_KIND); 45 152 : DynamicMap.mapOf(binder(), DASHBOARD_KIND); 46 152 : DynamicMap.mapOf(binder(), FILE_KIND); 47 152 : DynamicMap.mapOf(binder(), COMMIT_KIND); 48 152 : DynamicMap.mapOf(binder(), TAG_KIND); 49 152 : DynamicMap.mapOf(binder(), LABEL_KIND); 50 152 : DynamicMap.mapOf(binder(), SUBMIT_REQUIREMENT_KIND); 51 : 52 152 : DynamicSet.bind(binder(), GerritConfigListener.class).to(SetParent.class); 53 152 : DynamicSet.bind(binder(), ProjectCreationValidationListener.class) 54 152 : .to(CreateProject.ValidBranchListener.class); 55 : 56 152 : create(PROJECT_KIND).to(CreateProject.class); 57 152 : put(PROJECT_KIND).to(PutProject.class); 58 152 : get(PROJECT_KIND).to(GetProject.class); 59 152 : get(PROJECT_KIND, "description").to(GetDescription.class); 60 152 : put(PROJECT_KIND, "description").to(PutDescription.class); 61 152 : delete(PROJECT_KIND, "description").to(PutDescription.class); 62 : 63 152 : get(PROJECT_KIND, "access").to(GetAccess.class); 64 152 : post(PROJECT_KIND, "access").to(SetAccess.class); 65 152 : put(PROJECT_KIND, "access:review").to(CreateAccessChange.class); 66 152 : get(PROJECT_KIND, "check.access").to(CheckAccess.class); 67 : 68 152 : post(PROJECT_KIND, "check").to(Check.class); 69 : 70 152 : get(PROJECT_KIND, "parent").to(GetParent.class); 71 152 : put(PROJECT_KIND, "parent").to(SetParent.class); 72 : 73 152 : child(PROJECT_KIND, "children").to(ChildProjectsCollection.class); 74 152 : get(CHILD_PROJECT_KIND).to(GetChildProject.class); 75 : 76 152 : child(PROJECT_KIND, "labels").to(LabelsCollection.class); 77 152 : create(LABEL_KIND).to(CreateLabel.class); 78 152 : get(LABEL_KIND).to(GetLabel.class); 79 152 : put(LABEL_KIND).to(SetLabel.class); 80 152 : delete(LABEL_KIND).to(DeleteLabel.class); 81 152 : postOnCollection(LABEL_KIND).to(PostLabels.class); 82 : 83 152 : child(PROJECT_KIND, "submit_requirements").to(SubmitRequirementsCollection.class); 84 152 : create(SUBMIT_REQUIREMENT_KIND).to(CreateSubmitRequirement.class); 85 152 : put(SUBMIT_REQUIREMENT_KIND).to(UpdateSubmitRequirement.class); 86 152 : get(SUBMIT_REQUIREMENT_KIND).to(GetSubmitRequirement.class); 87 152 : delete(SUBMIT_REQUIREMENT_KIND).to(DeleteSubmitRequirement.class); 88 : 89 152 : get(PROJECT_KIND, "HEAD").to(GetHead.class); 90 152 : put(PROJECT_KIND, "HEAD").to(SetHead.class); 91 : 92 152 : put(PROJECT_KIND, "ban").to(BanCommit.class); 93 : 94 152 : post(PROJECT_KIND, "index").to(Index.class); 95 : 96 152 : child(PROJECT_KIND, "branches").to(BranchesCollection.class); 97 152 : create(BRANCH_KIND).to(CreateBranch.class); 98 152 : post(PROJECT_KIND, "create.change").to(CreateChange.class); 99 152 : put(BRANCH_KIND).to(PutBranch.class); 100 152 : get(BRANCH_KIND).to(GetBranch.class); 101 152 : delete(BRANCH_KIND).to(DeleteBranch.class); 102 152 : post(PROJECT_KIND, "branches:delete").to(DeleteBranches.class); 103 152 : get(BRANCH_KIND, "mergeable").to(CheckMergeability.class); 104 152 : factory(RefValidationHelper.Factory.class); 105 152 : get(BRANCH_KIND, "reflog").to(GetReflog.class); 106 152 : child(BRANCH_KIND, "files").to(FilesCollection.class); 107 152 : get(FILE_KIND, "content").to(GetContent.class); 108 : 109 152 : child(PROJECT_KIND, "commits").to(CommitsCollection.class); 110 152 : get(PROJECT_KIND, "commits:in").to(CommitsIncludedInRefs.class); 111 152 : get(COMMIT_KIND).to(GetCommit.class); 112 152 : get(COMMIT_KIND, "in").to(CommitIncludedIn.class); 113 152 : child(COMMIT_KIND, "files").to(FilesInCommitCollection.class); 114 : 115 152 : child(PROJECT_KIND, "tags").to(TagsCollection.class); 116 152 : create(TAG_KIND).to(CreateTag.class); 117 152 : get(TAG_KIND).to(GetTag.class); 118 152 : put(TAG_KIND).to(PutTag.class); 119 152 : delete(TAG_KIND).to(DeleteTag.class); 120 152 : post(PROJECT_KIND, "tags:delete").to(DeleteTags.class); 121 : 122 152 : child(PROJECT_KIND, "dashboards").to(DashboardsCollection.class); 123 152 : create(DASHBOARD_KIND).to(CreateDashboard.class); 124 152 : get(DASHBOARD_KIND).to(GetDashboard.class); 125 152 : put(DASHBOARD_KIND).to(SetDashboard.class); 126 152 : delete(DASHBOARD_KIND).to(DeleteDashboard.class); 127 : 128 152 : get(PROJECT_KIND, "config").to(GetConfig.class); 129 152 : put(PROJECT_KIND, "config").to(PutConfig.class); 130 152 : post(COMMIT_KIND, "cherrypick").to(CherryPickCommit.class); 131 : 132 152 : factory(ProjectNode.Factory.class); 133 152 : } 134 : 135 : /** Separately bind batch functionality. */ 136 152 : public static class BatchModule extends RestApiModule { 137 : @Override 138 : protected void configure() { 139 152 : get(PROJECT_KIND, "statistics.git").to(GetStatistics.class); 140 152 : post(PROJECT_KIND, "gc").to(GarbageCollect.class); 141 152 : post(PROJECT_KIND, "index.changes").to(IndexChanges.class); 142 152 : } 143 : } 144 : }