|
8 | 8 |
|
9 | 9 | import javax.ws.rs.client.ClientBuilder; |
10 | 10 |
|
| 11 | +import com.factset.protobuf.stach.extensions.models.Row; |
| 12 | +import com.factset.protobuf.stach.extensions.v2.StachUtilities; |
| 13 | +import com.google.protobuf.InvalidProtocolBufferException; |
| 14 | +import com.google.protobuf.Value; |
11 | 15 | import factset.analyticsapi.engines.models.*; |
12 | 16 | import org.apache.poi.xssf.usermodel.XSSFCell; |
13 | 17 | import org.apache.poi.xssf.usermodel.XSSFRow; |
@@ -42,19 +46,19 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi |
42 | 46 | try { |
43 | 47 | AfiOptimizerApi apiInstance = new AfiOptimizerApi(getApiClient()); |
44 | 48 | AFIOptimizationParameters afiItem = new AFIOptimizationParameters(); |
45 | | - |
| 49 | + |
46 | 50 | AFIOptimizerStrategy strategy = new AFIOptimizerStrategy(); |
47 | 51 | strategy.setId(STRATEGY_ID); |
48 | | - |
| 52 | + |
49 | 53 | OptimizerOutputTypes optOutputTypes = new OptimizerOutputTypes(); |
50 | 54 | OptimizerTradesList tradesList = new OptimizerTradesList(); |
51 | 55 | tradesList.setIdentifierType(TRADES_ID_TYPE); |
52 | 56 | tradesList.setIncludeCash(INCLUDE_CASH); |
53 | 57 | optOutputTypes.setTrades(tradesList); |
54 | | - |
| 58 | + |
55 | 59 | afiItem.setStrategy(strategy); |
56 | 60 | afiItem.setOutputTypes(optOutputTypes); |
57 | | - |
| 61 | + |
58 | 62 | AFIOptimizationParametersRoot afiOptimizerParam = new AFIOptimizationParametersRoot(); |
59 | 63 | afiOptimizerParam.setData(afiItem); |
60 | 64 |
|
@@ -111,12 +115,27 @@ public static void main(String[] args) throws InterruptedException, JsonProcessi |
111 | 115 | } |
112 | 116 |
|
113 | 117 | ObjectMapper mapper = new ObjectMapper(); |
114 | | - String json = mapper.writeValueAsString(tables); |
115 | | - System.out.println(json); // Prints the result in 2D table format. |
| 118 | + for (TableData table : tables) { |
| 119 | + // Prints the results in 2D table format. |
| 120 | + List<Row> rows = table.getRows(); |
| 121 | + String json = mapper.writeValueAsString(rows); |
| 122 | + System.out.println(json); |
| 123 | + |
| 124 | + // Prints the metadata |
| 125 | + if (table.getRawMetadata().size() > 0) System.out.println("Printing metadata..."); |
| 126 | + for (Map.Entry<String, List<Value>> rawMetadata : table.getRawMetadata().entrySet()) { |
| 127 | + for (Value val : rawMetadata.getValue()) { |
| 128 | + System.out.println(" " + rawMetadata.getKey() + ": " + StachUtilities.valueToString(val)); |
| 129 | + } |
| 130 | + } |
| 131 | + } |
116 | 132 | // Uncomment the following line to generate an Excel file |
117 | 133 | // generateExcel(tables); |
118 | 134 | } catch (ApiException e) { |
119 | 135 | handleException("AfiOptimizerEngineExample#Main", e); |
| 136 | + } catch (InvalidProtocolBufferException e) { |
| 137 | + System.out.println(e.getMessage()); |
| 138 | + e.printStackTrace(); |
120 | 139 | } |
121 | 140 | } |
122 | 141 |
|
|
0 commit comments