예제 #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;
  }
  @Override
  public void checkPromotion(
      OrderRoutingInstance instance, ProductRoute orderRoute, CommandMessage order)
      throws Exception {
    if (order.getActionType().equals(Constants.ACTION_REGISTER)) {
      String strSQL_Select =
          "select statis_list_id, status "
              + " from max_sms_promotion_eligible "
              + " where 1 = 1 "
              + "       and isdn = ? "
              + "       and status = ? ";

      String strISDN = order.getIsdn();

      Connection connection = null;
      PreparedStatement stmt = null;
      ResultSet rs = null;
      try {
        connection = Database.getConnection();
        stmt = connection.prepareStatement(strSQL_Select);
        stmt.setString(1, strISDN);
        stmt.setInt(2, Constants.STATUS_INACTIVE);
        rs = stmt.executeQuery();
        if (!rs.next()) {
          throw new AppException(Constants.ERROR_INVALID_PROMOTION);
        } else {
          int iStatus = rs.getInt(2);
          if (iStatus == Constants.STATUS_ACTIVE || iStatus == Constants.STATUS_CANCEL) {
            throw new AppException(Constants.ERROR_REGISTERED);
          }
          String primaryKey = rs.getString(1);
          order.setResponseValue("primaryKey", primaryKey);
        }
      } finally {
        Database.closeObject(stmt);
        Database.closeObject(rs);
        Database.closeObject(connection);
      }
    } else if (order.getActionType().equals(Constants.ACTION_UNREGISTER)) {
      String strSQL_Select =
          "select to_char(expirationdate,'dd/mm/yyyy hh24:mi:ss')"
              + "             from subscriberproduct "
              + "             where 1 = 1 "
              + "                   and sysdate < expirationdate "
              + "                   and productid = ? and isdn = ?";

      Connection connection = null;
      PreparedStatement stmt = null;
      ResultSet rs = null;
      try {
        connection = Database.getConnection();
        stmt = connection.prepareStatement(strSQL_Select);
        stmt.setLong(1, order.getProductId());
        stmt.setString(2, order.getIsdn());
        rs = stmt.executeQuery();
        if (!rs.next()) {
          throw new AppException(Constants.ERROR_INVALID_PROMOTION);
        }
      } finally {
        Database.closeObject(stmt);
        Database.closeObject(rs);
        Database.closeObject(connection);
      }
    }
  }