From 491afc3599cda24cb14e05392e30a21a626868b7 Mon Sep 17 00:00:00 2001 From: Trisha Anand Date: Wed, 10 Jun 2020 09:08:01 +0000 Subject: [PATCH] In case of global datasource, no need to check for organizationId during action create. --- .../server/services/ActionServiceImpl.java | 93 ++++++++++--------- 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java index 99f6cfa5c7..efea1a21da 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ActionServiceImpl.java @@ -143,11 +143,15 @@ public class ActionServiceImpl extends BaseService { + // datasource is found. Update the action. + action.setOrganizationId(datasource.getOrganizationId()); + return datasource; + }); } Mono pluginMono = datasourceMono.flatMap(datasource -> { @@ -415,31 +424,31 @@ public class ActionServiceImpl extends BaseService obj) .flatMap(res -> { - ActionExecutionResult result = (ActionExecutionResult) res; - Mono resultMono = Mono.just(result); - if (actionFromDto.getId() == null) { - // This is a dry-run. We shouldn't query the db because it'll throw NPE on null IDs - return resultMono; - } + ActionExecutionResult result = (ActionExecutionResult) res; + Mono resultMono = Mono.just(result); + if (actionFromDto.getId() == null) { + // This is a dry-run. We shouldn't query the db because it'll throw NPE on null IDs + return resultMono; + } - Mono actionFromDbMono = repository.findById(actionFromDto.getId()) - //If the action is found in the db (i.e. it is not a dry run, save the cached response - .flatMap(action -> { - if (result.getIsExecutionSuccess()) { - // If the plugin execution result is successful, then cache response body in - // the action and save it. - action.setCacheResponse(result.getBody().toString()); - return repository.save(action); - } - log.debug("Action execution resulted in failure beyond the proxy with the result of {}", result); - return Mono.just(action); - }); - return actionFromDbMono.zipWith(resultMono) - .map(tuple -> { - ActionExecutionResult executionResult = tuple.getT2(); - return executionResult; - }); - }); + Mono actionFromDbMono = repository.findById(actionFromDto.getId()) + //If the action is found in the db (i.e. it is not a dry run, save the cached response + .flatMap(action -> { + if (result.getIsExecutionSuccess()) { + // If the plugin execution result is successful, then cache response body in + // the action and save it. + action.setCacheResponse(result.getBody().toString()); + return repository.save(action); + } + log.debug("Action execution resulted in failure beyond the proxy with the result of {}", result); + return Mono.just(action); + }); + return actionFromDbMono.zipWith(resultMono) + .map(tuple -> { + ActionExecutionResult executionResult = tuple.getT2(); + return executionResult; + }); + }); } @Override @@ -526,22 +535,22 @@ public class ActionServiceImpl extends BaseService applicationPagesDTO.getPages()) - .flatMapMany(Flux::fromIterable) - .map(pageNameIdDTO -> pageNameIdDTO.getId()) - .collectList() - .flatMapMany(pages -> { - pageIds.addAll(pages); - return repository.findAllActionsByNameAndPageIds(finalName, pageIds, READ_ACTIONS, sort); - }) + .findNamesByApplicationId(params.getFirst(FieldName.APPLICATION_ID)) + .switchIfEmpty(Mono.error(new AppsmithException( + AppsmithError.NO_RESOURCE_FOUND, "pages for application", params.getFirst(FieldName.APPLICATION_ID))) + ) + .map(applicationPagesDTO -> applicationPagesDTO.getPages()) + .flatMapMany(Flux::fromIterable) + .map(pageNameIdDTO -> pageNameIdDTO.getId()) + .collectList() + .flatMapMany(pages -> { + pageIds.addAll(pages); + return repository.findAllActionsByNameAndPageIds(finalName, pageIds, READ_ACTIONS, sort); + }) .flatMap(this::setTransientFieldsInAction); } return repository.findAllActionsByNameAndPageIds(name, pageIds, READ_ACTIONS, sort) - .flatMap(this::setTransientFieldsInAction); + .flatMap(this::setTransientFieldsInAction); } private ActionConfiguration updateActionConfigurationForPagination(ActionConfiguration actionConfiguration,