Skip to content

Add pagination to group, org, bundle #1305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public interface GroupMemberService {

Mono<List<GroupMember>> getGroupMembers(String groupId, int page, int count);
Mono<List<GroupMember>> getGroupMembers(String groupId);

Mono<Boolean> addMember(String orgId, String groupId, String userId, MemberRole memberRole);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class GroupMemberServiceImpl implements GroupMemberService {
private final MongoUpsertHelper mongoUpsertHelper;

@Override
public Mono<List<GroupMember>> getGroupMembers(String groupId, int page, int count) {
public Mono<List<GroupMember>> getGroupMembers(String groupId) {
return biRelationService.getBySourceId(GROUP_MEMBER, groupId)
.map(GroupMember::from)
.collectList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private Mono<List<String>> getSuggestAdminIds(int limit, List<ResourcePermission

Set<String> adminUserIdSet = newHashSet(adminUserIds);
return Flux.fromIterable(adminGroupIds)
.flatMap(groupId -> groupMemberService.getGroupMembers(groupId, 1, 100))
.flatMap(groupMemberService::getGroupMembers)
.flatMapIterable(list -> list)
.map(GroupMember::getUserId)
.filter(it -> !adminUserIdSet.contains(it))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.lowcoder.infra.util;

import org.jetbrains.annotations.NotNull;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestParam;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

public class FluxHelper {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private Mono<Void> autoGrantPermissionsByFolderDefault(String applicationId, @Nu

@Override
public Flux<ApplicationInfoView> getRecycledApplications(String name) {
return userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(null, ApplicationStatus.RECYCLED, false, name, 0, 0);
return userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(null, ApplicationStatus.RECYCLED, false, name);
}

private Mono<Void> checkCurrentUserApplicationPermission(String applicationId, ResourceAction action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.lowcoder.api.application.view.ApplicationView;
import org.lowcoder.api.application.view.MarketplaceApplicationInfoView;
// should we not have a AgencyApplicationInfoView
import org.lowcoder.api.framework.view.PageResponseView;
import org.lowcoder.api.framework.view.ResponseView;
import org.lowcoder.api.home.SessionUserService;
import org.lowcoder.api.home.UserHomeApiService;
Expand Down Expand Up @@ -164,9 +165,12 @@ public Mono<ResponseView<List<ApplicationInfoView>>> getApplications(@RequestPar
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
ApplicationType applicationTypeEnum = applicationType == null ? null : ApplicationType.fromValue(applicationType);
return userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationTypeEnum, applicationStatus, withContainerSize, name, pageNum, pageSize)
.collectList()
.map(ResponseView::success);
var flux = userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationTypeEnum, applicationStatus, withContainerSize, name).cache();
Mono<Long> countMono = flux.count();
var flux1 = flux.skip((long) pageNum * pageSize);
if(pageSize > 0) flux1 = flux1.take(pageSize);
return flux1.collectList().zipWith(countMono)
.map(tuple -> PageResponseView.success(tuple.getT1(), pageNum, pageSize, Math.toIntExact(tuple.getT2())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private boolean orgAppCountBelowThreshold(String orgId, long orgAppCount) {

public Mono<Void> checkMaxDeveloperCount(String orgId, String developGroupId, String userId) {
return orgMemberService.getAllOrgAdmins(orgId)
.zipWith(groupMemberService.getGroupMembers(developGroupId, 1, 100))
.zipWith(groupMemberService.getGroupMembers(developGroupId))
.zipWith(getMaxDeveloperCount(), TupleUtils::merge)
.flatMap(tuple -> {
List<OrgMember> t1 = tuple.getT1();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.lowcoder.api.bundle;

import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.lowcoder.api.bundle.view.BundleInfoView;
import org.lowcoder.api.bundle.view.BundlePermissionView;
import org.lowcoder.api.bundle.view.MarketplaceBundleInfoView;
import org.lowcoder.api.framework.view.PageResponseView;
import org.lowcoder.api.framework.view.ResponseView;
import org.lowcoder.api.home.UserHomeApiService;
import org.lowcoder.api.util.BusinessEventPublisher;
Expand All @@ -18,10 +20,12 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

import static org.lowcoder.api.util.Pagination.fluxToPageResponseView;
import static org.lowcoder.sdk.exception.BizError.INVALID_PARAMETER;
import static org.lowcoder.sdk.util.ExceptionUtils.ofError;

Expand Down Expand Up @@ -100,12 +104,13 @@ public Mono<ResponseView<List<BundleInfoView>>> getRecycledBundles() {
* get all files under bundle
*/
@Override
public Mono<ResponseView<List<?>>> getElements(@PathVariable String bundleId,
@RequestParam(value = "applicationType", required = false) ApplicationType applicationType) {
public Mono<PageResponseView<?>> getElements(@PathVariable String bundleId,
@RequestParam(value = "applicationType", required = false) ApplicationType applicationType,
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
String objectId = gidService.convertBundleIdToObjectId(bundleId);
return bundleApiService.getElements(objectId, applicationType)
.collectList()
.map(ResponseView::success);
var flux = bundleApiService.getElements(objectId, applicationType).cache();
return fluxToPageResponseView(pageNum, pageSize, flux);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.lowcoder.api.bundle.view.BundleInfoView;
import org.lowcoder.api.bundle.view.BundlePermissionView;
import org.lowcoder.api.bundle.view.MarketplaceBundleInfoView;
import org.lowcoder.api.framework.view.PageResponseView;
import org.lowcoder.api.framework.view.ResponseView;
import org.lowcoder.domain.application.model.ApplicationType;
import org.lowcoder.domain.bundle.model.Bundle;
Expand Down Expand Up @@ -120,8 +121,10 @@ public interface BundleEndpoints
description = "Retrieve the contents of an Bundle Bundle within Lowcoder, including Bundles."
)
@GetMapping("/{bundleId}/elements")
public Mono<ResponseView<List<?>>> getElements(@PathVariable String bundleId,
@RequestParam(value = "applicationType", required = false) ApplicationType applicationType);
public Mono<PageResponseView<?>> getElements(@PathVariable String bundleId,
@RequestParam(value = "applicationType", required = false) ApplicationType applicationType,
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize);

@Operation(
tags = TAG_BUNDLE_MANAGEMENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.lowcoder.api.framework.view.PageResponseView;
import org.lowcoder.api.framework.view.ResponseView;
import org.lowcoder.api.permission.view.CommonPermissionView;
import org.lowcoder.api.util.BusinessEventPublisher;
Expand All @@ -29,6 +30,7 @@
import java.util.List;
import java.util.Locale;

import static org.lowcoder.api.util.Pagination.fluxToPageResponseView;
import static org.lowcoder.plugin.api.event.LowcoderEvent.EventType.*;
import static org.lowcoder.sdk.exception.BizError.INVALID_PARAMETER;
import static org.lowcoder.sdk.util.ExceptionUtils.ofError;
Expand Down Expand Up @@ -116,11 +118,11 @@ public Mono<ResponseView<DatasourceStructure>> getStructure(@PathVariable String
* name, type... and the plugin definition of it, excluding the detail configs such as the connection uri, password...
*/
@Override
public Mono<ResponseView<List<Datasource>>> listJsDatasourcePlugins(@RequestParam("appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type) {
public Mono<PageResponseView<?>> listJsDatasourcePlugins(@RequestParam("appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type,
@RequestParam(required = false, defaultValue = "0") int pageNum,
@RequestParam(required = false, defaultValue = "0") int pageSize) {
String objectId = gidService.convertApplicationIdToObjectId(applicationId);
return datasourceApiService.listJsDatasourcePlugins(objectId, name, type)
.collectList()
.map(ResponseView::success);
return fluxToPageResponseView(pageNum, pageSize, datasourceApiService.listJsDatasourcePlugins(objectId, name, type));
}

/**
Expand All @@ -139,26 +141,26 @@ public Mono<ResponseView<List<Object>>> getPluginDynamicConfig(

@SneakyThrows
@Override
public Mono<ResponseView<List<DatasourceView>>> listOrgDataSources(@RequestParam(name = "orgId") String orgId, @RequestParam(required = false) String name, @RequestParam(required = false) String type) {
public Mono<PageResponseView<?>> listOrgDataSources(@RequestParam(name = "orgId") String orgId, @RequestParam(required = false) String name, @RequestParam(required = false) String type,
@RequestParam(required = false, defaultValue = "0") int pageNum,
@RequestParam(required = false, defaultValue = "0") int pageSize) {
if (StringUtils.isBlank(orgId)) {
return ofError(BizError.INVALID_PARAMETER, "ORG_ID_EMPTY");
}
String objectId = gidService.convertOrganizationIdToObjectId(orgId);
return datasourceApiService.listOrgDataSources(objectId, name, type)
.collectList()
.map(ResponseView::success);
return fluxToPageResponseView(pageNum, pageSize, datasourceApiService.listOrgDataSources(objectId, name, type));
}

@Override
public Mono<ResponseView<List<DatasourceView>>> listAppDataSources(@RequestParam(name = "appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type) {
public Mono<PageResponseView<?>> listAppDataSources(@RequestParam(name = "appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type,
@RequestParam(required = false, defaultValue = "0") int pageNum,
@RequestParam(required = false, defaultValue = "0") int pageSize) {
if (StringUtils.isBlank(applicationId)) {
return ofError(BizError.INVALID_PARAMETER, "INVALID_APP_ID");
}
String objectId = gidService.convertApplicationIdToObjectId(applicationId);

return datasourceApiService.listAppDataSources(objectId, name, type)
.collectList()
.map(ResponseView::success);
return fluxToPageResponseView(pageNum, pageSize, datasourceApiService.listAppDataSources(objectId, name, type));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Nullable;
import jakarta.validation.Valid;
import org.lowcoder.api.framework.view.PageResponseView;
import org.lowcoder.api.framework.view.ResponseView;
import org.lowcoder.api.permission.view.CommonPermissionView;
import org.lowcoder.domain.datasource.model.Datasource;
Expand Down Expand Up @@ -99,7 +100,9 @@ public Mono<ResponseView<DatasourceStructure>> getStructure(@PathVariable String
description = "Retrieve a list of node service plugins available within Lowcoder."
)
@GetMapping("/jsDatasourcePlugins")
public Mono<ResponseView<List<Datasource>>> listJsDatasourcePlugins(@RequestParam("appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type);
public Mono<PageResponseView<?>> listJsDatasourcePlugins(@RequestParam("appId") String applicationId, @RequestParam(required = false) String name, @RequestParam(required = false) String type,
@RequestParam(required = false, defaultValue = "0") int pageNum,
@RequestParam(required = false, defaultValue = "0") int pageSize);

/**
* Proxy the request to the node service, besides, add the "extra" information from the data source config stored in the mongodb if exists to
Expand All @@ -123,7 +126,9 @@ public Mono<ResponseView<List<Object>>> getPluginDynamicConfig(
)
@JsonView(JsonViews.Public.class)
@GetMapping("/listByOrg")
public Mono<ResponseView<List<DatasourceView>>> listOrgDataSources(@RequestParam(name = "orgId") String orgId, @RequestParam String name, @RequestParam String type);
public Mono<PageResponseView<?>> listOrgDataSources(@RequestParam(name = "orgId") String orgId, @RequestParam String name, @RequestParam String type,
@RequestParam(required = false, defaultValue = "0") int pageNum,
@RequestParam(required = false, defaultValue = "0") int pageSize);

@Operation(
tags = TAG_DATASOURCE_MANAGEMENT,
Expand All @@ -134,7 +139,9 @@ public Mono<ResponseView<List<Object>>> getPluginDynamicConfig(
@Deprecated
@JsonView(JsonViews.Public.class)
@GetMapping("/listByApp")
public Mono<ResponseView<List<DatasourceView>>> listAppDataSources(@RequestParam(name = "appId") String applicationId, @RequestParam String name, @RequestParam String type);
public Mono<PageResponseView<?>> listAppDataSources(@RequestParam(name = "appId") String applicationId, @RequestParam String name, @RequestParam String type,
@RequestParam(required = false, defaultValue = "0") int pageNum,
@RequestParam(required = false, defaultValue = "0") int pageSize);

@Operation(
tags = TAG_DATASOURCE_PERMISSIONS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface FolderApiService {

Mono<Void> upsertLastViewTime(@Nullable String folderId);

Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType applicationType, @Nullable String name, Integer pageNum, Integer pageSize);
Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType applicationType, @Nullable String name);

Mono<Void> grantPermission(String folderId, Set<String> userIds, Set<String> groupIds, ResourceRole role);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public Mono<Void> upsertLastViewTime(@Nullable String folderId) {
* @return flux of {@link ApplicationInfoView} or {@link FolderInfoView}
*/
@Override
public Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType applicationType, @Nullable String name, Integer pageNum, Integer pageSize) {
var retMono = buildApplicationInfoViewTree(applicationType, name)
public Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType applicationType, @Nullable String name) {
return buildApplicationInfoViewTree(applicationType, name)
.flatMap(tree -> {
FolderNode<ApplicationInfoView, FolderInfoView> folderNode = tree.get(folderId);
if (folderNode == null) {
Expand Down Expand Up @@ -264,9 +264,7 @@ public Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType
});
})
.flatMapIterable(tuple -> tuple.getT1().getChildren())
.skip(pageNum * pageSize);
if(pageSize > 0) retMono = retMono.take(pageSize);
return retMono.map(node -> {
.map(node -> {
if (node instanceof ElementNode<ApplicationInfoView, FolderInfoView> elementNode) {
return elementNode.getSelf();
}
Expand All @@ -286,7 +284,7 @@ private Mono<Tree<ApplicationInfoView, FolderInfoView>> buildApplicationInfoView
.cache();

Flux<ApplicationInfoView> applicationInfoViewFlux =
userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationType, ApplicationStatus.NORMAL, false, null, 0, 0)
userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationType, ApplicationStatus.NORMAL, false, null)
.cache();

Mono<Map<String, String>> application2FolderMapMono = applicationInfoViewFlux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import static org.lowcoder.sdk.exception.BizError.INVALID_PARAMETER;
import static org.lowcoder.sdk.util.ExceptionUtils.ofError;

import java.util.List;

import org.lowcoder.api.application.view.ApplicationPermissionView;
import org.lowcoder.api.framework.view.PageResponseView;
import org.lowcoder.api.framework.view.ResponseView;
import org.lowcoder.api.util.BusinessEventPublisher;
import org.lowcoder.api.util.GidService;
Expand Down Expand Up @@ -68,16 +67,20 @@ public Mono<ResponseView<FolderInfoView>> update(@RequestBody Folder folder) {
* get all files under folder
*/
@Override
public Mono<ResponseView<List<?>>> getElements(@RequestParam(value = "id", required = false) String folderId,
@RequestParam(value = "applicationType", required = false) ApplicationType applicationType,
@RequestParam(required = false) String name,
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
public Mono<PageResponseView<?>> getElements(@RequestParam(value = "id", required = false) String folderId,
@RequestParam(value = "applicationType", required = false) ApplicationType applicationType,
@RequestParam(required = false) String name,
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
String objectId = gidService.convertFolderIdToObjectId(folderId);
return folderApiService.getElements(objectId, applicationType, name, pageNum, pageSize)
.collectList()
.delayUntil(__ -> folderApiService.upsertLastViewTime(objectId))
.map(ResponseView::success);
var flux = folderApiService.getElements(objectId, applicationType, name).cache();
var countMono = flux.count();
var flux1 = flux.skip((long) pageNum * pageSize);
if(pageSize > 0) flux1 = flux1.take(pageSize);
return flux1.collectList()
.delayUntil(__ -> folderApiService.upsertLastViewTime(objectId))
.zipWith(countMono)
.map(tuple -> PageResponseView.success(tuple.getT1(), pageNum, pageSize, Math.toIntExact(tuple.getT2())));
}

@Override
Expand Down
Loading
Loading