Пример #1
0
  // -------------------------------------------------------------------------
  @PUT
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Produces(MediaType.TEXT_HTML)
  public Response putHTML(@FormParam("name") String name, @FormParam("configxml") String xml) {
    if (data().getConfig().isLatest() == false) {
      return Response.status(Status.FORBIDDEN).entity(getHTML()).build();
    }

    name = StringUtils.trimToNull(name);
    xml = StringUtils.trimToNull(xml);
    if (name == null || xml == null) {
      FlexiBean out = createRootData();
      if (name == null) {
        out.put("err_nameMissing", true);
      }
      if (xml == null) {
        out.put("err_xmlMissing", true);
      }
      String html = getFreemarker().build("configs/config-update.ftl", out);
      return Response.ok(html).build();
    }

    URI uri = updateConfig(name, parseXML(xml));
    return Response.seeOther(uri).build();
  }
Пример #2
0
 /**
  * Creates the output root data.
  *
  * @return the output root data, not null
  */
 protected FlexiBean createRootData() {
   FlexiBean out = super.createRootData();
   ConfigDocument doc = data().getConfig();
   out.put("configDoc", doc);
   out.put("config", doc.getConfig().getValue());
   out.put("deleted", !doc.isLatest());
   return out;
 }
 /**
  * Creates the output root data.
  *
  * @return the output root data, not null
  */
 @Override
 protected FlexiBean createRootData() {
   FlexiBean out = super.createRootData();
   SecurityDocument doc = data().getSecurity();
   out.put("securityDoc", doc);
   out.put("security", doc.getSecurity());
   out.put("deleted", !doc.isLatest());
   return out;
 }
Пример #4
0
 /**
  * Creates the output root data.
  *
  * @return the output root data, not null
  */
 protected FlexiBean createRootData() {
   FlexiBean out = super.createRootData();
   PortfolioDocument doc = data().getPortfolio();
   out.put("portfolioDoc", doc);
   out.put("portfolio", doc.getPortfolio());
   out.put("childNodes", doc.getPortfolio().getRootNode().getChildNodes());
   out.put("deleted", !doc.isLatest());
   out.put("rootNode", doc.getPortfolio().getRootNode());
   return out;
 }
  // -------------------------------------------------------------------------
  @GET
  public String getHTML() {
    SecurityHistoryRequest request = new SecurityHistoryRequest(data().getSecurity().getUniqueId());
    SecurityHistoryResult result = data().getSecurityMaster().history(request);

    FlexiBean out = createRootData();
    out.put("versionsResult", result);
    out.put("versions", result.getSecurities());
    return getFreemarker().build(HTML_DIR + "securityversions.ftl", out);
  }
Пример #6
0
  private FlexiBean createPortfolioData() {
    PortfolioDocument doc = data().getPortfolio();
    PositionSearchRequest positionSearch = new PositionSearchRequest();
    positionSearch.setPositionObjectIds(doc.getPortfolio().getRootNode().getPositionIds());
    PositionSearchResult positionsResult = data().getPositionMaster().search(positionSearch);

    FlexiBean out = createRootData();
    out.put("positionsResult", positionsResult);
    out.put("positions", positionsResult.getPositions());
    return out;
  }
Пример #7
0
 // -------------------------------------------------------------------------
 @GET
 @Produces(MediaType.TEXT_HTML)
 public String getHTML() {
   FlexiBean out = createRootData();
   ConfigDocument doc = data().getConfig();
   out.put("configXml", createXML(doc));
   return getFreemarker().build("configs/config.ftl", out);
 }
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Response getJSON(
      @QueryParam("pgIdx") Integer pgIdx,
      @QueryParam("pgNum") Integer pgNum,
      @QueryParam("pgSze") Integer pgSze) {
    PagingRequest pr = buildPagingRequest(pgIdx, pgNum, pgSze);
    SecurityHistoryRequest request = new SecurityHistoryRequest(data().getSecurity().getUniqueId());
    request.setPagingRequest(pr);
    SecurityHistoryResult result = data().getSecurityMaster().history(request);

    FlexiBean out = createRootData();
    out.put("versionsResult", result);
    out.put("versions", result.getSecurities());
    out.put("paging", new WebPaging(result.getPaging(), data().getUriInfo()));
    String json = getFreemarker().build(JSON_DIR + "securityversions.ftl", out);
    return Response.ok(json).build();
  }
Пример #9
0
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 public Response getJSON(@Context Request request) {
   EntityTag etag = new EntityTag(data().getConfig().getUniqueId().toString());
   ResponseBuilder builder = request.evaluatePreconditions(etag);
   if (builder != null) {
     return builder.build();
   }
   FlexiBean out = createRootData();
   ConfigDocument doc = data().getConfig();
   String jsonConfig = StringUtils.stripToNull(toJSON(doc.getConfig().getValue(), doc.getType()));
   if (jsonConfig != null) {
     out.put("configJSON", jsonConfig);
   } else {
     out.put("configXML", StringEscapeUtils.escapeJavaScript(createXML(doc)));
   }
   out.put("type", doc.getType().getName());
   String json = getFreemarker().build("configs/jsonconfig.ftl", out);
   return Response.ok(json).tag(etag).build();
 }
 /**
  * Builds the Freemarker template creating the output string.
  *
  * @param template the template, not null
  * @param data the root data to merge, not null
  * @return the template, not null
  */
 @SuppressWarnings("unchecked")
 public String build(final Template template, final Object data) {
   if (data instanceof FlexiBean) {
     ((FlexiBean) data).put("freemarkerTemplateName", template.getName());
     ((FlexiBean) data).put("freemarkerLocale", template.getLocale());
     ((FlexiBean) data).put("freemarkerVersion", Configuration.getVersionNumber());
   }
   if (data instanceof Map<?, ?>) {
     ((Map<String, Object>) data).put("freemarkerTemplateName", template.getName());
     ((Map<String, Object>) data).put("freemarkerLocale", template.getLocale());
     ((Map<String, Object>) data).put("freemarkerVersion", Configuration.getVersionNumber());
   }
   try {
     StringWriter out = new StringWriter(1024 * 4);
     template.process(data, out);
     out.close();
     return out.toString();
   } catch (Exception ex) {
     return handleException(ex);
   }
 }
Пример #11
0
 /**
  * Creates the output root data.
  *
  * @return the output root data, not null
  */
 protected FlexiBean createRootData() {
   FlexiBean out = super.createRootData();
   HolidayDocument latestDoc = data().getHoliday();
   HolidayDocument versionedHoliday = data().getVersioned();
   out.put("latestHolidayDoc", latestDoc);
   out.put("latestHoliday", latestDoc.getHoliday());
   out.put("holidayDoc", versionedHoliday);
   out.put("holiday", versionedHoliday.getHoliday());
   out.put("deleted", !latestDoc.isLatest());
   List<Pair<Year, List<LocalDate>>> map = new ArrayList<Pair<Year, List<LocalDate>>>();
   List<LocalDate> dates = versionedHoliday.getHoliday().getHolidayDates();
   if (dates.size() > 0) {
     int year = dates.get(0).getYear();
     int start = 0;
     int pos = 0;
     for (; pos < dates.size(); pos++) {
       if (dates.get(pos).getYear() == year) {
         continue;
       }
       map.add(Pair.of(Year.of(year), dates.subList(start, pos)));
       year = dates.get(pos).getYear();
       start = pos;
     }
     map.add(Pair.of(Year.of(year), dates.subList(start, pos)));
   }
   out.put("holidayDatesByYear", map);
   return out;
 }
Пример #12
0
 /** Tests failure for empty sector classifications. */
 @Test(expectedExceptions = IllegalStateException.class)
 public void testEmptySectorClassifications() {
   final FlexiBean classifications = new FlexiBean();
   classifications.put(GICSCode.NAME, GICSCode.of("1020"));
   final Sector sector = Sector.of("INDUSTRIALS", classifications);
   final LegalEntitySector filter = new LegalEntitySector();
   filter.setClassifications(Collections.singleton(ICBCode.NAME));
   filter.getFilteredData(
       new LegalEntity(
           LegalEntityTest.TICKER,
           LegalEntityTest.SHORT_NAME,
           LegalEntityTest.CREDIT_RATINGS,
           sector,
           LegalEntityTest.REGION));
 }
Пример #13
0
  // -------------------------------------------------------------------------
  @PUT
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Produces(MediaType.TEXT_HTML)
  public Response putHTML(@FormParam("name") String name, @FormParam("hidden") Boolean isHidden) {
    PortfolioDocument doc = data().getPortfolio();
    if (doc.isLatest() == false) {
      return Response.status(Status.FORBIDDEN).entity(getHTML()).build();
    }

    name = StringUtils.trimToNull(name);
    DocumentVisibility visibility =
        BooleanUtils.isTrue(isHidden) ? DocumentVisibility.HIDDEN : DocumentVisibility.VISIBLE;
    if (name == null) {
      FlexiBean out = createRootData();
      out.put("err_nameMissing", true);
      String html = getFreemarker().build("portfolios/portfolio-update.ftl", out);
      return Response.ok(html).build();
    }
    URI uri = updatePortfolio(name, visibility, doc);
    return Response.seeOther(uri).build();
  }
Пример #14
0
  protected void addSecuritySpecificMetaData(ManageableSecurity security, FlexiBean out) {
    if (security.getSecurityType().equals(SwapSecurity.SECURITY_TYPE)) {
      SwapSecurity swapSecurity = (SwapSecurity) security;
      out.put("payLegType", swapSecurity.getPayLeg().accept(new SwapLegClassifierVisitor()));
      out.put(
          "receiveLegType", swapSecurity.getReceiveLeg().accept(new SwapLegClassifierVisitor()));
    }
    if (security.getSecurityType().equals(FutureSecurity.SECURITY_TYPE)) {
      FutureSecurity futureSecurity = (FutureSecurity) security;
      out.put("futureSecurityType", futureSecurity.accept(new FutureSecurityTypeVisitor()));
      out.put("basket", getBondFutureBasket(security));
      Security underlyingSecurity = getUnderlyingFutureSecurity(futureSecurity);
      if (underlyingSecurity != null) {
        out.put("underlyingSecurity", underlyingSecurity);
      }
    }
    if (security.getSecurityType().equals(EquityOptionSecurity.SECURITY_TYPE)) {
      EquityOptionSecurity equityOption = (EquityOptionSecurity) security;
      addUnderlyingSecurity(out, equityOption.getUnderlyingId());
    }
    if (security.getSecurityType().equals(IRFutureOptionSecurity.SECURITY_TYPE)) {
      IRFutureOptionSecurity irFutureOption = (IRFutureOptionSecurity) security;
      addUnderlyingSecurity(out, irFutureOption.getUnderlyingId());
    }
    if (security.getSecurityType().equals(SwaptionSecurity.SECURITY_TYPE)) {
      SwaptionSecurity swaptionSecurity = (SwaptionSecurity) security;
      addUnderlyingSecurity(out, swaptionSecurity.getUnderlyingId());
    }
    if (security.getSecurityType().equals(EquityBarrierOptionSecurity.SECURITY_TYPE)) {
      EquityBarrierOptionSecurity equityBarrierOptionSecurity =
          (EquityBarrierOptionSecurity) security;
      addUnderlyingSecurity(out, equityBarrierOptionSecurity.getUnderlyingId());
    }
    if (security.getSecurityType().equals(CapFloorSecurity.SECURITY_TYPE)) {
      CapFloorSecurity capFloorSecurity = (CapFloorSecurity) security;
      addUnderlyingSecurity(out, capFloorSecurity.getUnderlyingId());
    }
    if (security.getSecurityType().equals(CapFloorCMSSpreadSecurity.SECURITY_TYPE)) {
      CapFloorCMSSpreadSecurity capFloorCMSSpreadSecurity = (CapFloorCMSSpreadSecurity) security;
      Security shortUnderlying = getSecurity(capFloorCMSSpreadSecurity.getShortId());
      Security longUnderlying = getSecurity(capFloorCMSSpreadSecurity.getLongId());
      if (shortUnderlying != null) {
        out.put("shortSecurity", shortUnderlying);
      }
      if (longUnderlying != null) {
        out.put("longSecurity", longUnderlying);
      }
    }
    if (security.getSecurityType().equals(EquityIndexOptionSecurity.SECURITY_TYPE)) {
      EquityIndexOptionSecurity equityIndxOption = (EquityIndexOptionSecurity) security;
      addUnderlyingSecurity(out, equityIndxOption.getUnderlyingId());
    }
    if (security.getSecurityType().equals(FRASecurity.SECURITY_TYPE)) {
      FRASecurity fraSecurity = (FRASecurity) security;
      addUnderlyingSecurity(out, fraSecurity.getUnderlyingId());
    }
    if (security.getSecurityType().equals(SecurityEntryData.EXTERNAL_SENSITIVITIES_SECURITY_TYPE)) {
      RawSecurity rawSecurity = (RawSecurity) security;
      FudgeMsgEnvelope msg =
          OpenGammaFudgeContext.getInstance().deserialize(rawSecurity.getRawData());
      SecurityEntryData securityEntryData =
          OpenGammaFudgeContext.getInstance()
              .fromFudgeMsg(SecurityEntryData.class, msg.getMessage());

      out.put("securityEntryData", securityEntryData);
      out.put("securityAttributes", security.getAttributes());
      RawSecurity underlyingRawSecurity =
          (RawSecurity) getSecurity(securityEntryData.getFactorSetId());
      if (underlyingRawSecurity != null) {
        FudgeMsgEnvelope factorIdMsg =
            OpenGammaFudgeContext.getInstance().deserialize(underlyingRawSecurity.getRawData());
        @SuppressWarnings("unchecked")
        List<FactorExposureData> factorExposureDataList =
            OpenGammaFudgeContext.getInstance().fromFudgeMsg(List.class, factorIdMsg.getMessage());
        s_logger.error(factorExposureDataList.toString());
        List<FactorExposure> factorExposuresList = convertToFactorExposure(factorExposureDataList);
        out.put("factorExposuresList", factorExposuresList);
      } else {
        s_logger.error("Couldn't find security");
      }
    }
    if (security
        .getSecurityType()
        .equals(FactorExposureData.EXTERNAL_SENSITIVITIES_RISK_FACTORS_SECURITY_TYPE)) {
      RawSecurity rawSecurity = (RawSecurity) security;
      FudgeMsgEnvelope msg =
          OpenGammaFudgeContext.getInstance().deserialize(rawSecurity.getRawData());
      @SuppressWarnings("unchecked")
      List<FactorExposureData> factorExposureDataList =
          OpenGammaFudgeContext.getInstance().fromFudgeMsg(List.class, msg.getMessage());
      List<FactorExposure> factorExposuresList = convertToFactorExposure(factorExposureDataList);
      out.put("factorExposuresList", factorExposuresList);
    }
  }
Пример #15
0
 private void addUnderlyingSecurity(FlexiBean out, ExternalId externalId) {
   Security underlyingSec = getSecurity(externalId);
   if (underlyingSec != null) {
     out.put("underlyingSecurity", underlyingSec);
   }
 }
Пример #16
0
 /**
  * Creates the output root data.
  *
  * @return the output root data, not null
  */
 protected FlexiBean createRootData() {
   FlexiBean out = getFreemarker().createRootData();
   out.put("homeUris", new WebHomeUris(data().getUriInfo()));
   out.put("uris", new WebSecuritiesUris(data()));
   return out;
 }
 /**
  * Creates a new Freemarker root data map.
  *
  * @return the root data map, not null
  */
 public FlexiBean createRootData() {
   FlexiBean data = new FlexiBean();
   data.put("now", ZonedDateTime.now());
   return data;
 }