Exemplo n.º 1
0
  private boolean isDuplicate(String msisdn) {

    Mensagem lastMessage = msgDAO.findLastMessageByMsisdn(msisdn);
    if (lastMessage == null) {
      return false;
    }

    String interval = configDAO.findByName(DUPLICATED_CHECK_INTERVAL);
    Integer intervalAsInt;

    try {
      intervalAsInt = Integer.parseInt(interval);
    } catch (NumberFormatException exp) {
      intervalAsInt = 0;
    }

    Date dtEnd = lastMessage.getRequest();

    long dtBeginInMillis = System.currentTimeMillis();
    long dtEndInMillis = dtEnd.getTime();
    long diffInSeconds = (dtBeginInMillis - dtEndInMillis) / 1000;

    if (diffInSeconds > intervalAsInt) {
      return false;
    }

    return true;
  }
Exemplo n.º 2
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;
  }