ScreenshotService { @Transactional public List<Screenshot> searchScreenshots( List<Long> repositoryIds, List<String> bcp47Tags, String screenshotName, Screenshot.Status status, String name, String source, String target, SearchType searchType, ScreenshotRunType screenshotRunType, int offset, int limit) { CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<Screenshot> query = builder.createQuery(Screenshot.class); Root<Screenshot> screenshot = query.from(Screenshot.class); Join<Screenshot, ScreenshotRun> screenshotRunJoin = screenshot.join(Screenshot_.screenshotRun); Join<ScreenshotRun, Repository> repositoryJoin = screenshotRunJoin.join(ScreenshotRun_.repository); Join<Screenshot, Locale> localeJoin = screenshot.join(Screenshot_.locale); Join<Screenshot, ScreenshotTextUnit> screenshotTextUnits = screenshot.join(Screenshot_.screenshotTextUnits, JoinType.LEFT); Predicate conjunction = builder.conjunction(); if (ScreenshotRunType.LAST_SUCCESSFUL_RUN.equals(screenshotRunType)) { conjunction.getExpressions().add(builder.isTrue(screenshotRunJoin.get(ScreenshotRun_.lastSuccessfulRun))); } else { Path<ScreenshotRun> screenshotRunPath = repositoryJoin.get(Repository_.manualScreenshotRun); conjunction.getExpressions().add(builder.equal(screenshotRunPath, screenshotRunJoin.get(ScreenshotRun_.id))); } if (repositoryIds != null) { conjunction.getExpressions().add(repositoryJoin.get(Repository_.id).in(repositoryIds)); } if (bcp47Tags != null) { conjunction.getExpressions().add(localeJoin.get(Locale_.bcp47Tag).in(bcp47Tags)); } if (!Strings.isNullOrEmpty(screenshotName)) { Predicate predicate = getPredicateForSearchType( searchType, builder, screenshot.get(Screenshot_.name), screenshotName); conjunction.getExpressions().add(predicate); } if (status != null) { Predicate predicate = builder.equal(screenshot.get(Screenshot_.status), status); conjunction.getExpressions().add(predicate); } if (!Strings.isNullOrEmpty(name)) { Predicate predicate = getPredicateForSearchType( searchType, builder, screenshotTextUnits.get(ScreenshotTextUnit_.name), name); conjunction.getExpressions().add(predicate); } if (!Strings.isNullOrEmpty(source)) { Predicate predicate = getPredicateForSearchType( searchType, builder, screenshotTextUnits.get(ScreenshotTextUnit_.source), source); conjunction.getExpressions().add(predicate); } if (!Strings.isNullOrEmpty(target)) { Predicate targetPredicate = getPredicateForSearchType( searchType, builder, screenshotTextUnits.get(ScreenshotTextUnit_.target), target); Predicate renderedTargetPredicate = getPredicateForSearchType( searchType, builder, screenshotTextUnits.get(ScreenshotTextUnit_.renderedTarget), target); conjunction.getExpressions().add(builder.or(targetPredicate, renderedTargetPredicate)); } query.where(conjunction); query.orderBy(builder.asc(screenshot.get(Screenshot_.id))); List<Screenshot> screenshots = em.createQuery(query.distinct(true).select(screenshot)).setFirstResult(offset).setMaxResults(limit).getResultList(); return screenshots; }  @Transactional ScreenshotRun createOrUpdateScreenshotRun(ScreenshotRun screenshotRun, boolean setLastSuccessfulScreenshotRun); @Transactional List<Screenshot> searchScreenshots(
            List<Long> repositoryIds,
            List<String> bcp47Tags,
            String screenshotName,
            Screenshot.Status status,
            String name,
            String source,
            String target,
            SearchType searchType,
            ScreenshotRunType screenshotRunType, int offset, int limit); Map<Long, Set<Screenshot>> getScreenshotsByTmTextUnitId(Set<Long> tmTextUnitIds); void updateScreenshot(Screenshot screenshot);  }
@Test public void testSearchScreenshotsByRepository() throws RepositoryNameAlreadyUsedException { Repository repository = createScreenshotDataAsRepository(); List<Screenshot> searchScreenshots = screenshotService.searchScreenshots( Arrays.asList(repository.getId()), null, null, null, null, null, null, null, ScreenshotRunType.LAST_SUCCESSFUL_RUN, 0, 10); assertEquals("screen1", searchScreenshots.get(0).getName()); assertEquals("screen3", searchScreenshots.get(1).getName()); assertEquals("screen2", searchScreenshots.get(2).getName()); }
@Test public void testSearchScreenshotsByLocale() throws RepositoryNameAlreadyUsedException { Repository repository = createScreenshotDataAsRepository(); List<Screenshot> searchScreenshots = screenshotService.searchScreenshots( Arrays.asList(repository.getId()), Arrays.asList("fr-FR"), null, null, null, null, null, null, ScreenshotRunType.LAST_SUCCESSFUL_RUN, 0, 10); assertEquals("screen1", searchScreenshots.get(0).getName()); assertEquals("screen2", searchScreenshots.get(1).getName()); assertEquals(2, searchScreenshots.size()); searchScreenshots = screenshotService.searchScreenshots( Arrays.asList(repository.getId()), Arrays.asList("ko-KR"), null, null, null, null, null, null, ScreenshotRunType.LAST_SUCCESSFUL_RUN, 0, 10); assertEquals("screen3", searchScreenshots.get(0).getName()); assertEquals(1, searchScreenshots.size()); }
@Test public void testSearchScreenshotsByName() throws RepositoryNameAlreadyUsedException { Repository repository = createScreenshotDataAsRepository(); List<Screenshot> searchScreenshots = screenshotService.searchScreenshots( Arrays.asList(repository.getId()), null, "screen2", null, null, null, null, null, ScreenshotRunType.LAST_SUCCESSFUL_RUN, 0, 10); assertEquals("screen2", searchScreenshots.get(0).getName()); assertEquals(1, searchScreenshots.size()); }
@Test public void testSearchScreenshotsByStatus() throws RepositoryNameAlreadyUsedException { Repository repository = createScreenshotDataAsRepository(); List<Screenshot> searchScreenshots = screenshotService.searchScreenshots( Arrays.asList(repository.getId()), null, null, Screenshot.Status.NEEDS_REVIEW, null, null, null, null, ScreenshotRunType.LAST_SUCCESSFUL_RUN, 0, 10); assertEquals("screen3", searchScreenshots.get(0).getName()); assertEquals(1, searchScreenshots.size()); searchScreenshots = screenshotService.searchScreenshots( Arrays.asList(repository.getId()), null, null, Screenshot.Status.REJECTED, null, null, null, null, ScreenshotRunType.LAST_SUCCESSFUL_RUN, 0, 10); assertEquals("screen1", searchScreenshots.get(0).getName()); assertEquals(1, searchScreenshots.size()); searchScreenshots = screenshotService.searchScreenshots( Arrays.asList(repository.getId()), null, null, ACCEPTED, null, null, null, null, ScreenshotRunType.LAST_SUCCESSFUL_RUN, 0, 10); assertEquals("screen2", searchScreenshots.get(0).getName()); assertEquals(1, searchScreenshots.size()); }
@Test public void testSearchScreenshotsByPagination() throws RepositoryNameAlreadyUsedException { Repository repository = createScreenshotDataAsRepository(); List<Screenshot> searchScreenshots = screenshotService.searchScreenshots( Arrays.asList(repository.getId()), null, null, null, null, null, null, null, ScreenshotRunType.LAST_SUCCESSFUL_RUN, 1, 1); logger.debug("repository: {}", repository.getId()); assertEquals("screen3", searchScreenshots.get(0).getName()); assertEquals(1, searchScreenshots.size()); }
@Test public void testLastRunSuccessful() throws RepositoryNameAlreadyUsedException { Repository repository = createScreenshotDataAsRepository(); createScreenshotDataForRepository(repository); List<Screenshot> searchScreenshots = screenshotService.searchScreenshots( Arrays.asList(repository.getId()), null, null, null, null, null, null, null, ScreenshotRunType.LAST_SUCCESSFUL_RUN, 0, 10); assertEquals(3, searchScreenshots.size()); }