This commit is contained in:
parent
b9c9389ade
commit
8ed7c504ea
|
|
@ -20,6 +20,7 @@ import org.springframework.data.domain.Sort;
|
|||
import org.springframework.util.MultiValueMap;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.function.Tuple2;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -42,6 +43,9 @@ public interface NewActionServiceCE extends CrudService<NewAction, String> {
|
|||
|
||||
Mono<ActionDTO> updateUnpublishedAction(String id, ActionDTO action);
|
||||
|
||||
Mono<Tuple2<ActionDTO, NewAction>> updateUnpublishedActionWithoutAnalytics(
|
||||
String id, ActionDTO action, Optional<AclPermission> permission);
|
||||
|
||||
Mono<ActionDTO> findByUnpublishedNameAndPageId(String name, String pageId, AclPermission permission);
|
||||
|
||||
Mono<ActionDTO> findActionDTObyIdAndViewMode(String id, Boolean viewMode, AclPermission permission);
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ public class NewActionServiceCEImpl extends BaseService<NewActionRepository, New
|
|||
public static final PluginType JS_PLUGIN_TYPE = PluginType.JS;
|
||||
public static final String JS_PLUGIN_PACKAGE_NAME = "js-plugin";
|
||||
|
||||
private final NewActionRepository repository;
|
||||
protected final NewActionRepository repository;
|
||||
private final DatasourceService datasourceService;
|
||||
private final PluginService pluginService;
|
||||
private final PluginExecutorHelper pluginExecutorHelper;
|
||||
|
|
@ -552,28 +552,7 @@ public class NewActionServiceCEImpl extends BaseService<NewActionRepository, New
|
|||
@Override
|
||||
public Mono<ActionDTO> updateUnpublishedAction(String id, ActionDTO action) {
|
||||
|
||||
if (id == null) {
|
||||
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ID));
|
||||
}
|
||||
|
||||
// The client does not know about this field. Hence the default value takes over. Set this to null to ensure
|
||||
// the update doesn't lead to resetting of this field.
|
||||
action.setUserSetOnLoad(null);
|
||||
|
||||
Mono<NewAction> updatedActionMono = repository
|
||||
.findById(id, actionPermission.getEditPermission())
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ACTION, id)))
|
||||
.map(dbAction -> {
|
||||
final ActionDTO unpublishedAction = dbAction.getUnpublishedAction();
|
||||
copyNewFieldValuesIntoOldObject(action, unpublishedAction);
|
||||
return dbAction;
|
||||
})
|
||||
.flatMap(this::extractAndSetNativeQueryFromFormData)
|
||||
.cache();
|
||||
|
||||
return updatedActionMono
|
||||
.flatMap(savedNewAction ->
|
||||
this.validateAndSaveActionToRepository(savedNewAction).zipWith(Mono.just(savedNewAction)))
|
||||
return updateUnpublishedActionWithoutAnalytics(id, action, Optional.of(actionPermission.getEditPermission()))
|
||||
.zipWith(Mono.defer(() -> {
|
||||
if (action.getDatasource() != null && action.getDatasource().getId() != null) {
|
||||
return datasourceService.findById(action.getDatasource().getId());
|
||||
|
|
@ -603,6 +582,47 @@ public class NewActionServiceCEImpl extends BaseService<NewActionRepository, New
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an unpublished action in the database without sending an analytics event.
|
||||
*
|
||||
* This method performs an update of an unpublished action in the database without triggering an analytics event.
|
||||
*
|
||||
* @param id The unique identifier of the unpublished action to be updated.
|
||||
* @param action The updated action object.
|
||||
* @param permission An optional permission parameter for access control.
|
||||
* @return A Mono emitting a Tuple containing the updated ActionDTO and NewAction after modification.
|
||||
*
|
||||
* @throws AppsmithException if the provided ID is invalid or if the action is not found.
|
||||
*
|
||||
* @implNote
|
||||
* This method is used by {#updateUnpublishedAction(String, ActionDTO)}, but it does not send an analytics event. If analytics event tracking is not required for the update, this method can be used to improve performance and reduce overhead.
|
||||
*/
|
||||
@Override
|
||||
public Mono<Tuple2<ActionDTO, NewAction>> updateUnpublishedActionWithoutAnalytics(
|
||||
String id, ActionDTO action, Optional<AclPermission> permission) {
|
||||
if (id == null) {
|
||||
return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.ID));
|
||||
}
|
||||
|
||||
// The client does not know about this field. Hence, the default value takes over. Set this to null to ensure
|
||||
// the update doesn't lead to resetting of this field.
|
||||
action.setUserSetOnLoad(null);
|
||||
|
||||
Mono<NewAction> updatedActionMono = repository
|
||||
.findById(id, permission)
|
||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ACTION, id)))
|
||||
.map(dbAction -> {
|
||||
final ActionDTO unpublishedAction = dbAction.getUnpublishedAction();
|
||||
copyNewFieldValuesIntoOldObject(action, unpublishedAction);
|
||||
return dbAction;
|
||||
})
|
||||
.flatMap(this::extractAndSetNativeQueryFromFormData)
|
||||
.cache();
|
||||
|
||||
return updatedActionMono.flatMap(savedNewAction ->
|
||||
this.validateAndSaveActionToRepository(savedNewAction).zipWith(Mono.just(savedNewAction)));
|
||||
}
|
||||
|
||||
private Mono<NewAction> extractAndSetNativeQueryFromFormData(NewAction action) {
|
||||
Mono<Plugin> pluginMono = pluginService.getById(action.getPluginId());
|
||||
Mono<PluginExecutor> pluginExecutorMono = pluginExecutorHelper.getPluginExecutor(pluginMono);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user