chore: add generate view dto method for overriding (#29595)

## Description
> Add generateActionCollectionViewDTO method for overriding purposes

#### PR fixes following issue(s)
Fixes # (issue number)
> if no issue exists, please create an issue and ask the maintainers
about this first

#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

## Testing
> This is a refactor, not a change in functionality, hence no test
cases. Existing test cases should work fine.

#### 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 is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Introduced a new data transfer object for action collections to
enhance data handling and representation.

- **Refactor**
- Improved the `getActionCollectionsForViewMode` method for better
maintainability and separation of concerns.

- **Documentation**
- Updated public entity declarations to reflect structural changes in
data transfer objects.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com>
This commit is contained in:
Nilesh Sarupriya 2023-12-14 05:59:56 -06:00 committed by GitHub
parent 93b24a145a
commit 69c6875a9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 69 deletions

View File

@ -74,4 +74,6 @@ public interface ActionCollectionServiceCE extends CrudService<ActionCollection,
String contextId, CreatorContextType contextType, AclPermission permission, boolean viewMode);
Mono<ActionCollectionDTO> validateAndSaveCollection(ActionCollection actionCollection);
Mono<ActionCollectionViewDTO> generateActionCollectionViewDTO(ActionCollection actionCollection);
}

View File

@ -222,60 +222,51 @@ public class ActionCollectionServiceCEImpl extends BaseService<ActionCollectionR
.flatMapMany(branchedApplicationId -> repository
.findByApplicationIdAndViewMode(
branchedApplicationId, true, actionPermission.getExecutePermission())
// Filter out all the action collections which haven't been published
.flatMap(actionCollection -> {
if (actionCollection.getPublishedCollection() == null) {
return Mono.empty();
}
return Mono.just(actionCollection);
})
.flatMap(actionCollection -> {
ActionCollectionViewDTO actionCollectionViewDTO = new ActionCollectionViewDTO();
final ActionCollectionDTO publishedCollection = actionCollection.getPublishedCollection();
actionCollectionViewDTO.setId(actionCollection.getId());
actionCollectionViewDTO.setName(publishedCollection.getName());
actionCollectionViewDTO.setPageId(publishedCollection.getPageId());
actionCollectionViewDTO.setApplicationId(actionCollection.getApplicationId());
actionCollectionViewDTO.setVariables(publishedCollection.getVariables());
actionCollectionViewDTO.setBody(publishedCollection.getBody());
// Update default resources :
// actionCollection.defaultResources contains appId, collectionId and branch(optional).
// Default pageId will be taken from publishedCollection.defaultResources
DefaultResources defaults = actionCollection.getDefaultResources();
// Consider a situation when collection is not published but user is viewing in deployed
// mode
if (publishedCollection.getDefaultResources() != null && defaults != null) {
defaults.setPageId(publishedCollection
.getDefaultResources()
.getPageId());
} else {
log.debug(
"Unreachable state, unable to find default ids for actionCollection: {}",
actionCollection.getId());
if (defaults == null) {
defaults = new DefaultResources();
defaults.setApplicationId(actionCollection.getApplicationId());
defaults.setCollectionId(actionCollection.getId());
}
defaults.setPageId(actionCollection
.getPublishedCollection()
.getPageId());
}
actionCollectionViewDTO.setDefaultResources(defaults);
return Flux.fromIterable(publishedCollection
.getDefaultToBranchedActionIdsMap()
.values())
.flatMap(actionId -> {
return newActionService.findActionDTObyIdAndViewMode(
actionId, true, actionPermission.getExecutePermission());
})
.collectList()
.map(actionDTOList -> {
actionCollectionViewDTO.setActions(actionDTOList);
return actionCollectionViewDTO;
});
})
.map(responseUtils::updateActionCollectionViewDTOWithDefaultResources));
.flatMap(this::generateActionCollectionViewDTO));
}
@Override
public Mono<ActionCollectionViewDTO> generateActionCollectionViewDTO(ActionCollection actionCollection) {
if (actionCollection.getPublishedCollection() == null) {
return Mono.empty();
}
ActionCollectionViewDTO actionCollectionViewDTO = new ActionCollectionViewDTO();
final ActionCollectionDTO publishedCollection = actionCollection.getPublishedCollection();
actionCollectionViewDTO.setId(actionCollection.getId());
actionCollectionViewDTO.setName(publishedCollection.getName());
actionCollectionViewDTO.setPageId(publishedCollection.getPageId());
actionCollectionViewDTO.setApplicationId(actionCollection.getApplicationId());
actionCollectionViewDTO.setVariables(publishedCollection.getVariables());
actionCollectionViewDTO.setBody(publishedCollection.getBody());
// Update default resources :
// actionCollection.defaultResources contains appId, collectionId and branch(optional).
// Default pageId will be taken from publishedCollection.defaultResources
DefaultResources defaults = actionCollection.getDefaultResources();
// Consider a situation when collection is not published but user is viewing in deployed
// mode
if (publishedCollection.getDefaultResources() != null && defaults != null) {
defaults.setPageId(publishedCollection.getDefaultResources().getPageId());
} else {
log.debug(
"Unreachable state, unable to find default ids for actionCollection: {}", actionCollection.getId());
if (defaults == null) {
defaults = new DefaultResources();
defaults.setApplicationId(actionCollection.getApplicationId());
defaults.setCollectionId(actionCollection.getId());
}
defaults.setPageId(actionCollection.getPublishedCollection().getPageId());
}
actionCollectionViewDTO.setDefaultResources(defaults);
return Flux.fromIterable(
publishedCollection.getDefaultToBranchedActionIdsMap().values())
.flatMap(actionId -> newActionService.findActionDTObyIdAndViewMode(
actionId, true, actionPermission.getExecutePermission()))
.collectList()
.map(actionDTOList -> {
actionCollectionViewDTO.setActions(actionDTOList);
return actionCollectionViewDTO;
})
.map(responseUtils::updateActionCollectionViewDTOWithDefaultResources);
}
@Override

View File

@ -1,26 +1,13 @@
package com.appsmith.server.dtos;
import com.appsmith.external.models.ActionDTO;
import com.appsmith.external.models.DefaultResources;
import com.appsmith.external.models.JSValue;
import com.appsmith.server.dtos.ce.ActionCollectionCE_DTO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class ActionCollectionViewDTO {
String id;
String name;
String pageId;
String applicationId;
List<JSValue> variables;
List<ActionDTO> actions;
String body;
DefaultResources defaultResources;
}
public class ActionCollectionViewDTO extends ActionCollectionCE_DTO {}

View File

@ -0,0 +1,26 @@
package com.appsmith.server.dtos.ce;
import com.appsmith.external.models.ActionDTO;
import com.appsmith.external.models.DefaultResources;
import com.appsmith.external.models.JSValue;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
@ToString
public class ActionCollectionViewCE_DTO {
String id;
String name;
String pageId;
String applicationId;
List<JSValue> variables;
List<ActionDTO> actions;
String body;
DefaultResources defaultResources;
}