Пример #1
0
  // 点击关闭按钮(明细新增等)
  @RequestMapping("DtlInitReflash")
  public String DtlInitReflash(
      Model model, FTZ210205Form form, @PageableDefaults Pageable pageable) {
    FtzInMsgCtl query_FtzInMsgCtl = new FtzInMsgCtl();
    query_FtzInMsgCtl.setMsgId(form.getSelected_msgId());
    FtzInMsgCtl ftzInMsgCtl = ftz210205Serv.queryFtzInMsgCtl(query_FtzInMsgCtl);
    if (null == ftzInMsgCtl) {
      model.addAttribute(ResultMessages.error().add("w.sm.0001"));
      return "ftzmis/FTZ210205_Input_Dtl";
    }
    ftzInMsgCtl.setSubmitDate(DateUtil.getFormatDateAddSprit(ftzInMsgCtl.getSubmitDate()));
    ftzInMsgCtl.setBalanceCode(ftzInMsgCtl.getBalanceCode().trim());
    form.setFtzInMsgCtl(ftzInMsgCtl);

    FtzInTxnDtl query_FtzInTxnDtl = new FtzInTxnDtl();
    query_FtzInTxnDtl.setMsgId(form.getSelected_msgId());
    // 查询明细数据列表
    Page<FtzInTxnDtl> page = ftz210205Serv.queryFtzInTxnDtlPage(pageable, query_FtzInTxnDtl);
    if (page.getContent().size() > 0) {
      List<FtzInTxnDtl> ftzInTxnDtls = page.getContent();
      for (FtzInTxnDtl ftzInTxnDtl : ftzInTxnDtls) {
        ftzInTxnDtl.setTranDate(DateUtil.getFormatDateAddSprit(ftzInTxnDtl.getTranDate()));
      }
      model.addAttribute("page", page);
    }

    // 清空页面列表选择Key
    form.setSelected_msgId("");
    form.setSelected_seqNo(null);
    return "ftzmis/FTZ210205_Input_Dtl";
  }
Пример #2
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  @RequestMapping("Qry")
  public String query(
      BatchManageForm batchManageForm, @PageableDefaults Pageable pageable, Model model) {
    batchManageServ.transTimeFmtRemove(batchManageForm);

    BatTaskInfo query_batTaskInfo = new BatTaskInfo();
    query_batTaskInfo.setTaskName(batchManageForm.getQuery_task_name());
    query_batTaskInfo.setTaskStartType(batchManageForm.getQuery_task_type());
    query_batTaskInfo.setTaskStartTimeStart(batchManageForm.getQuery_taskStartTimeStart());
    query_batTaskInfo.setTaskStartTimeEnd(batchManageForm.getQuery_taskStartTimeEnd());
    if (null != batchManageForm.getQuery_task_start_day()
        && !"".equals(batchManageForm.getQuery_task_start_day())) {
      query_batTaskInfo.setTaskStartDay(
          Short.parseShort(batchManageForm.getQuery_task_start_day()));
    }

    Page page = batchManageServ.queryBatTaskInfoByPage(pageable, query_batTaskInfo);
    List<BatTaskInfo> taskInfos = page.getContent();
    for (int i = 0; i < taskInfos.size(); i++) {
      BatTaskInfo taskInfo = taskInfos.get(i);
      taskInfo.setTaskStartTime(DateUtil.getFormatTimeAddColon(taskInfo.getTaskStartTime()));
    }

    if (page.getContent().size() > 0) {
      model.addAttribute("page", page);
      batchManageServ.transTimeFmtAdd(batchManageForm);
      return "sysrunner/BMG_TASK_Qry";
    } else {
      model.addAttribute(ResultMessages.info().add("w.sm.0001"));
      batchManageServ.transTimeFmtAdd(batchManageForm);
      return "sysrunner/BMG_TASK_Qry";
    }
  }
Пример #3
0
  public void runAll(String dataPath, String logPath) {
    FileUtil fileData = new FileUtil(dataPath, "out", false);
    FileUtil fileLog = new FileUtil(logPath, "out", false);
    dalian = new Dalian(fileLog);
    System.out.println("Process jiabi data start.");
    int onepage = 1000;

    long count = jiabiBaseDao.count();
    for (int i = 0; i <= count / onepage; i++) {
      long t1 = System.currentTimeMillis();
      Page<SimJiabiBaseInfo> readPage = jiabiBaseDao.findAll(new PageRequest(i, onepage));
      long t2 = System.currentTimeMillis();
      System.out.println("找1000个的时间:" + (t2 - t1));
      for (SimJiabiBaseInfo jbi : readPage.getContent()) {
        HashMap<String, HashMap<Integer, Double>> ans = getSim(jbi.getFmid());
        if (ans != null && ans.size() != 0) MapHelper.write("J" + jbi.getFmid(), ans, fileData);
      }
      System.out.println(
          "The number of completed items: " + (i * onepage + readPage.getContent().size()));
    }

    fileData.close();
    fileLog.close();
    System.out.println("Process jiabi data end.");
  }
 @Test
 public void testFacetWithParametrizedQuery() {
   FacetPage<ProductBean> facetPage = repo.findAllFacetQueryPopularity(3, new PageRequest(0, 10));
   Assert.assertEquals(0, facetPage.getFacetFields().size());
   Page<FacetQueryEntry> facets = facetPage.getFacetQueryResult();
   Assert.assertEquals(1, facets.getContent().size());
   Assert.assertEquals("popularity:[* TO 3]", facets.getContent().get(0).getValue());
   Assert.assertEquals(3, facets.getContent().get(0).getValueCount());
 }
 @Test
 @SuppressWarnings("unchecked")
 public void findByTitleContaining() {
   Pageable pageable = new PageRequest(0, 1);
   Page<Episode> page = repository.findByTitleContaining("testEpisode", pageable);
   assertEquals("testEpisode1", page.getContent().get(0).getTitle());
   assertThat(page.getContent(), hasSize(1));
   assertThat(page, Matchers.<Episode>hasItems(hasProperty("title", is("testEpisode1"))));
 }
 @Test
 public void testFacetOnMulipleQueries() {
   FacetPage<ProductBean> facetPage =
       repo.findAllFacetQueryAvailableTrueAndAvailableFalse(new PageRequest(0, 10));
   Assert.assertEquals(0, facetPage.getFacetFields().size());
   Page<FacetQueryEntry> facets = facetPage.getFacetQueryResult();
   Assert.assertEquals(2, facets.getContent().size());
   Assert.assertEquals("inStock:true", facets.getContent().get(0).getValue());
   Assert.assertEquals(3, facets.getContent().get(0).getValueCount());
   Assert.assertEquals("inStock:false", facets.getContent().get(1).getValue());
   Assert.assertEquals(1, facets.getContent().get(1).getValueCount());
 }
  @Test
  public void testFacetWithDynamicPrefix() {
    FacetPage<ProductBean> facetPage =
        repo.findAllFacetOnNameWithDynamicPrefix("pro", new PageRequest(0, 10));
    Assert.assertEquals(1, facetPage.getFacetFields().size());
    Page<FacetFieldEntry> page = facetPage.getFacetResultPage("name");
    Assert.assertEquals(1, page.getContent().size());

    Assert.assertEquals("name", page.getContent().get(0).getField().getName());
    Assert.assertEquals("product", page.getContent().get(0).getValue());
    Assert.assertEquals(1, page.getContent().get(0).getValueCount());
  }
 /** Demo of named queries using paging but not sorting */
 @Test
 @Ignore
 public void testFindByBirthDateBetweenDatesWithNullPageable() {
   Sort sort = new Sort(new Sort.Order(Sort.Direction.ASC, "name"));
   PageRequest pageRequest = new PageRequest(0, 100, sort);
   Page<Author> authors =
       authorRepository.findByBirthDateBetweenDates(
           new LocalDate().minusYears(25), new LocalDate(), pageRequest);
   assertThat(authors).isNotNull();
   assertThat(authors.getContent()).isNotNull();
   assertThat(authors.getContent().size()).isEqualTo(4);
   assertThat(authors.getContent().get(0).getName()).isEqualTo(fozzie.getName());
 }
Пример #9
0
  @RequestMapping("QryAuthDtl")
  public String queryAuthDtl(Model model, FTZ210205Form form, @PageableDefaults Pageable pageable) {
    FtzInMsgCtl query_FtzInMsgCtl = new FtzInMsgCtl();
    query_FtzInMsgCtl.setMsgId(form.getSelected_msgId());
    FtzInMsgCtl result_FtzInMsgCtl = ftz210205Serv.queryFtzInMsgCtl(query_FtzInMsgCtl);
    if (null == result_FtzInMsgCtl) {
      model.addAttribute(ResultMessages.info().add("w.sm.0001"));
      form.setSelected_msgId("");
      form.setSelected_seqNo(null);
      return "ftzmis/FTZ210205_Auth_Qry_Dtl";
    } else {
      result_FtzInMsgCtl.setSubmitDate(
          DateUtil.getFormatDateAddSprit(result_FtzInMsgCtl.getSubmitDate()));
      result_FtzInMsgCtl.setSndDatetime(
          DateUtil.getFormatDateTimeAddSpritAndColon(result_FtzInMsgCtl.getSndDatetime()));
      result_FtzInMsgCtl.setAckDatetime(
          DateUtil.getFormatDateTimeAddSpritAndColon(result_FtzInMsgCtl.getAckDatetime()));
      result_FtzInMsgCtl.setBalanceCode(result_FtzInMsgCtl.getBalanceCode().trim());
      form.setFtzInMsgCtl(result_FtzInMsgCtl);
      FtzInTxnDtl query_FtzInTxnDtl = new FtzInTxnDtl();
      query_FtzInTxnDtl.setMsgId(form.getSelected_msgId());
      // 查询待审核数据
      if ("1".equals(form.getUnAuthFlag())) {
        query_FtzInTxnDtl.setChkStatus(CommonConst.FTZ_MSG_STATUS_INPUT_COMPLETED);
        Page<FtzInTxnDtl> page = ftz210205Serv.queryFtzInTxnDtlPage(pageable, query_FtzInTxnDtl);
        if (page.getContent().size() > 0) {
          List<FtzInTxnDtl> ftzInTxnDtls = page.getContent();
          for (FtzInTxnDtl ftzInTxnDtl : ftzInTxnDtls) {
            ftzInTxnDtl.setTranDate(DateUtil.getFormatDateAddSprit(ftzInTxnDtl.getTranDate()));
          }
          model.addAttribute("page", page);
        }
      }
      // 查询全部数据
      else {
        Page<FtzInTxnDtl> page = ftz210205Serv.queryFtzInTxnDtlPage(pageable, query_FtzInTxnDtl);
        if (page.getContent().size() > 0) {
          List<FtzInTxnDtl> ftzInTxnDtls = page.getContent();
          for (FtzInTxnDtl ftzInTxnDtl : ftzInTxnDtls) {
            ftzInTxnDtl.setTranDate(DateUtil.getFormatDateAddSprit(ftzInTxnDtl.getTranDate()));
          }
          model.addAttribute("page", page);
        }
      }

      form.setSelected_msgId("");
      form.setSelected_seqNo(null);
      return "ftzmis/FTZ210205_Auth_Qry_Dtl";
    }
  }
 @Test
 public void testFindPaginatedResources() {
   this.request("repository-based").xmlPost(new Sample("toto"));
   this.request("repository-based").xmlPost(new Sample("titi"));
   Response response = this.request("repository-based").setQueryParameter("page", "1").getXml();
   Page<Sample> samples = response.resource(new TypeReference<Page<Sample>>() {});
   Assertions.assertThat(samples).isNotNull();
   Assertions.assertThat(samples.getContent()).isNotNull();
   Assertions.assertThat(samples.getContent().size()).isEqualTo(2);
   Assertions.assertThat(samples.getTotalPages()).isEqualTo(1);
   Assertions.assertThat(samples.getTotalElements()).isEqualTo(2);
   Assertions.assertThat(samples.getContent().get(0).getName()).isIn("titi", "toto");
   Assertions.assertThat(samples.getContent().get(1).getName()).isIn("titi", "toto");
 }
  @Test
  public void search_setFilteredAttributes() {
    Specification<User> searchUserSpec = userSpecifications.idStartsWith(USER_A_NAME);
    userList =
        userList
            .stream()
            .filter(u -> u.getId().startsWith(USER_A_NAME))
            .collect(Collectors.toList());
    userResultsPage = new PageImpl<>(userList, userPageable, userList.size());

    when(userRepository.findAll(searchUserSpec, userPageable)).thenReturn(userResultsPage);
    Page<UserDTO> page = communityServiceImpl.search(searchUserSpec, userPageable);
    assertEquals(1, page.getContent().size());
    assertDTOWithHiddenValues(page.getContent().get(0), userA);
  }
Пример #12
0
  /**
   * GET /clinicHistorys -> get all the clinicHistorys.
   *
   * @throws URISyntaxException
   */
  @RequestMapping(
      value = "/clinicHistorys",
      method = RequestMethod.GET,
      produces = MediaType.APPLICATION_JSON_VALUE)
  @Timed
  public ResponseEntity<List<ClinicHistory>> getAllByFilter(
      @RequestParam(value = "page", required = false) Integer offset,
      @RequestParam(value = "per_page", required = false) Integer limit,
      @RequestParam(value = "firstName", required = false) String firstName,
      @RequestParam(value = "secondName", required = false) String secondName,
      @RequestParam(value = "paternalSurname", required = false) String paternalSurname,
      @RequestParam(value = "maternalSurname", required = false) String maternalSurname,
      @RequestParam(value = "cedula", required = false) String cedula)
      throws URISyntaxException {
    log.debug("REST request to get all ClinicHistorys");
    firstName = firstName == null ? "%" : "%" + firstName + "%";
    secondName = secondName == null ? "%" : "%" + secondName + "%";
    paternalSurname = paternalSurname == null ? "%" : "%" + paternalSurname + "%";
    maternalSurname = maternalSurname == null ? "%" : "%" + maternalSurname + "%";
    cedula = cedula == null ? "%" : cedula + "%";

    Page<ClinicHistory> page =
        clinicHistoryRepository.findByFilter(
            firstName,
            secondName,
            paternalSurname,
            maternalSurname,
            cedula,
            PaginationUtil.generatePageRequest(offset, limit));
    HttpHeaders headers =
        PaginationUtil.generatePaginationHttpHeaders(page, "/api/clinicHistorys", offset, limit);
    return new ResponseEntity<List<ClinicHistory>>(page.getContent(), headers, HttpStatus.OK);
  }
 @Override
 public Iterable<DocumentObject> findAll(Integer pageNumber, Integer pageSize) {
   Page<DocumentObject> page =
       documentObjectRepository.findAll(new PageRequest(pageNumber, pageSize));
   Iterable<DocumentObject> pagedDocumentObject = page.getContent();
   return pagedDocumentObject;
 }
  @ApiOperation(value = "带条件及翻页查询")
  @RequestMapping(value = "page", method = RequestMethod.GET)
  @ResponseBody
  public AjaxPage data(@ModelAttribute @Valid PageParam param) {
    List<SpecificationCondition> conditions = new ArrayList<SpecificationCondition>();
    if (StringUtils.isNotBlank(param.channelName))
      conditions.add(SpecificationCondition.eq("id.channelId", param.channelName.split("-")[0]));
    if (StringUtils.isNotBlank(param.categoryName))
      conditions.add(SpecificationCondition.eq("id.text", param.categoryName.split("-")[0]));
    if (StringUtils.isNotBlank(param.textType))
      conditions.add(SpecificationCondition.eq("textType", param.textType));
    if (StringUtils.isNotBlank(param.text))
      conditions.add(
          SpecificationCondition.equalOrLikeIgnoreCase("id.text", "%" + param.text.trim() + "%"));
    if (StringUtils.isNotBlank(param.textState))
      conditions.add(SpecificationCondition.eq("textState", param.textState));

    List<String> sortNames = new ArrayList<String>();
    if ("id.spId".equals(param.getSortName()) || "id.spServiceCode".equals(param.getSortName())) {
      sortNames.add("id.spId");
      sortNames.add("id.spServiceCode");
    } else sortNames.add(param.getSortName());

    SpecificationHelper<ChannelTextFilter> sh =
        new SpecificationHelper<ChannelTextFilter>(conditions, param.getSortOrder(), sortNames);
    Page<ChannelTextFilter> p = ctfService.page(new PageRequest(param), sh.createSpecification());
    List<ChannelTextFilter> list = p.getContent();
    Integer category = FiltrationType.CATEGORY.getValue().intValue();
    for (ChannelTextFilter ctf : list) {
      ctf.getId().setChannelId(channelService.findOneMatch(ctf.getId().getChannelId()));
      if (category.equals(ctf.getTextType()))
        ctf.getId().setText(tftypeService.findOneMatch(ctf.getId().getText()));
    }
    return AjaxPageUtil.toAjaxPage(p.getTotalElements(), list);
  }
  /** GET /evolutionPrescriptions -> get all the evolutionPrescriptions. */
  @RequestMapping(
      value = "/episodes/{episode_id}/evolutionPrescriptions",
      method = RequestMethod.GET,
      produces = MediaType.APPLICATION_JSON_VALUE)
  @Timed
  public ResponseEntity<List<EvolutionPrescription>> getAllByEpisode(
      @PathVariable(value = "episode_id") Long episodeId,
      @RequestParam(value = "page", required = false) Integer offset,
      @RequestParam(value = "per_page", required = false) Integer limit)
      throws URISyntaxException {
    Page<EvolutionPrescription> page;

    if (episodeId != null && episodeId > 0) {
      page =
          evolutionPrescriptionRepository.findByEpisode(
              episodeId, PaginationUtil.generatePageRequest(offset, limit));
    } else {
      page =
          evolutionPrescriptionRepository.findAll(
              PaginationUtil.generatePageRequest(offset, limit));
    }
    HttpHeaders headers =
        PaginationUtil.generatePaginationHttpHeaders(
            page, "/api/episodes/" + episodeId + "/evolutionPrescriptions", offset, limit);
    return new ResponseEntity<List<EvolutionPrescription>>(
        page.getContent(), headers, HttpStatus.OK);
  }
  @Test
  public void getTracks() {

    mockUnauthorizedServer
        .expect(
            requestTo(
                "https://api.soundcloud.com/resolve?url=http://soundcloud.com/mattslip&client_id=someApiKey"))
        .andExpect(method(GET))
        .andRespond(withResponse(jsonResource("testdata/resolveuser"), responseHeaders));

    mockUnauthorizedServer
        .expect(requestTo("https://api.soundcloud.com/users/3510549?client_id=someApiKey"))
        .andExpect(method(GET))
        .andRespond(withResponse(jsonResource("testdata/userprofile"), responseHeaders));

    mockUnauthorizedServer
        .expect(requestTo("https://api.soundcloud.com/users/3510549/tracks?client_id=someApiKey"))
        .andExpect(method(GET))
        .andRespond(withResponse(jsonResource("testdata/tracks"), responseHeaders));

    Page<Track> tracksPage =
        unauthorizedSoundCloud.usersOperations().userOperations("mattslip").getTracks();
    List<Track> tracks = tracksPage.getContent();
    assertEquals(0, tracksPage.getNumber());
    assertEquals(50, tracksPage.getTotalElements());

    assertNotNull(tracks);
    assertEquals(50, tracks.size());
    Track firstTrack = tracks.get(0);
    assertEquals("Kid Sister vs Daft Punk (Monsieur Adi Mashup)", firstTrack.getTitle());
    assertEquals(
        "http://soundcloud.com/monsieuradi/kid-sister-vs-daft-punk", firstTrack.getPermalinkUrl());
    assertEquals("39679670", firstTrack.getId());
  }
 @Test
 public void testPaginationNoElementsFound() {
   Pageable pageable = new PageRequest(0, 2);
   Page<ProductBean> page = repo.findByNameStartingWith("hpotsirhc", pageable);
   Assert.assertEquals(0, page.getNumberOfElements());
   Assert.assertTrue(page.getContent().isEmpty());
 }
 @Test
 public void getLeaders_setFilteredAttributes() {
   when(userRepository.findAll(userPageable)).thenReturn(userResultsPage);
   Page<UserDTO> page = communityServiceImpl.getLeaders(userPageable);
   assertDTOWithHiddenValues(page.getContent().get(0), userA);
   assertDTOWithHiddenValues(page.getContent().get(1), userB);
 }
  /**
   * Add all bean properties from the supplied bean to the representation
   *
   * @param value
   * @return
   */
  public ResponseEntityBuilder<ReadableRepresentation> withPage(
      Page<?> value, String uriTemplate, String... includeFields) {
    String[] fields = requestedFields == null ? includeFields : requestedFields;

    // Extract page data such as size, page number
    representation.withProperty("size", value.getSize());
    representation.withProperty("number", value.getNumber());
    representation.withProperty("numberOfElements", value.getNumberOfElements());
    representation.withProperty("totalElements", value.getTotalElements());

    // Next/back links
    if (value.hasNextPage()) {
      buildNextLink(representation, request);
    }
    if (value.hasPreviousPage()) {
      buildPreviousLink(representation, request);
    }

    // Build the content of the page
    for (Object object : value.getContent()) {
      Representation content = converter.convert(object, new UriTemplate(uriTemplate), fields);
      this.representation.withRepresentation("content", content);
    }
    return this;
  }
 @Override
 public List<OaCertificateType> findAll(Page page) {
   org.springframework.data.domain.Page<OaCertificateType> springDataPage =
       certificateTypeDAO.findAll(PageUtils.createPageable(page));
   page.setTotalCount(springDataPage.getTotalElements());
   return springDataPage.getContent();
 }
  @Test
  public void getFavoritesByUserId() {

    mockUnauthorizedServer
        .expect(requestTo("https://api.soundcloud.com/users/3510549?client_id=someApiKey"))
        .andExpect(method(GET))
        .andRespond(withResponse(jsonResource("testdata/userprofile"), responseHeaders));

    mockUnauthorizedServer
        .expect(
            requestTo("https://api.soundcloud.com/users/3510549/favorites?client_id=someApiKey"))
        .andExpect(method(GET))
        .andRespond(withResponse(jsonResource("testdata/favorites"), responseHeaders));

    Page<Track> tracksPage =
        unauthorizedSoundCloud.usersOperations().userOperations(3510549).getFavorites();
    assertEquals(0, tracksPage.getNumber());
    assertEquals(56, tracksPage.getTotalElements());
    List<Track> tracks = tracksPage.getContent();
    assertNotNull(tracks);
    assertEquals(50, tracks.size());
    Track firstTrack = tracks.get(0);
    assertEquals("Sneaky Sound System - Big (Oliver Remix)", firstTrack.getTitle());
    assertEquals(
        "http://soundcloud.com/weareoliver/sneaky-sound-system-big-oliver",
        firstTrack.getPermalinkUrl());
    assertEquals("22905377", firstTrack.getId());
  }
  @ApiOperation(value = "带条件及翻页查询")
  @RequestMapping(value = "page", method = RequestMethod.POST)
  @ResponseBody
  public AjaxPage page(@ModelAttribute @Valid PageParam param) {

    List<SpecificationCondition> conditions = new ArrayList<SpecificationCondition>();
    conditions.add(
        SpecificationCondition.equalOrLikeIgnoreCase(
            "textFilterPattern", param.getTextFilterPattern()));
    SpecificationHelper<TextFilter> sh = new SpecificationHelper<TextFilter>(conditions, param);
    Page<TextFilter> p = textFilterService.page(new PageRequest(param), sh.createSpecification());
    List<esms.etonenet.boss1069.web.decorate.TextFilter> list = new ArrayList<>();
    for (TextFilter textFilter : p.getContent()) {
      esms.etonenet.boss1069.web.decorate.TextFilter textFilters =
          new esms.etonenet.boss1069.web.decorate.TextFilter();
      List<Integer> inte =
          CheckBoxUtil.findx2Value(textFilter.getTextFilterCategoryFlag().intValue());
      textFilters.setTextFilterPattern(textFilter.getTextFilterPattern());
      StringBuffer sb = new StringBuffer();
      for (Integer integer : inte) {
        if (integer != null)
          sb.append(ContentFilterCategoryFlag.toDisplayMap().get(String.valueOf(integer)));
        sb.append(" ");
      }
      textFilters.setTextFilterCategoryFlagName(sb.toString().trim());
      list.add(textFilters);
    }
    return AjaxPageUtil.toAjaxPage(p.getTotalElements(), list);
  }
  @Test
  public void testFindAllSortingByName() {
    Sort sort = new Sort(new Sort.Order(Sort.Direction.ASC, "name"));
    PageRequest pageRequest = new PageRequest(0, 100, sort);
    Page<Author> authors = authorRepository.findAll(pageRequest);
    assertThat(authors).isNotNull();
    assertThat(authors.getContent().size()).isEqualTo(4);
    assertThat(authors.getContent().get(0).getName()).isEqualTo(fozzie.getName());

    sort = new Sort(new Sort.Order(Sort.Direction.DESC, "name"));
    pageRequest = new PageRequest(0, 100, sort);
    authors = authorRepository.findAll(pageRequest);
    assertThat(authors).isNotNull();
    assertThat(authors.getContent().size()).isEqualTo(4);
    assertThat(authors.getContent().get(0).getName()).isEqualTo(swedishChef.getName());
  }
Пример #24
0
  public WebPageDto(Page<T> page, String url) {
    this.url = url;
    this.totalPages = page.getTotalPages();
    this.totalElements = page.getTotalElements();
    this.firstPage = page.isFirstPage();
    this.lastPage = page.isLastPage();
    this.hasPreviousPage = page.hasPreviousPage();
    this.hasNextPage = page.hasNextPage();
    this.size = page.getSize();
    this.number = page.getNumber() + 1;
    this.content = page.getContent();

    int start, size;
    if (totalPages <= DEFAULT_PAGES) {
      start = 1;
      size = totalPages;
    } else {
      if (number <= DEFAULT_PAGES - DEFAULT_PAGES / 2) {
        start = 1;
        size = DEFAULT_PAGES;
      } else if (number >= totalPages - DEFAULT_PAGES / 2) {
        start = totalPages - DEFAULT_PAGES + 1;
        size = DEFAULT_PAGES;
      } else {
        start = number - DEFAULT_PAGES / 2;
        size = DEFAULT_PAGES;
      }
    }

    for (int i = 0; i < size; i++) {
      items.add(new PageItem(start + i, (start + i) == number));
    }
  }
  public DomainList<BeneficiaryDomain> getBeneficiariesByArrangement(
      ArrangementDomain arrangement, Integer pageIndex, Integer pageSize) {
    Pageable pageable = new PageRequest(pageIndex, pageSize);
    Page<BeneficiaryDomain> page = beneficiaryRepository.findByArrangement(arrangement, pageable);

    return new DomainList<BeneficiaryDomain>(page.getContent(), (int) page.getTotalElements());
  }
Пример #26
0
 @Override
 public void restartDataTracking() {
   Page<TwitterUser> existingUsers =
       twitterUserRepository.findAllListMembers(new PageRequest(0, 4000));
   tick5StatusListener.halt();
   tick5StatusListener.listen(existingUsers.getContent());
 }
  @Test
  public void shouldSortResultsGivenSortCriteria() {
    // given
    List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
    // first document
    String documentId = randomNumeric(5);
    SampleEntity sampleEntity1 = new SampleEntity();
    sampleEntity1.setId(documentId);
    sampleEntity1.setMessage("abc");
    sampleEntity1.setRate(10);
    sampleEntity1.setVersion(System.currentTimeMillis());

    IndexQuery indexQuery1 = new IndexQuery();
    indexQuery1.setId(documentId);
    indexQuery1.setObject(sampleEntity1);

    // second document
    String documentId2 = randomNumeric(5);
    SampleEntity sampleEntity2 = new SampleEntity();
    sampleEntity2.setId(documentId2);
    sampleEntity2.setMessage("xyz");
    sampleEntity2.setRate(5);
    sampleEntity2.setVersion(System.currentTimeMillis());

    IndexQuery indexQuery2 = new IndexQuery();
    indexQuery2.setId(documentId2);
    indexQuery2.setObject(sampleEntity2);

    // third document
    String documentId3 = randomNumeric(5);
    SampleEntity sampleEntity3 = new SampleEntity();
    sampleEntity3.setId(documentId3);
    sampleEntity3.setMessage("xyz");
    sampleEntity3.setRate(15);
    sampleEntity3.setVersion(System.currentTimeMillis());

    IndexQuery indexQuery3 = new IndexQuery();
    indexQuery3.setId(documentId3);
    indexQuery3.setObject(sampleEntity3);

    indexQueries.add(indexQuery1);
    indexQueries.add(indexQuery2);
    indexQueries.add(indexQuery3);

    elasticsearchTemplate.bulkIndex(indexQueries);
    elasticsearchTemplate.refresh(SampleEntity.class, true);

    SearchQuery searchQuery =
        new NativeSearchQueryBuilder()
            .withQuery(matchAllQuery())
            .withSort(new FieldSortBuilder("rate").ignoreUnmapped(true).order(SortOrder.ASC))
            .build();
    // when
    Page<SampleEntity> sampleEntities =
        elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class);
    // then
    assertThat(sampleEntities.getTotalElements(), equalTo(3L));
    assertThat(sampleEntities.getContent().get(0).getRate(), is(sampleEntity2.getRate()));
  }
 @Override
 public List<OaCertificateType> find(Page page, String typeName) {
   org.springframework.data.domain.Page<OaCertificateType> springDataPage =
       (org.springframework.data.domain.Page<OaCertificateType>)
           certificateTypeDAO.findByTypeNameContaining(typeName, PageUtils.createPageable(page));
   page.setTotalCount(springDataPage.getTotalElements());
   return springDataPage.getContent();
 }
  @Test
  public void findsFirstPageOfMatthews() throws Exception {

    Page<Customer> customers = repository.findByLastname("Matthews", new PageRequest(0, 2));

    assertThat(customers.getContent().size(), is(2));
    assertFalse(customers.hasPreviousPage());
  }
 @Override
 public <T> T queryForObject(StringQuery query, Class<T> clazz) {
   Page<T> page = queryForPage(query, clazz);
   Assert.isTrue(
       page.getTotalElements() < 2,
       "Expected 1 but found " + page.getTotalElements() + " results");
   return page.getTotalElements() > 0 ? page.getContent().get(0) : null;
 }