當前位置: 首頁>>代碼示例>>Java>>正文


Java PagedResources類代碼示例

本文整理匯總了Java中org.springframework.hateoas.PagedResources的典型用法代碼示例。如果您正苦於以下問題:Java PagedResources類的具體用法?Java PagedResources怎麽用?Java PagedResources使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PagedResources類屬於org.springframework.hateoas包,在下文中一共展示了PagedResources類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: events

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@GetMapping("events")
HttpEntity<Resources<?>> events(PagedResourcesAssembler<AbstractEvent<?>> assembler,
		@SortDefault("publicationDate") Pageable pageable,
		@RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime since,
		@RequestParam(required = false) String type) {

	QAbstractEvent $ = QAbstractEvent.abstractEvent;

	BooleanBuilder builder = new BooleanBuilder();

	// Apply date
	Optional.ofNullable(since).ifPresent(it -> builder.and($.publicationDate.after(it)));

	// Apply type
	Optional.ofNullable(type) //
			.flatMap(events::findEventTypeByName) //
			.ifPresent(it -> builder.and($.instanceOf(it)));

	Page<AbstractEvent<?>> result = events.findAll(builder, pageable);

	PagedResources<Resource<AbstractEvent<?>>> resource = assembler.toResource(result, event -> toResource(event));
	resource
			.add(links.linkTo(methodOn(EventController.class).events(assembler, pageable, since, type)).withRel("events"));

	return ResponseEntity.ok(resource);
}
 
開發者ID:olivergierke,項目名稱:sos,代碼行數:27,代碼來源:EventController.java

示例2: run

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@Override
public void run() {
    try {
        PagedResources<Tweet> tweetsResource = tweetClient.getTweetsByPage(pageIndex);

        tweetsResource.iterator().forEachRemaining(tweet -> {
            tweetRepository.save(tweet);
            log.info("SEARCH-SERVICE push: " + tweet.getText());
        });


        log.info(String.format("Total Page#: [%d] \n" +
                        "Size of Page: %d \n" +
                        "Number of Page: %d \n",
                tweetsResource.getMetadata().getTotalPages(),
                tweetsResource.getMetadata().getSize(),
                tweetsResource.getMetadata().getNumber()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:thinksky-sourcecode,項目名稱:microservices-prototype,代碼行數:22,代碼來源:PusherProcessor.java

示例3: importFromLocalResource

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@Test
public void importFromLocalResource() {
	String name1 = "foo";
	String type1 = "source";
	String uri1 = "file:///foo";
	String name2 = "bar";
	String type2 = "sink";
	String uri2 = "file:///bar";
	Properties apps = new Properties();
	apps.setProperty(type1 + "." + name1, uri1);
	apps.setProperty(type2 + "." + name2, uri2);
	List<AppRegistrationResource> resources = new ArrayList<>();
	resources.add(new AppRegistrationResource(name1, type1, uri1));
	resources.add(new AppRegistrationResource(name2, type2, uri2));
	PagedResources<AppRegistrationResource> pagedResources = new PagedResources<>(resources,
			new PagedResources.PageMetadata(resources.size(), 1, resources.size(), 1));
	when(appRegistryOperations.registerAll(apps, true)).thenReturn(pagedResources);
	String appsFileUri = "classpath:appRegistryCommandsTests-apps.properties";
	String result = appRegistryCommands.importFromResource(appsFileUri, true, true);
	assertEquals("Successfully registered applications: [source.foo, sink.bar]", result);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-dashboard,代碼行數:22,代碼來源:AppRegistryCommandsTests.java

示例4: testStatusWithSummary

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@Test
public void testStatusWithSummary() {
	Collection<AppStatusResource> data = new ArrayList<>();
	data.add(appStatusResource1);
	data.add(appStatusResource2);
	data.add(appStatusResource3);
	PagedResources.PageMetadata metadata = new PagedResources.PageMetadata(data.size(), 1, data.size(), 1);
	PagedResources<AppStatusResource> result = new PagedResources<>(data, metadata);
	when(runtimeOperations.status()).thenReturn(result);
	Object[][] expected = new String[][] {
			{"1", "deployed", "2"},
			{"2", "undeployed", "0"},
			{"3", "failed", "0"}
	};
	TableModel model = runtimeCommands.list(true, null).getModel();
	for (int row = 0; row < expected.length; row++) {
		for (int col = 0; col < expected[row].length; col++) {
			assertThat(String.valueOf(model.getValue(row + 1, col)), Matchers.is(expected[row][col]));
		}
	}
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-dashboard,代碼行數:22,代碼來源:RuntimeCommandsTests.java

示例5: testStatusWithoutSummary

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@Test
public void testStatusWithoutSummary() {
	Collection<AppStatusResource> data = new ArrayList<>();
	data.add(appStatusResource1);
	data.add(appStatusResource2);
	PagedResources.PageMetadata metadata = new PagedResources.PageMetadata(data.size(), 1, data.size(), 1);
	PagedResources<AppStatusResource> result = new PagedResources<>(data, metadata);
	when(runtimeOperations.status()).thenReturn(result);
	Object[][] expected = new String[][] {
			{"1", "deployed", "2"},
			{"10", "deployed"},
			{"20", "deployed"},
			{"2", "undeployed", "0"}
	};
	TableModel model = runtimeCommands.list(false, null).getModel();
	for (int row = 0; row < expected.length; row++) {
		for (int col = 0; col < expected[row].length; col++) {
			assertThat(String.valueOf(model.getValue(row + 1, col)), Matchers.is(expected[row][col]));
		}
	}
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-dashboard,代碼行數:22,代碼來源:RuntimeCommandsTests.java

示例6: list

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@RequestMapping
public PagedResources<AppStatusResource> list(PagedResourcesAssembler<AppStatus> assembler) {
	List<AppStatus> values = new ArrayList<>();

	for (ApplicationDefinition applicationDefinition : this.applicationDefinitionRepository.findAll()) {
		String key = forApplicationDefinition(applicationDefinition);
		String id = this.deploymentIdRepository.findOne(key);
		if (id != null) {
			values.add(appDeployer.status(id));
		}
	}

	Collections.sort(values, new Comparator<AppStatus>() {
		@Override
		public int compare(AppStatus o1, AppStatus o2) {
			return o1.getDeploymentId().compareTo(o2.getDeploymentId());
		}
	});
	return assembler.toResource(new PageImpl<>(values), statusAssembler);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-dashboard,代碼行數:21,代碼來源:RuntimeAppsController.java

示例7: getAllDashboards

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@Test
public void getAllDashboards() throws Exception {
  when(dashboardService.loadAll(any(Pageable.class))).thenReturn(new PageImpl<>(dashboardList()));

  MvcResult result =
      mvc()
          .perform(get("/api/dashboards"))
          .andExpect(status().isOk())
          .andExpect(containsPagedResources(DashboardResource.class))
          .andDo(document("dashboards/list"))
          .andReturn();

  PagedResources<DashboardResource> pagedResources =
      fromPagedResourceJson(result.getResponse().getContentAsString(), DashboardResource.class);
  assertThat(pagedResources.getContent()).hasSize(1);
}
 
開發者ID:reflectoring,項目名稱:infiniboard,代碼行數:17,代碼來源:DashboardControllerTest.java

示例8: getWidgets

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@Test
public void getWidgets() throws Exception {
  when(widgetConfigRepository.findAll(any(Pageable.class)))
      .thenReturn(new PageImpl<>(widgetConfigList()));
  MvcResult result =
      mvc()
          .perform(get("/api/dashboards/1/widgets"))
          .andExpect(status().isOk())
          .andExpect(containsPagedResources(WidgetConfigResource.class))
          .andDo(document("widgets/list"))
          .andReturn();

  PagedResources<WidgetConfigResource> resource =
      fromPagedResourceJson(
          result.getResponse().getContentAsString(), WidgetConfigResource.class);
  assertThat(resource.getContent()).hasSize(1);
}
 
開發者ID:reflectoring,項目名稱:infiniboard,代碼行數:18,代碼來源:WidgetControllerTest.java

示例9: list

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
/**
 * List Counters that match the given criteria.
 */
@RequestMapping(value = "", method = RequestMethod.GET)
public PagedResources<AggregateCounterResource> list(
		Pageable pageable, PagedResourcesAssembler<String> pagedAssembler,
		@RequestParam(value = "detailed", defaultValue = "false") boolean detailed,
		@RequestParam(value = "from", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime from,
		@RequestParam(value = "to", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) DateTime to,
		@RequestParam(value = "resolution", defaultValue = "hour") AggregateCounterResolution resolution) {
	List<String> names = new ArrayList<>(repository.list());
	long count = names.size();
	long pageEnd = Math.min(count, pageable.getOffset() + pageable.getPageSize());
	Page aggregateCounterPage = new PageImpl<>(names.subList(pageable.getOffset(), (int) pageEnd), pageable, names.size());
	PagedResources<AggregateCounterResource> resources = pagedAssembler.toResource(aggregateCounterPage, shallowAssembler);
	if (detailed) {
		to = providedOrDefaultToValue(to);
		from = providedOrDefaultFromValue(from, to, resolution);
		Interval interval = new Interval(from, to);
		List<AggregateCounterResource> aggregateCounts = new LinkedList<>();
		for (AggregateCounterResource aggregateCounterResource : resources) {
			AggregateCounter aggregateCount = repository.getCounts(aggregateCounterResource.getName(), interval, resolution);
			aggregateCounts.add(deepAssembler.toResource(aggregateCount));
		}
		return new PagedResources<>(aggregateCounts, resources.getMetadata());
	}
	return resources;
}
 
開發者ID:spring-projects,項目名稱:spring-analytics,代碼行數:29,代碼來源:AggregateCounterController.java

示例10: getProposalSubmissions

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@RequestMapping(method = RequestMethod.GET, value = "/proposalSubmissions")
public @ResponseBody
PagedResources<PersistentEntityResource> getProposalSubmissions(
        HttpServletRequest request, Principal principal, Pageable pageable,
        PersistentEntityResourceAssembler resourceAssembler) {

    Page<ProposalSubmission> proposalSubmissions;

    if (request.isUserInRole("ADMIN") || request.isUserInRole("COORDINATOR")) {
        proposalSubmissions = proposalSubmissionRepository.findAll(pageable);
    } else {
        Proponent proponent = proponentRepository.findOne(principal.getName());
        proposalSubmissions = proposalSubmissionRepository.findByAgent(proponent, pageable);
    }

    return pagedResourcesAssembler.toResource(proposalSubmissions, resourceAssembler);
}
 
開發者ID:UdL-EPS-SoftArch,項目名稱:entsoftarch-1516-server,代碼行數:18,代碼來源:ProposalSubmissionController.java

示例11: getProposals

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@RequestMapping(method = RequestMethod.GET, value = "/proposals")
public @ResponseBody PagedResources<PersistentEntityResource> getProposals(
        HttpServletRequest request, Principal principal, Pageable pageable,
        PersistentEntityResourceAssembler resourceAssembler) {

    Page<Proposal> proposals;

    if (request.isUserInRole("ADMIN"))
        proposals = proposalRepository.findAll(pageable);
    else {
        Proponent proponent = proponentRepository.findOne(principal.getName());
        proposals = proposalRepository.findByCreator(proponent, pageable);
    }

    return pagedResourcesAssembler.toResource(proposals, resourceAssembler);
}
 
開發者ID:UdL-EPS-SoftArch,項目名稱:entsoftarch-1516-server,代碼行數:17,代碼來源:ProposalController.java

示例12: deleteLightside

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@RequestMapping(value = "/action/database/{databaseName}/deleteLightside", method=RequestMethod.GET)
@ResponseBody
PagedResources<Resource<BrowsingLightsideStubsResource>> deleteLightside(
		@PathVariable("databaseName") String databaseName,
		@RequestParam(value= "exportFilename") String exportFilename,
		@RequestParam(value="withAnnotations", defaultValue = "false") boolean withAnnotations,
		   HttpServletRequest hsr, HttpSession session) 
				throws IOException {
	registerDb(hsr,session,databaseName);
	String lsDataDirectory = lsDataDirectory();
	File lsOutputFilename = new File(lsDataDirectory , exportFile2LightSideDir(exportFilename, withAnnotations));
	logger.info("DeleteLightside: dd:" + lsDataDirectory + " ef:" + exportFilename + 
			" wa:" + withAnnotations + " => "
			+ lsOutputFilename.toString());
	for (File f: lsOutputFilename.listFiles()) {
		f.delete();
	}
	lsOutputFilename.delete();
	return lightsideExports(databaseName, hsr, session);
}
 
開發者ID:DiscourseDB,項目名稱:discoursedb-core,代碼行數:21,代碼來源:BrowsingRestController.java

示例13: uploadLightside

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@RequestMapping(value = "/action/database/{databaseName}/uploadLightside", headers="content-type=multipart/*", method=RequestMethod.POST)
@ResponseBody
PagedResources<Resource<BrowsingLightsideStubsResource>> uploadLightside(
		@RequestParam("file_annotatedFileForUpload") MultipartFile file_annotatedFileForUpload,
		@PathVariable("databaseName") String databaseName,
		   HttpServletRequest hsr, HttpSession session) 
				throws IOException {
	registerDb(hsr,session, databaseName);
	String lsDataDirectory = lsDataDirectory();
	logger.info("Someone uploaded something!");
	if (!file_annotatedFileForUpload.isEmpty()) {
		try {
			logger.info("Not even empty!");
			File tempUpload = File.createTempFile("temp-file-name", ".csv");
			BufferedOutputStream stream = new BufferedOutputStream(
					new FileOutputStream(tempUpload));
               FileCopyUtils.copy(file_annotatedFileForUpload.getInputStream(), stream);
			stream.close();
			lightsideService.importAnnotatedData(tempUpload.toString());
		} catch (Exception e) {
			logger.error("Error importing to lightside: " + e);
		}
	}
	return lightsideExports(databaseName, hsr, session);
}
 
開發者ID:DiscourseDB,項目名稱:discoursedb-core,代碼行數:26,代碼來源:BrowsingRestController.java

示例14: exportLightsideAction

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@RequestMapping(value = "/action/database/{databaseName}/exportLightside", method=RequestMethod.GET)
@ResponseBody
@Deprecated
PagedResources<Resource<BrowsingLightsideStubsResource>> exportLightsideAction(
		@PathVariable("databaseName") String databaseName,
		@RequestParam(value= "exportFilename") String exportFilename,
		@RequestParam(value="withAnnotations", defaultValue = "false") boolean withAnnotations,
		@RequestParam(value= "dpId") long dpId,
		   HttpServletRequest hsr, HttpSession session) throws IOException {
	Assert.hasText(exportFilename, "No exportFilename specified");
	registerDb(hsr,session, databaseName);

	
	DiscoursePart dp = discoursePartRepository.findOne(dpId).get();
	String lsDataDirectory = lsDataDirectory();
	File lsOutputFilename = new File(lsDataDirectory , exportFile2LightSideDir(exportFilename, withAnnotations));
	logger.info(" Exporting dp " + dp.getName());
	Set<DiscoursePart> descendents = discoursePartService.findDescendentClosure(dp, Optional.empty());
	System.out.println(lsOutputFilename.getAbsoluteFile().toString());
	lsOutputFilename.mkdirs();
	for (DiscoursePart d: descendents) {
		File child = new File(lsOutputFilename, d.getId().toString());
		child.createNewFile();
	}
	return lightsideExports(databaseName, hsr, session);
}
 
開發者ID:DiscourseDB,項目名稱:discoursedb-core,代碼行數:27,代碼來源:BrowsingRestController.java

示例15: importLightsideAction

import org.springframework.hateoas.PagedResources; //導入依賴的package包/類
@RequestMapping(value = "/action/database/{databaseName}/importLightside", method=RequestMethod.GET)
@ResponseBody
@Deprecated
PagedResources<Resource<BrowsingLightsideStubsResource>> importLightsideAction(
		@RequestParam(value= "lightsideDirectory") String lightsideDirectory,
		@PathVariable("databaseName") String databaseName,
		   HttpServletRequest hsr, HttpSession session) throws IOException {
	registerDb(hsr,session, databaseName);

	String liteDataDirectory = lsDataDirectory();		
	lightsideService.importAnnotatedData(liteDataDirectory + "/" + lightsideDirectory);
	Optional<DiscoursePart> dp = lightsideName2DiscoursePartForImport(lightsideDirectory);
	//if (dp.isPresent()) {
	//	return subDiscourseParts(0,20, dp.get().getId());
	//} else {
		return lightsideExports(databaseName, hsr, session);
	//}
}
 
開發者ID:DiscourseDB,項目名稱:discoursedb-core,代碼行數:19,代碼來源:BrowsingRestController.java


注:本文中的org.springframework.hateoas.PagedResources類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。