예제 #1
0
 private String getOrderDetails() {
   StringBuilder output = new StringBuilder();
   for (Order order : orders) {
     output.append(order.toString());
   }
   return output.toString();
 }
예제 #2
0
  public String orderArrayToString() {
    StringBuilder orderString = new StringBuilder();
    int i = 1;
    for (Order order : myOrders) {
      orderString.append(String.format("%d. %s\n", i++, order.toString()));
    }

    return orderString.toString();
  }
    @Override
    public String respond(HttpExchange httpExchange) {
      InputStream body = httpExchange.getRequestBody();

      try {

        Order order = objectMapper.readValue(body, Order.class);
        logger.error(order.toString());

        Integer perc = COUNTRIES.get(order.getCountry());

        //     Optional<Reduction> reduction = Reduction.valueOfFrom(order.getReduction());

        if ("STANDARD".equalsIgnoreCase(order.getReduction()) && perc != null) {
          Double total = order.totalWithPerc(perc);

          total = getTotalWithReduction(total);
          String totalResponse = generateAndLog(total);
          return totalResponse;

        } else if ("HALF PRICE".equals(order.getReduction()) && perc != null) {
          Double total = order.totalWithPerc(perc);

          total = total / 2;
          String totalResponse = generateAndLog(total);
          return totalResponse;

        } else if ("PAY THE PRICE".equals(order.getReduction()) && perc != null) {
          Double total = order.totalWithPerc(perc);
          String totalResponse = generateAndLog(total);
          return totalResponse;
        } else {

          logger.error("ATTENTION NON GERE : ");
          String method = httpExchange.getRequestMethod();
          String uri = httpExchange.getRequestURI().getPath();
          logger.log(method + " " + uri + " " + stringify(httpExchange.getRequestBody()));
        }

        //                logger.log(message.getType() + ": " + message.getContent());
      } catch (IOException exception) {
        logger.error(exception.getMessage());
      }

      return NO_CONTENT;
    }
예제 #4
0
  public Videos search(String keyword, Type type, Sort sort, Order order) throws CMException {

    ReadApi api = getReadApi();

    Videos result = null;
    try {

      String token = getReadToken();
      switch (type) {
        case NAME:
          result = api.FindVideosByText(token, keyword, LIMIT, 0, FIELDS, CUSTOM_FIELDS);
          break;

        case TAG:
          Set<String> tags = new HashSet<String>(Arrays.asList(keyword.split(" ")));
          result =
              api.FindVideosByTags(
                  token,
                  EMPTY,
                  tags,
                  LIMIT,
                  0,
                  SortByTypeEnum.valueOf(sort.toString()),
                  SortOrderTypeEnum.valueOf(order.toString()),
                  FIELDS,
                  CUSTOM_FIELDS);
          break;

        case REFERENCE_ID:
          Set<String> ids = new HashSet<String>(Arrays.asList(keyword.split(" ")));
          result = api.FindVideosByReferenceIds(token, ids, FIELDS, CUSTOM_FIELDS);
          break;
      }
    } catch (BrightcoveException e) {
      throw new CMException(e.getMessage(), e);
    }

    return result;
  }
예제 #5
0
파일: Cosm.java 프로젝트: nuest/JCosmAPI
  /**
   * returns a list of feed objects based on a number of optional query parameters. If set to {@link
   * null}, a parameter is ignored.
   *
   * @param query Full text {@link String} search parameter. Should return any feeds matching this
   *     string
   * @param content parameter of type {@link Content} describing the type of results
   * @param tag Returns feeds containing datastreams tagged with the search query
   * @param user Returns feeds created by the user specified.
   * @param units Returns feeds containing datastreams with units specified by the search query.
   * @param status Parameter of type {@link Status}
   * @param order Parameter of type {@link Order}. Used for ordering the results.
   * @param show_user Include user login and user level for each feed. {@link Boolean} with possible
   *     values: true, false (default)
   * @param lat Used to find feeds located around this latitude. Used if ids/_datastreams_ are not
   *     specified.
   * @param lon Used to find feeds located around this longitude. Used if ids/_datastreams_ are not
   *     specified.
   * @param distance search radius
   * @param distance_units miles or kms
   * @return Array of {@link Feed} objects
   * @throws CosmException
   */
  public Feed[] getFeeds(
      String query,
      Content content,
      String tag,
      String user,
      String units,
      Status status,
      Order order,
      Boolean show_user,
      Double lat,
      Double lon,
      Double distance,
      DistanceUnit distance_units)
      throws CosmException {
    String q = "";
    boolean bAdd = false;

    if (query != null) {
      if (bAdd) q += '&';
      q += "q=" + query;
      bAdd = true;
    }
    if (content != null) {
      if (bAdd) q += '&';
      q += "content=" + content.toString();
      bAdd = true;
    }
    if (tag != null) {
      if (bAdd) q += '&';
      q += "tag=" + tag;
      bAdd = true;
    }
    if (user != null) {
      if (bAdd) q += '&';
      q += "user="******"units=" + units;
      bAdd = true;
    }
    if (status != null) {
      if (bAdd) q += '&';
      q += "status=" + status.toString();
      bAdd = true;
    }
    if (order != null) {
      if (bAdd) q += '&';
      q += "order=" + order.toString();
      bAdd = true;
    }
    if (show_user != null) {
      if (bAdd) q += '&';
      q += "show_user="******"lat=" + lat;
      bAdd = true;
    }
    if (lon != null) {
      if (bAdd) q += '&';
      q += "lon=" + lon;
      bAdd = true;
    }
    if (distance != null) {
      if (bAdd) q += '&';
      q += "distance=" + distance;
      bAdd = true;
    }
    if (distance_units != null) {
      if (bAdd) q += '&';
      q += "distance_units=" + distance_units.toString();
      bAdd = true;
    }

    try {
      URI uri =
          new URI(
              API_SCHEME,
              API_HOST,
              API_VERSION + API_RESOURCE_FEEDS + JSON_FILE_EXTENSION,
              q,
              null);
      HttpGet hr = new HttpGet(uri);
      HttpResponse response = this.client.execute(hr);
      StatusLine statusLine = response.getStatusLine();
      String body = this.client.getBody(response);
      if (statusLine.getStatusCode() == 200) {
        return CosmFactory.toFeeds(body);
      }
      throw new CosmException(statusLine, body);
    } catch (IOException e) {
      throw new CosmException(IO_EXCEPTION_MESSAGE);
    } catch (URISyntaxException e) {
      throw new CosmException(URL_SYNTAX_EXCEPTION_MESSAGE);
    }
  }
예제 #6
0
  public String toString(final int indent) {
    final StringBuilder builder = new StringBuilder();
    String indentString = "";

    for (int index = 0; index < indent; index++) {
      indentString += ' ';
    }

    builder
        .append(indentString)
        .append("Selection Id      : ")
        .append(getSelectionId())
        .append('\n');
    builder.append(indentString).append("Handicap          : ").append(getHandicap()).append('\n');
    builder.append(indentString).append("Status            : ").append(getStatus()).append('\n');
    builder
        .append(indentString)
        .append("Adjustment Factor : ")
        .append(getAdjustmentFactor())
        .append('\n');
    builder
        .append(indentString)
        .append("Last Odds Traded  : ")
        .append(getLastOddsTraded())
        .append('\n');
    builder
        .append(indentString)
        .append("Total Matched     : ")
        .append(getTotalMatched())
        .append('\n');
    builder
        .append(indentString)
        .append("Removal Date      : ")
        .append(getRemovalDate())
        .append('\n');

    if (getStartingPrices() == null) {
      builder.append(indentString).append("Starting Prices   : ").append("Not Set").append('\n');
    } else {
      builder
          .append(indentString)
          .append("Starting Prices   : ")
          .append('\n')
          .append(getStartingPrices().toString(indent + Indent.INDENT_SIZE));
    }

    if (getExchangePrices() == null) {
      builder.append(indentString).append("Exchange Prices   : ").append("Not Set").append('\n');
    } else {
      builder
          .append(indentString)
          .append("Exchange Prices   : ")
          .append('\n')
          .append(getExchangePrices().toString(indent + Indent.INDENT_SIZE));
    }

    builder.append(indentString).append("Orders            : ").append('\n');

    for (final Order order : getOrders()) {
      builder.append(order.toString(indent + Indent.INDENT_SIZE)).append('\n');
    }

    builder.append(indentString).append("Matches           : ").append('\n');

    for (final Match match : getMatches()) {
      builder.append(match.toString(indent + Indent.INDENT_SIZE)).append('\n');
    }

    return builder.toString();
  }