Skip to content

Commit 4dbb964

Browse files
authored
Merge pull request #99 from cloudsufi/bugfix/time_dataType
"[PLUGIN-1901] Time datatype support for actual value type"
2 parents 2c981e0 + b636e77 commit 4dbb964

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/main/java/io/cdap/plugin/servicenow/apiclient/ServiceNowTableAPIClientImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public class ServiceNowTableAPIClientImpl extends RestAPIClient {
6868
private static final String FIELD_CREATED_ON = "sys_created_on";
6969
private static final String FIELD_UPDATED_ON = "sys_updated_on";
7070
private static final String OAUTH_URL_TEMPLATE = "%s/oauth_token.do";
71+
private static final String GLIDE_TIME_DATATYPE = "glide_time";
72+
private static final String GLIDE_DATE_TIME_DATATYPE = "glide_date_time";
7173
private static final Gson GSON = new Gson();
7274
private final ServiceNowConnectorConfig conf;
7375
public static JsonArray serviceNowJsonResultArray;
@@ -309,6 +311,9 @@ public Schema fetchTableSchema(String tableName, String accessToken, SourceValue
309311
if (valueType.equals(SourceValueType.SHOW_DISPLAY_VALUE) &&
310312
!Objects.equals(field.getType(), field.getInternalType())) {
311313
columns.add(new ServiceNowColumn(field.getName(), field.getType()));
314+
} else if (valueType.equals(SourceValueType.SHOW_ACTUAL_VALUE) &&
315+
GLIDE_TIME_DATATYPE.equalsIgnoreCase(field.getInternalType())) {
316+
columns.add(new ServiceNowColumn(field.getName(), GLIDE_DATE_TIME_DATATYPE));
312317
} else {
313318
columns.add(new ServiceNowColumn(field.getName(), field.getInternalType()));
314319
}

src/test/java/io/cdap/plugin/servicenow/apiclient/ServiceNowTableAPIClientImplTest.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,42 @@ public void testFetchTableSchema_ActualValueType() throws Exception {
117117
schema.getField("user_name").getSchema().getUnionSchemas().get(0).getType());
118118
}
119119

120+
@Test
121+
public void testFetchTableSchema_GlideTimeFieldWithActualValueType() throws Exception {
122+
ServiceNowConnectorConfig mockConfig = Mockito.mock(ServiceNowConnectorConfig.class);
123+
ServiceNowTableAPIClientImpl impl = new ServiceNowTableAPIClientImpl(mockConfig);
124+
ServiceNowTableAPIClientImpl implSpy = Mockito.spy(impl);
125+
126+
String jsonResponse = "{\n" +
127+
" \"result\": {\n" +
128+
" \"columns\": {\n" +
129+
" \"u_start_time\": {\n" +
130+
" \"label\": \"Start Time\",\n" +
131+
" \"name\": \"u_start_time\",\n" +
132+
" \"type\": \"string\",\n" +
133+
" \"internal_type\": \"glide_time\"\n" +
134+
" }\n" +
135+
" }\n" +
136+
" }\n" +
137+
"}";
138+
139+
RestAPIResponse mockResponse = new RestAPIResponse(Collections.emptyMap(), jsonResponse, null);
140+
Mockito.doReturn(mockResponse).when(implSpy).executeGetWithRetries(Mockito.any());
141+
142+
Schema schema = implSpy.fetchTableSchema("u_custom_table", "dummy-access-token",
143+
SourceValueType.SHOW_ACTUAL_VALUE);
144+
145+
Assert.assertNotNull(schema);
146+
Assert.assertEquals("record", schema.getDisplayName());
147+
Assert.assertEquals(1, schema.getFields().size());
148+
149+
Schema.Field field = schema.getField("u_start_time");
150+
Assert.assertNotNull(field);
151+
152+
Schema fieldSchema = field.getSchema().getUnionSchemas().get(0);
153+
Assert.assertEquals(Schema.LogicalType.DATETIME, fieldSchema.getLogicalType());
154+
}
155+
120156
@Test
121157
public void testFetchTableSchema_DisplayValueType() throws Exception {
122158
ServiceNowConnectorConfig mockConfig = Mockito.mock(ServiceNowConnectorConfig.class);

0 commit comments

Comments
 (0)