Skip to content

Commit

Permalink
Add search by category feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonpoo authored and ludomikula committed Dec 4, 2024
1 parent 5987c18 commit 691a168
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,18 @@ public Map<String, Object> getEditingApplicationDSL() {
return dsl;
}

public String getCategory() {
if(editingApplicationDSL == null || editingApplicationDSL.get("settings") == null) return "";
Object settingsObject = editingApplicationDSL.get("settings");
if (settingsObject instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, Object> settings = (Map<String, Object>) editingApplicationDSL.get("settings");
return (String) settings.get("category");
} else {
return "";
}
}

public Map<String, Object> getEditingApplicationDSLOrNull() {return editingApplicationDSL; }

public Object getLiveContainerSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public interface ApplicationApiService {
Mono<ApplicationView> create(ApplicationEndpoints.CreateApplicationRequest createApplicationRequest);

Flux<ApplicationInfoView> getRecycledApplications(String name);
Flux<ApplicationInfoView> getRecycledApplications(String name, String category);

Mono<ApplicationView> delete(String applicationId);

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

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

private Mono<Void> checkCurrentUserApplicationPermission(String applicationId, ResourceAction action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public Mono<ResponseView<Boolean>> restore(@PathVariable String applicationId) {
}

@Override
public Mono<ResponseView<List<ApplicationInfoView>>> getRecycledApplications(@RequestParam(required = false) String name) {
return applicationApiService.getRecycledApplications(name)
public Mono<ResponseView<List<ApplicationInfoView>>> getRecycledApplications(@RequestParam(required = false) String name, @RequestParam(required = false) String category) {
return applicationApiService.getRecycledApplications(name, category)
.collectList()
.map(ResponseView::success);
}
Expand Down Expand Up @@ -159,13 +159,14 @@ public Mono<ResponseView<UserHomepageView>> getUserHomePage(@RequestParam(requir

@Override
public Mono<ResponseView<List<ApplicationInfoView>>> getApplications(@RequestParam(required = false) Integer applicationType,
@RequestParam(required = false) ApplicationStatus applicationStatus,
@RequestParam(defaultValue = "true") boolean withContainerSize,
@RequestParam(required = false) String name,
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
@RequestParam(required = false) ApplicationStatus applicationStatus,
@RequestParam(defaultValue = "true") boolean withContainerSize,
@RequestParam(required = false) String name,
@RequestParam(required = false) String category,
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
ApplicationType applicationTypeEnum = applicationType == null ? null : ApplicationType.fromValue(applicationType);
var flux = userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationTypeEnum, applicationStatus, withContainerSize, name).cache();
var flux = userHomeApiService.getAllAuthorisedApplications4CurrentOrgMember(applicationTypeEnum, applicationStatus, withContainerSize, name, category).cache();
Mono<Long> countMono = flux.count();
var flux1 = flux.skip((long) (pageNum - 1) * pageSize);
if(pageSize > 0) flux1 = flux1.take(pageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public interface ApplicationEndpoints
description = "List all the recycled Lowcoder Applications in the recycle bin where the authenticated or impersonated user has access."
)
@GetMapping("/recycle/list")
public Mono<ResponseView<List<ApplicationInfoView>>> getRecycledApplications(@RequestParam(required = false) String name);
public Mono<ResponseView<List<ApplicationInfoView>>> getRecycledApplications(@RequestParam(required = false) String name, @RequestParam(required = false) String category);

@Operation(
tags = TAG_APPLICATION_MANAGEMENT,
Expand Down Expand Up @@ -167,6 +167,7 @@ public Mono<ResponseView<List<ApplicationInfoView>>> getApplications(@RequestPar
@RequestParam(required = false) ApplicationStatus applicationStatus,
@RequestParam(defaultValue = "true") boolean withContainerSize,
@RequestParam(required = false) String name,
@RequestParam(required = false) String category,
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize);

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);
Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType applicationType, @Nullable String name, @Nullable String category);

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) {
return buildApplicationInfoViewTree(applicationType, name)
public Flux<?> getElements(@Nullable String folderId, @Nullable ApplicationType applicationType, @Nullable String name, @Nullable String category) {
return buildApplicationInfoViewTree(applicationType, name, category)
.flatMap(tree -> {
FolderNode<ApplicationInfoView, FolderInfoView> folderNode = tree.get(folderId);
if (folderNode == null) {
Expand Down Expand Up @@ -278,13 +278,13 @@ private Mono<Tree<Object, Folder>> buildFolderTree(String orgId) {
.map(folders -> new Tree<>(folders, Folder::getId, Folder::getParentFolderId, Collections.emptyList(), null, null));
}

private Mono<Tree<ApplicationInfoView, FolderInfoView>> buildApplicationInfoViewTree(@Nullable ApplicationType applicationType, @Nullable String name) {
private Mono<Tree<ApplicationInfoView, FolderInfoView>> buildApplicationInfoViewTree(@Nullable ApplicationType applicationType, @Nullable String name, @Nullable String category) {

Mono<OrgMember> orgMemberMono = sessionUserService.getVisitorOrgMemberCache()
.cache();

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

Mono<Map<String, String>> application2FolderMapMono = applicationInfoViewFlux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ public Mono<ResponseView<FolderInfoView>> update(@RequestBody Folder folder) {
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) String category,
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize) {
String objectId = gidService.convertFolderIdToObjectId(folderId);
var flux = folderApiService.getElements(objectId, applicationType, name).cache();
var flux = folderApiService.getElements(objectId, applicationType, name, category).cache();
var countMono = flux.count();
var flux1 = flux.skip((long) (pageNum - 1) * pageSize);
if(pageSize > 0) flux1 = flux1.take(pageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public interface FolderEndpoints
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) String category,
@RequestParam(required = false, defaultValue = "1") Integer pageNum,
@RequestParam(required = false, defaultValue = "0") Integer pageSize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface UserHomeApiService {
Mono<UserHomepageView> getUserHomePageView(ApplicationType applicationType);

Flux<ApplicationInfoView> getAllAuthorisedApplications4CurrentOrgMember(@Nullable ApplicationType applicationType,
@Nullable ApplicationStatus applicationStatus, boolean withContainerSize, @Nullable String name);
@Nullable ApplicationStatus applicationStatus, boolean withContainerSize, @Nullable String name, @Nullable String category);

Flux<BundleInfoView> getAllAuthorisedBundles4CurrentOrgMember(@Nullable BundleStatus bundleStatus);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Mono<UserHomepageView> getUserHomePageView(ApplicationType applicationTyp
}

return organizationService.getById(currentOrgId)
.zipWith(folderApiService.getElements(null, applicationType, null).collectList())
.zipWith(folderApiService.getElements(null, applicationType, null, null).collectList())
.map(tuple2 -> {
Organization organization = tuple2.getT1();
List<?> list = tuple2.getT2();
Expand Down Expand Up @@ -189,7 +189,7 @@ public Mono<UserHomepageView> getUserHomePageView(ApplicationType applicationTyp

@Override
public Flux<ApplicationInfoView> getAllAuthorisedApplications4CurrentOrgMember(@Nullable ApplicationType applicationType,
@Nullable ApplicationStatus applicationStatus, boolean withContainerSize, @Nullable String name) {
@Nullable ApplicationStatus applicationStatus, boolean withContainerSize, @Nullable String name, @Nullable String category) {

return sessionUserService.getVisitorOrgMemberCache()
.flatMapMany(orgMember -> {
Expand All @@ -204,7 +204,8 @@ public Flux<ApplicationInfoView> getAllAuthorisedApplications4CurrentOrgMember(@
})
.filter(application -> (isNull(applicationType) || application.getApplicationType() == applicationType.getValue())
&& (isNull(applicationStatus) || application.getApplicationStatus() == applicationStatus)
&& (isNull(name) || StringUtils.containsIgnoreCase(application.getName(), name)))
&& (isNull(name) || StringUtils.containsIgnoreCase(application.getName(), name))
&& (isNull(category) || StringUtils.containsIgnoreCase(application.getCategory(), category)))
.cache()
.collectList()
.flatMapIterable(Function.identity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void updateByGid() {
public void move() {

Mono<? extends List<?>> mono = folderApiService.move("app01", "folder02")
.then(folderApiService.getElements("folder02", null, null).collectList());
.then(folderApiService.getElements("folder02", null, null, null).collectList());

StepVerifier.create(mono)
.assertNext(list -> {
Expand Down

0 comments on commit 691a168

Please sign in to comment.