String templateKey = wsRequest.mandatoryParam(PARAM_LONG_TEMPLATE_ID);
String permission = wsRequest.mandatoryParam(PARAM_PERMISSION);
- WsGroup group = WsGroup.fromRequest(wsRequest);
+ WsGroupRef group = WsGroupRef.fromRequest(wsRequest);
DbSession dbSession = dbClient.openSession(false);
try {
return Optional.absent();
}
- WsProject wsProject = request.project().get();
- return Optional.of(componentFinder.getProjectByUuidOrKey(dbSession, wsProject.uuid(), wsProject.key()));
+ WsProjectRef wsProjectRef = request.project().get();
+ return Optional.of(componentFinder.getProjectByUuidOrKey(dbSession, wsProjectRef.uuid(), wsProjectRef.key()));
}
String getGroupName(DbSession dbSession, PermissionRequest request) {
* @return null if it's the anyone group
*/
@CheckForNull
- GroupDto getGroup(DbSession dbSession, WsGroup group) {
+ GroupDto getGroup(DbSession dbSession, WsGroupRef group) {
Long groupId = group.id();
String groupName = group.name();
class PermissionRequest {
private final String permission;
private final String userLogin;
- private final WsGroup group;
- private final Optional<WsProject> project;
+ private final WsGroupRef group;
+ private final Optional<WsProjectRef> project;
private final Integer page;
private final Integer pageSize;
private final String selected;
private String permission;
private String userLogin;
- private WsGroup group;
- private Optional<WsProject> project;
+ private WsGroupRef group;
+ private Optional<WsProjectRef> project;
private Integer page;
private Integer pageSize;
private String selected;
private void setGroup(Request request) {
if (withGroup) {
- this.group = WsGroup.fromRequest(request);
+ this.group = WsGroupRef.fromRequest(request);
}
}
private void setProject(Request request) {
- this.project = WsProject.fromRequest(request);
+ this.project = WsProjectRef.fromRequest(request);
}
private void checkPermissionParameter() {
return userLogin;
}
- WsGroup group() {
+ WsGroupRef group() {
return group;
}
- Optional<WsProject> project() {
+ Optional<WsProjectRef> project() {
return project;
}
String templateKey = wsRequest.mandatoryParam(PARAM_LONG_TEMPLATE_ID);
String permission = wsRequest.mandatoryParam(PARAM_PERMISSION);
- WsGroup group = WsGroup.fromRequest(wsRequest);
+ WsGroupRef group = WsGroupRef.fromRequest(wsRequest);
DbSession dbSession = dbClient.openSession(false);
try {
}
private void checkRequestAndPermissions(Request wsRequest) {
- Optional<WsProject> project = WsProject.fromRequest(wsRequest);
+ Optional<WsProjectRef> project = WsProjectRef.fromRequest(wsRequest);
boolean hasProject = project.isPresent();
boolean hasProjectUuid = hasProject && project.get().uuid() != null;
boolean hasProjectKey = hasProject && project.get().key() != null;
private List<ComponentDto> searchRootComponents(DbSession dbSession, Request wsRequest, Paging paging) {
String query = wsRequest.param(TEXT_QUERY);
- Optional<WsProject> project = WsProject.fromRequest(wsRequest);
+ Optional<WsProjectRef> project = WsProjectRef.fromRequest(wsRequest);
if (project.isPresent()) {
return singletonList(componentFinder.getProjectByUuidOrKey(dbSession, project.get().uuid(), project.get().key()));
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.permission.ws;
-
-import javax.annotation.Nullable;
-import org.sonar.api.server.ws.Request;
-
-import static org.sonar.server.permission.ws.Parameters.PARAM_GROUP_ID;
-import static org.sonar.server.permission.ws.Parameters.PARAM_GROUP_NAME;
-import static org.sonar.server.ws.WsUtils.checkRequest;
-
-/**
- * Group from a WS request. Guaranties the group id or the group name is provided, not both.
- */
-class WsGroup {
-
- private final Long id;
- private final String name;
-
- private WsGroup(Long id, String name) {
- checkRequest(id != null ^ name != null, "Group name or group id must be provided, not both.");
-
- this.id = id;
- this.name = name;
- }
-
- static WsGroup fromRequest(Request wsRequest) {
- Long id = wsRequest.paramAsLong(PARAM_GROUP_ID);
- String name = wsRequest.param(PARAM_GROUP_NAME);
-
- return new WsGroup(id, name);
- }
-
- @Nullable
- Long id() {
- return this.id;
- }
-
- @Nullable
- String name() {
- return this.name;
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.permission.ws;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.api.server.ws.Request;
+
+import static org.sonar.server.permission.ws.Parameters.PARAM_GROUP_ID;
+import static org.sonar.server.permission.ws.Parameters.PARAM_GROUP_NAME;
+import static org.sonar.server.ws.WsUtils.checkRequest;
+
+/**
+ * Group from a WS request. Guaranties the group id or the group name is provided, not both.
+ */
+class WsGroupRef {
+
+ private final Long id;
+ private final String name;
+
+ private WsGroupRef(@Nullable Long id, @Nullable String name) {
+ checkRequest(id != null ^ name != null, "Group name or group id must be provided, not both.");
+
+ this.id = id;
+ this.name = name;
+ }
+
+ static WsGroupRef fromRequest(Request wsRequest) {
+ Long id = wsRequest.paramAsLong(PARAM_GROUP_ID);
+ String name = wsRequest.param(PARAM_GROUP_NAME);
+
+ return new WsGroupRef(id, name);
+ }
+
+ @CheckForNull
+ Long id() {
+ return this.id;
+ }
+
+ @CheckForNull
+ String name() {
+ return this.name;
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package org.sonar.server.permission.ws;
-
-import com.google.common.base.Optional;
-import javax.annotation.Nullable;
-import org.sonar.api.server.ws.Request;
-
-import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_KEY;
-import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_UUID;
-import static org.sonar.server.ws.WsUtils.checkRequest;
-
-/**
- * Project identifiers from a WS request. Guaranties the project id and project key are not provided at the same time.
- */
-class WsProject {
- private final String uuid;
- private final String key;
-
- private WsProject(String uuid, String key) {
- checkRequest(uuid != null ^ key != null, "Project id or project key can be provided, not both.");
-
- this.uuid = uuid;
- this.key = key;
- }
-
- static Optional<WsProject> fromRequest(Request wsRequest) {
- if (hasNoProjectParam(wsRequest)) {
- return Optional.absent();
- }
-
- return Optional.of(new WsProject(
- wsRequest.param(PARAM_PROJECT_UUID),
- wsRequest.param(PARAM_PROJECT_KEY))
- );
- }
-
- @Nullable
- String uuid() {
- return this.uuid;
- }
-
- @Nullable
- String key() {
- return this.key;
- }
-
- private static boolean hasNoProjectParam(Request wsRequest) {
- return !wsRequest.hasParam(PARAM_PROJECT_UUID) && !wsRequest.hasParam(PARAM_PROJECT_KEY);
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.server.permission.ws;
+
+import com.google.common.base.Optional;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+import org.sonar.api.server.ws.Request;
+
+import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_KEY;
+import static org.sonar.server.permission.ws.Parameters.PARAM_PROJECT_UUID;
+import static org.sonar.server.ws.WsUtils.checkRequest;
+
+/**
+ * Project identifiers from a WS request. Guaranties the project id and project key are not provided at the same time.
+ */
+class WsProjectRef {
+ private final String uuid;
+ private final String key;
+
+ private WsProjectRef(@Nullable String uuid, @Nullable String key) {
+ checkRequest(uuid != null ^ key != null, "Project id or project key can be provided, not both.");
+
+ this.uuid = uuid;
+ this.key = key;
+ }
+
+ static Optional<WsProjectRef> fromRequest(Request wsRequest) {
+ if (hasNoProjectParam(wsRequest)) {
+ return Optional.absent();
+ }
+
+ return Optional.of(new WsProjectRef(
+ wsRequest.param(PARAM_PROJECT_UUID),
+ wsRequest.param(PARAM_PROJECT_KEY))
+ );
+ }
+
+ @CheckForNull
+ String uuid() {
+ return this.uuid;
+ }
+
+ @CheckForNull
+ String key() {
+ return this.key;
+ }
+
+ private static boolean hasNoProjectParam(Request wsRequest) {
+ return !wsRequest.hasParam(PARAM_PROJECT_UUID) && !wsRequest.hasParam(PARAM_PROJECT_KEY);
+ }
+}