本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}