/**
  * 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;
 }
 private void addSecurity(FinancialSecurity security) {
   FinancialSecurity clone = JodaBeanUtils.clone(security);
   SecurityDocument secDoc = _secMaster.add(new SecurityDocument(security));
   List<FinancialSecurity> securities = _securities.get(clone.getClass());
   if (securities == null) {
     securities = Lists.newArrayList();
     _securities.put(clone.getClass(), securities);
   }
   securities.add((FinancialSecurity) secDoc.getSecurity());
 }
 // -------------------------------------------------------------------------
 @Path("{versionId}")
 public WebSecurityVersionResource findVersion(@PathParam("versionId") String idStr) {
   data().setUriVersionId(idStr);
   SecurityDocument doc = data().getSecurity();
   UniqueId combined = doc.getUniqueId().withVersion(idStr);
   if (doc.getUniqueId().equals(combined) == false) {
     SecurityDocument versioned = data().getSecurityMaster().get(combined);
     data().setVersioned(versioned);
   } else {
     data().setVersioned(doc);
   }
   return new WebSecurityVersionResource(this);
 }
  // -------------------------------------------------------------------------
  @Test(enabled = false)
  public void test_equity() throws Exception {
    EquitySecurity sec = new EquitySecurity("London", "LON", "OpenGamma Ltd", Currency.GBP);
    sec.setName("OpenGamma");
    sec.setGicsCode(GICSCode.of("20102010"));
    sec.setShortName("OG");
    sec.setExternalIdBundle(ExternalIdBundle.of("Test", "OG"));
    SecurityDocument addDoc = new SecurityDocument(sec);
    SecurityDocument added = _secMaster.add(addDoc);

    SecurityDocument loaded = _secMaster.get(added.getUniqueId());
    assertEquals(added, loaded);
  }
 @Override
 public SecurityDocument update(SecurityDocument document) {
   final FudgeMsg payload = getFudgeSerializer().objectToFudgeMsg(document);
   final RestTarget target = _targetSecurity.resolve(document.getUniqueId().toString());
   s_logger.debug("update-post {} to {}", payload, target);
   final FudgeMsgEnvelope env = getRestClient().post(target, payload);
   if (env == null) {
     s_logger.debug("update-recv NULL");
     return null;
   }
   s_logger.debug("update-recv {}", env.getMessage());
   document.setUniqueId(getFudgeDeserializer().fudgeMsgToObject(UniqueId.class, env.getMessage()));
   return document;
 }
 @Override
 public SecurityDocument add(final SecurityDocument document) {
   final FudgeMsg payload = getFudgeSerializer().objectToFudgeMsg(document);
   s_logger.debug("add-post {} to {}", payload, _targetSecurity);
   final FudgeMsgEnvelope env = getRestClient().post(_targetSecurity, payload);
   if (env == null) {
     s_logger.debug("add-recv NULL");
     return null;
   }
   s_logger.debug("add-recv {}", env.getMessage());
   final UniqueId uid = getFudgeDeserializer().fudgeMsgToObject(UniqueId.class, env.getMessage());
   if (uid == null) {
     return null;
   }
   document.setUniqueId(uid);
   IdUtils.setInto(document.getSecurity(), uid);
   return document;
 }
 @Override
 public SecurityDocument correct(SecurityDocument document) {
   final FudgeMsg payload = getFudgeSerializer().objectToFudgeMsg(document);
   final RestTarget target = _targetSecurity.resolve(document.getUniqueId().toString());
   s_logger.debug("correct-put {} to {}", payload, target);
   final FudgeMsgEnvelope env = getRestClient().put(target, payload);
   if (env == null) {
     s_logger.debug("correct-recv NULL");
     return null;
   }
   s_logger.debug("correct-recv {}", env.getMessage());
   return document;
 }
  // -------------------------------------------------------------------------
  @Test(enabled = false)
  public void test_bond() throws Exception {
    ZonedDateTime zdt = ZonedDateTime.parse("2011-01-31T12:00Z[Europe/London]");
    GovernmentBondSecurity sec =
        new GovernmentBondSecurity(
            "US TREASURY N/B",
            "issuerType",
            "issuerDomicile",
            "market",
            Currency.GBP,
            SimpleYieldConvention.US_TREASURY_EQUIVALANT,
            new Expiry(zdt),
            "couponType",
            23.5d,
            SimpleFrequency.ANNUAL,
            DayCountFactory.INSTANCE.getDayCount("Act/Act"),
            zdt,
            zdt,
            zdt,
            129d,
            1324d,
            12d,
            1d,
            2d,
            3d);
    sec.addExternalId(ExternalId.of("abc", "def"));
    SecurityDocument addDoc = new SecurityDocument(sec);
    SecurityDocument added = _secMaster.add(addDoc);

    SecurityDocument loaded = _secMaster.get(added.getUniqueId());
    assertEquals(added, loaded);

    BondSecuritySearchRequest request = new BondSecuritySearchRequest();
    request.setIssuerName("*TREASURY*");
    SecuritySearchResult result = _secMaster.search(request);
    assertEquals(1, result.getDocuments().size());
    assertEquals(loaded, result.getFirstDocument());
  }
 protected void assert202(final SecurityDocument test) {
   UniqueId uniqueId = UniqueId.of("DbSec", "201", "1");
   assertNotNull(test);
   assertEquals(uniqueId, test.getUniqueId());
   assertEquals(_version2Instant, test.getVersionFromInstant());
   assertEquals(null, test.getVersionToInstant());
   assertEquals(_version2Instant, test.getCorrectionFromInstant());
   assertEquals(null, test.getCorrectionToInstant());
   ManageableSecurity security = test.getSecurity();
   assertNotNull(security);
   assertEquals(uniqueId, security.getUniqueId());
   assertEquals("TestSecurity202", security.getName());
   assertEquals("EQUITY", security.getSecurityType());
   assertEquals(
       ExternalIdBundle.of(ExternalId.of("C", "D"), ExternalId.of("E", "F")),
       security.getExternalIdBundle());
 }
  @Test
  public void test_remove_removed() {
    Instant now = Instant.now(_secMaster.getTimeSource());

    UniqueId uniqueId = UniqueId.of("DbSec", "101", "0");
    _secMaster.remove(uniqueId);
    SecurityDocument test = _secMaster.get(uniqueId);

    assertEquals(uniqueId, test.getUniqueId());
    assertEquals(_version1Instant, test.getVersionFromInstant());
    assertEquals(now, test.getVersionToInstant());
    assertEquals(_version1Instant, test.getCorrectionFromInstant());
    assertEquals(null, test.getCorrectionToInstant());
    ManageableSecurity security = test.getSecurity();
    assertNotNull(security);
    assertEquals(uniqueId, security.getUniqueId());
    assertEquals("TestSecurity101", security.getName());
    assertEquals("EQUITY", security.getSecurityType());
    assertEquals(
        ExternalIdBundle.of(
            ExternalId.of("A", "B"), ExternalId.of("C", "D"), ExternalId.of("E", "F")),
        security.getIdentifiers());
  }