Skip to content

Commit f018aa2

Browse files
Added validation for unsupported sObjects
1 parent 7aa22d3 commit f018aa2

File tree

4 files changed

+49
-7
lines changed

4 files changed

+49
-7
lines changed

src/main/java/io/cdap/plugin/salesforce/SalesforceConstants.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ public class SalesforceConstants {
8585
// SControl, EmailCapture, MailmergeTemplate contains binary fields which will cause the batch read to fail.
8686
public static final Set<String> UNSUPPORTED_BULK_API_OBJECTS = Collections.unmodifiableSet(
8787
new HashSet<>(Arrays.asList(
88-
"Attachment", "ContentVersion", "Document", "StaticResource", "SControl",
89-
"EmailCapture", "MailmergeTemplate", "AcceptedEventRelation", "CaseStatus",
90-
"ContentFolderItem", "ContractStatus", "DeclinedEventRelation",
91-
"FieldSecurityClassification", "OrderStatus", "PartnerRole", "RecentlyViewed",
92-
"SolutionStatus", "TaskPriority", "TaskStatus", "UndecidedEventRelation",
93-
"UserRecordAccess", "WorkOrderLineItemStatus", "WorkOrderStatus"
88+
"attachment", "contentversion", "document", "staticresource", "scontrol",
89+
"emailcapture", "mailmergetemplate", "acceptedeventrelation", "casestatus",
90+
"contentfolderitem", "contractstatus", "declinedeventrelation",
91+
"fieldsecurityclassification", "orderstatus", "partnerrole", "recentlyviewed",
92+
"solutionstatus", "taskpriority", "taskstatus", "undecidedeventrelation",
93+
"userrecordaccess", "workorderlineitemstatus", "workorderstatus"
9494
)));
9595

9696
}

src/main/java/io/cdap/plugin/salesforce/plugin/connector/SalesforceConnector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public BrowseDetail browse(boolean onlyReturnQueryableObjects) throws IOExceptio
128128
// Continue in case of returning only queryable sObjects and the current sObject is non-queryable.
129129
// Continue if sObject is not supported by Bulk APIs
130130
if (onlyReturnQueryableObjects &&
131-
(!isQueryable || SalesforceConstants.UNSUPPORTED_BULK_API_OBJECTS.contains(name))) {
131+
(!isQueryable || SalesforceConstants.UNSUPPORTED_BULK_API_OBJECTS.contains(name.toLowerCase()))) {
132132
continue;
133133
}
134134

src/main/java/io/cdap/plugin/salesforce/plugin/source/batch/SalesforceSourceConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public void validate(FailureCollector collector, @Nullable OAuthInfo oAuthInfo)
197197
try {
198198
boolean isSoql = isSoqlQuery();
199199
if (!isSoql) {
200+
validateSobject(collector);
200201
validateFilters(collector);
201202
}
202203
} catch (InvalidConfigException e) {
@@ -355,4 +356,11 @@ private boolean isCustomObject(String sObjectName, FailureCollector collector, O
355356
throw collector.getOrThrowException();
356357
}
357358
}
359+
360+
public void validateSobject(FailureCollector collector) {
361+
if (SalesforceConstants.UNSUPPORTED_BULK_API_OBJECTS.contains(sObjectName.toLowerCase())) {
362+
collector.addFailure(String.format("sObject type '%s' is not supported", sObjectName), null)
363+
.withConfigProperty(SalesforceSourceConstants.PROPERTY_SOBJECT_NAME);
364+
}
365+
}
358366
}

src/test/java/io/cdap/plugin/salesforce/plugin/source/batch/SalesforceSourceConfigTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ public void testPKChunkWithRestrictedQuery() throws Exception {
248248
testPKChunkInvalidConfig(config, SalesforceSourceConstants.PROPERTY_QUERY);
249249
}
250250

251+
@Test
252+
public void testInvalidSObjectValidation() throws Exception {
253+
SalesforceSourceConfig config = new SalesforceSourceConfigBuilder()
254+
.setReferenceName("Source")
255+
.setSObjectName("Attachment")
256+
.build();
257+
testInvalidSObjectConfig(config, SalesforceSourceConstants.PROPERTY_SOBJECT_NAME);
258+
}
259+
251260
@Test
252261
public void testPKChunkWithChunkSizeAboveMax() throws Exception {
253262
SalesforceSourceConfig config = new SalesforceSourceConfigBuilder()
@@ -297,4 +306,29 @@ private void testPKChunkInvalidConfig(SalesforceSourceConfig config, String stag
297306
}
298307
Assert.assertEquals(stageConfigName, failure.getCauses().get(0).getAttribute(CauseAttributes.STAGE_CONFIG));
299308
}
309+
310+
private void testInvalidSObjectConfig(SalesforceSourceConfig config, String stageConfigName) throws Exception {
311+
MockFailureCollector collector = new MockFailureCollector();
312+
SalesforceSourceConfig mock = Mockito.spy(config);
313+
314+
SalesforceConnectorConfig connectorConfig = Mockito.mock(SalesforceConnectorConfig.class);
315+
PowerMockito.whenNew(SalesforceConnectorConfig.class).withAnyArguments().thenReturn(connectorConfig);
316+
317+
SalesforceConnectorInfo salesforceConnectorInfo =
318+
new SalesforceConnectorInfo(null, connectorConfig,
319+
SalesforceConstants.isOAuthMacroFunction.apply(connectorConfig));
320+
321+
Mockito.when(mock.getConnection()).thenReturn(salesforceConnectorInfo);
322+
PowerMockito.when(salesforceConnectorInfo.canAttemptToEstablishConnection()).thenReturn(false);
323+
324+
ValidationFailure failure = null;
325+
mock.validate(collector, null);
326+
failure = collector.getValidationFailures().get(0);
327+
Assert.assertEquals(1, collector.getValidationFailures().size());
328+
Assert.assertEquals(stageConfigName,
329+
failure.getCauses().get(0).getAttribute(CauseAttributes.STAGE_CONFIG));
330+
String expectedMessage = "sObject type 'Attachment' is not supported";
331+
Assert.assertEquals(expectedMessage, failure.getMessage());
332+
}
333+
300334
}

0 commit comments

Comments
 (0)