@Override
  public void process(AGateway gateway, MessageTypes msgType, InboundMessage msg) {

    if (SystemPrevayler.getSystemPrevaylerModel().addReceivedMessage(msg)) {
      switch (msgType) {
        case STATUSREPORT:
          if (msg instanceof StatusReportMessage) {
            StatusReportMessage statusReportMessage = (StatusReportMessage) msg;
            String recipient =
                ContactFactory.getInstance()
                    .createContact(
                        Long.valueOf(statusReportMessage.getRecipient().replaceAll("\\D", "0")))
                    .getFormattedContact();
            LOGGER.info(
                "Processing a "
                    + MessageTypes.STATUSREPORT.name()
                    + " from Recipient: "
                    + recipient);
            Logger.getLogger("validContacts").info("recipient: " + recipient);
          }
          break;
        default:
          String originator =
              ContactFactory.getInstance()
                  .createContact(Long.valueOf(msg.getOriginator().replaceAll("\\D", "0")))
                  .getFormattedContact();
          LOGGER.info(
              "Processing a "
                  + MessageTypes.INBOUND.name()
                  + " Message Notification from Originator: "
                  + originator
                  + "; Text: "
                  + msg.getText());
          if (isFunctionMessage(msg)) {
            Integer requiredFunction = -1;
            try {
              requiredFunction = Integer.valueOf(msg.getText().trim());
            } catch (Exception e) {
              LOGGER.error(
                  "Error when parsing ReportRequiredType for value: " + msg.getText().trim());
            }

            switch (ReportRequiredType.parse(requiredFunction)) {
              case SMS_RATING:
                new Thread(new SmsRatingReport()).start();
                break;

              case EMAIL_RATING:
                new Thread(new EmailRatingReport()).start();
                break;

              case CLEAR_RECEIVED_MESSAGES:
                LOGGER.error("Cleanning the received messages...");
                SystemPrevayler.getSystemPrevaylerModel().clearReceivedMessages();
                break;

              case NOT_DEFINED:
                new Thread(new NotSupportedReport()).start();
                break;
            }
            SystemPrevayler.getSystemPrevaylerModel().getReceivedMessages().remove(msg);
          }
          break;
      }
      SystemPrevayler.takeSnapShot();
    }
    deleteMessage(msg);
  }
 private boolean isFunctionMessage(InboundMessage msg) {
   Contato originator =
       ContactFactory.getInstance()
           .createContact(Long.valueOf(msg.getOriginator().replaceAll("\\D", "0")));
   return isRecentlyMessage(msg) && isFromAdminContact(originator);
 }