Java Code Examples for org.springframework.data.web.PagedResourcesAssembler#toModel()

The following examples show how to use org.springframework.data.web.PagedResourcesAssembler#toModel() . 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: 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 2
Source File: JobExecutionController.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve all task job executions with the task name specified
 *
 * @param jobName name of the job. SQL server specific wildcards are enabled (eg.: myJob%,
 *     m_Job, ...)
 * @param pageable page-able collection of {@code TaskJobExecution}s.
 * @param assembler for the {@link TaskJobExecution}s
 * @return list task/job executions with the specified jobName.
 * @throws NoSuchJobException if the job with the given name does not exist.
 */
@RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public PagedModel<JobExecutionResource> retrieveJobsByParameters(
		@RequestParam(value = "name", required = false) String jobName,
		@RequestParam(value = "status", required = false) BatchStatus status,
		Pageable pageable, PagedResourcesAssembler<TaskJobExecution> assembler) throws NoSuchJobException, NoSuchJobExecutionException {
	List<TaskJobExecution> jobExecutions;
	Page<TaskJobExecution> page;

	if (jobName == null && status == null) {
		jobExecutions = taskJobService.listJobExecutions(pageable);
		page = new PageImpl<>(jobExecutions, pageable, taskJobService.countJobExecutions());
	} else {
		jobExecutions = taskJobService.listJobExecutionsForJob(pageable, jobName, status);
		page = new PageImpl<>(jobExecutions, pageable,
				taskJobService.countJobExecutionsForJob(jobName, status));
	}

	return assembler.toModel(page, jobAssembler);
}
 
Example 3
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 4
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 5
Source File: TaskExecutionController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve all task executions with the task name specified
 *
 * @param taskName name of the task
 * @param pageable page-able collection of {@code TaskExecution}s.
 * @param assembler for the {@link TaskExecution}s
 * @return the paged list of task executions
 */
@RequestMapping(value = "", method = RequestMethod.GET, params = "name")
@ResponseStatus(HttpStatus.OK)
public PagedModel<TaskExecutionResource> retrieveTasksByName(@RequestParam("name") String taskName,
		Pageable pageable, PagedResourcesAssembler<TaskJobExecutionRel> assembler) {
	this.taskDefinitionRepository.findById(taskName)
			.orElseThrow(() -> new NoSuchTaskDefinitionException(taskName));
	Page<TaskExecution> taskExecutions = this.explorer.findTaskExecutionsByName(taskName, pageable);
	Page<TaskJobExecutionRel> result = getPageableRelationships(taskExecutions, pageable);
	return assembler.toModel(result, this.taskAssembler);
}
 
Example 6
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);
}
 
Example 7
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 8
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 9
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 10
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 11
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 12
Source File: JobExecutionThinController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve all task job executions with the task name specified
 *
 * @param jobName name of the job
 * @param pageable page-able collection of {@code TaskJobExecution}s.
 * @param assembler for the {@link TaskJobExecution}s
 * @return list task/job executions with the specified jobName.
 * @throws NoSuchJobException if the job with the given name does not exist.
 */
@RequestMapping(value = "", method = RequestMethod.GET, params = "name", produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public PagedModel<JobExecutionThinResource> retrieveJobsByName(@RequestParam("name") String jobName,
		Pageable pageable, PagedResourcesAssembler<TaskJobExecution> assembler) throws NoSuchJobException {
	List<TaskJobExecution> jobExecutions = taskJobService.listJobExecutionsForJobWithStepCount(pageable, jobName);
	Page<TaskJobExecution> page = new PageImpl<>(jobExecutions, pageable,
			taskJobService.countJobExecutionsForJob(jobName, null));
	return assembler.toModel(page, jobAssembler);
}
 
Example 13
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 14
Source File: RuntimeStreamsController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * @param pageable the page
 * @param assembler the resource assembler
 *
 * @return a paged model for stream statuses
 */
@RequestMapping(method = RequestMethod.GET)
public PagedModel<StreamStatusResource> status(@RequestParam(value = "names", required = false) String[] names, Pageable pageable,
		PagedResourcesAssembler<Pair<String, List<AppStatus>>> assembler) {
	List<String> streamNames = (names!= null) ? Arrays.asList(names): new ArrayList<>();
	if (streamNames.isEmpty()) {
		streamNames = this.streamDeployer.getStreams();
	}
	return assembler.toModel(new PageImpl<>(getStreamStatusList(getPagedStreamNames(pageable, streamNames)),
			pageable, streamNames.size()), statusAssembler);
}
 
Example 15
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 16
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 17
Source File: RuntimeAppsController.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@RequestMapping
public PagedModel<AppStatusResource> list(Pageable pageable, PagedResourcesAssembler<AppStatus> assembler) {
	return assembler.toModel(streamDeployer.getAppStatuses(pageable), statusAssembler);
}
 
Example 18
Source File: JobExecutionThinController.java    From spring-cloud-dataflow with Apache License 2.0 3 votes vote down vote up
/**
 * Return a page-able list of {@link JobExecutionThinResource} defined jobs that
 * do not contain step execution detail.
 *
 * @param pageable page-able collection of {@code TaskJobExecution}s.
 * @param assembler for the {@link TaskJobExecution}s
 * @return a list of Task/Job executions(job executions do not contain step executions.
 * @throws NoSuchJobExecutionException in the event that a job execution id specified
 * is not present when looking up stepExecutions for the result.
 */
@RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public PagedModel<JobExecutionThinResource> listJobsOnly(Pageable pageable,
		PagedResourcesAssembler<TaskJobExecution> assembler) throws NoSuchJobExecutionException {
	List<TaskJobExecution> jobExecutions = taskJobService.listJobExecutionsWithStepCount(pageable);
	Page<TaskJobExecution> page = new PageImpl<>(jobExecutions, pageable, taskJobService.countJobExecutions());
	return assembler.toModel(page, jobAssembler);
}
 
Example 19
Source File: StreamDefinitionController.java    From spring-cloud-dataflow with Apache License 2.0 3 votes vote down vote up
/**
 * Return a page-able list of {@link StreamDefinitionResource} defined streams.
 *
 * @param pageable Pagination information
 * @param assembler assembler for {@link StreamDefinition}
 * @param search optional findByTaskNameContains parameter
 * @return list of stream definitions
 */
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public PagedModel<StreamDefinitionResource> list(Pageable pageable,
		@RequestParam(required = false) String search, PagedResourcesAssembler<StreamDefinition> assembler) {
	Page<StreamDefinition> streamDefinitions = this.streamService.findDefinitionByNameContains(pageable, search);
	return assembler.toModel(streamDefinitions, new Assembler(streamDefinitions));
}
 
Example 20
Source File: JobStepExecutionController.java    From spring-cloud-dataflow with Apache License 2.0 3 votes vote down vote up
/**
 * List all step executions.
 *
 * @param id the {@link JobExecution}.
 * @param pageable the pagination information.
 * @param assembler the resource assembler for step executions.
 * @return Collection of {@link StepExecutionResource} for the given jobExecutionId.
 * @throws NoSuchJobExecutionException if the job execution for the id specified does
 * not exist.
 */
@RequestMapping(value = { "" }, method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public PagedModel<StepExecutionResource> stepExecutions(@PathVariable("jobExecutionId") long id,
		Pageable pageable, PagedResourcesAssembler<StepExecution> assembler) throws NoSuchJobExecutionException {
	List<StepExecution> result;
	result = new ArrayList<>(jobService.getStepExecutions(id));
	Page<StepExecution> page = new PageImpl<>(result, pageable, result.size());
	return assembler.toModel(page, stepAssembler);
}