/** * Remove units that don't have at least one valid hsaBusinessClassificationCode. * * @param units * @param showUnitsWithTheseHsaBusinessClassificationCodes */ @Override protected void removeUnallowedUnits( SikSearchResultList<Unit> units, List<Integer> showUnitsWithTheseHsaBusinessClassificationCodes) { // Get all health care types that are unfiltered HealthcareTypeConditionHelper htch = new HealthcareTypeConditionHelper(); List<HealthcareType> allUnfilteredHealthcareTypes = htch.getAllUnfilteredHealthCareTypes(); for (int j = units.size() - 1; j >= 0; j--) { List<String> businessClassificationCodes = units.get(j).getHsaBusinessClassificationCode(); boolean found = unitHasValidBusinessClassificationCode( showUnitsWithTheseHsaBusinessClassificationCodes, businessClassificationCodes); // The unit might still be valid because of the unfiltered healthcare types if (!found) { // If this unit does not match any unfiltered health care type, don't include in search // result found = unitMatchesUnfilteredHealtcareType(units.get(j), allUnfilteredHealthcareTypes); } if (found) { units.remove(units.get(j)); } } }
@Test public void searchWithoutUnitNameCallsSearchServiceOnceEvenIfNoUnitsAreFound() throws Exception { this.form.setMunicipality("Kungälv"); this.searchService.addSearchAdvancedUnitsSearchResult(new SikSearchResultList<Unit>()); SikSearchResultList<Unit> result = this.strategy.performSearch( this.form, new UnitNameComparator(), 0, this.searchService, false); assertEquals("search service call count", 1, this.searchService.searchAdvancedUnitsCallCount); assertEquals("result count", 0, result.size()); }
/** * 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; }