org.springframework.hateoas.PagedModel Java Examples

The following examples show how to use org.springframework.hateoas.PagedModel. 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
Source File: JobExecutionDeserializationTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: FeignHalTests.java    From spring-cloud-openfeign with 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 File: AppRegistryController.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #4
Source File: AuditRecordController.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #5
Source File: AppRegistryController.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #6
Source File: TaskCommands.java    From spring-cloud-dataflow with 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 #7
Source File: AppRegistryCommands.java    From spring-cloud-dataflow with 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 #8
Source File: JobCommands.java    From spring-cloud-dataflow with 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 #9
Source File: TaskSchedulerCommands.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@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 #10
Source File: RuntimeCommandsTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@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 #11
Source File: RuntimeCommandsTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@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 #12
Source File: StarbucksClient.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@Test
public void discoverStoreSearch() {

	Traverson traverson = new Traverson(URI.create(String.format(SERVICE_URI, port)), MediaTypes.HAL_JSON);

	// Set up path traversal
	TraversalBuilder builder = traverson. //
			follow("stores", "search", "by-location");

	// Log discovered
	log.info("");
	log.info("Discovered link: {}", builder.asTemplatedLink());
	log.info("");

	Map<String, Object> parameters = new HashMap<>();
	parameters.put("location", "40.740337,-73.995146");
	parameters.put("distance", "0.5miles");

	PagedModel<EntityModel<Store>> resources = builder.//
			withTemplateParameters(parameters).//
			toObject(new PagedModelType<EntityModel<Store>>() {});

	PageMetadata metadata = resources.getMetadata();

	log.info("Got {} of {} stores: ", resources.getContent().size(), metadata.getTotalElements());

	StreamSupport.stream(resources.spliterator(), false).//
			map(EntityModel::getContent).//
			forEach(store -> log.info("{} - {}", store.name, store.address));
}
 
Example #13
Source File: StreamDefinitionController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Return a list of related stream definition resources based on the given stream name.
 * Related streams include the main stream and the tap stream(s) on the main stream.
 *
 * @param pageable Pagination information
 * @param name the name of an existing stream definition (required)
 * @param nested if should recursively findByTaskNameContains for related stream definitions
 * @param assembler resource assembler for stream definition
 * @return a list of related stream definitions
 */
@RequestMapping(value = "/{name}/related", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public PagedModel<StreamDefinitionResource> listRelated(Pageable pageable,
		@PathVariable("name") String name,
		@RequestParam(value = "nested", required = false, defaultValue = "false") boolean nested,
		PagedResourcesAssembler<StreamDefinition> assembler) {
	List<StreamDefinition> result = this.streamService.findRelatedStreams(name, nested);
	Page<StreamDefinition> page = new PageImpl<>(result, pageable, result.size());
	return assembler.toModel(page, new Assembler(page));
}
 
Example #14
Source File: RuntimeStreamsController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * @param streamNames comma separated list of streams to retrieve the statuses for
 */
@RequestMapping(value = "/{streamNames}", method = RequestMethod.GET)
public PagedModel<StreamStatusResource> streamStatus(@PathVariable("streamNames") String[] streamNames, Pageable pageable,
		PagedResourcesAssembler<Pair<String, List<AppStatus>>> assembler) {
	return assembler.toModel(new PageImpl<>(getStreamStatusList(getPagedStreamNames(pageable, Arrays.asList(streamNames))),
			pageable, streamNames.length), statusAssembler);
}
 
Example #15
Source File: SpannerRepositoryTests.java    From spring-cloud-gcp with 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 File: TaskPlatformController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the list of platform accounts available for launching tasks.
 * @param pageable the Pageable request
 * @param assembler the paged resource assembler for Launcher
 * @return the paged resources of type {@link LauncherResource}
 */
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public PagedModel<LauncherResource> list(Pageable pageable,
		@RequestParam(value = "schedulesEnabled", required = false) String schedulesEnabled,
		PagedResourcesAssembler<Launcher> assembler) {
	PagedModel<LauncherResource> result;
	if(StringUtils.hasText(schedulesEnabled) && schedulesEnabled.toLowerCase().equals("true")) {
		result = assembler.toModel(this.launcherService.getLaunchersWithSchedules(pageable), this.launcherAssembler);
	} else {
		result = assembler.toModel(this.launcherService.getAllLaunchers(pageable), this.launcherAssembler);
	}
	return result;
}
 
Example #17
Source File: DataRestResponseBuilder.java    From springdoc-openapi with 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 #18
Source File: RuntimeAppInstanceController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #19
Source File: TaskExecutionController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Return a page-able list of {@link TaskExecutionResource} defined tasks.
 *
 * @param pageable page-able collection of {@code TaskExecution}s.
 * @param assembler for the {@link TaskExecution}s
 * @return a list of task executions
 */
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public PagedModel<TaskExecutionResource> list(Pageable pageable,
		PagedResourcesAssembler<TaskJobExecutionRel> assembler) {
	Page<TaskExecution> taskExecutions = this.explorer.findAll(pageable);
	Page<TaskJobExecutionRel> result = getPageableRelationships(taskExecutions, pageable);
	return assembler.toModel(result, this.taskAssembler);
}
 
Example #20
Source File: AppRegistryTemplate.java    From spring-cloud-dataflow with 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 File: AppRegistryTemplate.java    From spring-cloud-dataflow with 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 File: TaskSchedulerController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #23
Source File: TaskSchedulerController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #24
Source File: CatalogClient.java    From microservice with 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 #25
Source File: JobTemplate.java    From spring-cloud-dataflow with 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 #26
Source File: SchedulerTemplate.java    From spring-cloud-dataflow with 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 #27
Source File: JobTemplate.java    From spring-cloud-dataflow with 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 #28
Source File: SchedulerTemplate.java    From spring-cloud-dataflow with 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 #29
Source File: TaskDefinitionController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Return a page-able list of {@link TaskDefinitionResource} defined tasks.
 *
 * @param pageable page-able collection of {@code TaskDefinitionResource}
 * @param search optional findByTaskNameContains parameter
 * @param manifest optional manifest flag to indicate whether the latest task execution requires task manifest update
 * @param assembler assembler for the {@link TaskDefinition}
 * @return a list of task definitions
 */
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public PagedModel<TaskDefinitionResource> list(Pageable pageable, @RequestParam(required = false) String search,
		@RequestParam(required = false) boolean manifest,
		PagedResourcesAssembler<TaskExecutionAwareTaskDefinition> assembler) {

	final Page<TaskDefinition> taskDefinitions;
	if (search != null) {
		taskDefinitions = repository.findByTaskNameContains(search, pageable);
	}
	else {
		taskDefinitions = repository.findAll(pageable);
	}

	final java.util.HashMap<String, TaskDefinition> taskDefinitionMap = new java.util.HashMap<>();

	for (TaskDefinition taskDefinition : taskDefinitions) {
		taskDefinitionMap.put(taskDefinition.getName(), taskDefinition);
	}

	final List<TaskExecution> taskExecutions;

	if (!taskDefinitionMap.isEmpty()) {
		taskExecutions = this.explorer.getLatestTaskExecutionsByTaskNames(
				taskDefinitionMap.keySet().toArray(new String[taskDefinitionMap.size()]));
	}
	else {
		taskExecutions = null;
	}

	final Page<TaskExecutionAwareTaskDefinition> taskExecutionAwareTaskDefinitions = taskDefinitions
			.map(new TaskDefinitionConverter(taskExecutions));

	PagedModel<TaskDefinitionResource> taskDefinitionResources = assembler.toModel(taskExecutionAwareTaskDefinitions, new Assembler(manifest));
	// Classify the composed task elements by iterating through the task definitions that are part of this page.
	updateComposedTaskElement(taskDefinitionResources.getContent());
	return taskDefinitionResources;
}
 
Example #30
Source File: JobInstanceController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}