/** * Converts an FpML 'AdjustableDate' or 'AdjustableDate2' to an {@code AdjustableDate}. * * @param baseEl the FpML adjustable date element * @return the adjustable date * @throws RuntimeException if unable to parse */ public AdjustableDate parseAdjustableDate(XmlElement baseEl) { // FpML content: ('unadjustedDate', 'dateAdjustments', 'adjustedDate?') Optional<XmlElement> unadjOptEl = baseEl.findChild("unadjustedDate"); if (unadjOptEl.isPresent()) { LocalDate unadjustedDate = parseDate(unadjOptEl.get()); Optional<XmlElement> adjustmentOptEl = baseEl.findChild("dateAdjustments"); Optional<XmlElement> adjustmentRefOptEl = baseEl.findChild("dateAdjustmentsReference"); if (!adjustmentOptEl.isPresent() && !adjustmentRefOptEl.isPresent()) { return AdjustableDate.of(unadjustedDate); } XmlElement adjustmentEl = adjustmentRefOptEl.isPresent() ? lookupReference(adjustmentRefOptEl.get()) : adjustmentOptEl.get(); BusinessDayAdjustment adjustment = parseBusinessDayAdjustments(adjustmentEl); return AdjustableDate.of(unadjustedDate, adjustment); } LocalDate adjustedDate = parseDate(baseEl.getChild("adjustedDate")); return AdjustableDate.of(adjustedDate); }
/** * Converts an FpML 'BusinessCentersOrReference.model' to a {@code HolidayCalendar}. * * @param baseEl the FpML business centers or reference element to parse * @return the holiday calendar * @throws RuntimeException if unable to parse */ public HolidayCalendarId parseBusinessCenters(XmlElement baseEl) { // FpML content: ('businessCentersReference' | 'businessCenters') // FpML 'businessCenters' content: ('businessCenter+') // Each 'businessCenter' is a location treated as a holiday calendar Optional<XmlElement> optionalBusinessCentersEl = baseEl.findChild("businessCenters"); XmlElement businessCentersEl = optionalBusinessCentersEl.orElseGet(() -> lookupReference(baseEl.getChild("businessCentersReference"))); HolidayCalendarId calendar = HolidayCalendarIds.NO_HOLIDAYS; for (XmlElement businessCenterEl : businessCentersEl.getChildren("businessCenter")) { calendar = calendar.combinedWith(parseBusinessCenter(businessCenterEl)); } return calendar; }
public void document() { XmlElement tradeDateEl = XmlElement.ofContent("tradeDate", "2000-06-30"); XmlElement tradeHeaderEl = XmlElement.ofChildren("tradeHeader", ImmutableList.of(tradeDateEl)); XmlElement tradeEl = XmlElement.ofChildren("trade", ImmutableMap.of("href", "foo"), ImmutableList.of(tradeHeaderEl)); XmlElement rootEl = XmlElement.ofChildren("dataDocument", ImmutableList.of(tradeEl)); FpmlDocument test = new FpmlDocument(rootEl, ImmutableMap.of(), FpmlPartySelector.any(), FpmlTradeInfoParserPlugin.standard(), REF_DATA); assertEquals(test.getFpmlRoot(), rootEl); assertEquals(test.getParties(), ImmutableListMultimap.of()); assertEquals(test.getReferences(), ImmutableMap.of()); assertEquals(test.getOurPartyHrefIds(), ImmutableList.of()); assertThrows(() -> test.lookupReference(tradeEl), FpmlParseException.class, ".*reference not found.*"); assertThrows(() -> test.validateNotPresent(tradeEl, "tradeHeader"), FpmlParseException.class, ".*tradeHeader.*"); }
XmlElement relativeToEl = lookupReference(baseEl.getChild("dateRelativeTo")); LocalDate baseDate; if (relativeToEl.hasContent()) {