Skip to content

feat(server): Enable upcoming integrations endpoint #40256

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 5 commits into from
Apr 16, 2025
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
@@ -1,5 +1,6 @@
package com.appsmith.server.controllers;

import com.appsmith.server.configurations.CloudServicesConfig;
import com.appsmith.server.constants.Url;
import com.appsmith.server.controllers.ce.PluginControllerCE;
import com.appsmith.server.plugins.base.PluginService;
Expand All @@ -11,7 +12,10 @@
@RequestMapping(Url.PLUGIN_URL)
public class PluginController extends PluginControllerCE {

public PluginController(PluginService service, PluginTriggerSolution pluginTriggerSolution) {
super(service, pluginTriggerSolution);
public PluginController(
PluginService service,
PluginTriggerSolution pluginTriggerSolution,
CloudServicesConfig cloudServicesConfig) {
super(service, pluginTriggerSolution, cloudServicesConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.appsmith.external.models.TriggerRequestDTO;
import com.appsmith.external.models.TriggerResultDTO;
import com.appsmith.external.views.Views;
import com.appsmith.server.configurations.CloudServicesConfig;
import com.appsmith.server.constants.FieldName;
import com.appsmith.server.constants.Url;
import com.appsmith.server.domains.Plugin;
import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.exceptions.AppsmithException;
import com.appsmith.server.plugins.base.PluginService;
import com.appsmith.server.plugins.solutions.PluginTriggerSolution;
import com.fasterxml.jackson.annotation.JsonView;
Expand All @@ -28,6 +30,7 @@
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

@RequestMapping(Url.PLUGIN_URL)
@RequiredArgsConstructor
Expand All @@ -38,6 +41,8 @@ public class PluginControllerCE {

private final PluginTriggerSolution pluginTriggerSolution;

private final CloudServicesConfig cloudServicesConfig;

@JsonView(Views.Public.class)
@GetMapping
public Mono<ResponseDTO<List<Plugin>>> getAll(@RequestParam String workspaceId) {
Expand Down Expand Up @@ -96,4 +101,21 @@ public Mono<ResponseDTO<TriggerResultDTO>> triggerMultipart(
serverWebExchange.getRequest().getHeaders())
.map(triggerResultDTO -> new ResponseDTO<>(HttpStatus.OK, triggerResultDTO));
}

@JsonView(Views.Public.class)
@GetMapping("/upcoming-integrations")
public Mono<ResponseDTO<List<Map<String, String>>>> getUpcomingIntegrations() {
log.debug("Fetching upcoming integrations from external API");
return service.getUpcomingIntegrations()
.map(integrations -> new ResponseDTO<>(HttpStatus.OK, integrations))
.onErrorResume(error -> {
if (error instanceof AppsmithException) {
log.warn("Cloud service error: {}", error.getMessage());
return Mono.just(new ResponseDTO<>(HttpStatus.OK.value(), List.of(), error.getMessage()));
}
log.warn("Error retrieving upcoming integrations from external service: {}", error.getMessage());
return Mono.just(new ResponseDTO<>(
HttpStatus.OK.value(), List.of(), "Unable to fetch upcoming integrations at this time"));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ public interface PluginServiceCE extends CrudService<Plugin, String> {
Mono<Map<String, Plugin>> findAllPluginsInWorkspace(String workspaceId);

Flux<Plugin> getPluginsByType(PluginType pluginType);

Mono<List<Map<String, String>>> getUpcomingIntegrations();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.appsmith.external.models.Datasource;
import com.appsmith.external.models.PluginType;
import com.appsmith.server.configurations.CloudServicesConfig;
import com.appsmith.server.constants.FieldName;
import com.appsmith.server.domains.Plugin;
import com.appsmith.server.domains.Workspace;
Expand All @@ -15,7 +16,9 @@
import com.appsmith.server.repositories.PluginRepository;
import com.appsmith.server.services.AnalyticsService;
import com.appsmith.server.services.BaseService;
import com.appsmith.server.services.ConfigService;
import com.appsmith.server.services.WorkspaceService;
import com.appsmith.util.WebClientUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -46,6 +49,7 @@
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -65,6 +69,7 @@ public class PluginServiceCEImpl extends BaseService<PluginRepository, Plugin, S
private final ReactiveRedisTemplate<String, String> reactiveTemplate;
private final ChannelTopic topic;
private final ObjectMapper objectMapper;
private final CloudServicesConfig cloudServicesConfig;

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

private final ConfigService configService;

@Autowired
public PluginServiceCEImpl(
Validator validator,
Expand All @@ -95,13 +102,17 @@ public PluginServiceCEImpl(
PluginManager pluginManager,
ReactiveRedisTemplate<String, String> reactiveTemplate,
ChannelTopic topic,
ObjectMapper objectMapper) {
ObjectMapper objectMapper,
CloudServicesConfig cloudServicesConfig,
ConfigService configService) {
super(validator, repository, analyticsService);
this.workspaceService = workspaceService;
this.pluginManager = pluginManager;
this.reactiveTemplate = reactiveTemplate;
this.topic = topic;
this.objectMapper = objectMapper;
this.cloudServicesConfig = cloudServicesConfig;
this.configService = configService;
}

@Override
Expand Down Expand Up @@ -660,6 +671,55 @@ public Flux<Plugin> getAllPlugins(String workspaceId) {
});
}

@Override
public Mono<List<Map<String, String>>> getUpcomingIntegrations() {
log.debug("Fetching upcoming integrations from external API");

return configService.getInstanceId().flatMap(instanceId -> {
String apiUrl = cloudServicesConfig.getBaseUrl()
+ "/api/v1/config/external-saas/upcoming-integrations?instanceId=" + instanceId;
return WebClientUtils.create()
.get()
.uri(apiUrl)
.retrieve()
.bodyToMono(Map.class)
.flatMap(response -> {
// Extract the integrations list from the response
if (response.containsKey("data")) {
List<Map<String, String>> integrations = new ArrayList<>();
List<?> data = (List<?>) response.get("data");
for (Object item : data) {
if (item instanceof Map) {
integrations.add((Map<String, String>) item);
}
}
return Mono.just(integrations);
} else if (response.containsKey("responseMeta")) {
Map<String, Object> responseMeta = (Map<String, Object>) response.get("responseMeta");
if (responseMeta.containsKey("error")) {
Map<String, Object> error = (Map<String, Object>) responseMeta.get("error");
if (error.containsKey("message")) {
String errorMessage = (String) error.get("message");
return Mono.error(new AppsmithException(
AppsmithError.INSTANCE_REGISTRATION_FAILURE, errorMessage));
}
}
return Mono.error(new RuntimeException("Unknown error in response metadata"));
}
return Mono.just(List.<Map<String, String>>of());
})
.onErrorResume(error -> {
if (error instanceof AppsmithException) {
return Mono.error(error);
}
log.warn(
"Error retrieving upcoming integrations from external service: {}", error.getMessage());
return Mono.error(
new RuntimeException("Error retrieving upcoming integrations: " + error.getMessage()));
});
});
}

@Data
static class PluginTemplatesMeta {
List<PluginTemplate> templates;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.appsmith.server.plugins.base;

import com.appsmith.server.configurations.CloudServicesConfig;
import com.appsmith.server.repositories.PluginRepository;
import com.appsmith.server.services.AnalyticsService;
import com.appsmith.server.services.ConfigService;
import com.appsmith.server.services.WorkspaceService;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.validation.Validator;
Expand All @@ -23,7 +25,9 @@ public PluginServiceImpl(
PluginManager pluginManager,
ReactiveRedisTemplate<String, String> reactiveTemplate,
ChannelTopic topic,
ObjectMapper objectMapper) {
ObjectMapper objectMapper,
CloudServicesConfig cloudServicesConfig,
ConfigService configService) {

super(
validator,
Expand All @@ -33,6 +37,8 @@ public PluginServiceImpl(
pluginManager,
reactiveTemplate,
topic,
objectMapper);
objectMapper,
cloudServicesConfig,
configService);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.appsmith.server.services.ce;

import com.appsmith.server.configurations.CloudServicesConfig;
import com.appsmith.server.domains.Plugin;
import com.appsmith.server.plugins.base.PluginServiceCE;
import com.appsmith.server.plugins.base.PluginServiceCEImpl;
import com.appsmith.server.repositories.PluginRepository;
import com.appsmith.server.services.AnalyticsService;
import com.appsmith.server.services.ConfigService;
import com.appsmith.server.services.WorkspaceService;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.validation.Validator;
Expand Down Expand Up @@ -56,6 +58,8 @@ public class PluginServiceCEImplTest {
ObjectMapper objectMapper;

PluginServiceCE pluginService;
CloudServicesConfig cloudServicesConfig;
ConfigService configService;

@BeforeEach
public void setUp() {
Expand All @@ -68,7 +72,9 @@ public void setUp() {
pluginManager,
reactiveTemplate,
topic,
objectMapper);
objectMapper,
cloudServicesConfig,
configService);
}

@Test
Expand Down