Skip to content

Commit

Permalink
Addition of query parameters for successfactors
Browse files Browse the repository at this point in the history
Addition of query parameters for successfactors
  • Loading branch information
vikasrathee-cs committed Nov 20, 2023
1 parent 024c4c4 commit b10567f
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/SuccessFactors-batchsource.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ For example: customManager. If an entity has hierarchical records, the source ou
entity it reads, with each record containing an additional field that holds the value from the navigational property
specified in the Expand Fields.

**Additional Query Parameters (M, O)**: Additional Query Parameters that can be added with the OData url.
e.g. Effective Dated queries.Multiple parameters can be added as separated by '&' sign.
e.g. fromDate=2023-01-01&toDate=2023-01-31

**Associated Entity Name (M, O)**: Name of the Associated Entity to be extracted
e.g.: EmpCompensationCalculated

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class SuccessFactorsPluginConfig extends PluginConfig {
private static final String NAME_SCHEMA = "schema";
private static final String PAGINATION_TYPE = "paginationType";
public static final String EXPAND_OPTION = "expandOption";
public static final String ADDITIONAL_QUERY_PARAMETERS = "additionalQueryParameters";
private static final String COMMON_ACTION = ResourceConstants.ERR_MISSING_PARAM_OR_MACRO_ACTION.getMsgForKey();
private static final Pattern PATTERN = Pattern.compile("\\(.*\\)");
private static final String SAP_SUCCESSFACTORS_ENTITY_NAME = "Entity Name";
Expand Down Expand Up @@ -89,6 +90,13 @@ public class SuccessFactorsPluginConfig extends PluginConfig {
"the Expand Fields.")
private final String expandOption;

@Name(ADDITIONAL_QUERY_PARAMETERS)
@Nullable
@Macro
@Description("Additional Query Parameters that can be added with the OData url. e.g. Effective Dated queries." +
"Multiple parameters can be added as separated by '&' sign. e.g. fromDate=2023-01-01&toDate=2023-01-31")
private final String additionalQueryParameters;

/**
* Basic parameters.
*/
Expand Down Expand Up @@ -130,6 +138,7 @@ public SuccessFactorsPluginConfig(String referenceName,
@Nullable String filterOption,
@Nullable String selectOption,
@Nullable String expandOption,
@Nullable String additionalQueryParameters,
String paginationType) {
this.connection = new SuccessFactorsConnectorConfig(username, password, baseURL);
this.referenceName = referenceName;
Expand All @@ -139,6 +148,7 @@ public SuccessFactorsPluginConfig(String referenceName,
this.selectOption = selectOption;
this.expandOption = expandOption;
this.paginationType = paginationType;
this.additionalQueryParameters = additionalQueryParameters;
}
@Nullable
public SuccessFactorsConnectorConfig getConnection() {
Expand Down Expand Up @@ -191,6 +201,11 @@ public String getPaginationType() {
return this.paginationType;
}

@Nullable
public String getAdditionalQueryParameters() {
return this.additionalQueryParameters;
}

/**
* Checks if the call to SuccessFactors service is required for metadata creation.
* condition parameters: ['host' | 'serviceName' | 'entityName' | 'username' | 'password']
Expand Down Expand Up @@ -284,6 +299,7 @@ public static class Builder {
private String selectOption;
private String expandOption;
private String paginationType;
private String additionalQueryParameters;

public Builder referenceName(String referenceName) {
this.referenceName = referenceName;
Expand Down Expand Up @@ -335,9 +351,15 @@ public Builder paginationType(@Nullable String paginationType) {
return this;
}

public Builder additionalQueryParameters(@Nullable String additionalQueryParameters) {
this.additionalQueryParameters = additionalQueryParameters;
return this;
}

public SuccessFactorsPluginConfig build() {
return new SuccessFactorsPluginConfig(referenceName, baseURL, entityName, associateEntityName, username, password,
filterOption, selectOption, expandOption, paginationType);
filterOption, selectOption, expandOption, additionalQueryParameters,
paginationType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ public URL getMetadataURL() {
* in {@code SuccessFactorsPluginConfig} and return it.
*/
private HttpUrl.Builder buildQueryOptions(HttpUrl.Builder urlBuilder, Boolean isDataFetch) {
if (SuccessFactorsUtil.isNotNullOrEmpty(pluginConfig.getAdditionalQueryParameters())) {
urlBuilder.query(pluginConfig.getAdditionalQueryParameters());
}
if (SuccessFactorsUtil.isNotNullOrEmpty(pluginConfig.getFilterOption())) {
urlBuilder.addQueryParameter(FILTER_OPTION, pluginConfig.getFilterOption());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void initializeTests() {
"filterOption",
"selectOption",
"expandOption",
"additionalQueryParameters",
null));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void testBuildExpandOutputSchema() throws SuccessFactorsServiceException
SuccessFactorsPluginConfig pluginConfig = new SuccessFactorsPluginConfig("referenceName",
"baseUR", "entityName", "associateEntityName", "username",
"password", "filterOption", "selectOption", "expandOption",
"paginationType");
"additionalQueryParameters", "paginationType");
Schema outputSchema = generator.buildExpandOutputSchema("Benefit",
"eligibleBenefits", "associatedEntity", pluginConfig);
int lastIndex = outputSchema.getFields().size() - 1;
Expand Down Expand Up @@ -155,7 +155,7 @@ public void testInvalidExpandName() throws SuccessFactorsServiceException {
SuccessFactorsPluginConfig pluginConfig = new SuccessFactorsPluginConfig("referenceName",
"baseUR", "entityName", "associateEntityName", "username",
"password", "filterOption", "selectOption", "expandOption",
"paginationType");
"additionalQueryParameters", "paginationType");
exception.expectMessage("'assEntity' not found in the 'Benefit' entity.");
generator.buildExpandOutputSchema("Benefit", "INVALID-NAVIGATION-NAME",
"assEntity", pluginConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ public void initializeTests() {
"filterOption",
"selectOption",
"expandOption",
"",
null));
}
@Test
public void testGetTesterURL() {
SuccessFactorsUrlContainer urlContainer = new SuccessFactorsUrlContainer(pluginConfig);
String expectedUrl = "https://baseurl/entityName?%24filter=filterOption&%24select=selectOption%2CexpandOption&%24" +
"expand=expandOption&%24top=1";
String expectedUrl = "https://baseurl/entityName?%24filter=filterOption&%24select=" +
"selectOption%2CexpandOption&%24expand=expandOption&%24top=1";
URL actualUrl = urlContainer.getTesterURL();
Assert.assertEquals(expectedUrl, actualUrl.toString());
}
Expand All @@ -62,4 +63,23 @@ public void testGetTotalRecordCountURL() {
URL actualUrl = urlContainer.getTotalRecordCountURL();
Assert.assertEquals(actualUrl.toString(), expectedUrl);
}

@Test
public void testGetURLWithAdditionalQueryParameters() {
pluginConfig = Mockito.spy(new SuccessFactorsPluginConfig("referenceName",
"https://successfactors.com",
"EmpJob",
"associatedEntity",
"username",
"password",
"",
"",
"",
"startDate=2023-01-01&endDate=2023-02-02",
null));
SuccessFactorsUrlContainer urlContainer = new SuccessFactorsUrlContainer(pluginConfig);
String expectedUrl = "https://successfactors.com/EmpJob?startDate=2023-01-01&endDate=2023-02-02&%24top=1";
URL actualUrl = urlContainer.getTesterURL();
Assert.assertEquals(expectedUrl, actualUrl.toString());
}
}
8 changes: 8 additions & 0 deletions widgets/SuccessFactors-batchsource.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@
"placeholder": "Eg. Products,Products/Suppliers"
}
},
{
"widget-type": "textbox",
"label": "Additional Query Parameters",
"name": "additionalQueryParameters",
"widget-attributes": {
"placeholder": "For example, fromDate=2023-01-01&toDate=2023-02-02"
}
},
{
"widget-type": "textbox",
"label": "Associated Entity Name",
Expand Down

0 comments on commit b10567f

Please sign in to comment.