WebPositionsResource extends AbstractWebPositionResource { @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON) public Response postJSON( @FormParam("quantity") String quantityStr, @FormParam("idscheme") String idScheme, @FormParam("idvalue") String idValue, @FormParam("tradesJson") String tradesJson, @FormParam("type") String type, @FormParam(POSITION_XML) String positionXml, @FormParam("uniqueIdScheme") String uniqueIdScheme) { uniqueIdScheme = StringUtils.trimToNull(uniqueIdScheme); type = StringUtils.trimToEmpty(type); URI uri = null; switch (type) { case "xml": uri = addPosition(positionXml, uniqueIdScheme); break; case StringUtils.EMPTY: quantityStr = StringUtils.replace(StringUtils.trimToNull(quantityStr), ",", ""); BigDecimal quantity = quantityStr != null && NumberUtils.isNumber(quantityStr) ? new BigDecimal(quantityStr) : null; idScheme = StringUtils.trimToNull(idScheme); idValue = StringUtils.trimToNull(idValue); tradesJson = StringUtils.trimToNull(tradesJson); if (quantity == null || idScheme == null || idValue == null) { return Response.status(Status.BAD_REQUEST).build(); } ExternalIdBundle id = ExternalIdBundle.of(ExternalId.of(idScheme, idValue)); UniqueId secUid = getSecurityUniqueId(id); if (secUid == null) { throw new DataNotFoundException("invalid " + idScheme + "~" + idValue); } Collection<ManageableTrade> trades = null; if (tradesJson != null) { trades = parseTrades(tradesJson); } else { trades = Collections.<ManageableTrade>emptyList(); } uri = addPosition(quantity, secUid, trades, uniqueIdScheme); break; default: throw new IllegalArgumentException("Can only add position by XML or completing provided web form"); } return Response.created(uri).build(); } WebPositionsResource(final PositionMaster positionMaster, final SecurityLoader securityLoader, final SecuritySource securitySource,
      final HistoricalTimeSeriesSource htsSource, final Map<ExternalScheme, String> externalSchemes); @GET @Produces(MediaType.TEXT_HTML) @SubscribeMaster(MasterType.POSITION) String getHTML(
      @QueryParam("pgIdx") Integer pgIdx,
      @QueryParam("pgNum") Integer pgNum,
      @QueryParam("pgSze") Integer pgSze,
      @QueryParam("identifier") String identifier,
      @QueryParam("minquantity") String minQuantityStr,
      @QueryParam("maxquantity") String maxQuantityStr,
      @QueryParam("positionId") List<String> positionIdStrs,
      @QueryParam("tradeId") List<String> tradeIdStrs,
      @QueryParam("uniqueIdScheme") String uniqueIdScheme); @GET @Produces(MediaType.APPLICATION_JSON) @SubscribeMaster(MasterType.POSITION) String getJSON(
      @QueryParam("pgIdx") Integer pgIdx,
      @QueryParam("pgNum") Integer pgNum,
      @QueryParam("pgSze") Integer pgSze,
      @QueryParam("identifier") String identifier,
      @QueryParam("minquantity") String minQuantityStr,
      @QueryParam("maxquantity") String maxQuantityStr,
      @QueryParam("positionId") List<String> positionIdStrs,
      @QueryParam("tradeId") List<String> tradeIdStrs,
      @QueryParam("uniqueIdScheme") String uniqueIdScheme); @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.TEXT_HTML) Response postHTML(
      @FormParam("quantity") String quantityStr,
      @FormParam("idscheme") String idScheme,
      @FormParam("idvalue") String idValue,
      @FormParam("type") String type,
      @FormParam(POSITION_XML) String positionXml,
      @FormParam("uniqueIdScheme") String uniqueIdScheme); @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_JSON) Response postJSON(
      @FormParam("quantity") String quantityStr,
      @FormParam("idscheme") String idScheme,
      @FormParam("idvalue") String idValue,
      @FormParam("tradesJson") String tradesJson,
      @FormParam("type") String type,
      @FormParam(POSITION_XML) String positionXml,
      @FormParam("uniqueIdScheme") String uniqueIdScheme); @Path("{positionId}") WebPositionResource findPosition(@Subscribe @PathParam("positionId") String idStr); static URI uri(WebPositionsData data);  }
@Test public void testAddPositionWithTrades() throws Exception { String tradesJson = getTradesJson(); Response response = _webPositionsResource.postJSON("10", SEC_ID.getScheme().getName(), SEC_ID.getValue(), tradesJson, null, null, null); assertNotNull(response); assertEquals(201, response.getStatus()); assertEquals("/positions/MemPos~1", getActualURL(response)); assertPositionAndTrades(); }
@Test public void testAddPositionWithEmptyTrades() throws Exception { String tradesJson = EMPTY_TRADES; Response response = _webPositionsResource.postJSON("10", SEC_ID.getScheme().getName(), SEC_ID.getValue(), tradesJson, null, null, null); assertNotNull(response); assertEquals(201, response.getStatus()); assertEquals("/positions/MemPos~1", getActualURL(response)); assertPositionWithNoTrades(); }
@Test public void testAddPositionWithNoTrades() throws Exception { Response response = _webPositionsResource.postJSON("10", SEC_ID.getScheme().getName(), SEC_ID.getValue(), null, null, null, null); assertNotNull(response); assertEquals(201, response.getStatus()); assertEquals("/positions/MemPos~1", getActualURL(response)); assertPositionWithNoTrades(); }