示例#1
0
  private void insertToMsgHist(
      Transacao tr, String message, StatusType statusType, MessageStatus messageStatus) {

    Historico hist = new Historico();
    hist.setDtCriacao(new Date());
    hist.setLa(tr.getLa());
    hist.setMensagem(tr.getMensagem());
    hist.setTxMensagem(message);
    hist.setMsisdn(tr.getMsisdn());
    hist.setOperadora(tr.getOperadora());
    hist.setMessageStatus(messageStatus);
    hist.setStatusType(statusType);
    hist.setParceiro(tr.getParceiro());
    hist.setValorTarifacao(tr.getValorTarifacao());
    hist.setRetentativa(1);
    hist.setUrl(null);
    historicoDAO.save(hist);
  }
示例#2
0
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    Date currentDate = new Date();

    try {
      moRequest = parseInputParameters(request);
      logger.info("MO Message: " + moRequest);
    } catch (Exception e) {
      logger.warn(loggerMessageDAO.getMessageById(5, e.getMessage()));
      response.sendError(HttpServletResponse.SC_BAD_REQUEST, loggerMessageDAO.getMessageById(6));
      return null;
    }

    String strLa = moRequest.getDestinationNumber();
    if (moRequest.getDestinationNumber().contains("-")) {
      strLa =
          moRequest
              .getDestinationNumber()
              .substring(0, moRequest.getDestinationNumber().indexOf("-"));
    }

    la = laDAO.findByNome(strLa);
    if (la == null) {
      logger.warn(loggerMessageDAO.getMessageById(7, moRequest.getDestinationNumber()));
      response.sendError(
          HttpServletResponse.SC_BAD_REQUEST,
          loggerMessageDAO.getMessageById(7, moRequest.getDestinationNumber()));
      return null;
    }

    if (isOptionIn()) {
      return null;
    }

    Mensagem msg = new Mensagem();
    msg.setLa(la);
    msg.setMensagem(moRequest.getTextMessage());
    msg.setMsisdn(moRequest.getOriginationNumber());
    msg.setOperadora(Integer.parseInt(moRequest.getCarrier()));
    msg.setProcessamento(currentDate);
    msg.setRequest(currentDate);

    Historico hist = new Historico();
    hist.setDtCriacao(currentDate);
    hist.setLa(la);
    hist.setMensagem(msg);
    hist.setTxMensagem(msg.getMensagem());
    hist.setMsisdn(msg.getMsisdn());
    hist.setOperadora(msg.getOperadora());
    hist.setStatusType(StatusType.FLOW_START);

    boolean isDuplicate = isDuplicate(msg.getMsisdn());

    if (isDuplicate) {
      msg.setMessageStatus(MessageStatus.DUPLICATE);
      hist.setMessageStatus(MessageStatus.DUPLICATE);
    } else {
      msg.setMessageStatus(MessageStatus.FLOW_START);
      hist.setMessageStatus(MessageStatus.FLOW_START);
    }

    try {

      msgDAO.save(msg);
      historicoDAO.save(hist);

      if (isDuplicate) {
        DuplicatedMessage dupMessage = new DuplicatedMessage();
        dupMessage.setCodigoOperadora(msg.getOperadora());
        dupMessage.setMensagem(msg);
        dupMessage.setSmsMtSent(0);
        dupMessage.setMsisdn(msg.getMsisdn());
        dupMessage.setDtCompra(Calendar.getInstance().getTime());
        duplicatedMessageDAO.save(dupMessage);
        return null;
      }

      if (!existsCampaign()) {

        hist.setMessageStatus(MessageStatus.CAMPAIGN_NOT_FOUND);
        msg.setMessageStatus(MessageStatus.CAMPAIGN_NOT_FOUND);
        msgDAO.update(msg);
        historicoDAO.update(hist);

        WithoutCampaignMsg withoutCampaignMsg = new WithoutCampaignMsg();
        withoutCampaignMsg.setCodigoOperadora(msg.getOperadora());
        withoutCampaignMsg.setMensagem(msg);
        withoutCampaignMsg.setSmsMtSent(0);
        withoutCampaignMsg.setTxtMensagem(msg.getMensagem());
        withoutCampaignMsg.setMsisdn(msg.getMsisdn());
        withoutCampaignMsgDAO.save(withoutCampaignMsg);
        return null;
      }

      if (reachedLimitOfBuying(msg)) {

        hist.setMessageStatus(MessageStatus.BUY_LIMIT_REACHED);
        msg.setMessageStatus(MessageStatus.BUY_LIMIT_REACHED);
        msgDAO.update(msg);
        historicoDAO.update(hist);

        BuyingLimitExceed bl = new BuyingLimitExceed();
        bl.setMensagem(msg);
        bl.setMsisdn(msg.getMsisdn());
        bl.setSmsMtSent(0);
        bl.setCodigoOperadora(msg.getOperadora());
        bl.setDtCompra(Calendar.getInstance().getTime());
        buyingLimitExceedDAO.save(bl);
        return null;
      }

      Sharecode sharecode = campaign.getRegra().getSharecode(msg.getOperadora());
      Transacao tr = new Transacao();
      tr.setDtSchedule(currentDate);
      tr.setDtTransacao(currentDate);
      tr.setKeycode(campaign.getRegra().getKeycode());
      tr.setLa(la);
      tr.setMensagem(msg);
      tr.setMsisdn(msg.getMsisdn());
      tr.setOperadora(msg.getOperadora());
      tr.setParceiro(keycode.getParceiro());
      tr.setRegra(campaign.getRegra());
      tr.setCampanha(campaign);
      tr.setSharecode(sharecode);
      tr.setValorTarifacao(sharecode.getTarifacao());
      tr.setDoubleOptionIn(0);

      switch (campaign.getFlowType()) {
        case Campanha.REQUIRES_AUTHORIZATION_FLOW:
          tr.setTransactionStatus(TransactionStatus.WAITING_TO_PROCESS);
          break;

        case Campanha.SIMPLIFIED_FLOW:
          tr.setTransactionStatus(TransactionStatus.TRANSACTION_AUTHORIZED);
          break;

        case Campanha.VOUCHER_FLOW:
          tr.setTransactionStatus(TransactionStatus.WAITING_TO_PROCESS);
          break;
      }

      transacaoDAO.save(tr);

    } catch (Exception e) {

      logger.error(loggerMessageDAO.getMessageById(8, e.getMessage()));
      hist.setMessageStatus(MessageStatus.ERROR);
      msg.setMessageStatus(MessageStatus.ERROR);
      msgDAO.update(msg);
      historicoDAO.update(hist);
    }

    return null;
  }
示例#3
0
  private boolean isOptionIn() {

    String optionInMsg = moRequest.getTextMessage();
    String expectedAnswer = configDAO.findByName(OPTION_IN_ANSWER);

    if (optionInMsg.equalsIgnoreCase(expectedAnswer)) {

      String originator = moRequest.getOriginationNumber();
      Transacao tr =
          transacaoDAO.findLastByMsisdnAndStatus(
              originator, TransactionStatus.WAIT_OPTION_IN_ANSWER);
      if (tr != null) {

        tr.setTransactionStatus(TransactionStatus.TRANSACTION_AUTHORIZED);
        transacaoDAO.update(tr);
        insertToMsgHist(
            tr,
            optionInMsg,
            StatusType.WAIT_OPTION_IN_ANSWER,
            MessageStatus.TRANSACTION_AUTHORIZED);

        OptionIn optionIn = optionInDAO.findByTransactionId(tr.getId());
        optionIn.setTimeOfAuthorization(Calendar.getInstance().getTime());
        optionIn.setIsAuthorized(1);
        optionInDAO.update(optionIn);

        logger.info(
            loggerMessageDAO.getMessageByShortcode(
                VOUCHER_AUTHORIZED,
                tr.getCampanha().getKeyword(),
                tr.getMsisdn(),
                tr.getId(),
                dateTimeFormat.format(Calendar.getInstance().getTime())));

        List<Transacao> trList =
            transacaoDAO.findAllByMsisdnAndStatus(
                originator, TransactionStatus.WAIT_OPTION_IN_ANSWER);
        for (Transacao t : trList) {
          t.setTransactionStatus(TransactionStatus.TRANSACTION_CANCELED);
          transacaoDAO.update(t);
          insertToMsgHist(
              t, null, StatusType.WAIT_OPTION_IN_ANSWER, MessageStatus.TRANSACTION_CANCELED);

          logger.info(
              loggerMessageDAO.getMessageByShortcode(
                  VOUCHER_CANCELED,
                  tr.getCampanha().getKeyword(),
                  tr.getMsisdn(),
                  tr.getId(),
                  dateTimeFormat.format(Calendar.getInstance().getTime())));
        }

        return true;

      } else {

        return false;
      }
    }

    return false;
  }