Java Code Examples for org.springframework.hateoas.PagedModel

The following examples show how to use org.springframework.hateoas.PagedModel. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * Return a page-able list of {@link AuditRecordResource}s.
 *
 * @param pageable Pagination information
 * @param assembler assembler for {@link AuditRecord}
 * @param actions Optional. For which {@link AuditActionType}s do you want to retrieve
 *     {@link AuditRecord}s
 * @param fromDate Optional. The fromDate must be {@link DateTimeFormatter}.ISO_DATE_TIME
 *     formatted. eg.: 2019-02-03T00:00:30
 * @param toDate Optional. The toDate must be {@link DateTimeFormatter}.ISO_DATE_TIME
 *     formatted. eg.: 2019-02-05T23:59:30
 * @param operations Optional. For which {@link AuditOperationType}s do you want to
 *     retrieve {@link AuditRecord}s
 * @return list of audit records
 */
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public PagedModel<AuditRecordResource> list(Pageable pageable,
		@RequestParam(required = false) AuditActionType[] actions,
		@RequestParam(required = false) AuditOperationType[] operations,
		@RequestParam(required = false) String fromDate,
		@RequestParam(required = false) String toDate,
		PagedResourcesAssembler<AuditRecord> assembler) {

	final Instant fromDateAsInstant = paresStringToInstant(fromDate);
	final Instant toDateAsInstant = paresStringToInstant(toDate);

	if (fromDate != null && toDate != null && fromDate.compareTo(toDate) > 0) {
		throw new InvalidDateRangeException("The fromDate cannot be after the toDate.");
	}

	final Page<AuditRecord> auditRecords = this.auditRecordService
			.findAuditRecordByAuditOperationTypeAndAuditActionTypeAndDate(pageable, actions, operations,
					fromDateAsInstant,
					toDateAsInstant);
	return assembler.toModel(auditRecords, new Assembler(auditRecords));
}
 
Example 2
Source Project: spring-cloud-openfeign   Source File: FeignHalTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPagedModel() {
	PagedModel<MarsRover> paged = feignHalClient.paged();
	assertThat(paged).isNotNull();
	assertThat(paged).isNotEmpty();

	assertThat(paged.hasLinks()).isTrue();
	assertThat(paged.hasLink("self")).isTrue();

	assertThat(paged.getLink("self")).map(Link::getHref).contains("/paged");

	Collection<MarsRover> collection = paged.getContent();
	assertThat(collection).isNotEmpty();

	MarsRover marsRover = collection.stream().findAny().orElse(null);
	assertThat(marsRover).isNotNull();
	assertThat(marsRover.getName()).isEqualTo("Curiosity");
}
 
Example 3
Source Project: spring-cloud-dataflow   Source File: TaskCommands.java    License: Apache License 2.0 6 votes vote down vote up
@CliCommand(value = EXECUTION_LIST, help = "List created task executions filtered by taskName")
public Table executionListByName(
		@CliOption(key = "name", help = "the task name to be used as a filter", optionContext = "existing-task disable-string-converter") String name) {

	final PagedModel<TaskExecutionResource> tasks;
	if (name == null) {
		tasks = taskOperations().executionList();
	}
	else {
		tasks = taskOperations().executionListByTaskName(name);
	}
	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("taskName", "Task Name");
	headers.put("executionId", "ID");
	headers.put("startTime", "Start Time");
	headers.put("endTime", "End Time");
	headers.put("exitCode", "Exit Code");
	final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(tasks, headers));
	return DataFlowTables.applyStyle(builder).build();
}
 
Example 4
Source Project: spring-cloud-dataflow   Source File: AppRegistryCommands.java    License: Apache License 2.0 6 votes vote down vote up
@CliCommand(value = UNREGISTER_ALL, help = "Unregister all applications")
public String unregisterAll() {
	appRegistryOperations().unregisterAll();

	StringBuilder msg = new StringBuilder()
			.append("Successfully unregistered applications.");

	PagedModel<AppRegistrationResource> appRegistrationResources = appRegistryOperations().list();

	if (!appRegistrationResources.getContent().isEmpty()) {
		msg.append(" The following were not unregistered as they are associated with an existing stream:");

		for(AppRegistrationResource appRegistrationResource : appRegistrationResources) {
			msg.append(String.format(" [%s:%s:%s]", appRegistrationResource.getName(),
					appRegistrationResource.getType(), appRegistrationResource.getVersion()));
		}
	}

	return msg.toString();
}
 
Example 5
Source Project: spring-cloud-dataflow   Source File: JobCommands.java    License: Apache License 2.0 6 votes vote down vote up
@CliCommand(value = STEP_EXECUTION_LIST, help = "List step executions filtered by jobExecutionId")
public Table stepExecutionList(@CliOption(key = {
		"id" }, help = "the job execution id to be used as a filter", mandatory = true) long id) {

	final PagedModel<StepExecutionResource> steps = jobOperations().stepExecutionList(id);

	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();

	modelBuilder.addRow().addValue("ID ").addValue("Step Name ").addValue("Job Exec Id ").addValue("Start Time ")
			.addValue("End Time ").addValue("Status ");
	for (StepExecutionResource step : steps) {
		modelBuilder.addRow().addValue(step.getStepExecution().getId())
				.addValue(step.getStepExecution().getStepName()).addValue(id)
				.addValue(step.getStepExecution().getStartTime()).addValue(step.getStepExecution().getEndTime())
				.addValue(step.getStepExecution().getStatus().name());
	}
	TableBuilder builder = new TableBuilder(modelBuilder.build());

	DataFlowTables.applyStyle(builder);

	return builder.build();
}
 
Example 6
@CliCommand(value = SCHEDULER_LIST, help = "List task schedules by task definition name")
public Table listByDefinition(
		@CliOption(key = { "platform" }, help = "the name platform from which to retrieve a list of schedules") String platform,
		@CliOption(key = { "definitionName" }, help = "the task definition name") String definitionName) {
	PagedModel<ScheduleInfoResource> schedules;
	if (Strings.isEmpty(definitionName)) {
		schedules = scheduleOperations().listByPlatform(platform);
	}
	else {
		schedules = scheduleOperations().list(definitionName, platform);
	}

	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("scheduleName", "Schedule Name");
	headers.put("taskDefinitionName", "Task Definition Name");
	headers.put("scheduleProperties", "Properties");
	final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(schedules, headers));
	return DataFlowTables.applyStyle(builder).build();
}
 
Example 7
@Test
public void testStatusWithSummary() {
	Collection<AppStatusResource> data = new ArrayList<>();
	data.add(appStatusResource1);
	data.add(appStatusResource2);
	data.add(appStatusResource3);
	PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(data.size(), 1, data.size(), 1);
	PagedModel<AppStatusResource> result = new PagedModel<>(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]));
		}
	}
}
 
Example 8
@Test
public void testStatusWithoutSummary() {
	Collection<AppStatusResource> data = new ArrayList<>();
	data.add(appStatusResource1);
	data.add(appStatusResource2);
	PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(data.size(), 1, data.size(), 1);
	PagedModel<AppStatusResource> result = new PagedModel<>(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]));
		}
	}
}
 
Example 9
@Test
public void testDeserializationOfMultipleJobExecutions() throws IOException {

	final ObjectMapper objectMapper = DataFlowTemplate.prepareObjectMapper(new ObjectMapper());

	final InputStream inputStream = JobExecutionDeserializationTests.class
			.getResourceAsStream("/JobExecutionJson.txt");

	final String json = new String(StreamUtils.copyToByteArray(inputStream));

	final PagedModel<EntityModel<JobExecutionResource>> paged = objectMapper.readValue(json,
			new TypeReference<PagedModel<EntityModel<JobExecutionResource>>>() {
			});
	final JobExecutionResource jobExecutionResource = paged.getContent().iterator().next().getContent();
	assertEquals("Expect 1 JobExecutionInfoResource", 6, paged.getContent().size());
	assertEquals(Long.valueOf(6), jobExecutionResource.getJobId());
	assertEquals("job200616815", jobExecutionResource.getName());
	assertEquals("COMPLETED", jobExecutionResource.getJobExecution().getStatus().name());
}
 
Example 10
/**
 * List app registrations. Optional type and findByTaskNameContains parameters can be passed to do
 * filtering. Search parameter only filters by {@code AppRegistration} name field.
 *
 * @param pageable Pagination information
 * @param pagedResourcesAssembler the resource assembler for app registrations
 * @param type the application type: source, sink, processor, task
 * @param search optional findByTaskNameContains parameter
 * @return the list of registered applications
 */
@RequestMapping(method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public PagedModel<? extends AppRegistrationResource> list(
		Pageable pageable,
		PagedResourcesAssembler<AppRegistration> pagedResourcesAssembler,
		@RequestParam(value = "type", required = false) ApplicationType type,
		@RequestParam(required = false) String search,
		@RequestParam(required = false) boolean defaultVersion) {

	Page<AppRegistration> pagedRegistrations = (defaultVersion) ?
			this.appRegistryService.findAllByTypeAndNameIsLikeAndDefaultVersionIsTrue(type, search, pageable)
			: this.appRegistryService.findAllByTypeAndNameIsLike(type, search,
			pageable);

	return pagedResourcesAssembler.toModel(pagedRegistrations, this.assembler);
}
 
Example 11
/**
 * Register all applications listed in a properties file or provided as key/value pairs.
 *
 * @param pageable Pagination information
 * @param pagedResourcesAssembler the resource asembly for app registrations
 * @param uri URI for the properties file
 * @param apps key/value pairs representing applications, separated by newlines
 * @param force if {@code true}, overwrites any pre-existing registrations
 * @return the collection of registered applications
 * @throws IOException if can't store the Properties object to byte output stream
 */
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public PagedModel<? extends AppRegistrationResource> registerAll(
		Pageable pageable,
		PagedResourcesAssembler<AppRegistration> pagedResourcesAssembler,
		@RequestParam(value = "uri", required = false) String uri,
		@RequestParam(value = "apps", required = false) String apps,
		@RequestParam(value = "force", defaultValue = "false") boolean force) throws IOException {
	List<AppRegistration> registrations = new ArrayList<>();

	if (StringUtils.hasText(uri)) {
		registrations.addAll(this.appRegistryService.importAll(force, this.resourceLoader.getResource(uri)));
	}
	else if (!StringUtils.isEmpty(apps)) {
		ByteArrayResource bar = new ByteArrayResource(apps.getBytes());
		registrations.addAll(this.appRegistryService.importAll(force, bar));
	}

	Collections.sort(registrations);
	prefetchMetadata(registrations);
	return pagedResourcesAssembler.toModel(new PageImpl<>(registrations, pageable, registrations.size()), this.assembler);
}
 
Example 12
Source Project: springdoc-openapi   Source File: DataRestResponseBuilder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Find search return type type.
 *
 * @param handlerMethod the handler method
 * @param methodResourceMapping the method resource mapping
 * @param domainType the domain type
 * @return the type
 */
private Type findSearchReturnType(HandlerMethod handlerMethod, MethodResourceMapping methodResourceMapping, Class<?> domainType) {
	Type returnType = null;
	Type returnRepoType = ReturnTypeParser.resolveType(methodResourceMapping.getMethod().getGenericReturnType(), methodResourceMapping.getMethod().getDeclaringClass());
	if (methodResourceMapping.isPagingResource()) {
		returnType = ResolvableType.forClassWithGenerics(PagedModel.class, domainType).getType();
	}
	else if (Iterable.class.isAssignableFrom(ResolvableType.forType(returnRepoType).getRawClass())) {
		returnType = ResolvableType.forClassWithGenerics(CollectionModel.class, domainType).getType();
	}
	else if (!ClassUtils.isPrimitiveOrWrapper(domainType)) {
		returnType = ResolvableType.forClassWithGenerics(EntityModel.class, domainType).getType();
	}
	if (returnType == null) {
		returnType = ReturnTypeParser.resolveType(handlerMethod.getMethod().getGenericReturnType(), handlerMethod.getBeanType());
		returnType = getType(returnType, domainType);
	}
	return returnType;
}
 
Example 13
Source Project: springdoc-openapi   Source File: AlbumController.java    License: Apache License 2.0 5 votes vote down vote up
@GetMapping("/api/albums")
public PagedModel<Album> getAllAlbums() {
	Album album1 = new Album("album-title-1", "album-description-1", "album-release-date-1");
	Album album2 = new Album("album-title-2", "album-description-2", "album-release-date-2");
	Page<Album> albumPage = new PageImpl<>(Arrays.asList(album1, album2));

	return pagedResourcesAssembler.toModel(albumPage, albumModelAssembler);
}
 
Example 14
Source Project: spring-cloud-openfeign   Source File: FeignHalController.java    License: Apache License 2.0 5 votes vote down vote up
@GetMapping("/paged")
public CollectionModel<MarsRover> getPaged() {
	MarsRover marsRover = new MarsRover();
	marsRover.setName("Curiosity");
	Link link = new Link("/paged", "self");
	PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(1, 1, 1);
	return new PagedModel<>(Collections.singleton(marsRover), metadata, link);
}
 
Example 15
Source Project: spring-cloud-gcp   Source File: SpannerRepositoryTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testRestEndpoint() {
	this.spannerRepositoryExample.runExample();

	TestRestTemplate testRestTemplate = new TestRestTemplate();
	ResponseEntity<PagedModel<Trade>> tradesResponse = testRestTemplate.exchange(
			String.format("http://localhost:%s/trades/", this.port),
			HttpMethod.GET,
			null,
			new ParameterizedTypeReference<PagedModel<Trade>>() {
			});
	assertThat(tradesResponse.getBody().getMetadata().getTotalElements()).isEqualTo(8);
}
 
Example 16
Source Project: spring-cloud-dataflow   Source File: TaskCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = LIST, help = "List created tasks")
public Table list() {
	final PagedModel<TaskDefinitionResource> tasks = taskOperations().list();
	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("name", "Task Name");
	headers.put("dslText", "Task Definition");
	headers.put("description", "description");
	headers.put("status", "Task Status");
	final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(tasks, headers));
	return DataFlowTables.applyStyle(builder).build();
}
 
Example 17
Source Project: spring-cloud-dataflow   Source File: TaskCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = PLATFORM_LIST, help = "List platform accounts for tasks")
public Table listPlatforms() {
	final PagedModel<LauncherResource> platforms = taskOperations().listPlatforms();
	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("name", "Platform Name");
	headers.put("type", "Platform Type");
	headers.put("description", "Description");
	final TableBuilder builder = new TableBuilder(new BeanListTableModel<>(platforms, headers));
	return DataFlowTables.applyStyle(builder).build();
}
 
Example 18
Source Project: spring-cloud-dataflow   Source File: StreamCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = LIST_STREAM, help = "List created streams")
public Table listStreams() {
	final PagedModel<StreamDefinitionResource> streams = streamOperations().list();
	LinkedHashMap<String, Object> headers = new LinkedHashMap<>();
	headers.put("name", "Stream Name");
	headers.put("description", "Description");
	headers.put("originalDslText", "Stream Definition");
	headers.put("statusDescription", "Status");
	BeanListTableModel<StreamDefinitionResource> model = new BeanListTableModel<>(streams, headers);
	return DataFlowTables.applyStyle(new TableBuilder(model)).build();
}
 
Example 19
Source Project: spring-cloud-dataflow   Source File: JobCommands.java    License: Apache License 2.0 5 votes vote down vote up
@CliCommand(value = EXECUTION_LIST, help = "List created job executions filtered by jobName")
public Table executionList(
		@CliOption(key = { "name" }, help = "the job name to be used as a filter", mandatory = false) String name) {

	final PagedModel<JobExecutionThinResource> jobs;
	if (name == null) {
		jobs = jobOperations().executionThinList();
	}
	else {
		jobs = jobOperations().executionThinListByJobName(name);
	}

	TableModelBuilder<Object> modelBuilder = new TableModelBuilder<>();

	modelBuilder.addRow().addValue("ID ").addValue("Task ID").addValue("Job Name ").addValue("Start Time ")
			.addValue("Step Execution Count ").addValue("Definition Status ");
	for (JobExecutionThinResource job : jobs) {
		modelBuilder.addRow().addValue(job.getExecutionId()).addValue(job.getTaskExecutionId())
				.addValue(job.getName())
				.addValue(job.getStartDateTime())
				.addValue(job.getStepExecutionCount())
				.addValue(job.isDefined() ? "Created" : "Destroyed");
	}
	TableBuilder builder = new TableBuilder(modelBuilder.build());

	DataFlowTables.applyStyle(builder);

	return builder.build();
}
 
Example 20
Source Project: spring-cloud-dataflow   Source File: AppRegistryTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PagedModel<AppRegistrationResource> importFromResource(String uri, boolean force) {
	MultiValueMap<String, Object> values = new LinkedMultiValueMap<>();
	values.add("uri", uri);
	values.add("force", Boolean.toString(force));
	return restTemplate.postForObject(appsLink.getHref(), values, AppRegistrationResource.Page.class);
}
 
Example 21
Source Project: spring-cloud-dataflow   Source File: AppRegistryTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PagedModel<AppRegistrationResource> registerAll(Properties apps, boolean force) {
	MultiValueMap<String, Object> values = new LinkedMultiValueMap<>();
	StringBuffer buffer = new StringBuffer();
	for (String key : apps.stringPropertyNames()) {
		buffer.append(String.format("%s=%s\n", key, apps.getProperty(key)));
	}
	values.add("apps", buffer.toString());
	values.add("force", Boolean.toString(force));
	return restTemplate.postForObject(appsLink.getHref(), values, AppRegistrationResource.Page.class);
}
 
Example 22
Source Project: spring-cloud-dataflow   Source File: SchedulerTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PagedModel<ScheduleInfoResource> list(String taskDefinitionName, String platform) {
	String url = schedulesInstanceLink.expand(taskDefinitionName).getHref();
	if(platform != null) {
		url = url + "?platform=" + platform;
	}
	return restTemplate.getForObject(url , ScheduleInfoResource.Page.class);
}
 
Example 23
Source Project: spring-cloud-dataflow   Source File: SchedulerTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PagedModel<ScheduleInfoResource> listByPlatform(String platform) {
	String url = schedulesLink.getHref();
	if(platform != null) {
		url = url + "?platform=" + platform;
	}
	return restTemplate.getForObject(url, ScheduleInfoResource.Page.class);
}
 
Example 24
/**
 * Return a page-able list of {@link JobInstanceResource} defined jobs.
 *
 * @param jobName the name of the job
 * @param pageable page-able collection of {@link JobInstance}s.
 * @param assembler for the {@link JobInstance}s
 * @return a list of Job Instance
 * @throws NoSuchJobException if the job for jobName specified does not exist.
 */
@RequestMapping(value = "", method = RequestMethod.GET, params = "name")
@ResponseStatus(HttpStatus.OK)
public PagedModel<JobInstanceResource> list(@RequestParam("name") String jobName, Pageable pageable,
		PagedResourcesAssembler<JobInstanceExecutions> assembler) throws NoSuchJobException {
	List<JobInstanceExecutions> jobInstances = taskJobService.listTaskJobInstancesForJobName(pageable, jobName);
	Page<JobInstanceExecutions> page = new PageImpl<>(jobInstances, pageable,
			taskJobService.countJobInstances(jobName));
	return assembler.toModel(page, jobAssembler);
}
 
Example 25
Source Project: spring-cloud-dataflow   Source File: JobTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PagedModel<JobExecutionResource> executionList() {
	String uriTemplate = executionsLink.getHref();
	uriTemplate = uriTemplate + "?size=2000";

	return restTemplate.getForObject(uriTemplate, JobExecutionResource.Page.class);
}
 
Example 26
Source Project: spring-cloud-dataflow   Source File: JobTemplate.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public PagedModel<JobExecutionThinResource> executionThinList() {
	String uriTemplate = executionsLink.getHref();
	uriTemplate = uriTemplate + "?size=2000";

	return restTemplate.getForObject(uriTemplate, JobExecutionThinResource.Page.class);
}
 
Example 27
Source Project: microservice   Source File: CatalogClient.java    License: Apache License 2.0 5 votes vote down vote up
@HystrixCommand(fallbackMethod = "getItemsCache", commandProperties = {
		@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "2") })
public Collection<Item> findAll() {
	PagedModel<Item> pagedResources = restTemplate.getForObject(
			catalogURL(), ItemPagedResources.class);
	this.itemsCache = pagedResources.getContent();
	return pagedResources.getContent();
}
 
Example 28
/**
 * Return a page-able list of {@link ScheduleInfo}s.
 *
 * @param assembler assembler for the {@link ScheduleInfo}
 * @param platform the name of the platform from which schedules will be retrieved.
 * @param pageable {@link Pageable} to be used
 * @return a list of Schedules
 */
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public PagedModel<ScheduleInfoResource> list(Pageable pageable,
		@RequestParam(value = "platform", required = false) String platform,
		PagedResourcesAssembler<ScheduleInfo> assembler) {
	List<ScheduleInfo> result = this.schedulerService.listForPlatform(platform);
	return assembler.toModel(new PageImpl<>(result, pageable, result.size()), taskAssembler);
}
 
Example 29
/**
 * Return a page-able list of {@link ScheduleInfo}s for a specific
 * {@link org.springframework.cloud.dataflow.core.TaskDefinition} name.
 *
 * @param taskDefinitionName name of the taskDefinition to search.
 * @param platform name of the platform from which the list is retrieved.
 * @param assembler assembler for the {@link ScheduleInfo}.
 * @return a list of Schedules.
 */
@RequestMapping("/instances/{taskDefinitionName}")
public PagedModel<ScheduleInfoResource> filteredList(@PathVariable String taskDefinitionName,
		@RequestParam(value = "platform", required = false) String platform,
		PagedResourcesAssembler<ScheduleInfo> assembler) {
	List<ScheduleInfo> result = this.schedulerService.list(taskDefinitionName, platform);
	int resultSize = result.size();
	Pageable pageable = PageRequest.of(0,
			(resultSize == 0) ? resultSize = 1 : resultSize); //handle empty result set
	Page<ScheduleInfo> page = new PageImpl<>(result, pageable,
			result.size());
	return assembler.toModel(page, taskAssembler);
}
 
Example 30
@RequestMapping
public PagedModel<AppInstanceStatusResource> list(Pageable pageable, @PathVariable String appId,
		PagedResourcesAssembler<AppInstanceStatus> assembler) {
	AppStatus status = streamDeployer.getAppStatus(appId);
	if (status.getState().equals(DeploymentState.unknown)) {
		throw new NoSuchAppException(appId);
	}
	List<AppInstanceStatus> appInstanceStatuses = new ArrayList<>(status.getInstances().values());
	Collections.sort(appInstanceStatuses, RuntimeAppInstanceController.INSTANCE_SORTER);
	return assembler.toModel(new PageImpl<>(appInstanceStatuses, pageable,
			appInstanceStatuses.size()), new RuntimeAppInstanceController.InstanceAssembler(status));
}