当前位置: 首页>>代码示例>>Java>>正文


Java PagedResourcesAssembler.toResource方法代码示例

本文整理汇总了Java中org.springframework.data.web.PagedResourcesAssembler.toResource方法的典型用法代码示例。如果您正苦于以下问题:Java PagedResourcesAssembler.toResource方法的具体用法?Java PagedResourcesAssembler.toResource怎么用?Java PagedResourcesAssembler.toResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.data.web.PagedResourcesAssembler的用法示例。


在下文中一共展示了PagedResourcesAssembler.toResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: events

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
@GetMapping("events")
HttpEntity<Resources<?>> events(PagedResourcesAssembler<AbstractEvent<?>> assembler,
		@SortDefault("publicationDate") Pageable pageable,
		@RequestParam(required = false) @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime since,
		@RequestParam(required = false) String type) {

	QAbstractEvent $ = QAbstractEvent.abstractEvent;

	BooleanBuilder builder = new BooleanBuilder();

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

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

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

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

	return ResponseEntity.ok(resource);
}
 
开发者ID:olivergierke,项目名称:sos,代码行数:27,代码来源:EventController.java

示例2: list

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
@RequestMapping
public PagedResources<AppStatusResource> list(PagedResourcesAssembler<AppStatus> assembler) {
	List<AppStatus> values = new ArrayList<>();

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

	Collections.sort(values, new Comparator<AppStatus>() {
		@Override
		public int compare(AppStatus o1, AppStatus o2) {
			return o1.getDeploymentId().compareTo(o2.getDeploymentId());
		}
	});
	return assembler.toResource(new PageImpl<>(values), statusAssembler);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:21,代码来源:RuntimeAppsController.java

示例3: list

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

示例4: getSubnets

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public HttpEntity<PagedResources<SubnetResource>> getSubnets(@RequestParam(required = false) String ip,
		@RequestParam(required = false) Long size, @PathVariable @NotNull Integer infraId, Pageable pageable,
		PagedResourcesAssembler<Subnet> pagedAssembler) {
	Page<Subnet> subnets;
	if (! Strings.isNullOrEmpty(ip)) {
		long ip4 = IpAddress.toLong(ip);
		if (size == null) {
			subnets = this.repository.findAllByInfraIdAndIp(infraId, ip4, pageable);
		} else {
			subnets = this.repository.findAllByInfraIdAndIpAndSize(infraId, ip4, size, pageable);
		}
	} else {
		subnets = this.repository.findAllByInfraId(infraId, pageable);
	}
	PagedResources<SubnetResource> page = pagedAssembler.toResource(subnets, assembler);
	page.add(InfrastructureResourceAssembler.link(infraId));
	return new ResponseEntity<>(page, HttpStatus.OK);
}
 
开发者ID:bozzo,项目名称:ipplan-api,代码行数:20,代码来源:SubnetController.java

示例5: findUsers

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
@ApiOperation(value = "Find users")
@GetMapping(produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
PagedResources<UserSearchResultResource> findUsers(
        @ApiParam(value = "The user's name")
        @RequestParam(value = "q", required = false) final String q,
        @PageableDefault(sort = {"id"}, direction = Sort.Direction.ASC) final Pageable page,
        final PagedResourcesAssembler<UserSearchResult> assembler
) {
    log.info("Called with q {}, page {}", q, page);

    // Build the self link which will be used for the next, previous, etc links
    final Link self = ControllerLinkBuilder
            .linkTo(
                    ControllerLinkBuilder
                            .methodOn(UserRestController.class)
                            .findUsers(
                                    q,
                                    page,
                                    assembler
                            )
            ).withSelfRel();

    return assembler.toResource(this.userSearchService.findUsers(
            q, page
    ), this.userSearchResultResourceAssembler, self);
}
 
开发者ID:JonkiPro,项目名称:REST-Web-Services,代码行数:29,代码来源:UserRestController.java

示例6: registerAll

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:40,代码来源:AppRegistryController.java

示例7: list

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
@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);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dashboard,代码行数:14,代码来源:ApplicationDefinitionController.java

示例8: getAllDashboards

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@RequestMapping(method = GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<PagedResources<DashboardResource>> getAllDashboards(
    @PageableDefault Pageable pageable, PagedResourcesAssembler pagedResourcesAssembler) {

  Page<Dashboard> dashboardsPage = service.loadAll(pageable);
  PagedResources<DashboardResource> pagedResources =
      pagedResourcesAssembler.toResource(dashboardsPage, dashboardResourceAssembler);
  return new ResponseEntity<>(pagedResources, OK);
}
 
开发者ID:reflectoring,项目名称:infiniboard,代码行数:11,代码来源:DashboardController.java

示例9: getWidgets

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@RequestMapping(method = GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<PagedResources<WidgetConfigResource>> getWidgets(
    @PathVariable String dashboardId,
    @PageableDefault Pageable pageable,
    PagedResourcesAssembler pagedResourcesAssembler) {
  Page<WidgetConfig> widgetConfigPage = widgetConfigRepository.findAll(pageable);
  WidgetConfigResourceAssembler assembler = new WidgetConfigResourceAssembler(dashboardId);
  PagedResources<WidgetConfigResource> pagedResources =
      pagedResourcesAssembler.toResource(widgetConfigPage, assembler);
  return new ResponseEntity<>(pagedResources, OK);
}
 
开发者ID:reflectoring,项目名称:infiniboard,代码行数:13,代码来源:WidgetController.java

示例10: list

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
/**
 * List Counters that match the given criteria.
 */
@RequestMapping(value = "", method = RequestMethod.GET)
public PagedResources<? extends MetricResource> list(Pageable pageable,
		PagedResourcesAssembler<String> pagedAssembler) {
	List<String> names = new ArrayList<>(repository.list());
	long count = names.size();
	long pageEnd = Math.min(count, pageable.getOffset() + pageable.getPageSize());
	Page fieldValueCounterPage = new PageImpl<>(names.subList(pageable.getOffset(), (int) pageEnd), pageable, names.size());
	return pagedAssembler.toResource(fieldValueCounterPage, shallowAssembler);
}
 
开发者ID:spring-projects,项目名称:spring-analytics,代码行数:13,代码来源:FieldValueCounterController.java

示例11: list

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
/**
 * List Counters that match the given criteria.
 */
@RequestMapping(value = "", method = RequestMethod.GET)
public PagedResources<? extends MetricResource> list(
		Pageable pageable,
		PagedResourcesAssembler<Metric<Double>> pagedAssembler,
		@RequestParam(value = "detailed", defaultValue = "false") boolean detailed) {
	/* Page */ Iterable<Metric<?>> metrics = metricRepository.findAll(/* pageable */);
	List<Metric<Double>> content = filterCounters(metrics);
	long count = content.size();
	long pageEnd = Math.min(count, pageable.getOffset() + pageable.getPageSize());
	Page counterPage = new PageImpl<>(content.subList(pageable.getOffset(), (int) pageEnd), pageable, content.size());
	ResourceAssembler<Metric<Double>, ? extends MetricResource> assemblerToUse =
			detailed ? counterResourceAssembler : shallowResourceAssembler;
	return pagedAssembler.toResource(counterPage, assemblerToUse);
}
 
开发者ID:spring-projects,项目名称:spring-analytics,代码行数:18,代码来源:CounterController.java

示例12: findAllPageable

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
/**
 * Find All Laws
 * @param pageable
 * @return Laws
 */
@GetMapping
public PagedResources<Resource<Law>> findAllPageable(final Pageable pageable, final PagedResourcesAssembler<Law> assembler) {
	
	PagedResources<Resource<Law>> pagedResources = assembler.toResource(lawsRepository.findAllByOrderByCodeDesc(pageable)
																					  .orElseThrow(ResourceNotFoundException :: new));
	pagedResources.forEach(this :: createVoteResource);
	
	return pagedResources;
}
 
开发者ID:sjcdigital,项目名称:temis-api,代码行数:15,代码来源:LawsController.java

示例13: findAll

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
/**
 * Get all Alderman
 * @return List Alderman
 */
@GetMapping
public PagedResources<Resource<Alderman>> findAll(final Pageable pageable, final PagedResourcesAssembler<Alderman> assembler) {
	final PagedResources<Resource<Alderman>> pagedResources = assembler.toResource(aldermanRepository.findAll(pageable));
	pagedResources.forEach(this :: createAldermanResource);
	return pagedResources;
}
 
开发者ID:sjcdigital,项目名称:temis-api,代码行数:11,代码来源:AldermanController.java

示例14: showClubs

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody 
public HttpEntity<PagedResources<ClubResource>> showClubs(@RequestParam(value = "q", required = false) String query, @PageableDefault(size = 10, page = 0, direction = Sort.Direction.DESC, sort = "name") Pageable pageable, PagedResourcesAssembler<Club> assembler) {
	Page<Club> clubs = this.clubService.findByNameContainingIgnoreCase(query, pageable);
	PagedResources<ClubResource> resources = assembler.toResource(clubs, clubResourceAssembler);
	return new ResponseEntity<PagedResources<ClubResource>>(resources, HttpStatus.OK);
}
 
开发者ID:stasbranger,项目名称:RotaryLive,代码行数:8,代码来源:ClubController.java

示例15: showUsers

import org.springframework.data.web.PagedResourcesAssembler; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody 
public HttpEntity<PagedResources<UserResource>> showUsers(@RequestParam(value = "q", required = false) String query, @PageableDefault(size = 10, page = 0, direction = Sort.Direction.DESC, sort = "name") Pageable pageable, PagedResourcesAssembler<User> assembler, HttpServletRequest httpServletRequest) {
	if(httpServletRequest.isUserInRole("ADMIN")){
		System.out.println(httpServletRequest.getUserPrincipal().getName() + " IS ADMIN");
	}		
	
	Page<User> users = (query == null || query.trim().equals("")) ? this.userService.findAll(pageable) : this.userService.findAll(query, pageable);
	PagedResources<UserResource> resources = assembler.toResource(users, userResourceAssembler);
	return new ResponseEntity<PagedResources<UserResource>>(resources, HttpStatus.OK);
}
 
开发者ID:stasbranger,项目名称:RotaryLive,代码行数:12,代码来源:UserController.java


注:本文中的org.springframework.data.web.PagedResourcesAssembler.toResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。