import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.Paging;
import org.sonar.api.web.UserRole;
import org.sonar.core.permission.ComponentPermissions;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDto;
import org.sonar.server.user.UserSession;
+import org.sonarqube.ws.Common;
import org.sonarqube.ws.Permissions.Permission;
import org.sonarqube.ws.Permissions.SearchProjectPermissionsResponse;
import org.sonarqube.ws.Permissions.SearchProjectPermissionsResponse.Project;
);
}
+ Paging paging = data.paging();
+ response.setPaging(
+ Common.Paging.newBuilder()
+ .setPageIndex(paging.pageIndex())
+ .setPageSize(paging.pageSize())
+ .setTotal(paging.total())
+ );
+
return response.build();
}
import com.google.common.collect.Table;
import java.util.List;
import java.util.Set;
+import org.sonar.api.utils.Paging;
import org.sonar.db.component.ComponentDto;
import static com.google.common.base.Objects.firstNonNull;
public class SearchProjectPermissionsData {
private final List<ComponentDto> rootComponents;
- private final int total;
+ private final Paging paging;
private final Table<Long, String, Integer> userCountByProjectIdAndPermission;
private final Table<Long, String, Integer> groupCountByProjectIdAndPermission;
private SearchProjectPermissionsData(Builder builder) {
this.rootComponents = copyOf(builder.projects);
- this.total = builder.total;
+ this.paging = builder.paging;
this.userCountByProjectIdAndPermission = copyOf(builder.userCountByProjectIdAndPermission);
this.groupCountByProjectIdAndPermission = copyOf(builder.groupCountByProjectIdAndPermission);
}
return rootComponents;
}
- public int total() {
- return total;
+ public Paging paging() {
+ return paging;
}
public int userCount(long rootComponentId, String permission) {
public static class Builder {
private List<ComponentDto> projects;
- private int total;
+ private Paging paging;
private Table<Long, String, Integer> userCountByProjectIdAndPermission;
private Table<Long, String, Integer> groupCountByProjectIdAndPermission;
return this;
}
- public Builder total(int total) {
- this.total = total;
+ public Builder paging(Paging paging) {
+ this.paging = paging;
return this;
}
List<Long> rootComponentIds = Lists.transform(rootComponents, ComponentToIdFunction.INSTANCE);
data.rootComponents(rootComponents)
- .total(countRootComponents)
+ .paging(paging(wsRequest, countRootComponents))
.userCountByProjectIdAndPermission(userCountByRootComponentIdAndPermission(dbSession, rootComponentIds))
.groupCountByProjectIdAndPermission(groupCountByRootComponentIdAndPermission(dbSession, rootComponentIds));
}
}
- private Paging paging(Request wsRequest, int total) {
+ private static Paging paging(Request wsRequest, int total) {
return forPageIndex(wsRequest.mandatoryParamAsInt(PAGE))
.withPageSize(wsRequest.mandatoryParamAsInt(PAGE_SIZE))
.andTotal(total);
"name": "See Source Code",
"description": "Ability to view the project\u0027s source code. (Users will also need \"Browse\" permission)"
}
- ]
+ ],
+ "paging": {
+ "pageIndex": 1,
+ "pageSize": 25,
+ "total": 4
+ }
}
"name": "See Source Code",
"description": "Ability to view the project's source code. (Users will also need \"Browse\" permission)"
}
- ]
+ ],
+ "paging": {
+ "pageIndex": 1,
+ "pageSize": 25,
+ "total": 0
+ }
}
private static final String QUERY_PARAMETER = "query";
private static final String COMPONENT_ID_PARAMETER = "componentId";
+ private static final String ANYONE_GROUP_PARAMETER = "anyoneGroup";
private final MyBatis myBatis;
public int countGroups(DbSession session, String permission, @Nullable Long componentId) {
Map<String, Object> parameters = new HashMap<>();
parameters.put("permission", permission);
- parameters.put("anyoneGroup", DefaultGroups.ANYONE);
+ parameters.put(ANYONE_GROUP_PARAMETER, DefaultGroups.ANYONE);
parameters.put(COMPONENT_ID_PARAMETER, componentId);
return mapper(session).countGroups(parameters);
*/
public void groupsCountByComponentIdAndPermission(final DbSession dbSession, final List<Long> componentIds, final ResultHandler resultHandler) {
final Map<String, Object> parameters = new HashMap<>();
- parameters.put("anyoneGroup", DefaultGroups.ANYONE);
+ parameters.put(ANYONE_GROUP_PARAMETER, DefaultGroups.ANYONE);
DatabaseUtils.executeLargeInputsWithoutOutput(componentIds, new Function<List<Long>, Void>() {
@Override
Map<String, Object> params = newHashMap();
params.put(QUERY_PARAMETER, query);
params.put(COMPONENT_ID_PARAMETER, componentId);
- params.put("anyoneGroup", DefaultGroups.ANYONE);
+ params.put(ANYONE_GROUP_PARAMETER, DefaultGroups.ANYONE);
return params;
}
this.total = total;
}
- @Deprecated
/**
* @deprecated since 5.2 please use the forPageIndex(...) builder method
*/
+ @Deprecated
public static Paging create(int pageSize, int pageIndex, int totalItems) {
return new Paging(pageSize, pageIndex, totalItems);
}