List of usage examples for org.springframework.data.domain Sort Sort
private Sort(Direction direction, List<String> properties)
From source file:org.callistasoftware.netcare.core.repository.AlarmRepositoryTest.java
@Test @Transactional/* ww w. j a v a 2s . co m*/ @Rollback(true) public void findByReportedTimeIsNotNull() { final PatientEntity patient = PatientEntity.newEntity("Peter", "", "123456"); patientRepo.save(patient); final CountyCouncilEntity cc = ccRepo.save(CountyCouncilEntity.newEntity(CountyCouncil.STOCKHOLM)); final CareUnitEntity cu = CareUnitEntity.newEntity("cu", cc); cuRepo.save(cu); final CareActorEntity ca = CareActorEntity.newEntity("Doctor Hook", "", "12345-67", cu); careActorRepo.save(ca); AlarmEntity e = AlarmEntity.newEntity(AlarmCause.PLAN_EXPIRES, patient, "hsa-123", 42L); e = repo.save(e); assertEquals(1, repo.findByResolvedTimeIsNullAndCareUnitHsaIdLike("hsa-123", new Sort(Sort.Direction.DESC, "createdTime")).size()); e.resolve(ca); e = repo.save(e); repo.flush(); assertEquals(0, repo.findByResolvedTimeIsNullAndCareUnitHsaIdLike("hsa-123", new Sort(Sort.Direction.DESC, "createdTime")).size()); }
From source file:com.trenako.results.SearchRangeTests.java
@Test public void shouldCreateSearchRangeForDates() { Date since = fulldate("2012/06/01 10:30:00.500"); Date max = fulldate("2012/06/30 10:30:00.500"); SearchRange range = new SearchRange(20, new Sort(Direction.DESC, "name"), since, max); Map<String, Object> params = range.asMap(); assertEquals(since, params.get("since")); assertEquals(max, params.get("max")); }
From source file:org.openmhealth.shim.OAuth1ShimBase.java
@Override @SuppressWarnings("unchecked") public AuthorizationRequestParameters getAuthorizationRequestParameters(String username, Map<String, String> additionalParameters) throws ShimException { String stateKey = OAuth1Utils.generateStateKey(); AccessParameters accessParams = accessParametersRepo.findByUsernameAndShimKey(username, getShimKey(), new Sort(DESC, "dateCreated")); if (accessParams != null && accessParams.getAccessToken() != null) { return AuthorizationRequestParameters.authorized(); }//from www . j av a 2 s.c o m HttpRequestBase tokenRequest = null; try { String callbackUrl = shimServerConfig.getCallbackUrl(getShimKey(), stateKey); Map<String, String> requestTokenParameters = new HashMap<>(); requestTokenParameters.put("oauth_callback", callbackUrl); String initiateAuthUrl = getBaseRequestTokenUrl(); tokenRequest = getRequestTokenRequest(initiateAuthUrl, null, null, requestTokenParameters); HttpResponse httpResponse = httpClient.execute(tokenRequest); Map<String, String> tokenParameters = OAuth1Utils.parseRequestTokenResponse(httpResponse); String token = tokenParameters.get(OAuth.OAUTH_TOKEN); String tokenSecret = tokenParameters.get(OAuth.OAUTH_TOKEN_SECRET); if (tokenSecret == null) { throw new ShimException("Request token could not be retrieved"); } URL authorizeUrl = signUrl(getBaseAuthorizeUrl(), token, tokenSecret, null); System.out.println("The authorization url is: "); System.out.println(authorizeUrl); /** * Build the auth parameters entity to return */ AuthorizationRequestParameters parameters = new AuthorizationRequestParameters(); parameters.setUsername(username); parameters.setRedirectUri(callbackUrl); parameters.setStateKey(stateKey); parameters.setAuthorizationUrl(authorizeUrl.toString()); parameters.setRequestParams(tokenParameters); /** * Store the parameters in a repo. */ authorizationRequestParametersRepo.save(parameters); return parameters; } catch (HttpClientErrorException e) { e.printStackTrace(); throw new ShimException("HTTP Error: " + e.getMessage()); } catch (IOException e) { e.printStackTrace(); throw new ShimException("Unable to initiate OAuth1 authorization, could not parse token parameters"); } finally { if (tokenRequest != null) { tokenRequest.releaseConnection(); } } }
From source file:com.luna.common.repository.PageAndSortUserRepositoryIT.java
@Test public void testFindByBaseInfoSexForSort() { for (int i = 0; i < 15; i++) { userRepository.save(createUser()); }//w w w. j a va 2 s . com Sort.Order idAsc = new Sort.Order(Sort.Direction.ASC, "id"); Sort.Order usernameDesc = new Sort.Order(Sort.Direction.DESC, "username"); Sort sort = new Sort(idAsc, usernameDesc); List<User> userList = userRepository.findByBaseInfoSex(Sex.male, sort); assertTrue(userList.get(0).getId() < userList.get(1).getId()); }
From source file:com.epam.ta.reportportal.database.dao.LaunchRepositoryTest.java
@Test public void testFindIdsByFilter() { FilterCondition nameCondition = new FilterCondition(Condition.CONTAINS, false, "Demo", "name"); FilterCondition numberCondition = new FilterCondition(Condition.LOWER_THAN_OR_EQUALS, false, "2", "number"); Filter filter = new Filter(Launch.class, Sets.newHashSet(nameCondition, numberCondition)); Sort sort = new Sort(Direction.DESC, "number"); List<Launch> launches = launchRepository.findIdsByFilter(filter, sort, 2); Assert.assertNotNull(launches);/* w w w. ja v a 2s. c o m*/ Assert.assertEquals(2, launches.size()); Assert.assertTrue(launches.get(0).getNumber().equals(2L)); Assert.assertTrue(launches.get(1).getNumber().equals(1L)); }
From source file:org.callistasoftware.netcare.core.spi.impl.AlarmServiceImpl.java
@Override public ServiceResult<Alarm[]> getCareUnitAlarms(String hsaId) { this.getLog().info("Get alarms for care unit {}", hsaId); final CareUnitEntity cu = this.cuRepo.findByHsaId(hsaId); if (cu == null) { this.getLog().warn("Care unit {} was not found in the system.", hsaId); return ServiceResultImpl.createFailedResult(new EntityNotFoundMessage(CareUnitEntity.class, hsaId)); }/*from w w w .j a v a 2 s .co m*/ this.verifyReadAccess(cu); final List<AlarmEntity> alarms = this.alarmRepo.findByResolvedTimeIsNullAndCareUnitHsaIdLike(hsaId, new Sort(Sort.Direction.DESC, "createdTime")); this.getLog().debug("Found {} alarms for care unit {}", alarms.size(), hsaId); return ServiceResultImpl.createSuccessResult( AlarmImpl.newFromEntities(alarms, LocaleContextHolder.getLocale()), new ListEntitiesMessage(AlarmEntity.class, alarms.size())); }
From source file:com.oakhole.auth.service.UserService.java
public Page<User> findAll(Map<String, Object> searchParams, int pageNumber, int pageSize, String sortDirection, String sortBy) {/* w w w . j a va 2 s.c o m*/ Map<String, SearchFilter> filters = SearchFilter.parse(searchParams); Specification<User> spec = DynamicSpecifications.bySearchFilter(filters.values(), User.class); Sort sort = new Sort("ASC".equals(sortDirection) ? Sort.Direction.ASC : Sort.Direction.DESC, sortBy); PageRequest pageRequest = new PageRequest(pageNumber, pageSize, sort); Page<User> userList = userDao.findAll(spec, pageRequest); return userList; }
From source file:io.github.autsia.crowly.tests.UserControllerTests.java
@Test public void checkPageSizeForUsers() { when(pageMock.getContent()).thenReturn(testUsersCollection.subList(0, 9)); when(userRepositoryMock.findAll(new PageRequest(0, 10, new Sort(Sort.Direction.ASC, "email")))) .thenReturn(pageMock);//from w w w. j av a 2 s . co m assertThat(usersController.users(10, 15, true, "email", null), is(testUsersCollection.subList(0, 9))); }
From source file:com.epam.ta.reportportal.core.widget.content.UniqueBugFilterStrategy.java
@Override public Map<String, List<ChartObject>> buildFilterAndLoadContent(UserFilter userFilter, ContentOptions contentOptions, String projectName) { Filter filter = userFilter.getFilter(); if (filter.getTarget().equals(Launch.class)) { filter.addCondition(new FilterCondition(Condition.EQUALS, false, projectName, Launch.PROJECT)); filter.addCondition(FilterConditionUtils.LAUNCH_IN_DEFAULT_MODE()); filter.addCondition(FilterConditionUtils.LAUNCH_NOT_IN_PROGRESS()); int limit = contentOptions.getItemsCount(); CriteriaMap<?> criteriaMap = criteriaMapFactory.getCriteriaMap(filter.getTarget()); List<Launch> launches = launchRepository.findIdsByFilter(filter, new Sort(userFilter.getSelectionOptions().isAsc() ? Sort.Direction.ASC : Sort.Direction.DESC, criteriaMap.getCriteriaHolder(userFilter.getSelectionOptions().getSortingColumnName()) .getQueryCriteria()), limit);/*from w ww . j a va 2 s. c o m*/ final String value = launches.stream().map(Launch::getId).collect(Collectors.joining(SEPARATOR)); filter = new Filter(TestItem.class, Sets.newHashSet(new FilterCondition(Condition.IN, false, value, TestItem.LAUNCH_CRITERIA))); } filter.addCondition(new FilterCondition(Condition.EXISTS, false, "true", TestItem.EXTERNAL_SYSTEM_ISSUES)); return widgetContentProvider.getChartContent(filter, userFilter.getSelectionOptions(), contentOptions); }
From source file:me.smoe.adar.utils.cam.o.CAMApplication.java
private void go(int cases, boolean buildScore) throws Exception { if (buildScore) { statistics.run();/*from w w w . j a v a 2 s.c o m*/ } Map<Long, String> cams = new HashMap<>(); for (CAM cam : camRepository.findAll()) { cams.put(cam.getId(), cam.getName()); } AtomicInteger succ = new AtomicInteger(); AtomicInteger fail = new AtomicInteger(); AtomicInteger wrong = new AtomicInteger(); AtomicInteger index = new AtomicInteger(); Page<CAMProduct> products = camProductRepository .findAll(new PageRequest(0, cases, new Sort(Direction.DESC, "id"))); int total = products.getSize(); for (CAMProduct product : products) { THREADPOOLEXECUTOR.execute(() -> { try { Long ca = caMatcher.matcher(product.getName(), product.getBrand(), product.getCategory(), product.getDesc(), 10000); // Long ca = me.smoe.adar.utils.cam.n.matcher.CAMatcher.matcher(product.getCategory(), 20); if (product.getCao().equals(ca)) { System.err.println( String.format("[CAM] Index: %s Id: %s Cao: %s Can: %s", index.incrementAndGet(), product.getId(), cams.get(product.getCao()), cams.get(ca))); } else if (ca != null && cams.get(product.getCao()).equals(cams.get(ca))) { System.err.println( String.format("[CAM] Index: %s Id: %s Cao: %s Can: %s", index.incrementAndGet(), product.getId(), cams.get(product.getCao()), cams.get(ca))); } else if (ca != null) { System.out.println( String.format("[CAM] Index: %s Id: %s Cao: %s Can: %s", index.incrementAndGet(), product.getId(), cams.get(product.getCao()), cams.get(ca))); } else { // System.out.println(String.format("[CAM] Index: %s Id: %s Cao: %s Can: %s", index.incrementAndGet(), product.getId(), cams.get(product.getCao()), cams.get(ca))); } if (ca == null) { fail.incrementAndGet(); return; } if (product.getCao().equals(ca)) { succ.incrementAndGet(); } else if (ca != null && cams.get(product.getCao()).equals(cams.get(ca))) { succ.incrementAndGet(); } else { wrong.incrementAndGet(); } } catch (Exception e) { e.printStackTrace(); } }); } while (!THREADPOOLEXECUTOR.getQueue().isEmpty()) { TimeUnit.SECONDS.sleep(1); } TimeUnit.SECONDS.sleep(2); System.out.println(); System.out.println("[CAM] : " + total); System.out.println("[CAM] ?: " + new BigDecimal(succ.get()).divide(new BigDecimal(total), 4, RoundingMode.HALF_UP) .multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP) + "%"); System.out.println("[CAM] : " + new BigDecimal(fail.get()).divide(new BigDecimal(total), 4, RoundingMode.HALF_UP) .multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP) + "%"); System.out.println("[CAM] : " + new BigDecimal(wrong.get()).divide(new BigDecimal(total), 4, RoundingMode.HALF_UP) .multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP) + "%"); System.exit(0); }