Пример #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;
  }