3 * Copyright (C) 2009-2016 SonarSource SA
4 * mailto:contact AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.permission.ws;
22 import org.sonar.api.server.ws.WebService.NewAction;
23 import org.sonar.core.permission.GlobalPermissions;
24 import org.sonar.core.permission.ProjectPermissions;
25 import org.sonar.core.util.Uuids;
27 import static java.lang.String.format;
28 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_DESCRIPTION;
29 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_ID;
30 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_GROUP_NAME;
31 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_ID;
32 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PERMISSION;
33 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_ID;
34 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY;
35 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_PROJECT_KEY_PATTERN;
36 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_ID;
37 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_TEMPLATE_NAME;
38 import static org.sonarqube.ws.client.permission.PermissionsWsParameters.PARAM_USER_LOGIN;
40 public class PermissionsWsParametersBuilder {
42 private static final String PERMISSION_PARAM_DESCRIPTION = format("Permission" +
44 "<li>Possible values for global permissions: %s</li>" +
45 "<li>Possible values for project permissions %s</li>" +
47 GlobalPermissions.ALL_ON_ONE_LINE,
48 ProjectPermissions.ALL_ON_ONE_LINE);
49 private static final String PROJECT_PERMISSION_PARAM_DESCRIPTION = format("Permission" +
51 "<li>Possible values for project permissions %s</li>" +
53 ProjectPermissions.ALL_ON_ONE_LINE);
55 private PermissionsWsParametersBuilder() {
56 // static methods only
59 public static void createPermissionParameter(NewAction action) {
60 action.createParam(PARAM_PERMISSION)
61 .setDescription(PERMISSION_PARAM_DESCRIPTION)
65 public static void createProjectPermissionParameter(NewAction action) {
66 action.createParam(PARAM_PERMISSION)
67 .setDescription(PROJECT_PERMISSION_PARAM_DESCRIPTION)
71 public static void createGroupNameParameter(NewAction action) {
72 action.createParam(PARAM_GROUP_NAME)
73 .setDescription("Group name or 'anyone' (case insensitive)")
74 .setExampleValue("sonar-administrators");
77 public static void createGroupIdParameter(NewAction action) {
78 action.createParam(PARAM_GROUP_ID)
79 .setDescription("Group id")
80 .setExampleValue("42");
83 public static void createProjectParameter(NewAction action) {
84 createProjectIdParameter(action);
85 createProjectKeyParameter(action);
88 private static void createProjectIdParameter(NewAction action) {
89 action.createParam(PARAM_PROJECT_ID)
90 .setDescription("Project id")
91 .setExampleValue("ce4c03d6-430f-40a9-b777-ad877c00aa4d");
94 private static void createProjectKeyParameter(NewAction action) {
95 action.createParam(PARAM_PROJECT_KEY)
96 .setDescription("Project key")
97 .setExampleValue("org.apache.hbas:hbase");
100 public static void createUserLoginParameter(NewAction action) {
101 action.createParam(PARAM_USER_LOGIN)
103 .setDescription("User login")
104 .setExampleValue("g.hopper");
107 public static void createTemplateParameters(NewAction action) {
108 createTemplateIdParameter(action);
109 createTemplateNameParameter(action);
112 private static void createTemplateIdParameter(NewAction action) {
113 action.createParam(PARAM_TEMPLATE_ID)
114 .setDescription("Template id")
115 .setExampleValue(Uuids.UUID_EXAMPLE_01);
118 private static void createTemplateNameParameter(NewAction action) {
119 action.createParam(PARAM_TEMPLATE_NAME)
120 .setDescription("Template name")
121 .setExampleValue("Default Permission Template for Projects");
124 public static void createTemplateProjectKeyPatternParameter(NewAction action) {
125 action.createParam(PARAM_PROJECT_KEY_PATTERN)
126 .setDescription("Project key pattern. Must be a valid Java regular expression")
127 .setExampleValue(".*\\.finance\\..*");
130 public static void createTemplateDescriptionParameter(NewAction action) {
131 action.createParam(PARAM_DESCRIPTION)
132 .setDescription("Description")
133 .setExampleValue("Permissions for all projects related to the financial service");
136 public static void createIdParameter(NewAction action) {
137 action.createParam(PARAM_ID)
139 .setDescription("Id")
140 .setExampleValue("af8cb8cc-1e78-4c4e-8c00-ee8e814009a5");