Skip to content

Commit 139a5e5

Browse files
committed
added business logic to service layer
1 parent 034bf9a commit 139a5e5

File tree

5 files changed

+65
-19
lines changed

5 files changed

+65
-19
lines changed

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.appsmith.server.dtos.ResponseDTO;
1111
import com.appsmith.server.plugins.base.PluginService;
1212
import com.appsmith.server.plugins.solutions.PluginTriggerSolution;
13-
import com.appsmith.util.WebClientUtils;
1413
import com.fasterxml.jackson.annotation.JsonView;
1514
import lombok.RequiredArgsConstructor;
1615
import lombok.extern.slf4j.Slf4j;
@@ -106,20 +105,8 @@ public Mono<ResponseDTO<TriggerResultDTO>> triggerMultipart(
106105
@GetMapping("/upcoming-integrations")
107106
public Mono<ResponseDTO<List<Map<String, String>>>> getUpcomingIntegrations() {
108107
log.debug("Fetching upcoming integrations from external API");
109-
110-
String apiUrl = cloudServicesConfig.getBaseUrl() + "/api/v1/config/external-saas/upcoming-integrations";
111-
112-
return WebClientUtils.create()
113-
.get()
114-
.uri(apiUrl)
115-
.retrieve()
116-
.bodyToMono(Map.class)
117-
.map(response -> {
118-
// Extract the integrations list from the response
119-
List<Map<String, String>> integrations =
120-
response.containsKey("data") ? (List<Map<String, String>>) response.get("data") : List.of();
121-
return new ResponseDTO<>(HttpStatus.OK, integrations);
122-
})
108+
return service.getUpcomingIntegrations()
109+
.map(integrations -> new ResponseDTO<>(HttpStatus.OK, integrations))
123110
.onErrorResume(error -> {
124111
log.warn("Error retrieving upcoming integrations from external service: {}", error.getMessage());
125112
return Mono.just(new ResponseDTO<>(

app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/base/PluginServiceCE.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ public interface PluginServiceCE extends CrudService<Plugin, String> {
5353
Mono<Map<String, Plugin>> findAllPluginsInWorkspace(String workspaceId);
5454

5555
Flux<Plugin> getPluginsByType(PluginType pluginType);
56+
57+
Mono<List<Map<String, String>>> getUpcomingIntegrations();
5658
}

app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/base/PluginServiceCEImpl.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.appsmith.external.models.Datasource;
44
import com.appsmith.external.models.PluginType;
5+
import com.appsmith.server.configurations.CloudServicesConfig;
56
import com.appsmith.server.constants.FieldName;
67
import com.appsmith.server.domains.Plugin;
78
import com.appsmith.server.domains.Workspace;
@@ -15,7 +16,9 @@
1516
import com.appsmith.server.repositories.PluginRepository;
1617
import com.appsmith.server.services.AnalyticsService;
1718
import com.appsmith.server.services.BaseService;
19+
import com.appsmith.server.services.ConfigService;
1820
import com.appsmith.server.services.WorkspaceService;
21+
import com.appsmith.util.WebClientUtils;
1922
import com.fasterxml.jackson.core.JsonProcessingException;
2023
import com.fasterxml.jackson.core.type.TypeReference;
2124
import com.fasterxml.jackson.databind.JsonNode;
@@ -46,6 +49,7 @@
4649
import java.net.URL;
4750
import java.nio.charset.Charset;
4851
import java.nio.file.Path;
52+
import java.util.ArrayList;
4953
import java.util.Collections;
5054
import java.util.HashMap;
5155
import java.util.HashSet;
@@ -65,6 +69,7 @@ public class PluginServiceCEImpl extends BaseService<PluginRepository, Plugin, S
6569
private final ReactiveRedisTemplate<String, String> reactiveTemplate;
6670
private final ChannelTopic topic;
6771
private final ObjectMapper objectMapper;
72+
private final CloudServicesConfig cloudServicesConfig;
6873

6974
private final Map<String, Mono<Map<?, ?>>> formCache = new HashMap<>();
7075
private final Map<String, Mono<Map<String, String>>> templateCache = new HashMap<>();
@@ -86,6 +91,8 @@ public class PluginServiceCEImpl extends BaseService<PluginRepository, Plugin, S
8691
public static final String KEY_COMMENT = "_comment";
8792
public static final String KEY_FILES = "files";
8893

94+
private final ConfigService configService;
95+
8996
@Autowired
9097
public PluginServiceCEImpl(
9198
Validator validator,
@@ -95,13 +102,17 @@ public PluginServiceCEImpl(
95102
PluginManager pluginManager,
96103
ReactiveRedisTemplate<String, String> reactiveTemplate,
97104
ChannelTopic topic,
98-
ObjectMapper objectMapper) {
105+
ObjectMapper objectMapper,
106+
CloudServicesConfig cloudServicesConfig,
107+
ConfigService configService) {
99108
super(validator, repository, analyticsService);
100109
this.workspaceService = workspaceService;
101110
this.pluginManager = pluginManager;
102111
this.reactiveTemplate = reactiveTemplate;
103112
this.topic = topic;
104113
this.objectMapper = objectMapper;
114+
this.cloudServicesConfig = cloudServicesConfig;
115+
this.configService = configService;
105116
}
106117

107118
@Override
@@ -660,6 +671,40 @@ public Flux<Plugin> getAllPlugins(String workspaceId) {
660671
});
661672
}
662673

674+
@Override
675+
public Mono<List<Map<String, String>>> getUpcomingIntegrations() {
676+
log.debug("Fetching upcoming integrations from external API");
677+
678+
return configService.getInstanceId().flatMap(instanceId -> {
679+
String apiUrl = cloudServicesConfig.getBaseUrl()
680+
+ "/api/v1/config/external-saas/upcoming-integrations?instanceId=" + instanceId;
681+
return WebClientUtils.create()
682+
.get()
683+
.uri(apiUrl)
684+
.retrieve()
685+
.bodyToMono(Map.class)
686+
.map(response -> {
687+
// Extract the integrations list from the response
688+
if (response.containsKey("data")) {
689+
List<Map<String, String>> integrations = new ArrayList<>();
690+
List<?> data = (List<?>) response.get("data");
691+
for (Object item : data) {
692+
if (item instanceof Map) {
693+
integrations.add((Map<String, String>) item);
694+
}
695+
}
696+
return integrations;
697+
}
698+
return List.<Map<String, String>>of();
699+
})
700+
.onErrorResume(error -> {
701+
log.warn(
702+
"Error retrieving upcoming integrations from external service: {}", error.getMessage());
703+
return Mono.just(List.<Map<String, String>>of());
704+
});
705+
});
706+
}
707+
663708
@Data
664709
static class PluginTemplatesMeta {
665710
List<PluginTemplate> templates;

app/server/appsmith-server/src/main/java/com/appsmith/server/plugins/base/PluginServiceImpl.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.appsmith.server.plugins.base;
22

3+
import com.appsmith.server.configurations.CloudServicesConfig;
34
import com.appsmith.server.repositories.PluginRepository;
45
import com.appsmith.server.services.AnalyticsService;
6+
import com.appsmith.server.services.ConfigService;
57
import com.appsmith.server.services.WorkspaceService;
68
import com.fasterxml.jackson.databind.ObjectMapper;
79
import jakarta.validation.Validator;
@@ -23,7 +25,9 @@ public PluginServiceImpl(
2325
PluginManager pluginManager,
2426
ReactiveRedisTemplate<String, String> reactiveTemplate,
2527
ChannelTopic topic,
26-
ObjectMapper objectMapper) {
28+
ObjectMapper objectMapper,
29+
CloudServicesConfig cloudServicesConfig,
30+
ConfigService configService) {
2731

2832
super(
2933
validator,
@@ -33,6 +37,8 @@ public PluginServiceImpl(
3337
pluginManager,
3438
reactiveTemplate,
3539
topic,
36-
objectMapper);
40+
objectMapper,
41+
cloudServicesConfig,
42+
configService);
3743
}
3844
}

app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/PluginServiceCEImplTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.appsmith.server.services.ce;
22

3+
import com.appsmith.server.configurations.CloudServicesConfig;
34
import com.appsmith.server.domains.Plugin;
45
import com.appsmith.server.plugins.base.PluginServiceCE;
56
import com.appsmith.server.plugins.base.PluginServiceCEImpl;
67
import com.appsmith.server.repositories.PluginRepository;
78
import com.appsmith.server.services.AnalyticsService;
9+
import com.appsmith.server.services.ConfigService;
810
import com.appsmith.server.services.WorkspaceService;
911
import com.fasterxml.jackson.databind.ObjectMapper;
1012
import jakarta.validation.Validator;
@@ -56,6 +58,8 @@ public class PluginServiceCEImplTest {
5658
ObjectMapper objectMapper;
5759

5860
PluginServiceCE pluginService;
61+
CloudServicesConfig cloudServicesConfig;
62+
ConfigService configService;
5963

6064
@BeforeEach
6165
public void setUp() {
@@ -68,7 +72,9 @@ public void setUp() {
6872
pluginManager,
6973
reactiveTemplate,
7074
topic,
71-
objectMapper);
75+
objectMapper,
76+
cloudServicesConfig,
77+
configService);
7278
}
7379

7480
@Test

0 commit comments

Comments
 (0)