Skip to content

Commit 1ad8412

Browse files
Merge pull request data-integrations#110 from data-integrations/backward-compatability-schema-fix
[PLUGIN-1902] Changes done for schema backward compatibility along with metadata API addition for DTS
2 parents ba37233 + 4af230c commit 1ad8412

40 files changed

+427
-226
lines changed

src/e2e-test/java/io/cdap/plugin/servicenowsink/actions/ServiceNowSinkPropertiesPageActions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static void getRecordFromServiceNowTable(String query, String tableName)
6262
System.getenv("SERVICE_NOW_PASSWORD"),
6363
"", "", "", null);
6464

65-
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection());
65+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), true);
6666
responseFromServiceNowTable = tableAPIClient.getRecordFromServiceNowTable(tableName, query);
6767
}
6868

src/e2e-test/java/io/cdap/plugin/tests/hooks/TestSetupHooks.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static void initializeServiceNowSourceConfig() {
6565
@Before(order = 2, value = "@SN_PRODUCT_CATALOG_ITEM")
6666
public static void createRecordInProductCatalogItemTable() throws IOException, ServiceNowAPIException {
6767
BeforeActions.scenario.write("Create new record in Product Catalog Item table");
68-
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection());
68+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), true);
6969
String uniqueId = "TestProductCatalogItem" + RandomStringUtils.randomAlphanumeric(10);
7070
String recordDetails = "{'name':'" + uniqueId + "','price':'2500'}";
7171
StringEntity entity = new StringEntity(recordDetails);
@@ -76,7 +76,7 @@ public static void createRecordInProductCatalogItemTable() throws IOException, S
7676
public static void createRecordInReceivingSlipLineTable()
7777
throws IOException, ServiceNowAPIException {
7878
BeforeActions.scenario.write("Create new record in Receiving Slip Line table");
79-
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection());
79+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), true);
8080
String uniqueId = "TestReceivingSlipLine" + RandomStringUtils.randomAlphanumeric(10);
8181
String recordDetails = "{'number':'" + uniqueId + "'}";
8282
StringEntity entity = new StringEntity(recordDetails);
@@ -88,7 +88,7 @@ public static void createRecordInReceivingSlipLineTable()
8888
public static void createRecordInDateTimeTable()
8989
throws IOException, ServiceNowAPIException {
9090
BeforeActions.scenario.write("Create new record in Date time table");
91-
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection());
91+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), false);
9292
String recordDetails = "{'u_date': '2025-05-28 15:07'," +
9393
" 'u_datetime1': '28.05.2025 03:07:56 PM'," +
9494
" 'u_datetime2': '28.05.2025 03.07.56 PM'," +
@@ -110,7 +110,7 @@ public static void createRecordInDateTimeTable()
110110

111111
@After(order = 2, value = "@SN_DATE_TIME_TABLE")
112112
public static void deleteRecord() throws ServiceNowAPIException, IOException {
113-
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection());
113+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), false);
114114
tableAPIClient.deleteRecordFromServiceNowTable(TablesInTableMode.DATE_TIME_TABLE.value, TestSetupHooks.systemId);
115115
BeforeActions.scenario.write("Record in Date time table: " + systemId + " deleted successfully");
116116
}
@@ -119,7 +119,7 @@ public static void deleteRecord() throws ServiceNowAPIException, IOException {
119119
public static void updateRecordInAgentAssistRecommendationTable()
120120
throws IOException, ServiceNowAPIException {
121121
BeforeActions.scenario.write("Create new record in Agent Assist Recommendation table");
122-
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection());
122+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), true);
123123
String uniqueId = "TestAgentAssist" + RandomStringUtils.randomAlphanumeric(10);
124124
String recordDetails = "{'active':'false','name':'" + uniqueId + "'}";
125125
StringEntity entity = new StringEntity(recordDetails);
@@ -130,7 +130,7 @@ public static void updateRecordInAgentAssistRecommendationTable()
130130
public static void updateRecordInAgentVendorCatalogItem()
131131
throws IOException, ServiceNowAPIException {
132132
BeforeActions.scenario.write("Create new record in Vendor Catalog Item table");
133-
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection());
133+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), true);
134134
String uniqueId = "TestVendorCatalog" + RandomStringUtils.randomAlphanumeric(10);
135135
String recordDetails = "{'out_of_stock':'false','product_id':'" + uniqueId + "'}";
136136
StringEntity entity = new StringEntity(recordDetails);
@@ -140,7 +140,7 @@ public static void updateRecordInAgentVendorCatalogItem()
140140
@Before(order = 2, value = "@SN_UPDATE_SERVICE_OFFERING")
141141
public static void updateRecordInServiceOffering() throws IOException, ServiceNowAPIException {
142142
BeforeActions.scenario.write("Create new record in Service Offering table");
143-
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection());
143+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), true);
144144
String uniqueId = "TestServiceOffering" + RandomStringUtils.randomAlphanumeric(10);
145145
String recordDetails = "{'purchase_date':'2022-05-28','end_date':'2022-06-05 15:00:00'," +
146146
" 'start_date':'2022-05-25 15:00:00','number':'" + uniqueId + "'}";

src/main/java/io/cdap/plugin/servicenow/ServiceNowBaseConfig.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@
2828
import io.cdap.plugin.servicenow.connector.ServiceNowConnectorConfig;
2929
import io.cdap.plugin.servicenow.restapi.RestAPIResponse;
3030
import io.cdap.plugin.servicenow.source.ServiceNowSourceConfig;
31+
import io.cdap.plugin.servicenow.util.SchemaType;
3132
import io.cdap.plugin.servicenow.util.ServiceNowConstants;
3233
import io.cdap.plugin.servicenow.util.SourceValueType;
33-
import org.apache.http.HttpStatus;
34-
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
35-
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
3634

37-
import java.io.IOException;
3835
import javax.annotation.Nullable;
3936

4037
/**
@@ -58,6 +55,11 @@ public ServiceNowBaseConfig(String clientId, String clientSecret, String restApi
5855
this.connection = new ServiceNowConnectorConfig(clientId, clientSecret, restApiEndpoint, user, password);
5956
}
6057

58+
@Nullable
59+
public Boolean getUseConnection() {
60+
return useConnection;
61+
}
62+
6163
@Nullable
6264
public ServiceNowConnectorConfig getConnection() {
6365
return connection;
@@ -83,7 +85,7 @@ public void validateCredentials(FailureCollector collector) {
8385
@VisibleForTesting
8486
public void validateServiceNowConnection(FailureCollector collector) {
8587
try {
86-
ServiceNowTableAPIClientImpl restApi = new ServiceNowTableAPIClientImpl(connection);
88+
ServiceNowTableAPIClientImpl restApi = new ServiceNowTableAPIClientImpl(connection, useConnection);
8789
restApi.getAccessToken();
8890
} catch (Exception e) {
8991
collector.addFailure("Unable to connect to ServiceNow Instance.",
@@ -123,13 +125,13 @@ public void validateTable(String tableName, SourceValueType valueType, FailureCo
123125
String tableField) {
124126
// Call API to fetch first record from the table
125127
ServiceNowTableAPIRequestBuilder requestBuilder = new ServiceNowTableAPIRequestBuilder(
126-
connection.getRestApiEndpoint(), tableName, false)
128+
connection.getRestApiEndpoint(), tableName, false, SchemaType.SCHEMA_API_BASED)
127129
.setExcludeReferenceLink(true)
128130
.setDisplayValue(valueType)
129131
.setLimit(1);
130132

131133
RestAPIResponse apiResponse = null;
132-
ServiceNowTableAPIClientImpl serviceNowTableAPIClient = new ServiceNowTableAPIClientImpl(connection);
134+
ServiceNowTableAPIClientImpl serviceNowTableAPIClient = new ServiceNowTableAPIClientImpl(connection, useConnection);
133135
try {
134136
String accessToken = serviceNowTableAPIClient.getAccessToken();
135137
requestBuilder.setAuthHeader(accessToken);

0 commit comments

Comments
 (0)