use of org.springframework.data.domain.Pageable in project hse-cws by holuhoev.
the class StudentWorkloadDatasource method getStudentSumWorkload.
public DataSourceResult getStudentSumWorkload(final Integer groupId, final Integer studentId, final Integer facultyId, final Integer instituteId, final Course course, final String studentFio, final EducationType educationType, final LocalDate fromDate, final LocalDate toDate, final Integer top, final Integer skip, final Boolean fetchTotal, final String orderBy) {
QStudent qStudent = QStudent.student;
QStudentWorkload qStudentWorkload = QStudentWorkload.studentWorkload;
BooleanBuilder studentBuilder = new BooleanBuilder();
BooleanBuilder workloadBuilder = new BooleanBuilder();
if (groupId != null) {
studentBuilder.and(qStudent.groupID.eq(groupId));
}
if (studentId != null) {
studentBuilder.and(qStudent.Id.eq(studentId));
}
if (facultyId != null) {
studentBuilder.and(qStudent.facultyID.eq(facultyId));
}
if (instituteId != null) {
studentBuilder.and(qStudent.instituteID.eq(instituteId));
}
if (course != null) {
studentBuilder.and(qStudent.course.eq(course));
}
if (studentFio != null && !studentFio.isEmpty()) {
studentBuilder.and(qStudent.fio.containsIgnoreCase(studentFio));
}
if (educationType != null) {
studentBuilder.and(qStudent.educationType.eq(educationType));
}
if (fromDate != null) {
workloadBuilder.and(qStudentWorkload.date.after(fromDate).or(qStudentWorkload.date.eq(fromDate)));
}
if (toDate != null) {
workloadBuilder.and(qStudentWorkload.date.before(toDate).or(qStudentWorkload.date.before(toDate)));
}
Iterable<Student> students;
if (top != null) {
String orderByString = isNullOrEmpty(orderBy) ? "fio" : orderBy;
Pageable limit = PageRequest.of(skip, top, Sort.Direction.ASC, orderByString);
students = studentRepository.findAll(studentBuilder, limit);
} else {
students = studentRepository.findAll(studentBuilder);
}
Stream<Student> studentStream = StreamSupport.stream(students.spliterator(), false);
List<StudentSumWorkload> result = studentStream.map(student -> {
BooleanBuilder builder = new BooleanBuilder();
builder.and(workloadBuilder).and(qStudentWorkload.studentId.eq(student.getId()));
// Если запросили тот период, по которому нет инфы, то запрашивать из руза и добавлять в загруженность
// Еще надо смотреть, что есть такой date == toDate, если нет, то искать макисмальный, а остальное запросить
Integer workload = StreamSupport.stream(studentWorkloadRepository.findAll(builder).spliterator(), false).mapToInt(StudentWorkload::getWorkload).sum();
return new StudentSumWorkload(student.getFio(), workload, student.getId());
}).collect(Collectors.toList());
Map<String, Object> hints = new HashMap<>();
hints.put("paging", true);
if (fetchTotal != null && fetchTotal) {
Long count = studentRepository.count(studentBuilder);
hints.put("total", count);
}
return DataSourceResult.create(result, hints);
}
use of org.springframework.data.domain.Pageable in project JavaForFun by gumartinm.
the class AdDescriptionRevisionServiceShould method test.
@Test
public void test() {
AdDescriptionRepository adDescriptionRepository = mock(AdDescriptionRepository.class);
AdDescriptionRevisionServiceImpl adDescriptionRevisionService = new AdDescriptionRevisionServiceImpl();
adDescriptionRevisionService.setRepository(adDescriptionRepository);
List<Revision<Integer, AdDescription>> adRevisions = new ArrayList<>();
Pageable pageRequest = new PageRequest(0, 1);
Page<Revision<Integer, AdDescription>> page = new PageImpl<>(adRevisions);
given(adDescriptionRepository.findRevisions(1L, pageRequest)).willReturn(page);
assertThat(adDescriptionRevisionService.findRevisions(1L, pageRequest), is(page));
}
use of org.springframework.data.domain.Pageable in project tutorials by eugenp.
the class MongoTemplateQueryLiveTest method givenUsersExist_whenFindingByPage_thenUsersAreFoundByPage.
@Test
public void givenUsersExist_whenFindingByPage_thenUsersAreFoundByPage() {
User user = new User();
user.setName("Eric");
user.setAge(45);
mongoTemplate.insert(user);
user = new User();
user.setName("Antony");
user.setAge(33);
mongoTemplate.insert(user);
user = new User();
user.setName("Alice");
user.setAge(35);
mongoTemplate.insert(user);
final Pageable pageableRequest = new PageRequest(0, 2);
Query query = new Query();
query.with(pageableRequest);
List<User> users = mongoTemplate.find(query, User.class);
assertThat(users.size(), is(2));
}
use of org.springframework.data.domain.Pageable in project tutorials by eugenp.
the class UserRepositoryLiveTest method givenUsersExist_whenFindingAllUsersWithPagination_thenUsersAreFoundAndOrderedOnPage.
@Test
public void givenUsersExist_whenFindingAllUsersWithPagination_thenUsersAreFoundAndOrderedOnPage() {
User user = new User();
user.setName("Brendan");
mongoOps.insert(user);
user = new User();
user.setName("Adam");
mongoOps.insert(user);
final Pageable pageableRequest = new PageRequest(0, 1);
final Page<User> page = userRepository.findAll(pageableRequest);
List<User> users = page.getContent();
assertThat(users.size(), is(1));
assertThat(page.getTotalPages(), is(2));
}
use of org.springframework.data.domain.Pageable in project tutorials-java by Artister.
the class ApplicationTests method pageTest.
@Test
public void pageTest() {
/**
* @see PageRequest
* page 从0开始
* size 大小
*/
Pageable pageable = new PageRequest(0, 5);
Page<User> Users = pagingSortRepository.findAll(pageable);
out.println("总页数" + Users.getTotalPages());
out.println("总记录数" + Users.getTotalElements());
out.println("当前第几页" + Users.getNumber() + 1);
out.println("当前页面的集合" + Users.getContent());
out.println("当前页面的记录数" + Users.getNumberOfElements());
}
Aggregations