List of usage examples for org.springframework.data.domain Page getNumberOfElements
int getNumberOfElements();
From source file:org.eclipse.hawkbit.repository.jpa.JpaRolloutManagement.java
private Long assignTargetsToGroupInNewTransaction(final JpaRollout rollout, final RolloutGroup group, final String targetFilter, final long limit) { return runInNewTransaction("assignTargetsToRolloutGroup", status -> { final PageRequest pageRequest = new PageRequest(0, Math.toIntExact(limit)); final List<Long> readyGroups = RolloutHelper.getGroupsByStatusIncludingGroup(rollout.getRolloutGroups(), RolloutGroupStatus.READY, group); final Page<Target> targets = targetManagement .findAllTargetsByTargetFilterQueryAndNotInRolloutGroups(pageRequest, readyGroups, targetFilter); createAssignmentOfTargetsToGroup(targets, group); return Long.valueOf(targets.getNumberOfElements()); });/*from ww w .j a va2 s .c o m*/ }
From source file:org.eclipse.hawkbit.repository.jpa.JpaRolloutManagement.java
private Long createActionsForTargetsInNewTransaction(final long rolloutId, final long groupId, final int limit) { return runInNewTransaction("createActionsForTargets", status -> { final PageRequest pageRequest = new PageRequest(0, limit); final Rollout rollout = rolloutRepository.findOne(rolloutId); final RolloutGroup group = rolloutGroupRepository.findOne(groupId); final DistributionSet distributionSet = rollout.getDistributionSet(); final ActionType actionType = rollout.getActionType(); final long forceTime = rollout.getForcedTime(); final Page<Target> targets = targetManagement.findAllTargetsInRolloutGroupWithoutAction(pageRequest, groupId);// w w w . j a v a2 s. co m if (targets.getTotalElements() > 0) { createScheduledAction(targets.getContent(), distributionSet, actionType, forceTime, rollout, group); } return Long.valueOf(targets.getNumberOfElements()); }); }
From source file:org.eclipse.hawkbit.repository.jpa.SoftwareManagementTest.java
@Test @Description("Queries and loads the metadata related to a given software module.") public void findAllSoftwareModuleMetadataBySwId() { SoftwareModule sw1 = testdataFactory.createSoftwareModuleApp(); SoftwareModule sw2 = testdataFactory.createSoftwareModuleOs(); for (int index = 0; index < 10; index++) { sw1 = softwareManagement.createSoftwareModuleMetadata(sw1.getId(), entityFactory.generateMetadata("key" + index, "value" + index)).getSoftwareModule(); }/*from www .j ava 2 s .c om*/ for (int index = 0; index < 20; index++) { sw2 = softwareManagement.createSoftwareModuleMetadata(sw2.getId(), new JpaSoftwareModuleMetadata("key" + index, sw2, "value" + index)).getSoftwareModule(); } final Page<SoftwareModuleMetadata> metadataOfSw1 = softwareManagement .findSoftwareModuleMetadataBySoftwareModuleId(sw1.getId(), new PageRequest(0, 100)); final Page<SoftwareModuleMetadata> metadataOfSw2 = softwareManagement .findSoftwareModuleMetadataBySoftwareModuleId(sw2.getId(), new PageRequest(0, 100)); assertThat(metadataOfSw1.getNumberOfElements()).isEqualTo(10); assertThat(metadataOfSw1.getTotalElements()).isEqualTo(10); assertThat(metadataOfSw2.getNumberOfElements()).isEqualTo(20); assertThat(metadataOfSw2.getTotalElements()).isEqualTo(20); }
From source file:org.eclipse.hawkbit.repository.jpa.SoftwareModuleManagementTest.java
@Test @Description("Queries and loads the metadata related to a given software module.") public void findAllSoftwareModuleMetadataBySwId() { final SoftwareModule sw1 = testdataFactory.createSoftwareModuleApp(); final int metadataCountSw1 = 8; final SoftwareModule sw2 = testdataFactory.createSoftwareModuleOs(); final int metadataCountSw2 = 10; for (int index = 0; index < metadataCountSw1; index++) { softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(sw1.getId()) .key("key" + index).value("value" + index).targetVisible(true)); }// ww w .ja v a 2s . c om for (int index = 0; index < metadataCountSw2; index++) { softwareModuleManagement.createMetaData(entityFactory.softwareModuleMetadata().create(sw2.getId()) .key("key" + index).value("value" + index).targetVisible(false)); } Page<SoftwareModuleMetadata> metadataSw1 = softwareModuleManagement .findMetaDataBySoftwareModuleId(PageRequest.of(0, 100), sw1.getId()); Page<SoftwareModuleMetadata> metadataSw2 = softwareModuleManagement .findMetaDataBySoftwareModuleId(PageRequest.of(0, 100), sw2.getId()); assertThat(metadataSw1.getNumberOfElements()).isEqualTo(metadataCountSw1); assertThat(metadataSw1.getTotalElements()).isEqualTo(metadataCountSw1); assertThat(metadataSw2.getNumberOfElements()).isEqualTo(metadataCountSw2); assertThat(metadataSw2.getTotalElements()).isEqualTo(metadataCountSw2); metadataSw1 = softwareModuleManagement .findMetaDataBySoftwareModuleIdAndTargetVisible(PageRequest.of(0, 100), sw1.getId()); metadataSw2 = softwareModuleManagement .findMetaDataBySoftwareModuleIdAndTargetVisible(PageRequest.of(0, 100), sw2.getId()); assertThat(metadataSw1.getNumberOfElements()).isEqualTo(metadataCountSw1); assertThat(metadataSw1.getTotalElements()).isEqualTo(metadataCountSw1); assertThat(metadataSw2.getNumberOfElements()).isEqualTo(0); assertThat(metadataSw2.getTotalElements()).isEqualTo(0); }
From source file:org.eclipse.hawkbit.repository.jpa.TargetManagementTest.java
@Test @Description("Queries and loads the metadata related to a given target.") public void findAllTargetMetadataByControllerId() { // create targets final Target target1 = createTargetWithMetadata("target1", 10); final Target target2 = createTargetWithMetadata("target2", 8); final Page<TargetMetadata> metadataOfTarget1 = targetManagement .findMetaDataByControllerId(PageRequest.of(0, 100), target1.getControllerId()); final Page<TargetMetadata> metadataOfTarget2 = targetManagement .findMetaDataByControllerId(PageRequest.of(0, 100), target2.getControllerId()); assertThat(metadataOfTarget1.getNumberOfElements()).isEqualTo(10); assertThat(metadataOfTarget1.getTotalElements()).isEqualTo(10); assertThat(metadataOfTarget2.getNumberOfElements()).isEqualTo(8); assertThat(metadataOfTarget2.getTotalElements()).isEqualTo(8); }
From source file:org.fao.geonet.OgpAppHandler.java
private void fillCaches(final ServiceContext context) { final Format formatService = context.getBean(Format.class); // this will initialize the formatter Thread fillCaches = new Thread(new Runnable() { @Override/* w w w .ja va 2 s . c o m*/ public void run() { final ServletContext servletContext = context.getServlet().getServletContext(); context.setAsThreadLocal(); ApplicationContextHolder.set(_applicationContext); GeonetWro4jFilter filter = (GeonetWro4jFilter) servletContext .getAttribute(GeonetWro4jFilter.GEONET_WRO4J_FILTER_KEY); @SuppressWarnings("unchecked") List<String> wro4jUrls = _applicationContext.getBean("wro4jUrlsToInitialize", List.class); for (String wro4jUrl : wro4jUrls) { Log.info(Geonet.GEONETWORK, "Initializing the WRO4J group: " + wro4jUrl + " cache"); final MockHttpServletRequest servletRequest = new MockHttpServletRequest(servletContext, "GET", "/static/" + wro4jUrl); final MockHttpServletResponse response = new MockHttpServletResponse(); try { filter.doFilter(servletRequest, response, new MockFilterChain()); } catch (Throwable t) { Log.info(Geonet.GEONETWORK, "Error while initializing the WRO4J group: " + wro4jUrl + " cache", t); } } final Page<Metadata> metadatas = _applicationContext.getBean(MetadataRepository.class) .findAll(new PageRequest(0, 1)); if (metadatas.getNumberOfElements() > 0) { Integer mdId = metadatas.getContent().get(0).getId(); context.getUserSession().loginAs( new User().setName("admin").setProfile(Profile.Administrator).setUsername("admin")); @SuppressWarnings("unchecked") List<String> formattersToInitialize = _applicationContext.getBean("formattersToInitialize", List.class); for (String formatterName : formattersToInitialize) { Log.info(Geonet.GEONETWORK, "Initializing the Formatter with id: " + formatterName); final MockHttpServletRequest servletRequest = new MockHttpServletRequest(servletContext); final MockHttpServletResponse response = new MockHttpServletResponse(); try { formatService.exec("eng", FormatType.html.toString(), mdId.toString(), null, formatterName, Boolean.TRUE.toString(), false, FormatterWidth._100, new ServletWebRequest(servletRequest, response)); } catch (Throwable t) { Log.info(Geonet.GEONETWORK, "Error while initializing the Formatter with id: " + formatterName, t); } } } } }); fillCaches.setDaemon(true); fillCaches.setName("Fill Caches Thread"); fillCaches.setPriority(Thread.MIN_PRIORITY); fillCaches.start(); }
From source file:org.springframework.data.elasticsearch.repository.support.DoubleIDRepositoryTest.java
@Test public void shouldSearchDocumentsGivenSearchQuery() { //given/*from ww w.jav a 2 s . com*/ Double documentId = RandomUtils.nextDouble(); DoubleIDEntity sampleEntity = new DoubleIDEntity(); sampleEntity.setId(documentId); sampleEntity.setMessage("some test message"); sampleEntity.setVersion(System.currentTimeMillis()); repository.save(sampleEntity); SearchQuery query = new NativeSearchQueryBuilder().withQuery(termQuery("message", "test")).build(); //when Page<DoubleIDEntity> page = repository.search(query); //then assertThat(page, is(notNullValue())); assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1))); }
From source file:org.springframework.data.elasticsearch.repository.support.DoubleIDRepositoryTest.java
@Test public void shouldSearchDocumentsGivenElasticsearchQuery() { //given/*from www .j av a 2 s.c o m*/ Double documentId = RandomUtils.nextDouble(); DoubleIDEntity sampleEntity = new DoubleIDEntity(); sampleEntity.setId(documentId); sampleEntity.setMessage("hello world."); sampleEntity.setVersion(System.currentTimeMillis()); repository.save(sampleEntity); //when Page<DoubleIDEntity> page = repository.search(termQuery("message", "world"), new PageRequest(0, 50)); //then assertThat(page, is(notNullValue())); assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1))); }
From source file:org.springframework.data.elasticsearch.repository.support.IntegerIDRepositoryTest.java
@Test public void shouldSearchDocumentsGivenSearchQuery() { //given//from w w w.j a va 2s . co m Integer documentId = RandomUtils.nextInt(); IntegerIDEntity sampleEntity = new IntegerIDEntity(); sampleEntity.setId(documentId); sampleEntity.setMessage("some test message"); sampleEntity.setVersion(System.currentTimeMillis()); repository.save(sampleEntity); SearchQuery query = new NativeSearchQueryBuilder().withQuery(termQuery("message", "test")).build(); //when Page<IntegerIDEntity> page = repository.search(query); //then assertThat(page, is(notNullValue())); assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1))); }
From source file:org.springframework.data.elasticsearch.repository.support.IntegerIDRepositoryTest.java
@Test public void shouldSearchDocumentsGivenElasticsearchQuery() { //given// www . j av a 2 s. c o m Integer documentId = RandomUtils.nextInt(); IntegerIDEntity sampleEntity = new IntegerIDEntity(); sampleEntity.setId(documentId); sampleEntity.setMessage("hello world."); sampleEntity.setVersion(System.currentTimeMillis()); repository.save(sampleEntity); //when Page<IntegerIDEntity> page = repository.search(termQuery("message", "world"), new PageRequest(0, 50)); //then assertThat(page, is(notNullValue())); assertThat(page.getNumberOfElements(), is(greaterThanOrEqualTo(1))); }