chore: added datasource-save event differentiator for analytics (#17237)
* chore: added datasource-save event differentiator for analytics * added more comments * code readability changes
This commit is contained in:
parent
794a422a82
commit
ab2d580e90
|
|
@ -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);
|
||||
})
|
||||
|
|
|
|||
|
|
@ -33,5 +33,8 @@ public interface DatasourceServiceCE extends CrudService<Datasource, String> {
|
|||
|
||||
Mono<Datasource> populateHintMessages(Datasource datasource);
|
||||
|
||||
Mono<Datasource> update(String datasourceId, Datasource datasource, Boolean isServerRefreshedUpdate);
|
||||
|
||||
Mono<Datasource> getValidDatasourceFromActionMono(ActionDTO actionDTO, AclPermission aclPermission);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,6 +198,13 @@ public class DatasourceServiceCEImpl extends BaseService<DatasourceRepository, D
|
|||
|
||||
@Override
|
||||
public Mono<Datasource> 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<Datasource> 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<DatasourceRepository, D
|
|||
|
||||
Mono<Datasource> 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<DatasourceRepository, D
|
|||
return dbDatasource;
|
||||
})
|
||||
.flatMap(this::validateAndSaveDatasourceToRepository)
|
||||
.flatMap(savedDatasource ->
|
||||
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<String, Object> 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<DatasourceRepository, D
|
|||
.map(this::sanitizeDatasource)
|
||||
.flatMap(this::validateDatasource)
|
||||
.flatMap(unsavedDatasource -> {
|
||||
|
||||
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;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user