Skip to content

Fixed search by category #1372

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 2 commits into from
Dec 4, 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 @@ -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 @@ -4,6 +4,7 @@
import jakarta.annotation.Nonnull;
import org.lowcoder.domain.application.model.Application;
import org.lowcoder.domain.application.model.ApplicationStatus;
import org.springframework.data.mongodb.repository.Aggregation;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.mongodb.repository.ReactiveMongoRepository;
import org.springframework.stereotype.Repository;
Expand All @@ -16,16 +17,16 @@
public interface ApplicationRepository extends ReactiveMongoRepository<Application, String>, CustomApplicationRepository {

// publishedApplicationDSL : 0 -> excludes publishedApplicationDSL from the return
@Query(fields = "{ publishedApplicationDSL : 0 , editingApplicationDSL : 0 }")
@Aggregation(pipeline = {"{ $project: { 'editingApplicationDSL.settings.category': 1, _id: 1, gid: 1, organizationId: 1, name: 1, applicationType: 1, applicationStatus: 1, publicToAll: 1, publicToMarketplace: 1, agencyProfile: 1, editingUserId: 1, lastEditedAt: 1, createdAt: 1, updatedAt: 1, createdBy: 1, modifiedBy: 1, _class: 1}}"})
Flux<Application> findByOrganizationId(String organizationId);


@Override
@Nonnull
@Query(fields = "{ publishedApplicationDSL : 0 , editingApplicationDSL : 0 }")
@Aggregation(pipeline = {"{ $project: { 'editingApplicationDSL.settings.category': 1, _id: 1, gid: 1, organizationId: 1, name: 1, applicationType: 1, applicationStatus: 1, publicToAll: 1, publicToMarketplace: 1, agencyProfile: 1, editingUserId: 1, lastEditedAt: 1, createdAt: 1, updatedAt: 1, createdBy: 1, modifiedBy: 1, _class: 1}}"})
Mono<Application> findById(@Nonnull String id);

@Query(fields = "{ publishedApplicationDSL : 0 , editingApplicationDSL : 0 }")
@Aggregation(pipeline = {"{ $project: { 'editingApplicationDSL.settings.category': 1, _id: 1, gid: 1, organizationId: 1, name: 1, applicationType: 1, applicationStatus: 1, publicToAll: 1, publicToMarketplace: 1, agencyProfile: 1, editingUserId: 1, lastEditedAt: 1, createdAt: 1, updatedAt: 1, createdBy: 1, modifiedBy: 1, _class: 1}}"})
Flux<Application> findByGid(@Nonnull String gid);

Mono<Long> countByOrganizationIdAndApplicationStatus(String organizationId, ApplicationStatus applicationStatus);
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
Loading