Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<groupId>io.cdap.plugin</groupId>
<artifactId>servicenow-plugins</artifactId>
<version>1.2.5-SNAPSHOT</version>
<version>1.2.5</version>
<name>ServiceNow Plugins</name>
<packaging>jar</packaging>
<description>Plugins for ServiceNow</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class ServiceNowTableAPIClientImpl extends RestAPIClient {
private static final String FIELD_CREATED_ON = "sys_created_on";
private static final String FIELD_UPDATED_ON = "sys_updated_on";
private static final String OAUTH_URL_TEMPLATE = "%s/oauth_token.do";
private static final String GLIDE_TIME_DATATYPE = "glide_time";
private static final String GLIDE_DATE_TIME_DATATYPE = "glide_date_time";
private static final Gson GSON = new Gson();
private final ServiceNowConnectorConfig conf;
public static JsonArray serviceNowJsonResultArray;
Expand Down Expand Up @@ -309,6 +311,9 @@ public Schema fetchTableSchema(String tableName, String accessToken, SourceValue
if (valueType.equals(SourceValueType.SHOW_DISPLAY_VALUE) &&
!Objects.equals(field.getType(), field.getInternalType())) {
columns.add(new ServiceNowColumn(field.getName(), field.getType()));
} else if (valueType.equals(SourceValueType.SHOW_ACTUAL_VALUE) &&
GLIDE_TIME_DATATYPE.equalsIgnoreCase(field.getInternalType())) {
columns.add(new ServiceNowColumn(field.getName(), GLIDE_DATE_TIME_DATATYPE));
} else {
columns.add(new ServiceNowColumn(field.getName(), field.getInternalType()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,42 @@ public void testFetchTableSchema_ActualValueType() throws Exception {
schema.getField("user_name").getSchema().getUnionSchemas().get(0).getType());
}

@Test
public void testFetchTableSchema_GlideTimeFieldWithActualValueType() throws Exception {
ServiceNowConnectorConfig mockConfig = Mockito.mock(ServiceNowConnectorConfig.class);
ServiceNowTableAPIClientImpl impl = new ServiceNowTableAPIClientImpl(mockConfig);
ServiceNowTableAPIClientImpl implSpy = Mockito.spy(impl);

String jsonResponse = "{\n" +
" \"result\": {\n" +
" \"columns\": {\n" +
" \"u_start_time\": {\n" +
" \"label\": \"Start Time\",\n" +
" \"name\": \"u_start_time\",\n" +
" \"type\": \"string\",\n" +
" \"internal_type\": \"glide_time\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}";

RestAPIResponse mockResponse = new RestAPIResponse(Collections.emptyMap(), jsonResponse, null);
Mockito.doReturn(mockResponse).when(implSpy).executeGetWithRetries(Mockito.any());

Schema schema = implSpy.fetchTableSchema("u_custom_table", "dummy-access-token",
SourceValueType.SHOW_ACTUAL_VALUE);

Assert.assertNotNull(schema);
Assert.assertEquals("record", schema.getDisplayName());
Assert.assertEquals(1, schema.getFields().size());

Schema.Field field = schema.getField("u_start_time");
Assert.assertNotNull(field);

Schema fieldSchema = field.getSchema().getUnionSchemas().get(0);
Assert.assertEquals(Schema.LogicalType.DATETIME, fieldSchema.getLogicalType());
}

@Test
public void testFetchTableSchema_DisplayValueType() throws Exception {
ServiceNowConnectorConfig mockConfig = Mockito.mock(ServiceNowConnectorConfig.class);
Expand Down