Java Code Examples for org.springframework.data.web.PagedResourcesAssembler

The following examples show how to use org.springframework.data.web.PagedResourcesAssembler. 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
Source Project: sos   Source File: EventController.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 2
@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);
}
 
Example 3
public static Resources<?> toResources(Iterable<?> source,
									   PersistentEntityResourceAssembler assembler,
									   PagedResourcesAssembler resourcesAssembler,
									   Class<?> domainType,
									   Link baseLink) {

	if (source instanceof Page) {
		Page<Object> page = (Page<Object>) source;
		return entitiesToResources(page, assembler, resourcesAssembler, domainType, baseLink);
	}
	else if (source instanceof Iterable) {
		return entitiesToResources((Iterable<Object>) source, assembler, domainType);
	}
	else {
		return new Resources(EMPTY_RESOURCE_LIST);
	}
}
 
Example 4
public static Resources<?> toResources(Iterable<?> source,
									   PersistentEntityResourceAssembler assembler,
									   PagedResourcesAssembler resourcesAssembler,
									   Class<?> domainType,
									   Link baseLink) {

	if (source instanceof Page) {
		Page<Object> page = (Page<Object>) source;
		return entitiesToResources(page, assembler, resourcesAssembler, domainType, baseLink);
	}
	else if (source instanceof Iterable) {
		return entitiesToResources((Iterable<Object>) source, assembler, domainType);
	}
	else {
		return new Resources(EMPTY_RESOURCE_LIST);
	}
}
 
Example 5
/**
 * 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 6
/**
 * 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 7
/**
 * 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 8
/**
 * 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 9
Source Project: training   Source File: FriendController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(path = "/users/{userId}/friends", method = RequestMethod.GET)
public HttpEntity<?> getFriends(@PathVariable Long userId, Pageable pageable,
                                PagedResourcesAssembler<Friend> assembler) {
    return Optional.of(friendRepository.findAllByUserId(userId, pageable))
            .map(a -> new ResponseEntity<>(assembler.toResource(a), HttpStatus.OK))
            .orElseThrow(() -> new RuntimeException("Could not retrieve friends for the supplied user id"));
}
 
Example 10
Source Project: training   Source File: FriendController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(path = "/users/{userId}/friends", method = RequestMethod.GET)
public HttpEntity<?> getFriends(@PathVariable Long userId, Pageable pageable,
                                PagedResourcesAssembler<Friend> assembler) {
    return Optional.of(friendRepository.findAllByUserId(userId, pageable))
            .map(a -> new ResponseEntity<>(assembler.toResource(a), HttpStatus.OK))
            .orElseThrow(() -> new RuntimeException("Could not retrieve friends for the supplied user id"));
}
 
Example 11
Source Project: restdocs-raml   Source File: NotesController.java    License: MIT License 5 votes vote down vote up
@Autowired
public NotesController(NoteRepository noteRepository, TagRepository tagRepository,
					   NoteResourceAssembler noteResourceAssembler,
					   TagResourceAssembler tagResourceAssembler,
					   PagedResourcesAssembler<Note> pagedResourcesAssembler) {
	this.noteRepository = noteRepository;
	this.tagRepository = tagRepository;
	this.noteResourceAssembler = noteResourceAssembler;
	this.tagResourceAssembler = tagResourceAssembler;
	this.pagedResourcesAssembler = pagedResourcesAssembler;
}
 
Example 12
Source Project: restdocs-raml   Source File: TagsController.java    License: MIT License 5 votes vote down vote up
@Autowired
public TagsController(TagRepository repository,
					  NoteResourceAssembler noteResourceAssembler,
					  TagResourceAssembler tagResourceAssembler,
					  PagedResourcesAssembler<Tag> pagedResourcesAssembler) {
	this.repository = repository;
	this.noteResourceAssembler = noteResourceAssembler;
	this.tagResourceAssembler = tagResourceAssembler;
	this.pagedResourcesAssembler = pagedResourcesAssembler;
}
 
Example 13
@RequestMapping
public PagedResources<AppInstanceStatusResource> list(@PathVariable String appId,
		PagedResourcesAssembler<AppInstanceStatus> assembler) {
	AppStatus status = appDeployer.status(appId);
	if (status != null) {
		List<AppInstanceStatus> appInstanceStatuses = new ArrayList<>(status.getInstances().values());
		Collections.sort(appInstanceStatuses, INSTANCE_SORTER);
		return assembler.toResource(new PageImpl<>(appInstanceStatuses), new InstanceAssembler(status));
	}
	throw new ResourceNotFoundException();
}
 
Example 14
/**
 * Register all applications listed in a properties file or provided as key/value pairs.
 * @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
 */
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public PagedResources<? extends AppRegistrationResource> registerAll(
		PagedResourcesAssembler<AppRegistration> pagedResourcesAssembler,
		@RequestParam(value = "uri", required = false) String uri,
		@RequestParam(value = "apps", required = false) Properties apps,
		@RequestParam(value = "force", defaultValue = "false") boolean force) {
	List<AppRegistration> registrations = new ArrayList<>();
	if (StringUtils.hasText(uri)) {
		registrations.addAll(appRegistry.importAll(force, uri));
	}
	else if (!CollectionUtils.isEmpty(apps)) {
		for (String key : apps.stringPropertyNames()) {
			String[] tokens = key.split("\\.", 2);
			if (tokens.length != 2) {
				throw new IllegalArgumentException("Invalid application key: " + key +
						"; the expected format is <name>.<type>");
			}
			String name = tokens[1];
			String type = tokens[0];
			if (force || null == appRegistry.find(name, type)) {
				try {
					registrations.add(appRegistry.save(name, type, new URI(apps.getProperty(key))));
				}
				catch (URISyntaxException e) {
					throw new IllegalArgumentException(e);
				}
			}
		}
	}
	Collections.sort(registrations);
	return pagedResourcesAssembler.toResource(new PageImpl<>(registrations), assembler);
}
 
Example 15
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public PagedResources<ApplicationDefinitionResource> list(Pageable pageable, @RequestParam(required=false) String search,
		PagedResourcesAssembler<ApplicationDefinition> assembler) {
	if (search != null) {
		final SearchPageable searchPageable = new SearchPageable(pageable, search);
		searchPageable.addColumns("DEFINITION_NAME", "DEFINITION");
		return assembler.toResource(definitionRepository.search(searchPageable), applicationAssembler);
	}
	else {
		return assembler.toResource(definitionRepository.findAll(pageable), applicationAssembler);
	}
}
 
Example 16
@Autowired
public LockingAndVersioningRestController(Repositories repositories, PagedResourcesAssembler<Object> assembler) {
	this.repositories = repositories;
	this.pagedResourcesAssembler = assembler;

	this.reflectionService = new ReflectionServiceImpl();
}
 
Example 17
protected static Resources<?> entitiesToResources(Page<Object> page,
										   PersistentEntityResourceAssembler assembler, PagedResourcesAssembler resourcesAssembler, Class<?> domainType,
										   Link baseLink) {

	if (page.getContent().isEmpty()) {
		return resourcesAssembler.toEmptyResource(page, domainType, baseLink);
	}

	return baseLink == null ? resourcesAssembler.toResource(page, assembler)
			: resourcesAssembler.toResource(page, assembler, baseLink);
}
 
Example 18
@Autowired
public ContentSearchRestController(Repositories repositories,
		ContentStoreService stores, PagedResourcesAssembler<Object> assembler) {
	// super(assembler);

	this.repositories = repositories;
	this.stores = stores;
	this.pagedResourcesAssembler = assembler;

	this.reflectionService = new ReflectionServiceImpl();
}
 
Example 19
protected static Resources<?> entitiesToResources(Page<Object> page,
										   PersistentEntityResourceAssembler assembler, PagedResourcesAssembler resourcesAssembler, Class<?> domainType,
										   Link baseLink) {

	if (page.getContent().isEmpty()) {
		return resourcesAssembler.toEmptyResource(page, domainType, baseLink);
	}

	return baseLink == null ? resourcesAssembler.toResource(page, assembler)
			: resourcesAssembler.toResource(page, assembler, baseLink);
}
 
Example 20
/**
 * 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 21
/**
 * 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 22
@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 23
/**
 * @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 24
/**
 * @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 25
/**
 * 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 26
/**
 * 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 27
/**
 * 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 28
/**
 * 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 29
/**
 * 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
/**
 * 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));
}