/**
   * Searches for units by the criterias specified in the provided form.
   *
   * @param theForm The form with the search criterias.
   * @return A list of matching units.
   * @throws KivException If no units were found with the provided criterias or if no connection to
   *     the LDAP server could be made.
   */
  public SikSearchResultList<Unit> doSearch(UnitSearchSimpleForm theForm) throws KivException {
    LOGGER.debug(CLASS_NAME + ".doSearch()");

    SikSearchResultList<Unit> list = new SikSearchResultList<Unit>();
    try {
      TimeMeasurement overAllTime = new TimeMeasurement();

      // start measurement
      overAllTime.start();
      if (!theForm.isEmpty()) {
        SearchUnitCriterions u = this.mapSearchCriterias(theForm);
        int currentMaxSearchResult = this.maxSearchResult;
        if ("true".equals(theForm.getShowAll())) {
          currentMaxSearchResult = Integer.MAX_VALUE;
        }
        list = this.getSearchService().searchUnits(u, currentMaxSearchResult);

        // stop measurement
        overAllTime.stop();

        if (list == null) {
          list = new SikSearchResultList<Unit>();
        }
        LogUtils.printSikSearchResultListToLog(this, "doSearch", overAllTime, LOGGER, list);
        if (list.size() == 0) {
          throw new KivNoDataFoundException();
        } else {
          Collections.sort(list, new UnitNameComparator());
        }
      }
    } catch (KivNoDataFoundException e) {
      throw e;
    } catch (KivException e) {
      LOGGER.error(e);
      list = new SikSearchResultList<Unit>();
    }
    return list;
  }