Esempio n. 1
0
  public MessageStatus scheduleMessage(MessageRequest message, String content) {
    if ((message.getRecipientNumber() == null || message.getRecipientNumber().isEmpty())
        && !ContactNumberType.PUBLIC.toString().equals(message.getPhoneNumberType())) {
      return MessageStatus.REJECTED;
    }

    MessageRequestDAO msgReqDao = coreManager.createMessageRequestDAO();

    msgReqDao.save(message);

    // TODO Check length of message and break if necessary
    logger.info("Constructing GatewayRequest...");
    GatewayRequest gwReq = storeManager.constructMessage(message, null);
    gwReq.setMessage(content);
    gwReq.getGatewayRequestDetails().setMessage(content);

    logger.info("Initializing OMP MessagingService...");
    MessagingService msgSvc = ompManager.createMessagingService();

    logger.info("Scheduling GatewayRequest...");

    msgSvc.scheduleMessage(gwReq);

    logger.info("Updating MessageRequest...");
    message.setDateProcessed(new Date());
    message.setStatus(MStatus.PENDING);
    logger.debug(message);

    msgReqDao.save(message);
    logger.info("Messages sent successfully");
    return MessageStatus.valueOf(message.getStatus().toString());
  }
Esempio n. 2
0
  public MessageStatus sendMessage(MessageRequest message) {
    if ((message.getRecipientNumber() == null || message.getRecipientNumber().isEmpty())
        && !ContactNumberType.PUBLIC.toString().equals(message.getPhoneNumberType())) {
      return MessageStatus.REJECTED;
    }

    Language defaultLanguage = coreManager.createLanguageDAO().getByCode(defaultLang);

    if (message.getLanguage() == null) {
      message.setLanguage(defaultLanguage);
    }

    MessageRequestDAO msgReqDao = coreManager.createMessageRequestDAO();

    message.setStatus(MStatus.QUEUED);
    msgReqDao.save(message);

    logger.debug("Constructing GatewayRequest...");
    GatewayRequest gwReq = storeManager.constructMessage(message, defaultLanguage);
    message.setGatewayRequestDetails(null);

    logger.debug("Initializing OMP MessagingService...");
    MessagingService msgSvc = ompManager.createMessagingService();

    logger.info("Sending GatewayRequest...");

    Map<Boolean, Set<GatewayResponse>> responses = msgSvc.sendMessage(gwReq);

    Boolean falseBool = false;
    if (responses.containsKey(falseBool)) {
      Set<GatewayResponse> resps = responses.get(falseBool);
      for (GatewayResponse gp : resps) {
        statHandler.handleStatus(gp);
      }
    }

    logger.info("Updating MessageRequest...");
    message.setGatewayRequestDetails(gwReq.getGatewayRequestDetails());
    message.setDateProcessed(new Date());
    message.setStatus(MStatus.PENDING);
    logger.debug(message);

    msgReqDao.save(message);

    logger.info("Messages sent successfully");
    return MessageStatus.valueOf(message.getStatus().toString());
  }