fix: Google sheets Bulk insert of empty array returns an error (#9725)

* fix/8924-Bulk Insert throwing error on empty data in google sheets new1

* fix/8924 Error in bulk insert empty data

* fix/8924 Code review fix for Google Sheet Bulk insert error

* fix/8924 Code review fix for Google Sheet Bulk insert error

* Fixed code review comments

* Methodconfig data changes since only empty Mono is being tested
This commit is contained in:
Leo Thomas 2021-12-17 10:13:08 +05:30 committed by GitHub
parent 2fac770530
commit ec755d261c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 2 deletions

View File

@ -83,7 +83,13 @@ public class BulkAppendMethod implements Method {
List<RowObject> rowObjectListFromBody = null;
try {
rowObjectListFromBody = this.getRowObjectListFromBody(this.objectMapper.readTree(methodConfig.getRowObjects()));
JsonNode body = this.objectMapper.readTree(methodConfig.getRowObjects());
if ( body.isEmpty()) {
return Mono.empty();
}
rowObjectListFromBody = this.getRowObjectListFromBody(body);
} catch (JsonProcessingException e) {
// Should never enter here
}

View File

@ -241,7 +241,19 @@ public class GoogleSheetsPlugin extends BasePlugin {
System.out.println(e.getMessage());
return Mono.just(errorResult);
});
});
})
.switchIfEmpty(handleEmptyMono());
}
/**
* Method to handle empty Mono
* @return Mono<ActionExecutionResult>
*/
private Mono<ActionExecutionResult> handleEmptyMono() {
final ActionExecutionResult result = new ActionExecutionResult();
result.setIsExecutionSuccess(true);
result.setBody(objectMapper.valueToTree(Map.of("message", "No operation was performed")));
return Mono.just(result);
}
@Override

View File

@ -0,0 +1,58 @@
package com.external.config;
import com.appsmith.external.models.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.BeforeClass;
import org.junit.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import java.util.ArrayList;
import java.util.List;
public class BulkAppendMethodTest {
final ObjectMapper objectMapper = new ObjectMapper();
/**
* To Test if it passes the empty Mono criteria,
* else it should fail
*/
@Test
public void testBulkAppendHandleEmptyMonoExecutePrerequisites() {
String[] testDataArray = {"[]", ""};
for(int i=0; i<testDataArray.length; i++) {
BulkAppendMethod bulkAppend = new BulkAppendMethod(objectMapper);
Mono<Object> monoTest = bulkAppend.executePrerequisites(getMethodConfigObject(testDataArray[i]), getOAuthObject());
StepVerifier.create(monoTest)
.expectComplete()
.verify();
}
}
/**
* Simulated oAuth2 object, just to bypass few case.
* @return
*/
private OAuth2 getOAuthObject(){
OAuth2 oAuth2 = new OAuth2();
oAuth2.setAuthenticationResponse(new AuthenticationResponse() );
oAuth2.getAuthenticationResponse().setToken("welcome123");
return oAuth2;
}
/**
* Simulated MethodConfig object with testable data.
* @param rowObject
* @return
*/
private MethodConfig getMethodConfigObject(String rowObject){
List properties = new ArrayList<Property>();
MethodConfig methodConfig = new MethodConfig(properties);
methodConfig.setRowObjects(rowObject);
return methodConfig;
}
}