예제 #1
0
  public CommandMessage parser(
      OrderRoutingInstance instance, ProductRoute orderRoute, CommandMessage order)
      throws Exception {
    Exception error = null;

    try {
      // check SMS syntax
      if (order.getChannel().equals("SMS")) {
        smsParser(instance, orderRoute, order);
      }

      if (order.getStatus() != Constants.ORDER_STATUS_DENIED) {
        order.setCause(orderRoute.getKeyword());

        order.setStatus(Constants.ORDER_STATUS_APPROVED);

        SubscriberCampaignImpl.createCampaignEvent(
            order.getUserId(),
            order.getUserName(),
            order.getOrderId(),
            order.getOrderDate(),
            order.getSubscriberId(),
            order.getSubProductId(),
            order.getIsdn(),
            order.getSubscriberType(),
            order.getProductId(),
            order.getServiceAddress(),
            order.getKeyword(),
            order.getCampaignId(),
            order.getSegmentId(),
            null,
            Constants.DEFAULT_ID,
            "",
            Constants.ORDER_STATUS_PENDING);
      }
    } catch (Exception e) {
      error = e;
    }

    if (error != null) {
      order.setStatus(Constants.ORDER_STATUS_DENIED);

      if (error instanceof AppException) {
        order.setCause(error.getMessage());
      } else {
        order.setDescription(error.getMessage());
      }
    }

    if ((error != null) && !(error instanceof AppException)) {
      throw error;
    }

    return order;
  }
예제 #2
0
  public boolean getBalanceQuery(
      CommandInstance instance, ProvisioningCommand provisioningCommand, CommandMessage request)
      throws Exception {
    Connection connection = Database.getConnection();

    PreparedStatement stmtUsage = null;
    ResultSet rsUsage = null;

    PreparedStatement stmtBalance = null;
    ResultSet rsBalance = null;
    try {
      request.setCause("success");

      double balanceAmount = 0.0D;

      String SQL =
          "Select * From SubscriberBalance Where sourceAddress = ? and balanceType = 'LOYALTY' ";

      stmtBalance = connection.prepareStatement(SQL);
      stmtBalance.setString(1, request.getIsdn());

      rsBalance = stmtBalance.executeQuery();

      if (rsBalance.next()) {
        balanceAmount = rsBalance.getDouble("balanceAmount");
      } else {
        throw new AppException(NOT_REGISTERED);
      }

      SQL =
          "Select * From SubscriberRank Where cycleDate = ? and sourceAddress = ? and balanceType = 'LOYALTY'";

      stmtUsage = connection.prepareStatement(SQL);

      stmtUsage.setDate(1, new java.sql.Date(request.getCycleDate().getTime()));
      stmtUsage.setString(2, request.getIsdn());

      rsUsage = stmtUsage.executeQuery();

      String response = "";

      double totalAmount = 0.0D;

      RankEntry rankRule = null;

      String rankStartDate = "";
      String rankExpirationDate = "";

      if (rsUsage.next()) {
        request.setCause("success");

        if (rsUsage.getDate("expirationDate") == null) {
          request.setCause("not-exist");
        } else {
          rankRule = RankFactory.getCache().getRank(rsUsage.getLong("rankId"));
        }

        totalAmount = rsUsage.getDouble("totalAmount");

        SimpleDateFormat formatDate = new SimpleDateFormat("dd/MM/yyyy");
        if (rsUsage.getDate("startDate") != null) {
          rankStartDate = formatDate.format(rsUsage.getDate("startDate"));
        }
        if (rsUsage.getDate("expirationDate") != null) {
          rankExpirationDate = formatDate.format(rsUsage.getDate("expirationDate"));
        }
      } else {
        request.setCause(NOT_REGISTERED);
      }

      // response = ProductFactory.getCache().getProductMessage(request, "vni");

      if (rankRule != null) {
        response =
            response.replaceAll(
                "<totalAmount>", String.valueOf(new Double(totalAmount).longValue()));
        response =
            response.replaceAll(
                "<balanceAmount>", String.valueOf(new Double(balanceAmount).longValue()));
        response = response.replaceAll("<fromDate>", rankStartDate);
        response = response.replaceAll("<toDate>", rankExpirationDate);
        response = response.replaceAll("<rank>", rankRule.getTitle());
      }

      // instance.getDispatcher().sendSMS(request, request.getServiceAddress(), request.getIsdn(),
      // response);

      request.setStatus(0);
    } catch (AppException e) {
      request.setCause(e.getMessage());
    } catch (Exception e) {
      throw e;
    } finally {
      Database.closeObject(rsUsage);
      Database.closeObject(stmtUsage);
      Database.closeObject(rsBalance);
      Database.closeObject(stmtBalance);

      Database.closeObject(connection);
    }
    return true;
  }
예제 #3
0
  public CommandMessage sendOrder(Object request, String correlationId, long timeout)
      throws Exception {
    if (timeout <= 0) {
      timeout = 30000;
    }

    long startTime = System.currentTimeMillis();

    QueueSession session = null;
    MessageProducer producer = null;
    Message message = null;
    Message callBack = null;

    CommandMessage response = null;

    if (request instanceof CommandMessage) {
      response = (CommandMessage) request;
    } else {
      response = new CommandMessage();
    }

    try {
      Queue sendQueue = QueueFactory.getQueue(QueueFactory.ORDER_REQUEST_QUEUE);
      session = QueueFactory.getSession();
      message = QueueFactory.createObjectMessage(session, request);
      producer = session.createProducer(sendQueue);

      try {
        long beforeSend = System.currentTimeMillis();
        producer.send(message);
        long afterSend = System.currentTimeMillis();
        log.info(
            "Send:"
                + (afterSend - beforeSend)
                + ((afterSend - beforeSend) > 20 ? "|high" : "|low")
                + "|SessionId:"
                + correlationId);
      } catch (Exception ex) {
        log.info("Send message error");
        throw ex;
      } finally {
        QueueFactory.closeQueue(producer);
        QueueFactory.closeQueue(session);
      }
      if (!correlationId.equals("")) {
        startTime = System.currentTimeMillis();
        long beforeReceive = System.currentTimeMillis();

        QueueFactory.callbackListerner.put(message.getJMSCorrelationID(), message);
        synchronized (message) {
          try {
            message.wait(timeout);
          } catch (Exception e) {

          } finally {
            callBack = (Message) QueueFactory.callbackOrder.remove(message.getJMSCorrelationID());
            QueueFactory.callbackListerner.remove(message.getJMSCorrelationID());
          }
        }

        long afterReceive = System.currentTimeMillis();

        log.info(
            "Receive:"
                + (afterReceive - beforeReceive)
                + ((afterReceive - beforeReceive) > 300 ? "|high " : "|low")
                + "|SessionId:'"
                + correlationId);
      }
      if (callBack == null) {
        throw new AppException("time-out");
      }
      Object content = QueueFactory.getContentMessage(callBack);

      if (content != null) {
        if (content instanceof CommandMessage) {
          response = (CommandMessage) content;
        } else {
          response.setStatus(Constants.ORDER_STATUS_DENIED);
          response.setCause(Constants.ERROR);
        }
      } else {
        response.setStatus(Constants.ORDER_STATUS_DENIED);
        response.setCause(Constants.ERROR_TIMEOUT);
      }

      log.info(
          "Cost time:" + (System.currentTimeMillis() - startTime) + "|sessionId:" + correlationId);
    } catch (Exception e) {
      log.info(e);
      response.setStatus(Constants.ORDER_STATUS_DENIED);
      response.setCause(Constants.ERROR_RESOURCE_BUSY);
      throw e;
    } finally {
    }

    if ((response != null) && (response.getStatus() == Constants.ORDER_STATUS_DENIED)) {
      log.error("sessionId = " + correlationId + ", timeout = " + timeout + " : " + response);
    }

    return response;
  }