Skip to content

Commit 9462313

Browse files
authored
feat(examples) : adding cache control and environmental variable changes (#66)
1 parent 62c6933 commit 9462313

16 files changed

+136
-97
lines changed

examples/src/examples/AfiInteractiveOptimizerEngineExample.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030

3131
public class AfiInteractiveOptimizerEngineExample {
3232
private static FdsApiClient apiClient = null;
33-
private static String BASE_PATH = "https://api.factset.com";
34-
private static String USERNAME = "<username-serial>";
35-
private static String PASSWORD = "<apiKey>";
36-
33+
private static String BASE_PATH = System.getenv("FACTSET_HOST");
34+
private static String USERNAME = System.getenv("FACTSET_USERNAME");
35+
private static String PASSWORD = System.getenv("FACTSET_PASSWORD");
36+
3737
private static String STRATEGY_ID = "CLIENT:/Analytics_api/AFIAPISIMPLE";
3838
private static IdentifierTypeEnum TRADES_ID_TYPE = IdentifierTypeEnum.ASSET;
3939
private static Boolean INCLUDE_CASH = false;
@@ -59,6 +59,9 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi
5959
afiOptimizerParam.setData(afiItem);
6060

6161
ApiResponse<Object> response = apiInstance.postAndOptimizeWithHttpInfo(null, null, afiOptimizerParam);
62+
// Comment the above line and uncomment the below lines to add cache control configuration. Results are by default cached for 12 hours; Setting max-stale=300 will fetch a cached result which is at max 5 minutes older.
63+
// String cacheControlInput = "max-stale=300";
64+
// ApiResponse<Object> response = apiInstance.postAndOptimizeWithHttpInfo(null, cacheControlInput, afiOptimizerParam);
6265
Map<String, List<String>> headers = response.getHeaders();
6366

6467
Object result = null;
@@ -166,7 +169,6 @@ private static FdsApiClient getApiClient() {
166169
apiClient.setBasePath(BASE_PATH);
167170
apiClient.setUsername(USERNAME);
168171
apiClient.setPassword(PASSWORD);
169-
170172
return apiClient;
171173
}
172174

examples/src/examples/AxpInteractiveOptimizerEngineExample.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030

3131
public class AxpInteractiveOptimizerEngineExample {
3232
private static FdsApiClient apiClient = null;
33-
private static String BASE_PATH = "https://api.factset.com";
34-
private static String USERNAME = "<username-serial>";
35-
private static String PASSWORD = "<apiKey>";
36-
33+
private static String BASE_PATH = System.getenv("FACTSET_HOST");
34+
private static String USERNAME = System.getenv("FACTSET_USERNAME");
35+
private static String PASSWORD = System.getenv("FACTSET_PASSWORD");
36+
3737
private static String AXIOMA_ACCOUNT_ID = "BENCH:SP50";
3838
private static String OPTIMIZATION_DATE = "09/01/2020";
3939
private static String OPTIMIZATION_CASHFLOW = "0";
@@ -77,6 +77,9 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi
7777
axpOptimizerParam.setData(axpItem);
7878

7979
ApiResponse<Object> response = apiInstance.postAndOptimizeWithHttpInfo(null, null, axpOptimizerParam);
80+
// Comment the above line and uncomment the below lines to add cache control configuration. Results are by default cached for 12 hours; Setting max-stale=300 will fetch a cached result which is at max 5 minutes older.
81+
// String cacheControlInput = "max-stale=300";
82+
// ApiResponse<Object> response = apiInstance.postAndOptimizeWithHttpInfo(null, cacheControlInput, axpOptimizerParam);
8083
Map<String, List<String>> headers = response.getHeaders();
8184

8285
Object result = null;
@@ -184,7 +187,6 @@ private static FdsApiClient getApiClient() {
184187
apiClient.setBasePath(BASE_PATH);
185188
apiClient.setUsername(USERNAME);
186189
apiClient.setPassword(PASSWORD);
187-
188190
return apiClient;
189191
}
190192

examples/src/examples/BpmInteractiveOptimizerEngineExample.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232

3333
public class BpmInteractiveOptimizerEngineExample {
3434
private static FdsApiClient apiClient = null;
35-
private static String BASE_PATH = "https://api.factset.com";
36-
private static String USERNAME = "<username-serial>";
37-
private static String PASSWORD = "<apiKey>";
38-
35+
private static String BASE_PATH = System.getenv("FACTSET_HOST");
36+
private static String USERNAME = System.getenv("FACTSET_USERNAME");
37+
private static String PASSWORD = System.getenv("FACTSET_PASSWORD");
38+
3939
private static String BPM_STRATEGY_ID = "CLIENT:/Aapi/BPMAPISIMPLE";
4040
private static IdentifierTypeEnum TRADES_ID_TYPE = IdentifierTypeEnum.ASSET;
4141
private static Boolean INCLUDE_CASH = false;
@@ -67,6 +67,9 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi
6767
bpmOptimizerParam.setData(bpmItem);
6868

6969
ApiResponse<Object> response = apiInstance.postAndOptimizeWithHttpInfo(null, null, bpmOptimizerParam);
70+
// Comment the above line and uncomment the below lines to add cache control configuration. Results are by default cached for 12 hours; Setting max-stale=300 will fetch a cached result which is at max 5 minutes older.
71+
// String cacheControlInput = "max-stale=300";
72+
// ApiResponse<Object> response = apiInstance.postAndOptimizeWithHttpInfo(null, cacheControlInput, bpmOptimizerParam);
7073
Map<String, List<String>> headers = response.getHeaders();
7174

7275
Object result = null;
@@ -174,7 +177,6 @@ private static FdsApiClient getApiClient() {
174177
apiClient.setBasePath(BASE_PATH);
175178
apiClient.setUsername(USERNAME);
176179
apiClient.setPassword(PASSWORD);
177-
178180
return apiClient;
179181
}
180182

examples/src/examples/FiInteractiveEngineExample.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434

3535
public class FiInteractiveEngineExample {
3636
private static FdsApiClient apiClient = null;
37-
private static String BASE_PATH = "https://api.factset.com";
38-
private static String USERNAME = "<username-serial>";
39-
private static String PASSWORD = "<apiKey>";
40-
37+
private static String BASE_PATH = System.getenv("FACTSET_HOST");
38+
private static String USERNAME = System.getenv("FACTSET_USERNAME");
39+
private static String PASSWORD = System.getenv("FACTSET_PASSWORD");
40+
4141
private static String FI_CALC_FROM_METHOD = "Price";
4242
private static Double FI_CALC_FROM_VALUE = 108.40299;
4343
private static Double FI_CALC_FROM_VALUE_2 = 100.285;
@@ -88,6 +88,9 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi
8888
fiCalcParam.data(calcParameters);
8989

9090
ApiResponse<Object> response = apiInstance.postAndCalculateWithHttpInfo(null, null, fiCalcParam);
91+
// Comment the above line and uncomment the below lines to add cache control configuration. Results are by default cached for 12 hours; Setting max-stale=300 will fetch a cached result which is at max 5 minutes older.
92+
// String cacheControlInput = "max-stale=300";
93+
// ApiResponse<Object> response = apiInstance.postAndCalculateWithHttpInfo(null, cacheControlInput, fiCalcParam);
9194
Map<String, List<String>> headers = response.getHeaders();
9295

9396
Object result = null;
@@ -191,7 +194,6 @@ private static FdsApiClient getApiClient() {
191194
apiClient.setBasePath(BASE_PATH);
192195
apiClient.setUsername(USERNAME);
193196
apiClient.setPassword(PASSWORD);
194-
195197
return apiClient;
196198
}
197199

examples/src/examples/FiabInteractiveEngineExample.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121

2222
public class FiabInteractiveEngineExample {
2323
private static FdsApiClient apiClient = null;
24-
private static String BASE_PATH = "https://api.factset.com";
25-
private static String USERNAME = "<username-serial>";
26-
private static String PASSWORD = "<apiKey>";
27-
24+
private static String BASE_PATH = System.getenv("FACTSET_HOST");
25+
private static String USERNAME = System.getenv("FACTSET_USERNAME");
26+
private static String PASSWORD = System.getenv("FACTSET_PASSWORD");
27+
2828
private static String FIAB_ACCOUNT_ID = "Client:/aapi/FIAB_TEST_HOLDINGS.ACCT";
2929
private static String FIAB_DOCUMENT = "Client:/aapi/AAPI_FIAB_BASE_DOC";
3030
private static String FIAB_DATE = "20200618";
3131
private static String FIAB_MSL = "CLIENT:$$MSL_AAPI_TESTING.OFDB";
3232
private static String FIAB_SETTINGS_DOCUMENT = "None";
33-
33+
3434
public static void main(String[] args) throws InterruptedException, JsonProcessingException {
3535
try {
3636
FiabCalculationsApi apiInstance = new FiabCalculationsApi(getApiClient());
3737
FIABCalculationParameters calcParameters = new FIABCalculationParameters();
38-
38+
3939
FIABIdentifier fiabID = new FIABIdentifier();
4040
fiabID.setId(FIAB_ACCOUNT_ID);
4141
calcParameters.setAccount(fiabID);
@@ -48,11 +48,11 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi
4848
calcParameters.setMsl(FIAB_MSL);
4949
ApiResponse<Void> response = apiInstance.runCalculationWithHttpInfo(calcParameters);
5050
Map<String, List<String>> headers = response.getHeaders();
51-
51+
5252
ApiResponse<FIABCalculationStatus> resultStatus = null;
5353
String[] locationList = headers.get("Location").get(0).split("/");
5454
String calculationId = locationList[locationList.length - 1];
55-
55+
5656
do {
5757
resultStatus = apiInstance.getCalculationByIdWithHttpInfo(calculationId);
5858
List<String> cacheControl = headers.get("Cache-Control");
@@ -70,7 +70,7 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi
7070
handleException("FiabEngineExample#Main", e);
7171
}
7272
}
73-
73+
7474
private static class FdsApiClient extends ApiClient {
7575
// Uncomment the below lines to use a proxy server
7676
/*@Override
@@ -79,22 +79,22 @@ protected void customizeClientBuilder(ClientBuilder clientBuilder) {
7979
clientConfig.connectorProvider( new ApacheConnectorProvider() );
8080
}*/
8181
}
82-
82+
8383
private static FdsApiClient getApiClient() {
8484
if (apiClient != null) {
8585
return apiClient;
8686
}
87-
87+
8888
apiClient = new FdsApiClient();
8989
apiClient.setConnectTimeout(30000);
9090
apiClient.setReadTimeout(30000);
9191
apiClient.setBasePath(BASE_PATH);
9292
apiClient.setUsername(USERNAME);
9393
apiClient.setPassword(PASSWORD);
94-
94+
9595
return apiClient;
9696
}
97-
97+
9898
private static void handleException(String method, ApiException e) {
9999
System.err.println("Exception when calling " + method);
100100
if (e.getResponseHeaders() != null && e.getResponseHeaders().containsKey("x-datadirect-request-key")) {

examples/src/examples/FpoInteractiveOptimizerEngineExample.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232

3333
public class FpoInteractiveOptimizerEngineExample {
3434
private static FdsApiClient apiClient = null;
35-
private static String BASE_PATH = "https://api.factset.com";
36-
private static String USERNAME = "<username-serial>";
37-
private static String PASSWORD = "<apiKey>";
38-
35+
private static String BASE_PATH = System.getenv("FACTSET_HOST");
36+
private static String USERNAME = System.getenv("FACTSET_USERNAME");
37+
private static String PASSWORD = System.getenv("FACTSET_PASSWORD");
38+
3939
private static String FPO_ACCOUNT_ID = "CLIENT:/FPO/1K_MAC_AMZN_AAPL.ACCT";
4040
private static String FPO_PA_DOC_NAME = "CLIENT:/FPO/FPO_MASTER";
4141
private static String FPO_OPTIMIZATION_DATE = "0M";
@@ -86,6 +86,9 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi
8686
fpoOptimizerParam.setData(fpoItem);
8787

8888
ApiResponse<Object> response = apiInstance.postAndOptimizeWithHttpInfo(null, null, fpoOptimizerParam);
89+
// Comment the above line and uncomment the below lines to add cache control configuration. Results are by default cached for 12 hours; Setting max-stale=300 will fetch a cached result which is at max 5 minutes older.
90+
// String cacheControlInput = "max-stale=300";
91+
// ApiResponse<Object> response = apiInstance.postAndOptimizeWithHttpInfo(null, cacheControlInput, fpoOptimizerParam);
8992
Map<String, List<String>> headers = response.getHeaders();
9093

9194
Object result = null;
@@ -193,7 +196,6 @@ private static FdsApiClient getApiClient() {
193196
apiClient.setBasePath(BASE_PATH);
194197
apiClient.setUsername(USERNAME);
195198
apiClient.setPassword(PASSWORD);
196-
197199
return apiClient;
198200
}
199201

examples/src/examples/PAEngineMultipleUnitExample.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
public class PAEngineMultipleUnitExample {
3535

3636
private static FdsApiClient apiClient = null;
37-
private static String BASE_PATH = "https://api.factset.com";
38-
private static String USERNAME = "<username-serial>";
39-
private static String PASSWORD = "<apiKey>";
40-
37+
private static String BASE_PATH = System.getenv("FACTSET_HOST");
38+
private static String USERNAME = System.getenv("FACTSET_USERNAME");
39+
private static String PASSWORD = System.getenv("FACTSET_PASSWORD");
40+
4141
private static String PA_DEFAULT_DOCUMENT = "PA_DOCUMENTS:DEFAULT";
4242
private static String COMPONENT_NAME = "Weights";
4343
private static String COMPONENT_CATEGORY = "Weights / Exposures";
@@ -112,7 +112,10 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi
112112
ApiResponse<Object> createResponse = null;
113113

114114
createResponse = apiInstance.postAndCalculateWithHttpInfo(null, null, calcParameters);
115-
115+
116+
// Comment the above line and uncomment the below lines to add cache control configuration. Results are by default cached for 12 hours; Setting max-stale=300 will fetch a cached result which is at max 5 minutes older.
117+
// String cacheControlInput = "max-stale=300";
118+
// createResponse = apiInstance.postAndCalculateWithHttpInfo(null, cacheControlInput, calcParameters);
116119
CalculationStatusRoot status = (CalculationStatusRoot) createResponse.getData();
117120
String calculationId = status.getData().getCalculationid();
118121
System.out.println("Calculation Id: " + calculationId);
@@ -251,7 +254,7 @@ private static FdsApiClient getApiClient() {
251254
apiClient.setBasePath(BASE_PATH);
252255
apiClient.setUsername(USERNAME);
253256
apiClient.setPassword(PASSWORD);
254-
257+
255258
return apiClient;
256259
}
257260

examples/src/examples/PAEngineSingleUnitExample.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
public class PAEngineSingleUnitExample {
3333

3434
private static FdsApiClient apiClient = null;
35-
private static String BASE_PATH = "https://api.factset.com";
36-
private static String USERNAME = "<username-serial>";
37-
private static String PASSWORD = "<apiKey>";
38-
35+
private static String BASE_PATH = System.getenv("FACTSET_HOST");
36+
private static String USERNAME = System.getenv("FACTSET_USERNAME");
37+
private static String PASSWORD = System.getenv("FACTSET_PASSWORD");
38+
3939
private static String PA_DEFAULT_DOCUMENT = "PA_DOCUMENTS:DEFAULT";
4040
private static String COMPONENT_NAME = "Weights";
4141
private static String COMPONENT_CATEGORY = "Weights / Exposures";
@@ -104,7 +104,10 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi
104104
// Run Calculation Request
105105
PaCalculationsApi apiInstance = new PaCalculationsApi(getApiClient());
106106
ApiResponse<Object> response = apiInstance.postAndCalculateWithHttpInfo(null, null, calcParameters);
107-
107+
// Comment the above line and uncomment the below lines to add cache control configuration. Results are by default cached for 12 hours; Setting max-stale=300 will fetch a cached result which is at max 5 minutes older.
108+
// String cacheControlInput = "max-stale=300";
109+
// ApiResponse<Object> response = apiInstance.postAndCalculateWithHttpInfo(null, cacheControlInput, calcParameters);
110+
108111
ApiResponse<CalculationStatusRoot> getStatus = null;
109112
Object result = null;
110113
switch (response.getStatusCode()) {
@@ -239,10 +242,10 @@ private static FdsApiClient getApiClient() {
239242
apiClient.setBasePath(BASE_PATH);
240243
apiClient.setUsername(USERNAME);
241244
apiClient.setPassword(PASSWORD);
242-
245+
243246
return apiClient;
244247
}
245-
248+
246249
private static void handleException(String method, ApiException e) {
247250
System.err.println("Exception when calling " + method);
248251
if (e.getResponseHeaders() != null && e.getResponseHeaders().containsKey("x-datadirect-request-key")) {

examples/src/examples/PubEngineMultipleUnitExample.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
public class PubEngineMultipleUnitExample {
2020

2121
private static FdsApiClient apiClient = null;
22-
private static String BASE_PATH = "https://api.factset.com";
23-
private static String USERNAME = "<username-serial>";
24-
private static String PASSWORD = "<apiKey>";
25-
22+
private static String BASE_PATH = System.getenv("FACTSET_HOST");
23+
private static String USERNAME = System.getenv("FACTSET_USERNAME");
24+
private static String PASSWORD = System.getenv("FACTSET_PASSWORD");
25+
2626
private static String PUB_DEFAULT_DOCUMENT = "Client:/AAPI/Puma Test Doc.Pub_bridge_pdf";
2727
private static String PUB_DEFAULT_ACCOUNT = "BENCH:SP50";
2828

@@ -52,7 +52,9 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi
5252
PubCalculationsApi apiInstance = new PubCalculationsApi(getApiClient());
5353

5454
ApiResponse<Object> createResponse = apiInstance.postAndCalculateWithHttpInfo(null, null, calcParameters);
55-
55+
// Comment the above line and uncomment the below lines to add cache control configuration. Results are by default cached for 12 hours; Setting max-stale=300 will fetch a cached result which is at max 5 minutes older.
56+
// String cacheControlInput = "max-stale=300";
57+
// ApiResponse<Object> createResponse = apiInstance.postAndCalculateWithHttpInfo(null, cacheControlInput, calcParameters);
5658
CalculationStatusRoot status = (CalculationStatusRoot) createResponse.getData();
5759
String calculationId = status.getData().getCalculationid();
5860

0 commit comments

Comments
 (0)