Skip to content

Commit

Permalink
chore: Code split for saving and updating action (#27635)
Browse files Browse the repository at this point in the history
## Description

There's a dependency on pageId and newPage in the implementation of
creating or updating action. Creation flow of module will also create a
document in the newAction collection. The expectation here is to use the
underlying implementation. We need to introduce code split here to make
sure module creation flow can leverage this implementation.

#### PR fixes following issue(s)
Fixes #27563 
> if no issue exists, please create an issue and ask the maintainers
about this first
>
>
#### 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

- Chore (housekeeping or task changes that don't impact user perception)

## 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
- [x] 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
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] 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
  • Loading branch information
subrata71 authored Sep 28, 2023
1 parent e37d3b8 commit 98fd558
Show file tree
Hide file tree
Showing 3 changed files with 307 additions and 274 deletions.
Original file line number Diff line number Diff line change
@@ -1,279 +1,13 @@
package com.appsmith.external.models;

import com.appsmith.external.dtos.DslExecutableDTO;
import com.appsmith.external.dtos.LayoutExecutableUpdateDTO;
import com.appsmith.external.exceptions.ErrorDTO;
import com.appsmith.external.helpers.Identifiable;
import com.appsmith.external.views.Views;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.appsmith.external.models.ce.ActionCE_DTO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.springframework.data.annotation.Transient;

import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Getter
@Setter
@NoArgsConstructor
@ToString
public class ActionDTO implements Identifiable, Executable {

@Transient
@JsonView(Views.Public.class)
private String id;

@Transient
@JsonView(Views.Public.class)
String applicationId;

@Transient
@JsonView(Views.Public.class)
String workspaceId;

@Transient
@JsonView(Views.Public.class)
PluginType pluginType;

// name of the plugin. used to log analytics events where pluginName is a required attribute
// It'll be null if not set
@Transient
@JsonView(Views.Public.class)
String pluginName;

@Transient
@JsonView(Views.Public.class)
String pluginId;

@JsonView(Views.Public.class)
String name;

// The FQN for an action will also include any collection it is a part of as collectionName.actionName
@JsonView(Views.Public.class)
String fullyQualifiedName;

@JsonView(Views.Public.class)
Datasource datasource;

@JsonView(Views.Public.class)
String pageId;

@JsonView(Views.Public.class)
String collectionId;

@JsonView(Views.Public.class)
ActionConfiguration actionConfiguration;

// this attribute carries error messages while processing the actionCollection
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@Transient
@JsonView(Views.Public.class)
List<ErrorDTO> errorReports;

@JsonView(Views.Public.class)
Boolean executeOnLoad;

@JsonView(Views.Public.class)
Boolean clientSideExecution;

/*
* This is a list of fields specified by the client to signify which fields have dynamic bindings in them.
* TODO: The server can use this field to simplify our Mustache substitutions in the future
*/
@JsonView(Views.Public.class)
List<Property> dynamicBindingPathList;

@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonView(Views.Public.class)
Boolean isValid;

@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonView(Views.Public.class)
Set<String> invalids;

@Transient
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonView(Views.Public.class)
Set<String> messages = new HashSet<>();

// This is a list of keys that the client whose values the client needs to send during action execution.
// These are the Mustache keys that the server will replace before invoking the API
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
@JsonView(Views.Public.class)
Set<String> jsonPathKeys;

@JsonView(Views.Internal.class)
String cacheResponse;

@Transient
@JsonView(Views.Public.class)
String templateId; // If action is created via a template, store the id here.

@Transient
@JsonView(Views.Public.class)
String providerId; // If action is created via a template, store the template's provider id here.

@Transient
@JsonView(Views.Public.class)
ActionProvider provider;

@JsonView(Views.Internal.class)
Boolean userSetOnLoad = false;

@JsonView(Views.Public.class)
Boolean confirmBeforeExecute = false;

@Transient
@JsonView(Views.Public.class)
Documentation documentation;

@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC")
@JsonView(Views.Public.class)
Instant deletedAt = null;

@Deprecated
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "UTC")
@JsonView(Views.Public.class)
Instant archivedAt = null;

@Transient
@JsonView(Views.Internal.class)
protected Set<Policy> policies = new HashSet<>();

@Transient
@JsonView(Views.Public.class)
public Set<String> userPermissions = new HashSet<>();

// This field will be used to store the default/root actionId and applicationId for actions generated for git
// connected applications and will be used to connect actions across the branches
@JsonView(Views.Internal.class)
DefaultResources defaultResources;

// This field will be used to store analytics data related to this specific domain object. It's been introduced in
// order to track
// success metrics of modules. Learn more on GitHub issue#24734
@JsonView(Views.Public.class)
AnalyticsInfo eventData;

@JsonView(Views.Internal.class)
protected Instant createdAt;

@JsonView(Views.Internal.class)
protected Instant updatedAt;

/**
* If the Datasource is null, create one and set the autoGenerated flag to true. This is required because spring-data
* cannot add the createdAt and updatedAt properties for null embedded objects. At this juncture, we couldn't find
* a way to disable the auditing for nested objects.
*
* @return
*/
@JsonView(Views.Public.class)
public Datasource getDatasource() {
if (this.datasource == null) {
this.datasource = new Datasource();
this.datasource.setIsAutoGenerated(true);
}
return datasource;
}

@Override
@JsonView(Views.Public.class)
public String getValidName() {
if (this.fullyQualifiedName == null) {
return this.name;
} else {
return this.fullyQualifiedName;
}
}

@Override
public EntityReferenceType getEntityReferenceType() {
if (this.getPluginType() == null) {
return null;
}
return this.getPluginType().equals(PluginType.JS) ? EntityReferenceType.JSACTION : EntityReferenceType.ACTION;
}

public void sanitiseToExportDBObject() {
this.setEventData(null);
this.setDefaultResources(null);
this.setCacheResponse(null);
if (this.getDatasource() != null) {
this.getDatasource().setCreatedAt(null);
this.getDatasource().setDatasourceStorages(null);
}
if (this.getUserPermissions() != null) {
this.getUserPermissions().clear();
}
if (this.getPolicies() != null) {
this.getPolicies().clear();
}
}

@Override
public Set<String> getSelfReferencingDataPaths() {
if (this.getActionConfiguration() == null) {
return new HashSet<>();
}
return this.getActionConfiguration().getSelfReferencingDataPaths();
}

@Override
public ActionConfiguration getExecutableConfiguration() {
return this.getActionConfiguration();
}

@Override
public String getConfigurationPath() {
return this.getValidName() + ".actionConfiguration";
}

@Override
public String getCompleteDynamicBindingPath(String fieldPath) {
return this.getConfigurationPath() + "." + fieldPath;
}

@Override
public boolean hasExtractableBinding() {
return PluginType.JS.equals(this.getPluginType());
}

@Override
public DslExecutableDTO getDslExecutable() {
DslExecutableDTO dslExecutableDTO = new DslExecutableDTO();

dslExecutableDTO.setId(this.getId());
dslExecutableDTO.setPluginType(this.getPluginType());
dslExecutableDTO.setJsonPathKeys(this.getJsonPathKeys());
dslExecutableDTO.setName(this.getValidName());
dslExecutableDTO.setCollectionId(this.getCollectionId());
dslExecutableDTO.setClientSideExecution(this.getClientSideExecution());
dslExecutableDTO.setConfirmBeforeExecute(this.getConfirmBeforeExecute());
if (this.getDefaultResources() != null) {
dslExecutableDTO.setDefaultActionId(this.getDefaultResources().getActionId());
dslExecutableDTO.setDefaultCollectionId(this.getDefaultResources().getCollectionId());
}

if (this.getExecutableConfiguration() != null) {
dslExecutableDTO.setTimeoutInMillisecond(
this.getExecutableConfiguration().getTimeoutInMillisecond());
}

return dslExecutableDTO;
}

@Override
public LayoutExecutableUpdateDTO createLayoutExecutableUpdateDTO() {
LayoutExecutableUpdateDTO layoutExecutableUpdateDTO = Executable.super.createLayoutExecutableUpdateDTO();
layoutExecutableUpdateDTO.setCollectionId(this.getCollectionId());

return layoutExecutableUpdateDTO;
}
}
public class ActionDTO extends ActionCE_DTO {}
Loading

0 comments on commit 98fd558

Please sign in to comment.