chore: Split ActionViewDTO (#29157)

> Pull Request Template
>
> Use this template to quickly create a well written pull request.
Delete all quotes before creating the pull request.
>
## Description
> Add a TL;DR when description is extra long (helps content team)
>
> Please include a summary of the changes and which issue has been
fixed. Please also include relevant motivation
> and context. List any dependencies that are required for this change
>
> Links to Notion, Figma or any other documents that might be relevant
to the PR
>
>
#### PR fixes following issue(s)
Fixes #29155

#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
> Please delete options that are not relevant.
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update
>
>
>
## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [ ] Manual
- [ ] JUnit
- [ ] Jest
- [ ] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
This commit is contained in:
subratadeypappu 2023-11-28 14:24:51 +06:00 committed by GitHub
parent da2e1c2822
commit 8fc45fef8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 86 additions and 75 deletions

View File

@ -1,50 +1,13 @@
package com.appsmith.server.dtos;
import com.appsmith.external.models.DefaultResources;
import com.appsmith.external.views.Views;
import com.fasterxml.jackson.annotation.JsonView;
import com.appsmith.server.dtos.ce.ActionViewCE_DTO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import java.util.Set;
import static com.appsmith.external.constants.ActionConstants.DEFAULT_ACTION_EXECUTION_TIMEOUT_MS;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class ActionViewDTO {
@JsonView(Views.Public.class)
String id;
@JsonView(Views.Public.class)
String name;
@JsonView(Views.Public.class)
String pageId;
@JsonView(Views.Public.class)
Integer timeoutInMillisecond;
@JsonView(Views.Public.class)
Boolean confirmBeforeExecute;
@JsonView(Views.Public.class)
Set<String> jsonPathKeys;
@JsonView(Views.Internal.class)
DefaultResources defaultResources;
// Overriding the getter to ensure that for actions missing action configuration, the timeout is
// still set for the client to use as a guideline (even though this would be an invalid action
// and hence would return an action execution error.
@JsonView(Views.Public.class)
public Integer getTimeoutInMillisecond() {
return (timeoutInMillisecond == null || timeoutInMillisecond <= 0)
? DEFAULT_ACTION_EXECUTION_TIMEOUT_MS
: timeoutInMillisecond;
}
}
public class ActionViewDTO extends ActionViewCE_DTO {}

View File

@ -0,0 +1,50 @@
package com.appsmith.server.dtos.ce;
import com.appsmith.external.models.DefaultResources;
import com.appsmith.external.views.Views;
import com.fasterxml.jackson.annotation.JsonView;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import java.util.Set;
import static com.appsmith.external.constants.ActionConstants.DEFAULT_ACTION_EXECUTION_TIMEOUT_MS;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class ActionViewCE_DTO {
@JsonView(Views.Public.class)
String id;
@JsonView(Views.Public.class)
String name;
@JsonView(Views.Public.class)
String pageId;
@JsonView(Views.Public.class)
Integer timeoutInMillisecond;
@JsonView(Views.Public.class)
Boolean confirmBeforeExecute;
@JsonView(Views.Public.class)
Set<String> jsonPathKeys;
@JsonView(Views.Internal.class)
DefaultResources defaultResources;
// Overriding the getter to ensure that for actions missing action configuration, the timeout is
// still set for the client to use as a guideline (even though this would be an invalid action
// and hence would return an action execution error.
@JsonView(Views.Public.class)
public Integer getTimeoutInMillisecond() {
return (timeoutInMillisecond == null || timeoutInMillisecond <= 0)
? DEFAULT_ACTION_EXECUTION_TIMEOUT_MS
: timeoutInMillisecond;
}
}

View File

@ -75,6 +75,8 @@ public interface NewActionServiceCE extends CrudService<NewAction, String> {
Flux<ActionViewDTO> getActionsForViewMode(String defaultApplicationId, String branchName);
ActionViewDTO generateActionViewDTO(NewAction action, ActionDTO actionDTO);
Mono<ActionDTO> deleteUnpublishedAction(String id);
Flux<ActionDTO> getUnpublishedActions(MultiValueMap<String, String> params, Boolean includeJsActions);

View File

@ -780,42 +780,38 @@ public class NewActionServiceCEImpl extends BaseService<NewActionRepository, New
// No need to sort the results
return findAllByApplicationIdAndViewMode(applicationId, true, actionPermission.getExecutePermission(), null)
.filter(newAction -> !PluginType.JS.equals(newAction.getPluginType()))
.map(action -> {
ActionViewDTO actionViewDTO = new ActionViewDTO();
actionViewDTO.setId(action.getDefaultResources().getActionId());
actionViewDTO.setName(action.getPublishedAction().getValidName());
actionViewDTO.setPageId(action.getPublishedAction().getPageId());
actionViewDTO.setConfirmBeforeExecute(
action.getPublishedAction().getConfirmBeforeExecute());
// Update defaultResources
DefaultResources defaults = action.getDefaultResources();
// Consider a situation when action is not published but user is viewing in deployed mode
if (action.getPublishedAction().getDefaultResources() != null) {
defaults.setPageId(action.getPublishedAction()
.getDefaultResources()
.getPageId());
defaults.setCollectionId(action.getPublishedAction()
.getDefaultResources()
.getCollectionId());
} else {
defaults.setPageId(null);
defaults.setCollectionId(null);
}
actionViewDTO.setDefaultResources(defaults);
if (action.getPublishedAction().getJsonPathKeys() != null
&& !action.getPublishedAction().getJsonPathKeys().isEmpty()) {
Set<String> jsonPathKeys;
jsonPathKeys = new HashSet<>();
jsonPathKeys.addAll(action.getPublishedAction().getJsonPathKeys());
actionViewDTO.setJsonPathKeys(jsonPathKeys);
}
if (action.getPublishedAction().getActionConfiguration() != null) {
actionViewDTO.setTimeoutInMillisecond(action.getPublishedAction()
.getActionConfiguration()
.getTimeoutInMillisecond());
}
return actionViewDTO;
});
.map(action -> generateActionViewDTO(action, action.getPublishedAction()));
}
@Override
public ActionViewDTO generateActionViewDTO(NewAction action, ActionDTO actionDTO) {
ActionViewDTO actionViewDTO = new ActionViewDTO();
actionViewDTO.setId(action.getDefaultResources().getActionId());
actionViewDTO.setName(actionDTO.getValidName());
actionViewDTO.setPageId(actionDTO.getPageId());
actionViewDTO.setConfirmBeforeExecute(actionDTO.getConfirmBeforeExecute());
// Update defaultResources
DefaultResources defaults = action.getDefaultResources();
// Consider a situation when action is not published but user is viewing in deployed mode
if (actionDTO.getDefaultResources() != null) {
defaults.setPageId(actionDTO.getDefaultResources().getPageId());
defaults.setCollectionId(actionDTO.getDefaultResources().getCollectionId());
} else {
defaults.setPageId(null);
defaults.setCollectionId(null);
}
actionViewDTO.setDefaultResources(defaults);
if (actionDTO.getJsonPathKeys() != null && !actionDTO.getJsonPathKeys().isEmpty()) {
Set<String> jsonPathKeys;
jsonPathKeys = new HashSet<>();
jsonPathKeys.addAll(actionDTO.getJsonPathKeys());
actionViewDTO.setJsonPathKeys(jsonPathKeys);
}
if (actionDTO.getActionConfiguration() != null) {
actionViewDTO.setTimeoutInMillisecond(
actionDTO.getActionConfiguration().getTimeoutInMillisecond());
}
return actionViewDTO;
}
@Override