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(
|
.setAuthentication(
|
||||||
((UpdatableConnection) connection).getAuthenticationDTO(
|
((UpdatableConnection) connection).getAuthenticationDTO(
|
||||||
datasource.getDatasourceConfiguration().getAuthentication()));
|
datasource.getDatasourceConfiguration().getAuthentication()));
|
||||||
datasourceMono1 = datasourceService.update(datasource.getId(), datasource);
|
datasourceMono1 = datasourceService.update(datasource.getId(), datasource, Boolean.TRUE);
|
||||||
}
|
}
|
||||||
return datasourceMono1.thenReturn(connection);
|
return datasourceMono1.thenReturn(connection);
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -33,5 +33,8 @@ public interface DatasourceServiceCE extends CrudService<Datasource, String> {
|
||||||
|
|
||||||
Mono<Datasource> populateHintMessages(Datasource datasource);
|
Mono<Datasource> populateHintMessages(Datasource datasource);
|
||||||
|
|
||||||
|
Mono<Datasource> update(String datasourceId, Datasource datasource, Boolean isServerRefreshedUpdate);
|
||||||
|
|
||||||
Mono<Datasource> getValidDatasourceFromActionMono(ActionDTO actionDTO, AclPermission aclPermission);
|
Mono<Datasource> getValidDatasourceFromActionMono(ActionDTO actionDTO, AclPermission aclPermission);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,13 @@ public class DatasourceServiceCEImpl extends BaseService<DatasourceRepository, D
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Datasource> update(String id, Datasource datasource) {
|
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) {
|
if (id == null) {
|
||||||
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ID));
|
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)
|
Mono<Datasource> datasourceMono = repository.findById(id)
|
||||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.DATASOURCE, id)));
|
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.DATASOURCE, id)));
|
||||||
|
|
||||||
return datasourceMono
|
return datasourceMono
|
||||||
.map(dbDatasource -> {
|
.map(dbDatasource -> {
|
||||||
copyNestedNonNullProperties(datasource, dbDatasource);
|
copyNestedNonNullProperties(datasource, dbDatasource);
|
||||||
|
|
@ -218,9 +226,19 @@ public class DatasourceServiceCEImpl extends BaseService<DatasourceRepository, D
|
||||||
return dbDatasource;
|
return dbDatasource;
|
||||||
})
|
})
|
||||||
.flatMap(this::validateAndSaveDatasourceToRepository)
|
.flatMap(this::validateAndSaveDatasourceToRepository)
|
||||||
.flatMap(savedDatasource ->
|
.flatMap(savedDatasource -> {
|
||||||
analyticsService.sendUpdateEvent(savedDatasource, getAnalyticsProperties(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);
|
.flatMap(this::populateHintMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -302,13 +320,13 @@ public class DatasourceServiceCEImpl extends BaseService<DatasourceRepository, D
|
||||||
.map(this::sanitizeDatasource)
|
.map(this::sanitizeDatasource)
|
||||||
.flatMap(this::validateDatasource)
|
.flatMap(this::validateDatasource)
|
||||||
.flatMap(unsavedDatasource -> {
|
.flatMap(unsavedDatasource -> {
|
||||||
|
return repository.save(unsavedDatasource)
|
||||||
return repository.save(unsavedDatasource).map(savedDatasource -> {
|
.map(savedDatasource -> {
|
||||||
// datasource.pluginName is a transient field. It was set by validateDatasource method
|
// 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
|
// object from db will have pluginName=null so set it manually from the unsaved datasource obj
|
||||||
savedDatasource.setPluginName(unsavedDatasource.getPluginName());
|
savedDatasource.setPluginName(unsavedDatasource.getPluginName());
|
||||||
return savedDatasource;
|
return savedDatasource;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -255,7 +255,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE {
|
||||||
}
|
}
|
||||||
oAuth2.setAuthenticationResponse(authenticationResponse);
|
oAuth2.setAuthenticationResponse(authenticationResponse);
|
||||||
datasource.getDatasourceConfiguration().setAuthentication(oAuth2);
|
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
|
// 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()
|
.getDatasourceConfiguration()
|
||||||
.getAuthentication()
|
.getAuthentication()
|
||||||
.setAuthenticationStatus(AuthenticationDTO.AuthenticationStatus.IN_PROGRESS);
|
.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,
|
.onErrorMap(ConnectException.class,
|
||||||
error -> new AppsmithException(
|
error -> new AppsmithException(
|
||||||
|
|
@ -432,7 +432,7 @@ public class AuthenticationServiceCEImpl implements AuthenticationServiceCE {
|
||||||
return Mono.just(datasource);
|
return Mono.just(datasource);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.flatMap(datasource -> datasourceService.update(datasource.getId(), datasource))
|
.flatMap(datasource -> datasourceService.update(datasource.getId(), datasource, Boolean.TRUE))
|
||||||
.onErrorMap(ConnectException.class,
|
.onErrorMap(ConnectException.class,
|
||||||
error -> new AppsmithException(
|
error -> new AppsmithException(
|
||||||
AppsmithError.AUTHENTICATION_FAILURE,
|
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
|
// We return the same object instead of the update value because the updates value
|
||||||
// will be in the encrypted form
|
// will be in the encrypted form
|
||||||
return datasourceService
|
return datasourceService
|
||||||
.update(datasource.getId(), datasource)
|
.update(datasource.getId(), datasource, Boolean.TRUE)
|
||||||
.thenReturn(datasource);
|
.thenReturn(datasource);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user