|
26 | 26 |
|
27 | 27 | import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
28 | 28 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 29 | +import org.apache.commons.lang3.tuple.ImmutablePair; |
| 30 | +import org.apache.commons.lang3.tuple.Pair; |
29 | 31 | import org.commonmark.node.Document; |
30 | 32 | import org.symphonyoss.symphony.messageml.MessageMLContext; |
31 | 33 | import org.symphonyoss.symphony.messageml.MessageMLParser; |
32 | 34 | import org.symphonyoss.symphony.messageml.exceptions.InvalidInputException; |
| 35 | +import org.symphonyoss.symphony.messageml.util.IDataProvider; |
33 | 36 | import org.symphonyoss.symphony.messageml.util.XmlPrintStream; |
| 37 | +import org.symphonyoss.symphony.messageml.util.instrument.resolver.InstrumentKind; |
| 38 | +import org.symphonyoss.symphony.messageml.util.instrument.resolver.InstrumentResolution; |
| 39 | +import org.symphonyoss.symphony.messageml.util.instrument.resolver.MarketSector; |
| 40 | +import org.symphonyoss.symphony.messageml.util.instrument.resolver.ResolutionResults; |
34 | 41 | import org.w3c.dom.Node; |
35 | 42 |
|
| 43 | +import java.util.Collections; |
36 | 44 | import java.util.List; |
| 45 | +import java.util.stream.Collectors; |
| 46 | +import java.util.stream.IntStream; |
37 | 47 |
|
38 | 48 |
|
39 | 49 | /** |
@@ -182,4 +192,61 @@ private void validateTargetIdForUIActions() throws InvalidInputException { |
182 | 192 | uiAction.setAttribute(TARGET_ID, dialog.getPresentationMlIdAttribute()); |
183 | 193 | } |
184 | 194 | } |
| 195 | + |
| 196 | + public void enhanceFinancialTags(MessageML result, IDataProvider dataProvider) |
| 197 | + throws InvalidInputException { |
| 198 | + |
| 199 | + List<Tag> elements = result.getChildrenOfType(Tag.class) |
| 200 | + .stream() |
| 201 | + .map(element -> Tag.class.cast(element)) |
| 202 | + .collect(Collectors.toList()); |
| 203 | + if (elements != null && !elements.isEmpty()) {processFinancialTags(elements, dataProvider);} |
| 204 | + } |
| 205 | + |
| 206 | + private void processFinancialTags(List<Tag> elements, IDataProvider dataProvider) |
| 207 | + throws InvalidInputException { |
| 208 | + List<Pair<InstrumentResolution, Tag>> instrumentResolutionMap = |
| 209 | + IntStream.range(0, elements.size()) |
| 210 | + .mapToObj(index -> buildInstrumentResolutionRequest(elements.get(index), index)) |
| 211 | + .collect(Collectors.toList()); |
| 212 | + // Build resolver api request |
| 213 | + List<InstrumentResolution> criteria = |
| 214 | + instrumentResolutionMap.stream().map(Pair::getLeft).collect(Collectors.toList()); |
| 215 | + ResolutionResults results = dataProvider.getFinTagPresentation(criteria); |
| 216 | + // update financial tag element data |
| 217 | + instrumentResolutionMap.forEach(entry -> { |
| 218 | + String resolutionId = entry.getLeft().getResolutionId(); |
| 219 | + if (results != null && results.getInstruments() != null && results.getInstruments() |
| 220 | + .containsKey(resolutionId)) { |
| 221 | + entry.getRight() |
| 222 | + .setInstrument( |
| 223 | + results.getInstruments().get(resolutionId).getInstrument()); |
| 224 | + } |
| 225 | + } |
| 226 | + ); |
| 227 | + for (Tag element : elements) {element.validateFallBackTicker();} |
| 228 | + } |
| 229 | + |
| 230 | + private Pair<InstrumentResolution, Tag> buildInstrumentResolutionRequest(Tag tag, |
| 231 | + Integer order) { |
| 232 | + InstrumentResolution resolution = new InstrumentResolution(); |
| 233 | + resolution.setResolutionId(order.toString()); |
| 234 | + resolution.setBbgCompTicker(tag.getTagAttributes().getBbgcompticker()); |
| 235 | + resolution.setFigi(tag.getTagAttributes().getFigi()); |
| 236 | + resolution.setFigiTicker(tag.getTagAttributes().getFigiTicker()); |
| 237 | + resolution.setUniqueId(tag.getTagAttributes().getUniqueId()); |
| 238 | + resolution.setIsin(tag.getTagAttributes().getIsin()); |
| 239 | + resolution.setUsCode(tag.getTagAttributes().getUscode()); |
| 240 | + resolution.setFullBbgCompTicker(tag.getTagAttributes().getFullBbgCompTicker()); |
| 241 | + resolution.setLocalCode(tag.getTagAttributes().getLocalcode()); |
| 242 | + resolution.setOperationalMic(tag.getTagAttributes().getOperationalMic()); |
| 243 | + resolution.setInstrumentClass( |
| 244 | + InstrumentKind.fromValue(tag.getTagAttributes().getInstrumentclass())); |
| 245 | + resolution.setCountryCode(tag.getTagAttributes().getCountrycode()); |
| 246 | + resolution.setReturnMainListing(tag.getTagAttributes().getReturnMainListing()); |
| 247 | + resolution.setBbgMarketSector( |
| 248 | + MarketSector.fromValue(tag.getTagAttributes().getBbgmarketsector())); |
| 249 | + return new ImmutablePair<>(resolution, tag); |
| 250 | + } |
| 251 | + |
185 | 252 | } |
0 commit comments