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());
  }
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public Map<Boolean, Set<GatewayResponse>> sendMessage(GatewayRequest messageDetails) {
    logger.debug("Sending message to gateway");
    Set<GatewayResponse> responseList = null;
    Map<Boolean, Set<GatewayResponse>> result = new HashMap<Boolean, Set<GatewayResponse>>();
    try {
      if ((messageDetails.getRecipientsNumber() == null
              || messageDetails.getRecipientsNumber().isEmpty())
          && !ContactNumberType.PUBLIC
              .toString()
              .equals(messageDetails.getMessageRequest().getPhoneNumberType())) {
        messageDetails.setMessageStatus(MStatus.INVALIDNUM);
      } else {
        responseList = this.getGatewayManager().sendMessage(messageDetails);
        result.put(true, responseList);
        logger.debug(responseList);
        logger.debug("Updating message status");
        messageDetails.setResponseDetails(responseList);
        messageDetails.setMessageStatus(MStatus.SENT);
      }
    } catch (MotechException me) {
      logger.error("Error sending message", me);
      messageDetails.setMessageStatus(MStatus.SCHEDULED);

      GatewayMessageHandler orHandler = getGatewayManager().getMessageHandler();
      responseList =
          orHandler.parseMessageResponse(
              messageDetails,
              "error: 901 - Cannot Connect to gateway | Details: " + me.getMessage());
      result.put(false, responseList);
    }
    this.getCache().mergeMessage(messageDetails);

    return result;
  }
  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());
  }