Skip to content

Commit 7dc58f5

Browse files
Merge pull request #120 from cloudsufi/bump-up-and-cherrypick
[cherrypick] [PLUGIN-1902] Bump up to 1.2.7-SNAPSHOT and Changes done for schema backward compatibility along with metadata API addition for DTS
2 parents e0e8975 + f5a292e commit 7dc58f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+532
-225
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<groupId>io.cdap.plugin</groupId>
2222
<artifactId>servicenow-plugins</artifactId>
23-
<version>1.2.6</version>
23+
<version>1.2.7-SNAPSHOT</version>
2424
<name>ServiceNow Plugins</name>
2525
<packaging>jar</packaging>
2626
<description>Plugins for ServiceNow</description>

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
@@ -61,7 +61,7 @@ public static void getRecordFromServiceNowTable(String query, String tableName)
6161
System.getenv("SERVICE_NOW_PASSWORD"),
6262
"", "", "", null);
6363

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

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

Lines changed: 49 additions & 6 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,18 +76,50 @@ 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);
8383
systemId = tableAPIClient.createRecord(TablesInTableMode.RECEIVING_SLIP_LINE.value, entity);
84+
BeforeActions.scenario.write("New Record in Receiving Slip Line table: " + systemId + " created successfully");
85+
}
86+
87+
@Before(order = 2, value = "@SN_DATE_TIME_TABLE")
88+
public static void createRecordInDateTimeTable()
89+
throws IOException, ServiceNowAPIException {
90+
BeforeActions.scenario.write("Create new record in Date time table");
91+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), false);
92+
String recordDetails = "{'u_date': '2025-05-28 15:07'," +
93+
" 'u_datetime1': '28.05.2025 03:07:56 PM'," +
94+
" 'u_datetime2': '28.05.2025 03.07.56 PM'," +
95+
" 'u_datetime3': '2025-05-28 15:07:56'," +
96+
" 'u_datetime4': '28.05.2025 15:07:56'," +
97+
" 'u_datetime5': '28.05.2025 15.07.56'," +
98+
" 'u_datetime6': '28-05-2025 15:07:56'," +
99+
" 'u_datetime7': '28-05-2025 15.07.56'," +
100+
" 'u_datetime8': '05/28/2025 15:07:56'," +
101+
" 'u_datetime9': '28/05/2025 15:07:56'," +
102+
" 'u_datetime10': '05-28-2025 15:07:56'," +
103+
" 'u_datetime11': '28-05-25 15.07.56'," +
104+
" 'u_datetime13': '05-28-2025 15:07'," +
105+
" 'u_datetime': '28-05-2025 15.07'}";
106+
StringEntity entity = new StringEntity(recordDetails);
107+
systemId = tableAPIClient.createRecordInDisplayMode(TablesInTableMode.DATE_TIME_TABLE.value, entity);
108+
BeforeActions.scenario.write("New Record in Date time table: " + systemId + " created successfully");
109+
}
110+
111+
@After(order = 2, value = "@SN_DATE_TIME_TABLE")
112+
public static void deleteRecord() throws ServiceNowAPIException, IOException {
113+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), false);
114+
tableAPIClient.deleteRecordFromServiceNowTable(TablesInTableMode.DATE_TIME_TABLE.value, TestSetupHooks.systemId);
115+
BeforeActions.scenario.write("Record in Date time table: " + systemId + " deleted successfully");
84116
}
85117

86118
@Before(order = 2, value = "@SN_UPDATE_AGENT_ASSIST_RECOMMENDATION")
87119
public static void updateRecordInAgentAssistRecommendationTable()
88120
throws IOException, ServiceNowAPIException {
89121
BeforeActions.scenario.write("Create new record in Agent Assist Recommendation table");
90-
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection());
122+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), true);
91123
String uniqueId = "TestAgentAssist" + RandomStringUtils.randomAlphanumeric(10);
92124
String recordDetails = "{'active':'false','name':'" + uniqueId + "'}";
93125
StringEntity entity = new StringEntity(recordDetails);
@@ -98,7 +130,7 @@ public static void updateRecordInAgentAssistRecommendationTable()
98130
public static void updateRecordInAgentVendorCatalogItem()
99131
throws IOException, ServiceNowAPIException {
100132
BeforeActions.scenario.write("Create new record in Vendor Catalog Item table");
101-
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection());
133+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), true);
102134
String uniqueId = "TestVendorCatalog" + RandomStringUtils.randomAlphanumeric(10);
103135
String recordDetails = "{'out_of_stock':'false','product_id':'" + uniqueId + "'}";
104136
StringEntity entity = new StringEntity(recordDetails);
@@ -108,7 +140,7 @@ public static void updateRecordInAgentVendorCatalogItem()
108140
@Before(order = 2, value = "@SN_UPDATE_SERVICE_OFFERING")
109141
public static void updateRecordInServiceOffering() throws IOException, ServiceNowAPIException {
110142
BeforeActions.scenario.write("Create new record in Service Offering table");
111-
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection());
143+
ServiceNowTableAPIClientImpl tableAPIClient = new ServiceNowTableAPIClientImpl(config.getConnection(), true);
112144
String uniqueId = "TestServiceOffering" + RandomStringUtils.randomAlphanumeric(10);
113145
String recordDetails = "{'purchase_date':'2022-05-28','end_date':'2022-06-05 15:00:00'," +
114146
" 'start_date':'2022-05-25 15:00:00','number':'" + uniqueId + "'}";
@@ -234,6 +266,7 @@ public static void updateTempSourceBQTableForServiceOffering() throws IOExceptio
234266
public static void setTempTargetBQTable() {
235267
bqTargetTable = "TestSN_table" + RandomStringUtils.randomAlphanumeric(10);
236268
BeforeActions.scenario.write("BigQuery Target table name: " + bqTargetTable);
269+
PluginPropertyUtils.addPluginProp("bqTargetTable", bqTargetTable);
237270
}
238271

239272
@Before(order = 1, value = "@CONNECTION")
@@ -243,7 +276,7 @@ public static void setNewConnectionName() {
243276
BeforeActions.scenario.write("New Connection name: " + connectionName);
244277
}
245278

246-
@After(order = 1, value = "@BQ_SINK_CLEANUP")
279+
@After(order = 1, value = "@BQ_SINK_CLEANUP or @BQ_SINK")
247280
public static void deleteTempTargetBQTable() throws IOException, InterruptedException {
248281
try {
249282
BigQueryClient.dropBqQuery(bqTargetTable);
@@ -257,4 +290,14 @@ public static void deleteTempTargetBQTable() throws IOException, InterruptedExce
257290
}
258291
}
259292
}
293+
294+
@After(order = 1, value = "@BQ_SOURCE_TEST_RECEIVING_SLIP_LINE or @BQ_SOURCE_UPDATE_SERVICE_OFFERING or " +
295+
"@BQ_SOURCE_UPDATE_VENDOR_CATALOG_ITEM or @BQ_SOURCE_UPDATE_AGENT_ASSIST_RECOMMENDATION or " +
296+
"@BQ_SOURCE_UPDATE_RECEIVING_SLIP_LINE or @BQ_SOURCE_SERVICE_OFFERING or @BQ_SOURCE_VENDOR_CATALOG_ITEM or " +
297+
"@BQ_SOURCE_AGENT_ASSIST_RECOMMENDATION")
298+
public static void deleteTempSourceBQTable() throws IOException, InterruptedException {
299+
BigQueryClient.dropBqQuery(bqSourceTable);
300+
PluginPropertyUtils.removePluginProp("bqSourceTable");
301+
BeforeActions.scenario.write("BQ source Table " + bqSourceTable + " deleted successfully");
302+
}
260303
}

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)