CaseService extends RecordService { public List<Long> getCPSearchResult(String shortId, String name, int ageFrom, int ageTo, String caregiver, Date date) { ConditionGroup conditionGroup = ConditionGroup.clause(); SQLCondition ageSearchCondition = generateAgeSearchCondition(ageFrom, ageTo); if (ageSearchCondition != null) { conditionGroup.and(ageSearchCondition); } conditionGroup.and(Condition.column(NameAlias.builder(RecordModel.COLUMN_OWNED_BY).build()) .eq(PrimeroAppConfiguration.getCurrentUser().getUsername())); if(!TextUtils.isEmpty(caregiver)){ conditionGroup.and(Condition.column(NameAlias.builder(RecordModel.COLUMN_CAREGIVER).build()) .like(getWrappedCondition(caregiver))); } if(!TextUtils.isEmpty(shortId)){ conditionGroup.and(Condition.column(NameAlias.builder(RecordModel.COLUMN_SHORT_ID).build()) .like(getWrappedCondition(shortId))); } if(!TextUtils.isEmpty(name)){ conditionGroup.and(Condition.column(NameAlias.builder(RecordModel.COLUMN_NAME).build()) .like(getWrappedCondition(name))); } if (date != null) { conditionGroup.and(Condition.column(NameAlias.builder(Case.COLUMN_REGISTRATION_DATE) .build()).eq(date)); } return extractIds(caseDao.getCaseListByConditionGroup(PrimeroAppConfiguration.getCurrentUsername(), PrimeroAppConfiguration.getApiBaseUrl(), conditionGroup)); } CaseService(CaseDao caseDao, CasePhotoDao casePhotoDao, IncidentDao incidentDao); List<Case> getAll(); Case getById(long caseId); Case getByUniqueId(String uniqueId); List<String> getIncidentsByCaseId(String caseUniqueId); List<Long> getAllOrderByDateASC(); List<Long> getAllOrderByDateDES(); List<Long> getAllOrderByAgeASC(); List<Long> getAllOrderByAgeDES(); List<Long> getCPSearchResult(String shortId, String name, int ageFrom, int ageTo,
                                        String caregiver, Date date); List<Long> getAllSyncedRecordsId(); List<Long> getGBVSearchResult(String shortId, String name, String location, Date registrationDate); Case saveOrUpdate(ItemValuesMap itemValues, List<String> photoPaths); Case save(ItemValuesMap itemValues, List<String> photoPaths); void savePhoto(Case child, List<String> photoPaths); Case update(ItemValuesMap itemValues, List<String> photoBitPaths); void updatePhoto(Case child, List<String> photoPaths); Case deleteByRecordId(long recordId); Case getByInternalId(String id); boolean hasSameRev(String id, String rev); static final String TAG; static final String CASE_DISPLAY_ID; static final String CASE_ID; static final String CASE_PRIMARY_ID; }
@Test public void should_get_CP_search_result_by_condition_group() throws Exception { Case searchCaseOne = new Case(10000L); Case searchCaseTwo = new Case(10001L); Case searchCaseThree = new Case(10002L); Case searchCaseFour = new Case(10003L); List<Case> searchResult = Arrays.asList(new Case[]{ searchCaseOne, searchCaseTwo, searchCaseThree, searchCaseFour}); when(caseDao.getCaseListByConditionGroup(anyString(), anyString(), any(ConditionGroup .class))).thenReturn (searchResult); List<Long> actual = caseService.getCPSearchResult("", "", 0, 0, "", null); assertThat("Should return id list", actual, is(Arrays.asList(new Long[]{10000L, 10001L, 10002L, 10003L}))); }