Merge branch 'bug/marketplace-integration-add-to-page' into 'release'

After migrating the database to marketplace, add new template to page stopped working. Fixing that by fetching the provider from marketplace service.

See merge request theappsmith/internal-tools-server!279
This commit is contained in:
Trisha Anand 2020-04-13 17:44:08 +00:00
commit d955dfd8bf
3 changed files with 30 additions and 5 deletions

View File

@ -66,7 +66,7 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
private final DatasourceContextService datasourceContextService;
private final PluginExecutorHelper pluginExecutorHelper;
private final SessionUserService sessionUserService;
private final ProviderService providerService;
private final MarketplaceService marketplaceService;
@Autowired
public ActionServiceImpl(Scheduler scheduler,
@ -82,7 +82,7 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
DatasourceContextService datasourceContextService,
PluginExecutorHelper pluginExecutorHelper,
SessionUserService sessionUserService,
ProviderService providerService) {
MarketplaceService marketplaceService) {
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository, analyticsService);
this.repository = repository;
this.datasourceService = datasourceService;
@ -92,7 +92,7 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
this.datasourceContextService = datasourceContextService;
this.pluginExecutorHelper = pluginExecutorHelper;
this.sessionUserService = sessionUserService;
this.providerService = providerService;
this.marketplaceService = marketplaceService;
}
private Boolean validateActionName(String name) {
@ -556,8 +556,8 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
Mono<Action> providerUpdateMono = null;
if ((action.getTemplateId() != null) && (action.getProviderId() != null)) {
providerUpdateMono = providerService
.getById(action.getProviderId())
providerUpdateMono = marketplaceService
.getProviderById(action.getProviderId())
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, "Provider")))
.map(provider -> {
ActionProvider actionProvider = new ActionProvider();

View File

@ -1,6 +1,7 @@
package com.appsmith.server.services;
import com.appsmith.external.models.ApiTemplate;
import com.appsmith.external.models.Provider;
import com.appsmith.server.dtos.ProviderPaginatedDTO;
import org.springframework.util.MultiValueMap;
import reactor.core.publisher.Mono;
@ -12,4 +13,5 @@ public interface MarketplaceService {
Mono<List<ApiTemplate>> getTemplates(MultiValueMap<String, String> params);
Mono<List<String>> getCategories();
Mono<Boolean> subscribeAndUpdateStatisticsOfProvider(String providerId);
Mono<Provider> getProviderById(String id);
}

View File

@ -1,6 +1,7 @@
package com.appsmith.server.services;
import com.appsmith.external.models.ApiTemplate;
import com.appsmith.external.models.Provider;
import com.appsmith.server.configurations.MarketplaceConfig;
import com.appsmith.server.dtos.ProviderPaginatedDTO;
import com.appsmith.server.exceptions.AppsmithError;
@ -141,6 +142,28 @@ public class MarketplaceServiceImpl implements MarketplaceService {
.bodyToMono(Boolean.class);
}
@Override
public Mono<Provider> getProviderById(String id) {
URI uri = buildFullURI(null, PROVIDER_PATH + "/" + id);
return webClient
.get()
.uri(uri)
.retrieve()
.bodyToMono(String.class)
.flatMap(stringBody -> {
Provider provider = null;
try {
provider = objectMapper.readValue(stringBody, Provider.class);
} catch (JsonProcessingException e) {
return Mono.error(new AppsmithException(AppsmithError.JSON_PROCESSING_ERROR, e));
}
return Mono.just(provider);
})
.timeout(Duration.ofMillis(timeoutInMillis))
.doOnError(error -> Mono.error(new AppsmithException(AppsmithError.MARKETPLACE_TIMEOUT)));
}
private URI buildFullURI(MultiValueMap<String, String> params, String path) {
UriComponentsBuilder uriBuilder = UriComponentsBuilder.newInstance();
try {