[Bug Fix] : Mongo Form Find - Projection field is parsed correctly (#4976)

* Parsing the field projection in Mongo Form

* Added test case to assert Projection field working.
This commit is contained in:
Trisha Anand 2021-06-08 19:27:55 +05:30 committed by GitHub
parent 5b7add87db
commit 1bb54b0c7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -89,7 +89,7 @@ public class Find extends MongoCommand {
}
if (!StringUtils.isNullOrEmpty(this.projection)) {
document.put("projection", this.projection);
document.put("projection", parseSafely("Projection", this.projection));
}
// Default to returning 10 documents if not mentioned

View File

@ -57,6 +57,7 @@ import static com.external.plugins.constants.ConfigurationIndex.DELETE_LIMIT;
import static com.external.plugins.constants.ConfigurationIndex.DELETE_QUERY;
import static com.external.plugins.constants.ConfigurationIndex.DISTINCT_KEY;
import static com.external.plugins.constants.ConfigurationIndex.DISTINCT_QUERY;
import static com.external.plugins.constants.ConfigurationIndex.FIND_PROJECTION;
import static com.external.plugins.constants.ConfigurationIndex.FIND_QUERY;
import static com.external.plugins.constants.ConfigurationIndex.FIND_SORT;
import static com.external.plugins.constants.ConfigurationIndex.INPUT_TYPE;
@ -1304,4 +1305,36 @@ public class MongoPluginTest {
.verifyComplete();
}
@Test
public void testFindCommandProjection() {
ActionConfiguration actionConfiguration = new ActionConfiguration();
Map<Integer, Object> configMap = new HashMap<>();
configMap.put(BSON, Boolean.FALSE);
configMap.put(INPUT_TYPE, "FORM");
configMap.put(COMMAND, "FIND");
configMap.put(FIND_QUERY, "{ age: { \"$gte\": 30 } }");
configMap.put(FIND_SORT, "{ id: 1 }");
configMap.put(FIND_PROJECTION, "{ name: 1 }");
configMap.put(COLLECTION, "users");
actionConfiguration.setPluginSpecifiedTemplates(generateMongoFormConfigTemplates(configMap));
DatasourceConfiguration dsConfig = createDatasourceConfiguration();
Mono<MongoClient> dsConnectionMono = pluginExecutor.datasourceCreate(dsConfig);
Mono<Object> executeMono = dsConnectionMono.flatMap(conn -> pluginExecutor.executeParameterized(conn, new ExecuteActionDTO(), dsConfig, actionConfiguration));
StepVerifier.create(executeMono)
.assertNext(obj -> {
System.out.println(obj);
ActionExecutionResult result = (ActionExecutionResult) obj;
assertNotNull(result);
assertTrue(result.getIsExecutionSuccess());
assertNotNull(result.getBody());
assertEquals(2, ((ArrayNode) result.getBody()).size());
JsonNode value = ((ArrayNode) result.getBody()).get(0).get("name");
assertNotNull(value);
})
.verifyComplete();
}
}