Merge remote-tracking branch 'origin/release' into fix-10771_text_widget_warning

This commit is contained in:
Preet 2022-03-22 17:32:59 +05:30
commit 5ebdb9dcff
19 changed files with 224 additions and 242 deletions

View File

@ -17,7 +17,10 @@
"**/Smoke_TestSuite/ClientSideTests/DisplayWidgets/Table_Filter_spec*.js", "**/Smoke_TestSuite/ClientSideTests/DisplayWidgets/Table_Filter_spec*.js",
"**/Smoke_TestSuite/ClientSideTests/Onboarding/FirstTimeUserOnboarding_spec*.js", "**/Smoke_TestSuite/ClientSideTests/Onboarding/FirstTimeUserOnboarding_spec*.js",
"**/Smoke_TestSuite/ClientSideTests/LayoutValidation/AppPageLayout.spec.js", "**/Smoke_TestSuite/ClientSideTests/LayoutValidation/AppPageLayout.spec.js",
"**/Smoke_TestSuite/ClientSideTests/Templates/Fork_Template_spec.js" "**/Smoke_TestSuite/ClientSideTests/Templates/Fork_Template_spec.js",
"**/Smoke_TestSuite/ClientSideTests/GenerateCRUD/MySQL_Spec.js",
"**/Smoke_TestSuite/ServerSideTests/Datasources/MySQL_spec.js",
"**/Smoke_TestSuite/ServerSideTests/Datasources/MySQLNoiseTest_spec.js"
], ],
"chromeWebSecurity": false, "chromeWebSecurity": false,
"viewportHeight": 1100, "viewportHeight": 1100,

View File

@ -214,7 +214,9 @@ describe("Validate CRUD queries for Postgres along with UI flow verifications",
.click(); .click();
cy.wait(5000); cy.wait(5000);
cy.xpath(generatePage.sortByDropdown).click(); //Sorting by descending to verify newly added record - also sorting is verified cy.get(generatePage.sortByDropdown)
.last()
.click(); //Sorting by descending to verify newly added record - also sorting is verified
cy.xpath(generatePage.descending).click(); cy.xpath(generatePage.descending).click();
cy.wait(2000); //for descending to take effect! cy.wait(2000); //for descending to take effect!
cy.xpath(generatePage.currentNameField).should("have.value", "CRUD User31"); //Verifying Addition is success cy.xpath(generatePage.currentNameField).should("have.value", "CRUD User31"); //Verifying Addition is success

View File

@ -17,7 +17,7 @@
"genderField": "//input[@placeholder='gender']", "genderField": "//input[@placeholder='gender']",
"emailField": "//input[@placeholder='email']", "emailField": "//input[@placeholder='email']",
"submitBtn": "span:contains('Submit')", "submitBtn": "span:contains('Submit')",
"sortByDropdown": "//div[@type='CANVAS_WIDGET']/div[contains(@class, 't--widget-dropdownwidget')][2]", "sortByDropdown": "span[name='dropdown']",
"ascending": "//div[text()='Ascending']", "ascending": "//div[text()='Ascending']",
"descending": "//div[text()='Descending']", "descending": "//div[text()='Descending']",
"currentNameField": "//div[@type='FORM_WIDGET']//span[text()='name:']//ancestor::div[contains(@class,'t--widget-textwidget')]/following-sibling::div[contains(@class, 't--widget-inputwidgetv2')][1]//input", "currentNameField": "//div[@type='FORM_WIDGET']//span[text()='name:']//ancestor::div[contains(@class,'t--widget-textwidget')]/following-sibling::div[contains(@class, 't--widget-inputwidgetv2')][1]//input",

View File

@ -207,7 +207,9 @@ function* handleQueryCreatedSaga(actionPayload: ReduxAction<QueryAction>) {
const queryTemplate = pluginTemplates[pluginId]; const queryTemplate = pluginTemplates[pluginId];
// Do not show template view if the query has body(code) or if there are no templates // Do not show template view if the query has body(code) or if there are no templates
const showTemplate = !( const showTemplate = !(
!!actionConfiguration.body || isEmpty(queryTemplate) !!actionConfiguration.body ||
!!actionConfiguration.formData?.body ||
isEmpty(queryTemplate)
); );
history.replace( history.replace(
QUERIES_EDITOR_ID_URL(applicationId, pageId, id, { QUERIES_EDITOR_ID_URL(applicationId, pageId, id, {

View File

@ -112,7 +112,6 @@ public class DatasourceStructure {
String title; String title;
String body; String body;
Object configuration; Object configuration;
ActionConfiguration actionConfiguration;
// To create templates for plugins which store the configurations // To create templates for plugins which store the configurations
// in List<Property> format // in List<Property> format
@ -131,20 +130,13 @@ public class DatasourceStructure {
} }
/** /**
* Create templates by passing UQI framework config and ActionConfiguration Object. * Create templates by passing UQI framework config.
* * <p>
* For integrations that use UQI interface, a config map is used to indicate the required template. However, * For integrations that use UQI interface, a config map is used to indicate the required template.
* some properties like `actionConfiguration.path` cannot be configured via the config map since the config
* map only models the formData attribute. Such properties are configured via ActionConfiguration object.
*
* This seemed like a good choice over only using the ActionConfiguration object and skipping out on the
* UQI/formData configuration map - as it would allow the Client application to re-use the UQI related
* template code and augment the remaining fields with ActionConfiguration object.
*/ */
public Template(String title, Map<String, ?> configuration, ActionConfiguration actionConfiguration) { public Template(String title, Map<String, ?> configuration) {
this.title = title; this.title = title;
this.configuration = configuration; this.configuration = configuration;
this.actionConfiguration = actionConfiguration;
} }
// Creating templates without configuration // Creating templates without configuration

View File

@ -1,6 +1,5 @@
package com.external.utils; package com.external.utils;
import com.appsmith.external.models.ActionConfiguration;
import com.appsmith.external.models.DatasourceStructure.Template; import com.appsmith.external.models.DatasourceStructure.Template;
import com.external.plugins.constants.AmazonS3Action; import com.external.plugins.constants.AmazonS3Action;
@ -13,6 +12,7 @@ import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData
import static com.external.plugins.AmazonS3Plugin.DEFAULT_URL_EXPIRY_IN_MINUTES; import static com.external.plugins.AmazonS3Plugin.DEFAULT_URL_EXPIRY_IN_MINUTES;
import static com.external.plugins.AmazonS3Plugin.NO; import static com.external.plugins.AmazonS3Plugin.NO;
import static com.external.plugins.AmazonS3Plugin.YES; import static com.external.plugins.AmazonS3Plugin.YES;
import static com.external.plugins.constants.FieldName.BODY;
import static com.external.plugins.constants.FieldName.BUCKET; import static com.external.plugins.constants.FieldName.BUCKET;
import static com.external.plugins.constants.FieldName.COMMAND; import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.CREATE_DATATYPE; import static com.external.plugins.constants.FieldName.CREATE_DATATYPE;
@ -20,6 +20,7 @@ import static com.external.plugins.constants.FieldName.CREATE_EXPIRY;
import static com.external.plugins.constants.FieldName.LIST_SIGNED_URL; import static com.external.plugins.constants.FieldName.LIST_SIGNED_URL;
import static com.external.plugins.constants.FieldName.LIST_UNSIGNED_URL; import static com.external.plugins.constants.FieldName.LIST_UNSIGNED_URL;
import static com.external.plugins.constants.FieldName.LIST_WHERE; import static com.external.plugins.constants.FieldName.LIST_WHERE;
import static com.external.plugins.constants.FieldName.PATH;
import static com.external.plugins.constants.FieldName.READ_DATATYPE; import static com.external.plugins.constants.FieldName.READ_DATATYPE;
import static com.external.plugins.constants.FieldName.READ_EXPIRY; import static com.external.plugins.constants.FieldName.READ_EXPIRY;
@ -75,32 +76,18 @@ public class TemplateUtils {
Map<String, Object> configMap = new HashMap<>(); Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, COMMAND, AmazonS3Action.DELETE_MULTIPLE_FILES.name()); setValueSafelyInFormData(configMap, COMMAND, AmazonS3Action.DELETE_MULTIPLE_FILES.name());
setValueSafelyInFormData(configMap, BUCKET, bucketName); setValueSafelyInFormData(configMap, BUCKET, bucketName);
setValueSafelyInFormData(configMap, PATH, LIST_OF_FILES_STRING);
/** return new Template(DELETE_MULTIPLE_FILES_TEMPLATE_NAME, configMap);
* Since S3 uses UQI interface, a config map is used to indicate the required template. However, some
* properties like `actionConfiguration.path` cannot be configured via the config map since the config map only
* models the formData attribute. Such properties are configured via ActionConfiguration object.
*/
ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setPath(LIST_OF_FILES_STRING);
return new Template(DELETE_MULTIPLE_FILES_TEMPLATE_NAME, configMap, actionConfiguration);
} }
private static Template getDeleteFileTemplate(String bucketName, String fileName) { private static Template getDeleteFileTemplate(String bucketName, String fileName) {
Map<String, Object> configMap = new HashMap<>(); Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, COMMAND, AmazonS3Action.DELETE_FILE.name()); setValueSafelyInFormData(configMap, COMMAND, AmazonS3Action.DELETE_FILE.name());
setValueSafelyInFormData(configMap, BUCKET, bucketName); setValueSafelyInFormData(configMap, BUCKET, bucketName);
setValueSafelyInFormData(configMap, PATH, fileName);
/** return new Template(DELETE_FILE_TEMPLATE_NAME, configMap);
* Since S3 uses UQI interface, a config map is used to indicate the required template. However, some
* properties like `actionConfiguration.path` cannot be configured via the config map since the config map only
* models the formData attribute. Such properties are configured via ActionConfiguration object.
*/
ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setPath(fileName);
return new Template(DELETE_FILE_TEMPLATE_NAME, configMap, actionConfiguration);
} }
private static Template getReadFileTemplate(String bucketName, String fileName) { private static Template getReadFileTemplate(String bucketName, String fileName) {
@ -109,16 +96,9 @@ public class TemplateUtils {
setValueSafelyInFormData(configMap, BUCKET, bucketName); setValueSafelyInFormData(configMap, BUCKET, bucketName);
setValueSafelyInFormData(configMap, READ_DATATYPE, YES); setValueSafelyInFormData(configMap, READ_DATATYPE, YES);
setValueSafelyInFormData(configMap, READ_EXPIRY, DEFAULT_URL_EXPIRY_IN_MINUTES); setValueSafelyInFormData(configMap, READ_EXPIRY, DEFAULT_URL_EXPIRY_IN_MINUTES);
setValueSafelyInFormData(configMap, PATH, fileName);
/** return new Template(READ_FILE_TEMPLATE_NAME, configMap);
* Since S3 uses UQI interface, a config map is used to indicate the required template. However, some
* properties like `actionConfiguration.path` cannot be configured via the config map since the config map only
* models the formData attribute. Such properties are configured via ActionConfiguration object.
*/
ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setPath(fileName);
return new Template(READ_FILE_TEMPLATE_NAME, configMap, actionConfiguration);
} }
private static Template getCreateFileTemplate(String bucketName, String fileName) { private static Template getCreateFileTemplate(String bucketName, String fileName) {
@ -127,17 +107,10 @@ public class TemplateUtils {
setValueSafelyInFormData(configMap, BUCKET, bucketName); setValueSafelyInFormData(configMap, BUCKET, bucketName);
setValueSafelyInFormData(configMap, CREATE_DATATYPE, YES); setValueSafelyInFormData(configMap, CREATE_DATATYPE, YES);
setValueSafelyInFormData(configMap, CREATE_EXPIRY, DEFAULT_URL_EXPIRY_IN_MINUTES); setValueSafelyInFormData(configMap, CREATE_EXPIRY, DEFAULT_URL_EXPIRY_IN_MINUTES);
setValueSafelyInFormData(configMap, PATH, fileName);
setValueSafelyInFormData(configMap, BODY, FILE_PICKER_DATA_EXPRESSION);
/** return new Template(CREATE_FILE_TEMPLATE_NAME, configMap);
* Since S3 uses UQI interface, a config map is used to indicate the required template. However, some
* properties like `actionConfiguration.path` cannot be configured via the config map since the config map only
* models the formData attribute. Such properties are configured via ActionConfiguration object.
*/
ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setPath(fileName);
actionConfiguration.setBody(FILE_PICKER_DATA_EXPRESSION);
return new Template(CREATE_FILE_TEMPLATE_NAME, configMap, actionConfiguration);
} }
private static Template getCreateMultipleFilesTemplate(String bucketName) { private static Template getCreateMultipleFilesTemplate(String bucketName) {
@ -146,17 +119,10 @@ public class TemplateUtils {
setValueSafelyInFormData(configMap, BUCKET, bucketName); setValueSafelyInFormData(configMap, BUCKET, bucketName);
setValueSafelyInFormData(configMap, CREATE_DATATYPE, YES); setValueSafelyInFormData(configMap, CREATE_DATATYPE, YES);
setValueSafelyInFormData(configMap, CREATE_EXPIRY, DEFAULT_URL_EXPIRY_IN_MINUTES); setValueSafelyInFormData(configMap, CREATE_EXPIRY, DEFAULT_URL_EXPIRY_IN_MINUTES);
setValueSafelyInFormData(configMap, PATH, DEFAULT_DIR);
setValueSafelyInFormData(configMap, BODY, FILE_PICKER_MULTIPLE_FILES_DATA_EXPRESSION);
/** return new Template(CREATE_MULTIPLE_FILES_TEMPLATE_NAME, configMap);
* Since S3 uses UQI interface, a config map is used to indicate the required template. However, some
* properties like `actionConfiguration.path` cannot be configured via the config map since the config map only
* models the formData attribute. Such properties are configured via ActionConfiguration object.
*/
ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setPath(DEFAULT_DIR);
actionConfiguration.setBody(FILE_PICKER_MULTIPLE_FILES_DATA_EXPRESSION);
return new Template(CREATE_MULTIPLE_FILES_TEMPLATE_NAME, configMap, actionConfiguration);
} }
private static Template getListFilesTemplate(String bucketName) { private static Template getListFilesTemplate(String bucketName) {
@ -169,6 +135,6 @@ public class TemplateUtils {
put("condition", "AND"); put("condition", "AND");
}}); }});
return new Template(LIST_FILES_TEMPLATE_NAME, configMap, new ActionConfiguration()); return new Template(LIST_FILES_TEMPLATE_NAME, configMap);
} }
} }

View File

@ -1075,9 +1075,9 @@ public class AmazonS3PluginTest {
// Check read file template // Check read file template
Template readFileTemplate = templates.get(1); Template readFileTemplate = templates.get(1);
assertEquals(READ_FILE_TEMPLATE_NAME, readFileTemplate.getTitle()); assertEquals(READ_FILE_TEMPLATE_NAME, readFileTemplate.getTitle());
assertEquals(DEFAULT_FILE_NAME, readFileTemplate.getActionConfiguration().getPath());
Map<String, Object> readFileConfig = (Map<String, Object>) readFileTemplate.getConfiguration(); Map<String, Object> readFileConfig = (Map<String, Object>) readFileTemplate.getConfiguration();
assertEquals(DEFAULT_FILE_NAME, getValueSafelyFromFormData(readFileConfig, PATH));
assertEquals(AmazonS3Action.READ_FILE.name(), getValueSafelyFromFormData(readFileConfig, COMMAND)); assertEquals(AmazonS3Action.READ_FILE.name(), getValueSafelyFromFormData(readFileConfig, COMMAND));
assertEquals(expectedBucketName, getValueSafelyFromFormData(readFileConfig, BUCKET)); assertEquals(expectedBucketName, getValueSafelyFromFormData(readFileConfig, BUCKET));
assertEquals(YES, getValueSafelyFromFormData(readFileConfig, READ_DATATYPE)); assertEquals(YES, getValueSafelyFromFormData(readFileConfig, READ_DATATYPE));
@ -1086,10 +1086,10 @@ public class AmazonS3PluginTest {
// Check create file template // Check create file template
Template createFileTemplate = templates.get(2); Template createFileTemplate = templates.get(2);
assertEquals(CREATE_FILE_TEMPLATE_NAME, createFileTemplate.getTitle()); assertEquals(CREATE_FILE_TEMPLATE_NAME, createFileTemplate.getTitle());
assertEquals(DEFAULT_FILE_NAME, createFileTemplate.getActionConfiguration().getPath());
assertEquals(FILE_PICKER_DATA_EXPRESSION, createFileTemplate.getActionConfiguration().getBody());
Map<String, Object> createFileConfig = (Map<String, Object>) createFileTemplate.getConfiguration(); Map<String, Object> createFileConfig = (Map<String, Object>) createFileTemplate.getConfiguration();
assertEquals(DEFAULT_FILE_NAME, getValueSafelyFromFormData(createFileConfig, PATH));
assertEquals(FILE_PICKER_DATA_EXPRESSION, getValueSafelyFromFormData(createFileConfig, BODY));
assertEquals(AmazonS3Action.UPLOAD_FILE_FROM_BODY.name(), assertEquals(AmazonS3Action.UPLOAD_FILE_FROM_BODY.name(),
getValueSafelyFromFormData(createFileConfig, COMMAND)); getValueSafelyFromFormData(createFileConfig, COMMAND));
assertEquals(expectedBucketName, getValueSafelyFromFormData(createFileConfig, BUCKET)); assertEquals(expectedBucketName, getValueSafelyFromFormData(createFileConfig, BUCKET));
@ -1099,11 +1099,11 @@ public class AmazonS3PluginTest {
// Check create multiple files template // Check create multiple files template
Template createMultipleFilesTemplate = templates.get(3); Template createMultipleFilesTemplate = templates.get(3);
assertEquals(CREATE_MULTIPLE_FILES_TEMPLATE_NAME, createMultipleFilesTemplate.getTitle()); assertEquals(CREATE_MULTIPLE_FILES_TEMPLATE_NAME, createMultipleFilesTemplate.getTitle());
assertEquals(DEFAULT_DIR, createMultipleFilesTemplate.getActionConfiguration().getPath());
assertEquals(FILE_PICKER_MULTIPLE_FILES_DATA_EXPRESSION,
createMultipleFilesTemplate.getActionConfiguration().getBody());
Map<String, Object> createMultipleFilesConfig = (Map<String, Object>) createMultipleFilesTemplate.getConfiguration(); Map<String, Object> createMultipleFilesConfig = (Map<String, Object>) createMultipleFilesTemplate.getConfiguration();
assertEquals(DEFAULT_DIR, getValueSafelyFromFormData(createMultipleFilesConfig, PATH));
assertEquals(FILE_PICKER_MULTIPLE_FILES_DATA_EXPRESSION,
getValueSafelyFromFormData(createMultipleFilesConfig, BODY));
assertEquals(AmazonS3Action.UPLOAD_MULTIPLE_FILES_FROM_BODY.name(), assertEquals(AmazonS3Action.UPLOAD_MULTIPLE_FILES_FROM_BODY.name(),
getValueSafelyFromFormData(createMultipleFilesConfig, COMMAND)); getValueSafelyFromFormData(createMultipleFilesConfig, COMMAND));
assertEquals(expectedBucketName, getValueSafelyFromFormData(createMultipleFilesConfig, BUCKET)); assertEquals(expectedBucketName, getValueSafelyFromFormData(createMultipleFilesConfig, BUCKET));
@ -1113,9 +1113,9 @@ public class AmazonS3PluginTest {
// Check delete file template // Check delete file template
Template deleteFileTemplate = templates.get(4); Template deleteFileTemplate = templates.get(4);
assertEquals(DELETE_FILE_TEMPLATE_NAME, deleteFileTemplate.getTitle()); assertEquals(DELETE_FILE_TEMPLATE_NAME, deleteFileTemplate.getTitle());
assertEquals(DEFAULT_FILE_NAME, deleteFileTemplate.getActionConfiguration().getPath());
Map<String, Object> deleteFileConfig = (Map<String, Object>) deleteFileTemplate.getConfiguration(); Map<String, Object> deleteFileConfig = (Map<String, Object>) deleteFileTemplate.getConfiguration();
assertEquals(DEFAULT_FILE_NAME, getValueSafelyFromFormData(deleteFileConfig, PATH));
assertEquals(AmazonS3Action.DELETE_FILE.name(), getValueSafelyFromFormData(deleteFileConfig, assertEquals(AmazonS3Action.DELETE_FILE.name(), getValueSafelyFromFormData(deleteFileConfig,
COMMAND)); COMMAND));
assertEquals(expectedBucketName, getValueSafelyFromFormData(deleteFileConfig, BUCKET)); assertEquals(expectedBucketName, getValueSafelyFromFormData(deleteFileConfig, BUCKET));
@ -1123,10 +1123,10 @@ public class AmazonS3PluginTest {
// Check delete multiple files template // Check delete multiple files template
Template deleteMultipleFilesTemplate = templates.get(5); Template deleteMultipleFilesTemplate = templates.get(5);
assertEquals(DELETE_MULTIPLE_FILES_TEMPLATE_NAME, deleteMultipleFilesTemplate.getTitle()); assertEquals(DELETE_MULTIPLE_FILES_TEMPLATE_NAME, deleteMultipleFilesTemplate.getTitle());
assertEquals(LIST_OF_FILES_STRING, deleteMultipleFilesTemplate.getActionConfiguration().getPath());
Map<String, Object> deleteMultipleFilesConfig = Map<String, Object> deleteMultipleFilesConfig =
(Map<String, Object>) deleteMultipleFilesTemplate.getConfiguration(); (Map<String, Object>) deleteMultipleFilesTemplate.getConfiguration();
assertEquals(LIST_OF_FILES_STRING, getValueSafelyFromFormData(deleteMultipleFilesConfig, PATH));
assertEquals(AmazonS3Action.DELETE_MULTIPLE_FILES.name(), assertEquals(AmazonS3Action.DELETE_MULTIPLE_FILES.name(),
getValueSafelyFromFormData(deleteMultipleFilesConfig, COMMAND)); getValueSafelyFromFormData(deleteMultipleFilesConfig, COMMAND));
assertEquals(expectedBucketName, getValueSafelyFromFormData(deleteMultipleFilesConfig, BUCKET)); assertEquals(expectedBucketName, getValueSafelyFromFormData(deleteMultipleFilesConfig, BUCKET));

View File

@ -231,7 +231,7 @@ public class MongoPlugin extends BasePlugin {
smartBsonSubstitution = Boolean.parseBoolean((String) smartSubstitutionObject); smartBsonSubstitution = Boolean.parseBoolean((String) smartSubstitutionObject);
} }
// Smartly substitute in actionConfiguration.body and replace all the bindings with values. // Smartly substitute in formData.body and replace all the bindings with values.
if (TRUE.equals(smartBsonSubstitution)) { if (TRUE.equals(smartBsonSubstitution)) {
// If not raw, then it must be form input. // If not raw, then it must be form input.

View File

@ -26,6 +26,7 @@ import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresen
import static com.external.plugins.constants.FieldName.AGGREGATE; import static com.external.plugins.constants.FieldName.AGGREGATE;
import static com.external.plugins.constants.FieldName.AGGREGATE_LIMIT; import static com.external.plugins.constants.FieldName.AGGREGATE_LIMIT;
import static com.external.plugins.constants.FieldName.AGGREGATE_PIPELINES; import static com.external.plugins.constants.FieldName.AGGREGATE_PIPELINES;
import static com.external.plugins.constants.FieldName.BODY;
import static com.external.plugins.constants.FieldName.COLLECTION; import static com.external.plugins.constants.FieldName.COLLECTION;
import static com.external.plugins.constants.FieldName.COMMAND; import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.SMART_SUBSTITUTION; import static com.external.plugins.constants.FieldName.SMART_SUBSTITUTION;
@ -123,17 +124,17 @@ public class Aggregate extends MongoCommand {
setValueSafelyInFormData(configMap, AGGREGATE_PIPELINES, "[ {\"$sort\" : {\"_id\": 1} } ]"); setValueSafelyInFormData(configMap, AGGREGATE_PIPELINES, "[ {\"$sort\" : {\"_id\": 1} } ]");
setValueSafelyInFormData(configMap, AGGREGATE_LIMIT, "10"); setValueSafelyInFormData(configMap, AGGREGATE_LIMIT, "10");
String rawQuery = "{\n" + String rawQuery = "{\n" +
" \"aggregate\": \"" + collectionName + "\",\n" + " \"aggregate\": \"" + collectionName + "\",\n" +
" \"pipeline\": " + "[ {\"$sort\" : {\"_id\": 1} } ],\n" + " \"pipeline\": " + "[ {\"$sort\" : {\"_id\": 1} } ],\n" +
" \"limit\": 10,\n" + " \"limit\": 10,\n" +
" \"explain\": \"true\"\n" + // Specifies to return the information on the processing of the pipeline. (This also avoids the use of the 'cursor' aggregate key according to Mongo doc) " \"explain\": \"true\"\n" + // Specifies to return the information on the processing of the pipeline. (This also avoids the use of the 'cursor' aggregate key according to Mongo doc)
"}\n"; "}\n";
setValueSafelyInFormData(configMap, BODY, rawQuery);
return Collections.singletonList(new DatasourceStructure.Template( return Collections.singletonList(new DatasourceStructure.Template(
"Aggregate", "Aggregate",
rawQuery, null,
configMap configMap
)); ));
} }

View File

@ -16,6 +16,7 @@ import java.util.Map;
import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData; import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData;
import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData; import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData;
import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData; import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData;
import static com.external.plugins.constants.FieldName.BODY;
import static com.external.plugins.constants.FieldName.COLLECTION; import static com.external.plugins.constants.FieldName.COLLECTION;
import static com.external.plugins.constants.FieldName.COMMAND; import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.COUNT; import static com.external.plugins.constants.FieldName.COUNT;
@ -69,10 +70,11 @@ public class Count extends MongoCommand {
" \"count\": \"" + collectionName + "\",\n" + " \"count\": \"" + collectionName + "\",\n" +
" \"query\": " + "{\"_id\": {\"$exists\": true}} \n" + " \"query\": " + "{\"_id\": {\"$exists\": true}} \n" +
"}\n"; "}\n";
setValueSafelyInFormData(configMap, BODY, rawQuery);
return Collections.singletonList(new DatasourceStructure.Template( return Collections.singletonList(new DatasourceStructure.Template(
"Count", "Count",
rawQuery, null,
configMap configMap
)); ));
} }

View File

@ -17,6 +17,7 @@ import java.util.Map;
import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData; import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData;
import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData; import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData;
import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData; import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData;
import static com.external.plugins.constants.FieldName.BODY;
import static com.external.plugins.constants.FieldName.COLLECTION; import static com.external.plugins.constants.FieldName.COLLECTION;
import static com.external.plugins.constants.FieldName.COMMAND; import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.DELETE; import static com.external.plugins.constants.FieldName.DELETE;
@ -105,10 +106,11 @@ public class Delete extends MongoCommand {
" }\n" + " }\n" +
" ]\n" + " ]\n" +
"}\n"; "}\n";
setValueSafelyInFormData(configMap, BODY, rawQuery);
return Collections.singletonList(new DatasourceStructure.Template( return Collections.singletonList(new DatasourceStructure.Template(
"Delete", "Delete",
rawQuery, null,
configMap configMap
)); ));
} }

View File

@ -16,6 +16,7 @@ import java.util.Map;
import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData; import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData;
import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData; import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData;
import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData; import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData;
import static com.external.plugins.constants.FieldName.BODY;
import static com.external.plugins.constants.FieldName.COLLECTION; import static com.external.plugins.constants.FieldName.COLLECTION;
import static com.external.plugins.constants.FieldName.COMMAND; import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.DISTINCT; import static com.external.plugins.constants.FieldName.DISTINCT;
@ -51,7 +52,7 @@ public class Distinct extends MongoCommand {
if (!StringUtils.isNullOrEmpty(key)) { if (!StringUtils.isNullOrEmpty(key)) {
return Boolean.TRUE; return Boolean.TRUE;
} else if (StringUtils.isNullOrEmpty(key)) { } else if (StringUtils.isNullOrEmpty(key)) {
fieldNamesWithNoConfiguration.add("Key/Field"); fieldNamesWithNoConfiguration.add("Key/Field");
} }
} }
@ -92,13 +93,12 @@ public class Distinct extends MongoCommand {
" \"query\": { \"_id\": ObjectId(\"id_of_document_to_distinct\") }," + " \"query\": { \"_id\": ObjectId(\"id_of_document_to_distinct\") }," +
" \"key\": \"_id\"," + " \"key\": \"_id\"," +
"}\n"; "}\n";
setValueSafelyInFormData(configMap, BODY, rawQuery);
return Collections.singletonList(new DatasourceStructure.Template(
"Distinct",
return Collections.singletonList(new DatasourceStructure.Template( null,
"Distinct", configMap
rawQuery, ));
configMap
));
} }
} }

View File

@ -16,6 +16,7 @@ import java.util.Map;
import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData; import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData;
import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData; import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData;
import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData; import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData;
import static com.external.plugins.constants.FieldName.BODY;
import static com.external.plugins.constants.FieldName.COLLECTION; import static com.external.plugins.constants.FieldName.COLLECTION;
import static com.external.plugins.constants.FieldName.COMMAND; import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.FIND; import static com.external.plugins.constants.FieldName.FIND;
@ -139,10 +140,11 @@ public class Find extends MongoCommand {
" },\n" + " },\n" +
" \"limit\": 10\n" + " \"limit\": 10\n" +
"}\n"; "}\n";
setValueSafelyInFormData(configMap, BODY, rawQuery);
return new DatasourceStructure.Template( return new DatasourceStructure.Template(
"Find", "Find",
rawQuery, null,
configMap configMap
); );
} }
@ -161,10 +163,11 @@ public class Find extends MongoCommand {
" \"_id\": ObjectId(\"id_to_query_with\")\n" + " \"_id\": ObjectId(\"id_to_query_with\")\n" +
" }\n" + " }\n" +
"}\n"; "}\n";
setValueSafelyInFormData(configMap, BODY, rawQuery);
return new DatasourceStructure.Template( return new DatasourceStructure.Template(
"Find by ID", "Find by ID",
rawQuery, null,
configMap configMap
); );
} }

View File

@ -24,6 +24,7 @@ import java.util.stream.Collectors;
import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData; import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData;
import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData; import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData;
import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData; import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData;
import static com.external.plugins.constants.FieldName.BODY;
import static com.external.plugins.constants.FieldName.COLLECTION; import static com.external.plugins.constants.FieldName.COLLECTION;
import static com.external.plugins.constants.FieldName.COMMAND; import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.INSERT; import static com.external.plugins.constants.FieldName.INSERT;
@ -114,10 +115,11 @@ public class Insert extends MongoCommand {
" }\n" + " }\n" +
" ]\n" + " ]\n" +
"}\n"; "}\n";
setValueSafelyInFormData(configMap, BODY, rawQuery);
return Collections.singletonList(new DatasourceStructure.Template( return Collections.singletonList(new DatasourceStructure.Template(
"Insert", "Insert",
rawQuery, null,
configMap configMap
)); ));
} }

View File

@ -17,6 +17,7 @@ import java.util.Map;
import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData; import static com.appsmith.external.helpers.PluginUtils.getValueSafelyFromFormData;
import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData; import static com.appsmith.external.helpers.PluginUtils.setValueSafelyInFormData;
import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData; import static com.appsmith.external.helpers.PluginUtils.validConfigurationPresentInFormData;
import static com.external.plugins.constants.FieldName.BODY;
import static com.external.plugins.constants.FieldName.COLLECTION; import static com.external.plugins.constants.FieldName.COLLECTION;
import static com.external.plugins.constants.FieldName.COMMAND; import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.SMART_SUBSTITUTION; import static com.external.plugins.constants.FieldName.SMART_SUBSTITUTION;
@ -122,10 +123,11 @@ public class UpdateMany extends MongoCommand {
" }\n" + " }\n" +
" ]\n" + " ]\n" +
"}\n"; "}\n";
setValueSafelyInFormData(configMap, BODY, rawQuery);
return Collections.singletonList(new DatasourceStructure.Template( return Collections.singletonList(new DatasourceStructure.Template(
"Update", "Update",
rawQuery, null,
configMap configMap
)); ));
} }

View File

@ -31,6 +31,7 @@ import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import static com.external.plugins.constants.FieldName.BODY;
import static com.external.plugins.constants.FieldName.COMMAND; import static com.external.plugins.constants.FieldName.COMMAND;
import static com.external.plugins.constants.FieldName.RAW; import static com.external.plugins.constants.FieldName.RAW;
@ -92,7 +93,7 @@ public class MongoPluginUtils {
// We reached here. This means either this is a RAW command input or some configuration error has happened // We reached here. This means either this is a RAW command input or some configuration error has happened
// in which case, we default to RAW // in which case, we default to RAW
return actionConfiguration.getBody(); return (String) PluginUtils.getValueSafelyFromFormData(formData, BODY);
} }
public static String getDatabaseName(DatasourceConfiguration datasourceConfiguration) { public static String getDatabaseName(DatasourceConfiguration datasourceConfiguration) {

View File

@ -1,7 +1,7 @@
{ {
"dependencies": { "dependencies": {
"actionConfiguration.body": [ "actionConfiguration.formData.body.data": [
"actionConfiguration.formData.smartSubstitution" "actionConfiguration.formData.smartSubstitution.data"
] ]
} }
} }

View File

@ -255,16 +255,16 @@ public class MongoPluginTest {
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig); Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig);
ActionConfiguration actionConfiguration = new ActionConfiguration(); ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setBody("{\n" +
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
setValueSafelyInFormData(configMap, BODY, "{\n" +
" find: \"users\",\n" + " find: \"users\",\n" +
" filter: { \"age\": { \"$gte\": 30 } },\n" + " filter: { \"age\": { \"$gte\": 30 } },\n" +
" sort: { id: 1 },\n" + " sort: { id: 1 },\n" +
" limit: 10,\n" + " limit: 10,\n" +
" }"); " }");
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
actionConfiguration.setFormData(configMap); actionConfiguration.setFormData(configMap);
Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, new ExecuteActionDTO(), dsConfig, actionConfiguration)); Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, new ExecuteActionDTO(), dsConfig, actionConfiguration));
@ -288,7 +288,7 @@ public class MongoPluginTest {
*/ */
List<RequestParamDTO> expectedRequestParams = new ArrayList<>(); List<RequestParamDTO> expectedRequestParams = new ArrayList<>();
expectedRequestParams.add(new RequestParamDTO(ACTION_CONFIGURATION_BODY, expectedRequestParams.add(new RequestParamDTO(ACTION_CONFIGURATION_BODY,
actionConfiguration.getBody(), null, null, null)); getValueSafelyFromFormData(actionConfiguration.getFormData(), BODY), null, null, null));
assertEquals(result.getRequest().getRequestParams().toString(), expectedRequestParams.toString()); assertEquals(result.getRequest().getRequestParams().toString(), expectedRequestParams.toString());
}) })
.verifyComplete(); .verifyComplete();
@ -300,16 +300,16 @@ public class MongoPluginTest {
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig); Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig);
ActionConfiguration actionConfiguration = new ActionConfiguration(); ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setBody("{\n" +
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
setValueSafelyInFormData(configMap, BODY, "{\n" +
" find: \"users\",\n" + " find: \"users\",\n" +
" filter: { $is: {} },\n" + " filter: { $is: {} },\n" +
" sort: { id: 1 },\n" + " sort: { id: 1 },\n" +
" limit: 10,\n" + " limit: 10,\n" +
" }"); " }");
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
actionConfiguration.setFormData(configMap); actionConfiguration.setFormData(configMap);
Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, new ExecuteActionDTO(), dsConfig, actionConfiguration)); Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, new ExecuteActionDTO(), dsConfig, actionConfiguration));
@ -329,7 +329,7 @@ public class MongoPluginTest {
*/ */
List<RequestParamDTO> expectedRequestParams = new ArrayList<>(); List<RequestParamDTO> expectedRequestParams = new ArrayList<>();
expectedRequestParams.add(new RequestParamDTO(ACTION_CONFIGURATION_BODY, expectedRequestParams.add(new RequestParamDTO(ACTION_CONFIGURATION_BODY,
actionConfiguration.getBody(), null, null, null)); getValueSafelyFromFormData(actionConfiguration.getFormData(), BODY), null, null, null));
assertEquals(result.getRequest().getRequestParams().toString(), expectedRequestParams.toString()); assertEquals(result.getRequest().getRequestParams().toString(), expectedRequestParams.toString());
}) })
.verifyComplete(); .verifyComplete();
@ -341,7 +341,11 @@ public class MongoPluginTest {
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig); Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig);
ActionConfiguration actionConfiguration = new ActionConfiguration(); ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setBody("{\n" +
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
setValueSafelyInFormData(configMap, BODY, "{\n" +
" insert: \"users\",\n" + " insert: \"users\",\n" +
" documents: [\n" + " documents: [\n" +
" {\n" + " {\n" +
@ -352,10 +356,6 @@ public class MongoPluginTest {
" },\n" + " },\n" +
" ],\n" + " ],\n" +
" }"); " }");
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
actionConfiguration.setFormData(configMap); actionConfiguration.setFormData(configMap);
Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, new ExecuteActionDTO(), dsConfig, actionConfiguration)); Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, new ExecuteActionDTO(), dsConfig, actionConfiguration));
@ -392,7 +392,11 @@ public class MongoPluginTest {
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig); Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig);
ActionConfiguration actionConfiguration = new ActionConfiguration(); ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setBody("{\n" +
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
setValueSafelyInFormData(configMap, BODY, "{\n" +
" findAndModify: \"users\",\n" + " findAndModify: \"users\",\n" +
" query: " + " query: " +
"{ " + "{ " +
@ -400,10 +404,6 @@ public class MongoPluginTest {
" },\n" + " },\n" +
" update: { $set: { gender: \"F\" }}\n" + " update: { $set: { gender: \"F\" }}\n" +
"}"); "}");
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
actionConfiguration.setFormData(configMap); actionConfiguration.setFormData(configMap);
Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, new ExecuteActionDTO(), dsConfig, actionConfiguration)); Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, new ExecuteActionDTO(), dsConfig, actionConfiguration));
@ -433,14 +433,14 @@ public class MongoPluginTest {
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig); Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig);
ActionConfiguration actionConfiguration = new ActionConfiguration(); ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setBody("{\n" +
" find: \"users\",\n" +
" limit: 1,\n" +
" }");
Map<String, Object> configMap = new HashMap<>(); Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE); setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW"); setValueSafelyInFormData(configMap, COMMAND, "RAW");
setValueSafelyInFormData(configMap, BODY, "{\n" +
" find: \"users\",\n" +
" limit: 1,\n" +
" }");
actionConfiguration.setFormData(configMap); actionConfiguration.setFormData(configMap);
Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, new ExecuteActionDTO(), dsConfig, actionConfiguration)); Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, new ExecuteActionDTO(), dsConfig, actionConfiguration));
@ -503,58 +503,47 @@ public class MongoPluginTest {
//Assert Find command //Assert Find command
DatasourceStructure.Template findTemplate = templates.get(0); DatasourceStructure.Template findTemplate = templates.get(0);
assertEquals(findTemplate.getTitle(), "Find"); assertEquals("Find", findTemplate.getTitle());
assertEquals(findTemplate.getBody(), "{\n" + assertEquals("{\n" +
" \"find\": \"users\",\n" + " \"find\": \"users\",\n" +
" \"filter\": {\n" + " \"filter\": {\n" +
" \"gender\": \"F\"\n" + " \"gender\": \"F\"\n" +
" },\n" + " },\n" +
" \"sort\": {\n" + " \"sort\": {\n" +
" \"_id\": 1\n" + " \"_id\": 1\n" +
" },\n" + " },\n" +
" \"limit\": 10\n" + " \"limit\": 10\n" +
"}\n"); "}\n",
assertEquals(getValueSafelyFromFormData((Map<String, Object>) findTemplate.getConfiguration(), COMMAND), "FIND"); getValueSafelyFromFormData((Map<String, Object>) findTemplate.getConfiguration(), BODY));
assertEquals("FIND", getValueSafelyFromFormData((Map<String, Object>) findTemplate.getConfiguration(), COMMAND));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) findTemplate.getConfiguration(), FIND_QUERY), assertEquals("{ \"gender\": \"F\"}",
"{ \"gender\": \"F\"}"); getValueSafelyFromFormData((Map<String, Object>) findTemplate.getConfiguration(), FIND_QUERY));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) findTemplate.getConfiguration(), FIND_SORT), assertEquals("{\"_id\": 1}",
"{\"_id\": 1}"); getValueSafelyFromFormData((Map<String, Object>) findTemplate.getConfiguration(), FIND_SORT));
//Assert Find By Id command //Assert Find By Id command
DatasourceStructure.Template findByIdTemplate = templates.get(1); DatasourceStructure.Template findByIdTemplate = templates.get(1);
assertEquals(findByIdTemplate.getTitle(), "Find by ID"); assertEquals("Find by ID", findByIdTemplate.getTitle());
assertEquals(findByIdTemplate.getBody(), "{\n" + assertEquals("{\n" +
" \"find\": \"users\",\n" + " \"find\": \"users\",\n" +
" \"filter\": {\n" + " \"filter\": {\n" +
" \"_id\": ObjectId(\"id_to_query_with\")\n" + " \"_id\": ObjectId(\"id_to_query_with\")\n" +
" }\n" + " }\n" +
"}\n"); "}\n",
assertEquals( getValueSafelyFromFormData((Map<String, Object>) findByIdTemplate.getConfiguration(), COMMAND), "FIND"); getValueSafelyFromFormData((Map<String, Object>) findByIdTemplate.getConfiguration(), BODY));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) findByIdTemplate.getConfiguration(), FIND_QUERY), assertEquals("FIND", getValueSafelyFromFormData((Map<String, Object>) findByIdTemplate.getConfiguration(), COMMAND));
"{\"_id\": ObjectId(\"id_to_query_with\")}"); assertEquals("{\"_id\": ObjectId(\"id_to_query_with\")}",
getValueSafelyFromFormData((Map<String, Object>) findByIdTemplate.getConfiguration(), FIND_QUERY));
// Assert Insert command // Assert Insert command
DatasourceStructure.Template insertTemplate = templates.get(2); DatasourceStructure.Template insertTemplate = templates.get(2);
assertEquals(insertTemplate.getTitle(), "Insert"); assertEquals("Insert", insertTemplate.getTitle());
assertEquals(insertTemplate.getBody(), "{\n" + assertEquals("{\n" +
" \"insert\": \"users\",\n" + " \"insert\": \"users\",\n" +
" \"documents\": [\n" + " \"documents\": [\n" +
" {\n" + " {\n" +
" \"_id\": ObjectId(\"a_valid_object_id_hex\"),\n" + " \"_id\": ObjectId(\"a_valid_object_id_hex\"),\n" +
" \"age\": 1,\n" +
" \"dob\": new Date(\"2019-07-01\"),\n" +
" \"gender\": \"new value\",\n" +
" \"luckyNumber\": NumberLong(\"1\"),\n" +
" \"name\": \"new value\",\n" +
" \"netWorth\": NumberDecimal(\"1\"),\n" +
" \"updatedByCommand\": {},\n" +
" }\n" +
" ]\n" +
"}\n");
assertEquals(getValueSafelyFromFormData((Map<String, Object>) insertTemplate.getConfiguration(),COMMAND), "INSERT");
assertEquals(getValueSafelyFromFormData((Map<String, Object>) insertTemplate.getConfiguration(), INSERT_DOCUMENT),
"[{ \"_id\": ObjectId(\"a_valid_object_id_hex\"),\n" +
" \"age\": 1,\n" + " \"age\": 1,\n" +
" \"dob\": new Date(\"2019-07-01\"),\n" + " \"dob\": new Date(\"2019-07-01\"),\n" +
" \"gender\": \"new value\",\n" + " \"gender\": \"new value\",\n" +
@ -562,12 +551,26 @@ public class MongoPluginTest {
" \"name\": \"new value\",\n" + " \"name\": \"new value\",\n" +
" \"netWorth\": NumberDecimal(\"1\"),\n" + " \"netWorth\": NumberDecimal(\"1\"),\n" +
" \"updatedByCommand\": {},\n" + " \"updatedByCommand\": {},\n" +
"}]"); " }\n" +
" ]\n" +
"}\n",
getValueSafelyFromFormData((Map<String, Object>) insertTemplate.getConfiguration(), BODY));
assertEquals("INSERT", getValueSafelyFromFormData((Map<String, Object>) insertTemplate.getConfiguration(), COMMAND));
assertEquals("[{ \"_id\": ObjectId(\"a_valid_object_id_hex\"),\n" +
" \"age\": 1,\n" +
" \"dob\": new Date(\"2019-07-01\"),\n" +
" \"gender\": \"new value\",\n" +
" \"luckyNumber\": NumberLong(\"1\"),\n" +
" \"name\": \"new value\",\n" +
" \"netWorth\": NumberDecimal(\"1\"),\n" +
" \"updatedByCommand\": {},\n" +
"}]",
getValueSafelyFromFormData((Map<String, Object>) insertTemplate.getConfiguration(), INSERT_DOCUMENT));
// Assert Update command // Assert Update command
DatasourceStructure.Template updateTemplate = templates.get(3); DatasourceStructure.Template updateTemplate = templates.get(3);
assertEquals(updateTemplate.getTitle(), "Update"); assertEquals("Update", updateTemplate.getTitle());
assertEquals(updateTemplate.getBody(), "{\n" + assertEquals("{\n" +
" \"update\": \"users\",\n" + " \"update\": \"users\",\n" +
" \"updates\": [\n" + " \"updates\": [\n" +
" {\n" + " {\n" +
@ -577,17 +580,17 @@ public class MongoPluginTest {
" \"u\": { \"$set\": { \"gender\": \"new value\" } }\n" + " \"u\": { \"$set\": { \"gender\": \"new value\" } }\n" +
" }\n" + " }\n" +
" ]\n" + " ]\n" +
"}\n"); "}\n", getValueSafelyFromFormData((Map<String, Object>) updateTemplate.getConfiguration(), BODY));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) updateTemplate.getConfiguration(),COMMAND), "UPDATE"); assertEquals("UPDATE", getValueSafelyFromFormData((Map<String, Object>) updateTemplate.getConfiguration(), COMMAND));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) updateTemplate.getConfiguration(), UPDATE_QUERY), assertEquals("{ \"_id\": ObjectId(\"id_of_document_to_update\") }",
"{ \"_id\": ObjectId(\"id_of_document_to_update\") }"); getValueSafelyFromFormData((Map<String, Object>) updateTemplate.getConfiguration(), UPDATE_QUERY));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) updateTemplate.getConfiguration(), UPDATE_OPERATION), assertEquals("{ \"$set\": { \"gender\": \"new value\" } }",
"{ \"$set\": { \"gender\": \"new value\" } }"); getValueSafelyFromFormData((Map<String, Object>) updateTemplate.getConfiguration(), UPDATE_OPERATION));
// Assert Delete Command // Assert Delete Command
DatasourceStructure.Template deleteTemplate = templates.get(4); DatasourceStructure.Template deleteTemplate = templates.get(4);
assertEquals(deleteTemplate.getTitle(), "Delete"); assertEquals("Delete", deleteTemplate.getTitle());
assertEquals(deleteTemplate.getBody(), "{\n" + assertEquals("{\n" +
" \"delete\": \"users\",\n" + " \"delete\": \"users\",\n" +
" \"deletes\": [\n" + " \"deletes\": [\n" +
" {\n" + " {\n" +
@ -597,51 +600,51 @@ public class MongoPluginTest {
" \"limit\": 1\n" + " \"limit\": 1\n" +
" }\n" + " }\n" +
" ]\n" + " ]\n" +
"}\n"); "}\n", getValueSafelyFromFormData((Map<String, Object>) deleteTemplate.getConfiguration(), BODY));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) deleteTemplate.getConfiguration(),COMMAND), "DELETE"); assertEquals("DELETE", getValueSafelyFromFormData((Map<String, Object>) deleteTemplate.getConfiguration(), COMMAND));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) deleteTemplate.getConfiguration(), DELETE_QUERY), assertEquals("{ \"_id\": ObjectId(\"id_of_document_to_delete\") }",
"{ \"_id\": ObjectId(\"id_of_document_to_delete\") }"); getValueSafelyFromFormData((Map<String, Object>) deleteTemplate.getConfiguration(), DELETE_QUERY));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) deleteTemplate.getConfiguration(), DELETE_LIMIT), assertEquals("SINGLE",
"SINGLE"); getValueSafelyFromFormData((Map<String, Object>) deleteTemplate.getConfiguration(), DELETE_LIMIT));
// Assert Count Command // Assert Count Command
DatasourceStructure.Template countTemplate = templates.get(5); DatasourceStructure.Template countTemplate = templates.get(5);
assertEquals(countTemplate.getTitle(), "Count"); assertEquals("Count", countTemplate.getTitle());
assertEquals(countTemplate.getBody(), "{\n" + assertEquals("{\n" +
" \"count\": \"users\",\n" + " \"count\": \"users\",\n" +
" \"query\": " + "{\"_id\": {\"$exists\": true}} \n" + " \"query\": " + "{\"_id\": {\"$exists\": true}} \n" +
"}\n"); "}\n", getValueSafelyFromFormData((Map<String, Object>) countTemplate.getConfiguration(), BODY));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) countTemplate.getConfiguration(),COMMAND), "COUNT"); assertEquals("COUNT", getValueSafelyFromFormData((Map<String, Object>) countTemplate.getConfiguration(), COMMAND));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) countTemplate.getConfiguration(), COUNT_QUERY), assertEquals("{\"_id\": {\"$exists\": true}}",
"{\"_id\": {\"$exists\": true}}"); getValueSafelyFromFormData((Map<String, Object>) countTemplate.getConfiguration(), COUNT_QUERY));
// Assert Distinct Command // Assert Distinct Command
DatasourceStructure.Template distinctTemplate = templates.get(6); DatasourceStructure.Template distinctTemplate = templates.get(6);
assertEquals(distinctTemplate.getTitle(), "Distinct"); assertEquals("Distinct", distinctTemplate.getTitle());
assertEquals(distinctTemplate.getBody(), "{\n" + assertEquals("{\n" +
" \"distinct\": \"users\",\n" + " \"distinct\": \"users\",\n" +
" \"query\": { \"_id\": ObjectId(\"id_of_document_to_distinct\") }," + " \"query\": { \"_id\": ObjectId(\"id_of_document_to_distinct\") }," +
" \"key\": \"_id\"," + " \"key\": \"_id\"," +
"}\n"); "}\n", getValueSafelyFromFormData((Map<String, Object>) distinctTemplate.getConfiguration(), BODY));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) distinctTemplate.getConfiguration(),COMMAND), "DISTINCT"); assertEquals("DISTINCT", getValueSafelyFromFormData((Map<String, Object>) distinctTemplate.getConfiguration(), COMMAND));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) distinctTemplate.getConfiguration(), DISTINCT_QUERY), assertEquals("{ \"_id\": ObjectId(\"id_of_document_to_distinct\") }",
"{ \"_id\": ObjectId(\"id_of_document_to_distinct\") }"); getValueSafelyFromFormData((Map<String, Object>) distinctTemplate.getConfiguration(), DISTINCT_QUERY));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) distinctTemplate.getConfiguration(), DISTINCT_KEY), assertEquals("_id",
"_id"); getValueSafelyFromFormData((Map<String, Object>) distinctTemplate.getConfiguration(), DISTINCT_KEY));
// Assert Aggregate Command // Assert Aggregate Command
DatasourceStructure.Template aggregateTemplate = templates.get(7); DatasourceStructure.Template aggregateTemplate = templates.get(7);
assertEquals(aggregateTemplate.getTitle(), "Aggregate"); assertEquals("Aggregate", aggregateTemplate.getTitle());
assertEquals(aggregateTemplate.getBody(), "{\n" + assertEquals("{\n" +
" \"aggregate\": \"users\",\n" + " \"aggregate\": \"users\",\n" +
" \"pipeline\": " + "[ {\"$sort\" : {\"_id\": 1} } ],\n" + " \"pipeline\": " + "[ {\"$sort\" : {\"_id\": 1} } ],\n" +
" \"limit\": 10,\n" + " \"limit\": 10,\n" +
" \"explain\": \"true\"\n" + " \"explain\": \"true\"\n" +
"}\n"); "}\n", getValueSafelyFromFormData((Map<String, Object>) aggregateTemplate.getConfiguration(), BODY));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) aggregateTemplate.getConfiguration(), COMMAND), "AGGREGATE"); assertEquals("AGGREGATE", getValueSafelyFromFormData((Map<String, Object>) aggregateTemplate.getConfiguration(), COMMAND));
assertEquals(getValueSafelyFromFormData((Map<String, Object>) aggregateTemplate.getConfiguration(), AGGREGATE_PIPELINES), assertEquals("[ {\"$sort\" : {\"_id\": 1} } ]",
"[ {\"$sort\" : {\"_id\": 1} } ]"); getValueSafelyFromFormData((Map<String, Object>) aggregateTemplate.getConfiguration(), AGGREGATE_PIPELINES));
}) })
@ -831,16 +834,16 @@ public class MongoPluginTest {
datasourceConfiguration.getConnection().getSsl().setAuthType(SSLDetails.AuthType.DEFAULT); datasourceConfiguration.getConnection().getSsl().setAuthType(SSLDetails.AuthType.DEFAULT);
ActionConfiguration actionConfiguration = new ActionConfiguration(); ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setBody("{\n" +
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
setValueSafelyInFormData(configMap, BODY, "{\n" +
" find: \"users\",\n" + " find: \"users\",\n" +
" filter: { age: { $gte: 30 } },\n" + " filter: { age: { $gte: 30 } },\n" +
" sort: { id: 1 },\n" + " sort: { id: 1 },\n" +
" limit: 10,\n" + " limit: 10,\n" +
" }"); " }");
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
actionConfiguration.setFormData(configMap); actionConfiguration.setFormData(configMap);
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(datasourceConfiguration); Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(datasourceConfiguration);
@ -870,16 +873,16 @@ public class MongoPluginTest {
datasourceConfiguration.getConnection().getSsl().setAuthType(SSLDetails.AuthType.DISABLED); datasourceConfiguration.getConnection().getSsl().setAuthType(SSLDetails.AuthType.DISABLED);
ActionConfiguration actionConfiguration = new ActionConfiguration(); ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setBody("{\n" +
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
setValueSafelyInFormData(configMap, BODY, "{\n" +
" find: \"users\",\n" + " find: \"users\",\n" +
" filter: { age: { $gte: 30 } },\n" + " filter: { age: { $gte: 30 } },\n" +
" sort: { id: 1 },\n" + " sort: { id: 1 },\n" +
" limit: 10,\n" + " limit: 10,\n" +
" }"); " }");
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
actionConfiguration.setFormData(configMap); actionConfiguration.setFormData(configMap);
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(datasourceConfiguration); Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(datasourceConfiguration);
@ -909,16 +912,16 @@ public class MongoPluginTest {
datasourceConfiguration.getConnection().getSsl().setAuthType(SSLDetails.AuthType.ENABLED); datasourceConfiguration.getConnection().getSsl().setAuthType(SSLDetails.AuthType.ENABLED);
ActionConfiguration actionConfiguration = new ActionConfiguration(); ActionConfiguration actionConfiguration = new ActionConfiguration();
actionConfiguration.setBody("{\n" +
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
setValueSafelyInFormData(configMap, BODY, "{\n" +
" find: \"users\",\n" + " find: \"users\",\n" +
" filter: { age: { $gte: 30 } },\n" + " filter: { age: { $gte: 30 } },\n" +
" sort: { id: 1 },\n" + " sort: { id: 1 },\n" +
" limit: 10,\n" + " limit: 10,\n" +
" }"); " }");
Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW");
actionConfiguration.setFormData(configMap); actionConfiguration.setFormData(configMap);
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(datasourceConfiguration); Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(datasourceConfiguration);
@ -1799,16 +1802,16 @@ public class MongoPluginTest {
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig); Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig);
ActionConfiguration actionConfiguration = new ActionConfiguration(); ActionConfiguration actionConfiguration = new ActionConfiguration();
// Set bad attribute for limit key
actionConfiguration.setBody("{\n" +
" find: \"users\",\n" +
" filter: \"filter\",\n" +
" limit: 10,\n" +
" }");
Map<String, Object> configMap = new HashMap<>(); Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE); setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW"); setValueSafelyInFormData(configMap, COMMAND, "RAW");
// Set bad attribute for limit key
setValueSafelyInFormData(configMap, BODY, "{\n" +
" find: \"users\",\n" +
" filter: \"filter\",\n" +
" limit: 10,\n" +
" }");
actionConfiguration.setFormData(configMap); actionConfiguration.setFormData(configMap);
Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn,
@ -1833,15 +1836,15 @@ public class MongoPluginTest {
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig); Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig);
ActionConfiguration actionConfiguration = new ActionConfiguration(); ActionConfiguration actionConfiguration = new ActionConfiguration();
// Set bad attribute for limit key
actionConfiguration.setBody("{\n" +
" find: \"users\",\n" +
" limit: [10],\n" +
" }");
Map<String, Object> configMap = new HashMap<>(); Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE); setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW"); setValueSafelyInFormData(configMap, COMMAND, "RAW");
// Set bad attribute for limit key
setValueSafelyInFormData(configMap, BODY, "{\n" +
" find: \"users\",\n" +
" limit: [10],\n" +
" }");
actionConfiguration.setFormData(configMap); actionConfiguration.setFormData(configMap);
Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn,
@ -1866,15 +1869,15 @@ public class MongoPluginTest {
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig); Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig);
ActionConfiguration actionConfiguration = new ActionConfiguration(); ActionConfiguration actionConfiguration = new ActionConfiguration();
// Set unrecognized key limitx
actionConfiguration.setBody("{\n" +
" find: \"users\",\n" +
" limitx: 10,\n" +
" }");
Map<String, Object> configMap = new HashMap<>(); Map<String, Object> configMap = new HashMap<>();
setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE); setValueSafelyInFormData(configMap, SMART_SUBSTITUTION, Boolean.TRUE);
setValueSafelyInFormData(configMap, COMMAND, "RAW"); setValueSafelyInFormData(configMap, COMMAND, "RAW");
// Set unrecognized key limitx
setValueSafelyInFormData(configMap, BODY, "{\n" +
" find: \"users\",\n" +
" limitx: 10,\n" +
" }");
actionConfiguration.setFormData(configMap); actionConfiguration.setFormData(configMap);
Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn,

View File

@ -323,8 +323,9 @@ public class CreateDBTablePageSolutionCEImpl implements CreateDBTablePageSolutio
// index 1 in plugin specified templates // index 1 in plugin specified templates
if (Entity.S3_PLUGIN_PACKAGE_NAME.equals(plugin.getPackageName()) && !CollectionUtils.isEmpty(templateActionList)) { if (Entity.S3_PLUGIN_PACKAGE_NAME.equals(plugin.getPackageName()) && !CollectionUtils.isEmpty(templateActionList)) {
final Map<String, Object> formData = templateActionList.get(0).getUnpublishedAction().getActionConfiguration().getFormData();
mappedColumnsAndTableName.put( mappedColumnsAndTableName.put(
(String) templateActionList.get(0).getUnpublishedAction().getActionConfiguration().getFormData().get("bucket"), (String) ((Map<?,?>)formData.get("bucket")).get("data"),
tableName tableName
); );
} }