@SuppressWarnings("unchecked")
  public String execute() {
    gatewayId = transportService.getDefaultGateway();

    if (gatewayId == null || gatewayId.trim().length() == 0) {
      message = i18n.getString("please_select_a_gateway_type_to_send_sms");

      return ERROR;
    }

    if (smsMessage == null || smsMessage.trim().length() == 0) {
      message = i18n.getString("no_message");

      return ERROR;
    }

    User currentUser = currentUserService.getCurrentUser();

    if (sendTarget != null && sendTarget.equals("phone")) {
      try {
        ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY);
        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        recipients = mapper.readValue(recipients.iterator().next(), Set.class);
      } catch (JsonParseException e) {
        e.printStackTrace();
      } catch (JsonMappingException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }

      message =
          messageSender.sendMessage(
              smsSubject, smsMessage, currentUser, true, recipients, gatewayId);
    } else if (sendTarget.equals("userGroup")) {
      UserGroup group = userGroupService.getUserGroup(userGroup);

      if (group == null) {
        message = i18n.getString("selected_user_group_is_unavailable");

        return ERROR;
      }

      if (group.getMembers() == null || group.getMembers().isEmpty()) {
        message = i18n.getString("selected_user_group_has_no_member");

        return ERROR;
      }

      message =
          messageSender.sendMessage(
              smsSubject, smsMessage, currentUser, false, group.getMembers(), gatewayId);
    } else if (sendTarget.equals("user")) {
      Collection<OrganisationUnit> units =
          selectionTreeManager.getReloadedSelectedOrganisationUnits();

      if (units != null && !units.isEmpty()) {
        Set<User> users = new HashSet<User>();

        for (OrganisationUnit unit : units) {
          users.addAll(unit.getUsers());
        }

        if (users.isEmpty()) {
          message = i18n.getString("there_is_no_user_assigned_to_selected_units");

          return ERROR;
        }

        message =
            messageSender.sendMessage(smsSubject, smsMessage, currentUser, false, users, gatewayId);
      }
    } else if (sendTarget.equals("unit")) {
      for (OrganisationUnit unit : selectionTreeManager.getSelectedOrganisationUnits()) {
        if (unit.getPhoneNumber() != null && !unit.getPhoneNumber().isEmpty()) {
          recipients.add(unit.getPhoneNumber());
        }
      }

      if (recipients.isEmpty()) {
        message = i18n.getString("selected_units_have_no_phone_number");

        return ERROR;
      }

      message =
          messageSender.sendMessage(
              smsSubject, smsMessage, currentUser, true, recipients, gatewayId);
    } else {
      Patient patient = null;
      Set<String> phones = new HashSet<String>();

      try {
        ObjectMapper mapper = new ObjectMapper().setVisibility(JsonMethod.FIELD, Visibility.ANY);
        mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        recipients = mapper.readValue(recipients.iterator().next(), Set.class);
      } catch (JsonParseException e) {
        e.printStackTrace();
      } catch (JsonMappingException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }

      for (String patientId : recipients) {
        patient = patientService.getPatient(Integer.parseInt(patientId));

        if (patient != null
            && patient.getPhoneNumber() != null
            && !patient.getPhoneNumber().isEmpty()) {
          phones.add(patient.getPhoneNumber());
        }
      }

      if (phones.isEmpty()) {
        message = i18n.getString("selected_persons_have_no_phone_number");

        return ERROR;
      }

      message =
          messageSender.sendMessage(smsSubject, smsMessage, currentUser, true, phones, gatewayId);
    }

    if (message != null && !message.equals("success")) {
      message = i18n.getString(message);

      return ERROR;
    }

    return SUCCESS;
  }
 public Map<String, String> getGatewayMap() {
   return transportService.getGatewayMap();
 }