Skip to content

Commit 5de2d64

Browse files
committed
Moved Business logic related to feature flag check to service layer from controllers for Workspace and Applications.
1 parent 0830042 commit 5de2d64

File tree

8 files changed

+69
-45
lines changed

8 files changed

+69
-45
lines changed

app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCE.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public interface ApplicationServiceCE extends CrudService<Application, String> {
3131

3232
Flux<Application> findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder(String workspaceId);
3333

34+
Flux<Application> findByWorkspaceIdAndBaseApplicationsForHome(String workspaceId);
35+
3436
Mono<Application> save(Artifact application);
3537

3638
Mono<Application> updateApplicationWithPresets(String branchedApplicationId, Application application);

app/server/appsmith-server/src/main/java/com/appsmith/server/applications/base/ApplicationServiceCEImpl.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
import com.appsmith.server.services.AnalyticsService;
3737
import com.appsmith.server.services.AssetService;
3838
import com.appsmith.server.services.BaseService;
39+
import com.appsmith.server.services.FeatureFlagService;
3940
import com.appsmith.server.services.PermissionGroupService;
4041
import com.appsmith.server.services.SessionUserService;
4142
import com.appsmith.server.services.UserDataService;
4243
import com.appsmith.server.services.WorkspaceService;
44+
import com.appsmith.external.enums.FeatureFlagEnum;
4345
import com.appsmith.server.solutions.ApplicationPermission;
4446
import com.appsmith.server.solutions.DatasourcePermission;
4547
import com.appsmith.server.solutions.PolicySolution;
@@ -91,6 +93,7 @@ public class ApplicationServiceCEImpl extends BaseService<ApplicationRepository,
9193
private final WorkspaceService workspaceService;
9294
private final WorkspacePermission workspacePermission;
9395
private final ObservationRegistry observationRegistry;
96+
private final FeatureFlagService featureFlagService;
9497

9598
private static final Integer MAX_RETRIES = 5;
9699

@@ -109,7 +112,8 @@ public ApplicationServiceCEImpl(
109112
UserDataService userDataService,
110113
WorkspaceService workspaceService,
111114
WorkspacePermission workspacePermission,
112-
ObservationRegistry observationRegistry) {
115+
ObservationRegistry observationRegistry,
116+
FeatureFlagService featureFlagService) {
113117

114118
super(validator, repository, analyticsService);
115119
this.policySolution = policySolution;
@@ -123,6 +127,7 @@ public ApplicationServiceCEImpl(
123127
this.workspaceService = workspaceService;
124128
this.workspacePermission = workspacePermission;
125129
this.observationRegistry = observationRegistry;
130+
this.featureFlagService = featureFlagService;
126131
}
127132

128133
@Override
@@ -250,6 +255,28 @@ public Flux<Application> findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder
250255
}));
251256
}
252257

258+
/**
259+
* This method is used to fetch all the applications for a given workspaceId. It sorts the applications based
260+
* on feature flag - either alphabetically or by recently used order.
261+
* For git connected applications only default branched application is returned.
262+
*
263+
* @param workspaceId workspaceId for which applications are to be fetched
264+
* @return Flux of applications sorted based on feature flag
265+
*/
266+
@Override
267+
public Flux<Application> findByWorkspaceIdAndBaseApplicationsForHome(String workspaceId) {
268+
Mono<Boolean> isAlphabeticalOrderingEnabled = featureFlagService.check(FeatureFlagEnum.release_alphabetical_ordering_enabled);
269+
return isAlphabeticalOrderingEnabled.flatMapMany(isEnabled -> {
270+
if (isEnabled) {
271+
// If alphabetical ordering is enabled, then we need to sort the applications in alphabetical order
272+
return findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder(workspaceId);
273+
} else {
274+
// If alphabetical ordering is disabled, then we need to sort the applications in recently used order
275+
return findByWorkspaceIdAndBaseApplicationsInRecentlyUsedOrder(workspaceId);
276+
}
277+
});
278+
}
279+
253280
@Override
254281
public Mono<Application> save(Artifact artifact) {
255282
Application application = (Application) artifact;

app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ApplicationController.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import com.appsmith.server.imports.internal.partial.PartialImportService;
1212
import com.appsmith.server.services.ApplicationPageService;
1313
import com.appsmith.server.services.ApplicationSnapshotService;
14-
import com.appsmith.server.services.FeatureFlagService;
1514
import com.appsmith.server.solutions.UserReleaseNotes;
1615
import com.appsmith.server.themes.base.ThemeService;
1716
import lombok.extern.slf4j.Slf4j;
@@ -34,8 +33,7 @@ public ApplicationController(
3433
PartialExportService partialExportService,
3534
PartialImportService partialImportService,
3635
ImportService importService,
37-
ExportService exportService,
38-
FeatureFlagService featureFlagService) {
36+
ExportService exportService) {
3937
super(
4038
artifactService,
4139
service,
@@ -47,7 +45,6 @@ public ApplicationController(
4745
partialExportService,
4846
partialImportService,
4947
importService,
50-
exportService,
51-
featureFlagService);
48+
exportService);
5249
}
5350
}

app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/WorkspaceController.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.appsmith.server.constants.Url;
44
import com.appsmith.server.controllers.ce.WorkspaceControllerCE;
5-
import com.appsmith.server.services.FeatureFlagService;
65
import com.appsmith.server.services.UserWorkspaceService;
76
import com.appsmith.server.services.WorkspaceService;
87
import org.springframework.web.bind.annotation.RequestMapping;
@@ -12,8 +11,8 @@
1211
@RequestMapping(Url.WORKSPACE_URL)
1312
public class WorkspaceController extends WorkspaceControllerCE {
1413

15-
public WorkspaceController(WorkspaceService workspaceService, UserWorkspaceService userWorkspaceService, FeatureFlagService featureFlagService) {
14+
public WorkspaceController(WorkspaceService workspaceService, UserWorkspaceService userWorkspaceService) {
1615

17-
super(workspaceService, userWorkspaceService, featureFlagService);
16+
super(workspaceService, userWorkspaceService);
1817
}
1918
}

app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/ApplicationControllerCE.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030
import com.appsmith.server.projections.ApplicationSnapshotResponseDTO;
3131
import com.appsmith.server.services.ApplicationPageService;
3232
import com.appsmith.server.services.ApplicationSnapshotService;
33-
import com.appsmith.server.services.FeatureFlagService;
3433
import com.appsmith.server.solutions.UserReleaseNotes;
3534
import com.appsmith.server.themes.base.ThemeService;
36-
import com.appsmith.external.enums.FeatureFlagEnum;
3735
import com.fasterxml.jackson.annotation.JsonView;
3836
import jakarta.validation.Valid;
3937
import lombok.RequiredArgsConstructor;
@@ -77,7 +75,6 @@ public class ApplicationControllerCE {
7775
private final PartialImportService partialImportService;
7876
private final ImportService importService;
7977
private final ExportService exportService;
80-
private final FeatureFlagService featureFlagService;
8178

8279
@JsonView(Views.Public.class)
8380
@PostMapping
@@ -133,21 +130,9 @@ public Mono<ResponseDTO<Application>> delete(@PathVariable String branchedApplic
133130
public Mono<ResponseDTO<List<Application>>> findByWorkspaceIdAndRecentlyUsedOrder(
134131
@RequestParam(required = false) String workspaceId) {
135132
log.debug("Going to get all applications by workspace id {}", workspaceId);
136-
137-
Mono<Boolean> isAlphabeticalOrderingEnabled = featureFlagService.check(FeatureFlagEnum.release_alphabetical_ordering_enabled);
138-
return isAlphabeticalOrderingEnabled.flatMap(isEnabled -> {
139-
if (isEnabled) {
140-
// If alphabetical ordering is enabled, then we need to sort the applications in alphabetical order
141-
return service.findByWorkspaceIdAndBaseApplicationsInAlphabeticalOrder(workspaceId)
142-
.collectList()
143-
.map(applications -> new ResponseDTO<>(HttpStatus.OK, applications));
144-
} else {
145-
// If alphabetical ordering is disabled, then we need to sort the applications in recently used order
146-
return service.findByWorkspaceIdAndBaseApplicationsInRecentlyUsedOrder(workspaceId)
147-
.collectList()
148-
.map(applications -> new ResponseDTO<>(HttpStatus.OK, applications));
149-
}
150-
});
133+
return service.findByWorkspaceIdAndBaseApplicationsForHome(workspaceId)
134+
.collectList()
135+
.map(applications -> new ResponseDTO<>(HttpStatus.OK, applications));
151136
}
152137

153138
@JsonView(Views.Public.class)

app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/WorkspaceControllerCE.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
import com.appsmith.server.dtos.PermissionGroupInfoDTO;
88
import com.appsmith.server.dtos.ResponseDTO;
99
import com.appsmith.server.dtos.UpdatePermissionGroupDTO;
10-
import com.appsmith.server.services.FeatureFlagService;
1110
import com.appsmith.server.services.UserWorkspaceService;
1211
import com.appsmith.server.services.WorkspaceService;
13-
import com.appsmith.external.enums.FeatureFlagEnum;
1412
import com.fasterxml.jackson.annotation.JsonView;
1513
import jakarta.validation.Valid;
1614
import lombok.RequiredArgsConstructor;
@@ -35,7 +33,6 @@
3533
public class WorkspaceControllerCE {
3634
private final WorkspaceService service;
3735
private final UserWorkspaceService userWorkspaceService;
38-
private final FeatureFlagService featureFlagService;
3936

4037
@JsonView(Views.Public.class)
4138
@GetMapping("/{id}")
@@ -109,19 +106,8 @@ public Mono<ResponseDTO<Workspace>> deleteLogo(@PathVariable String workspaceId)
109106
@JsonView(Views.Public.class)
110107
@GetMapping("/home")
111108
public Mono<ResponseDTO<List<Workspace>>> workspacesForHome() {
112-
Mono<Boolean> isAlphabeticalOrderingEnabled = featureFlagService.check(FeatureFlagEnum.release_alphabetical_ordering_enabled);
113-
return isAlphabeticalOrderingEnabled.flatMap(isEnabled -> {
114-
if (isEnabled) {
115-
// If alphabetical ordering is enabled, then we need to sort the workspaces in alphabetical order
116-
return userWorkspaceService
117-
.getUserWorkspacesInAlphabeticalOrder()
118-
.map(workspaces -> new ResponseDTO<>(HttpStatus.OK, workspaces));
119-
} else {
120-
// If alphabetical ordering is disabled, then we need to sort the workspaces in recently used order
121-
return userWorkspaceService
122-
.getUserWorkspacesByRecentlyUsedOrder()
123-
.map(workspaces -> new ResponseDTO<>(HttpStatus.OK, workspaces));
124-
}
125-
});
109+
return userWorkspaceService
110+
.getUserWorkspacesForHome()
111+
.map(workspaces -> new ResponseDTO<>(HttpStatus.OK, workspaces));
126112
}
127113
}

app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserWorkspaceServiceCE.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ Mono<MemberInfoDTO> updatePermissionGroupForMember(
2727
Mono<List<Workspace>> getUserWorkspacesByRecentlyUsedOrder();
2828

2929
Mono<List<Workspace>> getUserWorkspacesInAlphabeticalOrder();
30+
31+
Mono<List<Workspace>> getUserWorkspacesForHome();
3032
}

app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserWorkspaceServiceCEImpl.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
import com.appsmith.server.exceptions.AppsmithException;
1414
import com.appsmith.server.helpers.AppsmithComparators;
1515
import com.appsmith.server.repositories.UserRepository;
16+
import com.appsmith.server.services.FeatureFlagService;
1617
import com.appsmith.server.services.OrganizationService;
1718
import com.appsmith.server.services.PermissionGroupService;
1819
import com.appsmith.server.services.SessionUserService;
1920
import com.appsmith.server.services.UserDataService;
2021
import com.appsmith.server.services.WorkspaceService;
22+
import com.appsmith.external.enums.FeatureFlagEnum;
2123
import com.appsmith.server.solutions.PermissionGroupPermission;
2224
import com.appsmith.server.solutions.WorkspacePermission;
2325
import lombok.extern.slf4j.Slf4j;
@@ -55,6 +57,7 @@ public class UserWorkspaceServiceCEImpl implements UserWorkspaceServiceCE {
5557
private final OrganizationService organizationService;
5658
private final WorkspacePermission workspacePermission;
5759
private final PermissionGroupPermission permissionGroupPermission;
60+
private final FeatureFlagService featureFlagService;
5861

5962
@Autowired
6063
public UserWorkspaceServiceCEImpl(
@@ -65,7 +68,8 @@ public UserWorkspaceServiceCEImpl(
6568
PermissionGroupService permissionGroupService,
6669
OrganizationService organizationService,
6770
WorkspacePermission workspacePermission,
68-
PermissionGroupPermission permissionGroupPermission) {
71+
PermissionGroupPermission permissionGroupPermission,
72+
FeatureFlagService featureFlagService) {
6973
this.sessionUserService = sessionUserService;
7074
this.workspaceService = workspaceService;
7175
this.userRepository = userRepository;
@@ -74,6 +78,7 @@ public UserWorkspaceServiceCEImpl(
7478
this.organizationService = organizationService;
7579
this.workspacePermission = workspacePermission;
7680
this.permissionGroupPermission = permissionGroupPermission;
81+
this.featureFlagService = featureFlagService;
7782
}
7883

7984
@Override
@@ -433,4 +438,25 @@ public Mono<List<Workspace>> getUserWorkspacesInAlphabeticalOrder() {
433438
.sort(Comparator.comparing(workspace -> workspace.getName().toLowerCase()))
434439
.collectList();
435440
}
441+
442+
/**
443+
* Returns a list of workspaces for the current user, sorted based on feature flag.
444+
* If alphabetical ordering is enabled, returns workspaces in alphabetical order.
445+
* Otherwise, returns workspaces in recently used order.
446+
*
447+
* @return Mono containing the list of workspaces
448+
*/
449+
@Override
450+
public Mono<List<Workspace>> getUserWorkspacesForHome() {
451+
Mono<Boolean> isAlphabeticalOrderingEnabled = featureFlagService.check(FeatureFlagEnum.release_alphabetical_ordering_enabled);
452+
return isAlphabeticalOrderingEnabled.flatMap(isEnabled -> {
453+
if (isEnabled) {
454+
// If alphabetical ordering is enabled, then we need to sort the workspaces in alphabetical order
455+
return getUserWorkspacesInAlphabeticalOrder();
456+
} else {
457+
// If alphabetical ordering is disabled, then we need to sort the workspaces in recently used order
458+
return getUserWorkspacesByRecentlyUsedOrder();
459+
}
460+
});
461+
}
436462
}

0 commit comments

Comments
 (0)