diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceContextServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceContextServiceCEImpl.java index 93babde9a1..9ebea2c22b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceContextServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceContextServiceCEImpl.java @@ -116,7 +116,7 @@ public class DatasourceContextServiceCEImpl implements DatasourceContextServiceC .setAuthentication( ((UpdatableConnection) connection).getAuthenticationDTO( datasource.getDatasourceConfiguration().getAuthentication())); - datasourceMono1 = datasourceService.update(datasource.getId(), datasource); + datasourceMono1 = datasourceService.update(datasource.getId(), datasource, Boolean.TRUE); } return datasourceMono1.thenReturn(connection); }) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceServiceCE.java index ed668eae23..8f68633a68 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceServiceCE.java @@ -33,5 +33,8 @@ public interface DatasourceServiceCE extends CrudService { Mono populateHintMessages(Datasource datasource); + Mono update(String datasourceId, Datasource datasource, Boolean isServerRefreshedUpdate); + Mono getValidDatasourceFromActionMono(ActionDTO actionDTO, AclPermission aclPermission); + } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceServiceCEImpl.java index 221883da13..1b00df0c73 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/DatasourceServiceCEImpl.java @@ -198,6 +198,13 @@ public class DatasourceServiceCEImpl extends BaseService update(String id, Datasource datasource) { + // since there was no datasource update differentiator between server invoked due to refresh token, + // and user invoked. Hence the update is overloaded to provide the boolean for key diff. + // since the base controller uses the default method from CRUD interface, we are adding keys manually for the user invoked flow + return update(id, datasource, Boolean.FALSE); + } + + public Mono update(String id, Datasource datasource, Boolean isServerRefreshedUpdate) { if (id == null) { return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ID)); } @@ -207,6 +214,7 @@ public class DatasourceServiceCEImpl extends BaseService datasourceMono = repository.findById(id) .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.DATASOURCE, id))); + return datasourceMono .map(dbDatasource -> { copyNestedNonNullProperties(datasource, dbDatasource); @@ -218,9 +226,19 @@ public class DatasourceServiceCEImpl extends BaseService - analyticsService.sendUpdateEvent(savedDatasource, getAnalyticsProperties(savedDatasource)) - ) + .flatMap(savedDatasource -> { + + // this key will present in the analytics as a diff b/w server and user invoked flows + String isDatasourceUpdateServerInvokedKey = "isDatasourceUpdateServerInvoked"; + Map analyticsProperties = getAnalyticsProperties(savedDatasource); + + if (isServerRefreshedUpdate.equals(Boolean.TRUE)) { + analyticsProperties.put(isDatasourceUpdateServerInvokedKey, Boolean.TRUE); + } else { + analyticsProperties.put(isDatasourceUpdateServerInvokedKey, Boolean.FALSE); + } + return analyticsService.sendUpdateEvent(savedDatasource, analyticsProperties); + }) .flatMap(this::populateHintMessages); } @@ -302,13 +320,13 @@ public class DatasourceServiceCEImpl extends BaseService { - - return repository.save(unsavedDatasource).map(savedDatasource -> { - // datasource.pluginName is a transient field. It was set by validateDatasource method - // object from db will have pluginName=null so set it manually from the unsaved datasource obj - savedDatasource.setPluginName(unsavedDatasource.getPluginName()); - return savedDatasource; - }); + return repository.save(unsavedDatasource) + .map(savedDatasource -> { + // datasource.pluginName is a transient field. It was set by validateDatasource method + // object from db will have pluginName=null so set it manually from the unsaved datasource obj + savedDatasource.setPluginName(unsavedDatasource.getPluginName()); + return savedDatasource; + }); }); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java index 96135adb8f..02c518d02f 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/AuthenticationServiceCEImpl.java @@ -255,7 +255,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { } oAuth2.setAuthenticationResponse(authenticationResponse); datasource.getDatasourceConfiguration().setAuthentication(oAuth2); - return datasourceService.update(datasource.getId(), datasource); + return datasourceService.update(datasource.getId(), datasource, Boolean.TRUE); }); }) // We have no use of the datasource object during redirection, we merely send the response as a success state @@ -367,7 +367,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { .getDatasourceConfiguration() .getAuthentication() .setAuthenticationStatus(AuthenticationDTO.AuthenticationStatus.IN_PROGRESS); - return datasourceService.update(datasource.getId(), datasource).thenReturn(appsmithToken); + return datasourceService.update(datasource.getId(), datasource, Boolean.TRUE).thenReturn(appsmithToken); }) .onErrorMap(ConnectException.class, error -> new AppsmithException( @@ -432,7 +432,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { return Mono.just(datasource); }); }) - .flatMap(datasource -> datasourceService.update(datasource.getId(), datasource)) + .flatMap(datasource -> datasourceService.update(datasource.getId(), datasource, Boolean.TRUE)) .onErrorMap(ConnectException.class, error -> new AppsmithException( AppsmithError.AUTHENTICATION_FAILURE, @@ -479,7 +479,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE { // We return the same object instead of the update value because the updates value // will be in the encrypted form return datasourceService - .update(datasource.getId(), datasource) + .update(datasource.getId(), datasource, Boolean.TRUE) .thenReturn(datasource); }); })