Removes pageId from actions no longer in DSL and adds pageIds for actions in DSL in actions collection
This commit is contained in:
parent
cf2ebe53b3
commit
2a47a442be
|
|
@ -2,13 +2,21 @@ package com.appsmith.server.repositories;
|
|||
|
||||
import com.appsmith.server.domains.Action;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Repository
|
||||
public interface ActionRepository extends BaseRepository<Action, String> {
|
||||
|
||||
Mono<Action> findById(String id);
|
||||
|
||||
Mono<Action> findByName(String name);
|
||||
|
||||
Flux<Action> findActionsByNameIn(Set<String> names);
|
||||
|
||||
Flux<Action> saveAll(List<Action> actions);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,12 @@ package com.appsmith.server.services;
|
|||
import com.appsmith.external.models.ActionExecutionResult;
|
||||
import com.appsmith.server.domains.Action;
|
||||
import com.appsmith.server.dtos.ExecuteActionDTO;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ActionService extends CrudService<Action, String> {
|
||||
|
||||
Mono<ActionExecutionResult> executeAction(ExecuteActionDTO executeActionDTO);
|
||||
|
|
@ -13,4 +17,7 @@ public interface ActionService extends CrudService<Action, String> {
|
|||
|
||||
Mono<Action> findByName(String name);
|
||||
|
||||
Flux<Action> findActionsByNameIn(Set<String> names);
|
||||
|
||||
Flux<Action> saveAll(List<Action> actions);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -381,6 +381,16 @@ public class ActionServiceImpl extends BaseService<ActionRepository, Action, Str
|
|||
return repository.findByName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Action> findActionsByNameIn(Set<String> names) {
|
||||
return repository.findActionsByNameIn(names);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Action> saveAll(List<Action> actions) {
|
||||
return repository.saveAll(actions);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function replaces the variables in the Object with the actual params
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.constants.FieldName;
|
||||
import com.appsmith.server.domains.Action;
|
||||
import com.appsmith.server.domains.Layout;
|
||||
import com.appsmith.server.domains.Page;
|
||||
import com.appsmith.server.dtos.DslActionDTO;
|
||||
|
|
@ -15,6 +16,8 @@ import org.jgrapht.graph.DefaultEdge;
|
|||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
|
|
@ -97,16 +100,8 @@ public class LayoutServiceImpl implements LayoutService {
|
|||
//Walk through the DSL and extract the basic relationship of widgets with actions in the DSL.
|
||||
extractWidgetRelationship(dsl, graph);
|
||||
|
||||
Mono<Set<DslActionDTO>> actionsInPage = Flux.fromIterable(graph.vertexSet())
|
||||
/**
|
||||
* TODO : Instead of finding each action by name, bulk search for actions by Name should be done.
|
||||
*/
|
||||
.flatMap(mustacheKey -> actionService.findByName(mustacheKey))
|
||||
.map(action -> {
|
||||
action.setPageId(pageId);
|
||||
return action;
|
||||
})
|
||||
.flatMap(actionService::save)
|
||||
Mono<Set<DslActionDTO>> actionsInPage = updatePageIdsForActionsAndReturnDslActions(graph.vertexSet(), pageId)
|
||||
.flatMapMany(Flux::fromIterable)
|
||||
.map(action -> {
|
||||
//Update the graph here to include action-widget dependecy via dynamic bindings in the action.
|
||||
if (action.getJsonPathKeys() != null && !action.getJsonPathKeys().isEmpty()) {
|
||||
|
|
@ -271,5 +266,43 @@ public class LayoutServiceImpl implements LayoutService {
|
|||
return topVertices;
|
||||
}
|
||||
|
||||
Mono<List<Action>> updatePageIdsForActionsAndReturnDslActions(Set<String> nodes, String pageId) {
|
||||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
||||
params.set(FieldName.PAGE_ID, pageId);
|
||||
|
||||
Flux<Action> actionsInPage = actionService.get(params);
|
||||
Flux<Action> actionsInDsl = actionService.findActionsByNameIn(nodes);
|
||||
|
||||
Mono<List<Action>> actionsWithoutPage = actionsInPage
|
||||
.map(action -> {
|
||||
action.setPageId(null);
|
||||
return action;
|
||||
}).collectList();
|
||||
|
||||
Mono<List<Action>> actionsWithPage = actionsInDsl
|
||||
.map(action -> {
|
||||
action.setPageId(pageId);
|
||||
return action;
|
||||
}).collectList();
|
||||
|
||||
return Mono.zip(actionsWithoutPage, actionsWithPage)
|
||||
.flatMap(tuple -> {
|
||||
List<Action> olderActions = tuple.getT1();
|
||||
List<Action> newActions = tuple.getT2();
|
||||
for (Action oldAction:olderActions) {
|
||||
for (Action newAction:newActions) {
|
||||
if (oldAction.getName() == newAction.getName()) {
|
||||
olderActions.remove(oldAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newActions.addAll(olderActions);
|
||||
return actionService.saveAll(newActions)
|
||||
.collectList()
|
||||
.then(actionsInDsl.collectList());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user