本文整理汇总了Java中org.springframework.data.web.PagedResourcesAssembler类的典型用法代码示例。如果您正苦于以下问题:Java PagedResourcesAssembler类的具体用法?Java PagedResourcesAssembler怎么用?Java PagedResourcesAssembler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PagedResourcesAssembler类属于org.springframework.data.web包,在下文中一共展示了PagedResourcesAssembler类的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: search
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
@PostMapping(value = "/filter", consumes = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation("Search stored documents using metadata.")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Returns search results", response = StoredDocumentHalResourceCollection.class),
@ApiResponse(code = 400, message = "Error when search criteria not specified")
})
public ResponseEntity<Object> search(
@Valid @RequestBody MetadataSearchCommand metadataSearchCommand,
Pageable pageable,
PagedResourcesAssembler<StoredDocumentHalResource> assembler) {
Page<StoredDocumentHalResource> page = searchService.findStoredDocumentsByMetadata(metadataSearchCommand, pageable).map(StoredDocumentHalResource::new);
return ResponseEntity
.ok()
.contentType(V1MediaType.V1_HAL_DOCUMENT_PAGE_MEDIA_TYPE)
.body(assembler.toResource(page));
}
示例3: searchOwned
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
@PostMapping(value = "/owned")
@ApiOperation("Search stored documents by ownership.")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Returns search results", response = StoredDocumentHalResourceCollection.class),
@ApiResponse(code = 400, message = "Error when search criteria not specified")
})
public ResponseEntity<Object> searchOwned(
Pageable pageable,
PagedResourcesAssembler<StoredDocumentHalResource> assembler) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
Page<StoredDocumentHalResource> page = searchService.findStoredDocumentsByCreator(authentication.getName(), pageable).map(StoredDocumentHalResource::new);
return ResponseEntity
.ok()
.contentType(V1MediaType.V1_HAL_DOCUMENT_PAGE_MEDIA_TYPE)
.body(assembler.toResource(page));
}
示例4: 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);
}
示例5: 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;
}
示例6: retrieve
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
@ApiOperation(value = "Lists a workflow's revisions")
@ApiImplicitParams({ @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query", value = "Results page you want to retrieve (0..N)"),
@ApiImplicitParam(name = "size", dataType = "integer", paramType = "query", value = "Number of records per page."),
@ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "Sorting criteria in the format: property(,asc|desc). " +
"Default sort order is ascending. " + "Multiple sort criteria are supported.") })
@ApiResponses(value = @ApiResponse(code = 404, message = "Bucket or workflow not found"))
@RequestMapping(value = "/buckets/{bucketId}/workflows/{workflowId}/revisions", method = GET)
public PagedResources list(@PathVariable Long bucketId, @PathVariable Long workflowId,
@ApiParam("Query string for searching workflows. See <a href=\"http://doc.activeeon.com/latest/user/ProActiveUserGuide.html#_searching_for_workflows\">Searching for workflows</a> for more information about supported fields and operations.") @RequestParam(required = false) Optional<String> query,
@ApiParam(hidden = true) Pageable pageable, @ApiParam(hidden = true) PagedResourcesAssembler assembler)
throws QueryExpressionBuilderException {
return workflowRevisionService.listWorkflows(bucketId,
Optional.ofNullable(workflowId),
query,
pageable,
assembler);
}
示例7: listWorkflows
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
private void listWorkflows(Optional<Long> wId) throws QueryExpressionBuilderException {
when(bucketRepository.findOne(anyLong())).thenReturn(mock(Bucket.class));
when(workflowRepository.findOne(anyLong())).thenReturn(mock(Workflow.class));
PagedResourcesAssembler mockedAssembler = mock(PagedResourcesAssembler.class);
when(mockedAssembler.toResource(any(PageImpl.class),
any(WorkflowRevisionResourceAssembler.class))).thenReturn(null);
if (wId.isPresent()) {
when(workflowRevisionRepository.getRevisions(anyLong(),
any(Pageable.class))).thenReturn(mock(PageImpl.class));
} else {
when(workflowRepository.getMostRecentRevisions(anyLong(),
any(Pageable.class))).thenReturn(mock(PageImpl.class));
}
workflowRevisionService.listWorkflows(DUMMY_ID, wId, Optional.empty(), null, mockedAssembler);
}
示例8: registerAll
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
/**
* Register all applications listed in a properties file or provided as key/value
* pairs.
*
* @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 PagedResources<? extends AppRegistrationResource> registerAll(
Pageable pageable,
PagedResourcesAssembler<AppRegistration> pagedResourcesAssembler,
@RequestParam(value = "uri", required = false) String uri,
@RequestParam(value = "apps", required = false) Properties apps,
@RequestParam(value = "force", defaultValue = "false") boolean force) throws IOException {
List<AppRegistration> registrations = new ArrayList<>();
if (StringUtils.hasText(uri)) {
registrations.addAll(appRegistry.importAll(force, resourceLoader.getResource(uri)));
}
else if (!CollectionUtils.isEmpty(apps)) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
apps.store(baos, "");
ByteArrayResource bar = new ByteArrayResource(baos.toByteArray(), "Inline properties");
registrations.addAll(appRegistry.importAll(force, bar));
}
Collections.sort(registrations);
prefetchMetadata(registrations);
return pagedResourcesAssembler.toResource(
new PageImpl<>(registrations, pageable, appRegistry.findAll().size()),
assembler);
}
示例9: list
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
/**
* Return a page-able list of {@link StreamDefinitionResource} defined streams.
*
* @param pageable page-able collection of {@code StreamDefinitionResource}s.
* @param assembler assembler for {@link StreamDefinition}
* @param search optional search parameter
* @return list of stream definitions
*/
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
public PagedResources<StreamDefinitionResource> list(Pageable pageable,
@RequestParam(required = false) String search, PagedResourcesAssembler<StreamDefinition> assembler) {
Page<StreamDefinition> streamDefinitions;
if (search != null) {
final SearchPageable searchPageable = new SearchPageable(pageable, search);
searchPageable.addColumns("DEFINITION_NAME", "DEFINITION");
streamDefinitions = streamDefinitionRepository.search(searchPageable);
long count = streamDefinitions.getContent().size();
long to = Math.min(count, pageable.getOffset() + pageable.getPageSize());
streamDefinitions = new PageImpl<>(streamDefinitions.getContent(), pageable,
streamDefinitions.getTotalElements());
}
else {
streamDefinitions = streamDefinitionRepository.findAll(pageable);
}
return assembler.toResource(streamDefinitions, new Assembler(streamDefinitions));
}
示例10: listRelated
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
/**
* 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 name the name of an existing stream definition (required)
* @param nested if should recursively search 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 PagedResources<StreamDefinitionResource> listRelated(Pageable pageable,
@PathVariable("name") String name,
@RequestParam(value = "nested", required = false, defaultValue = "false") boolean nested,
PagedResourcesAssembler<StreamDefinition> assembler) {
Set<StreamDefinition> relatedDefinitions = new LinkedHashSet<>();
StreamDefinition currentStreamDefinition = streamDefinitionRepository.findOne(name);
if (currentStreamDefinition == null) {
throw new NoSuchStreamDefinitionException(name);
}
Iterable<StreamDefinition> definitions = streamDefinitionRepository.findAll();
List<StreamDefinition> result = new ArrayList<>(findRelatedDefinitions(currentStreamDefinition, definitions,
relatedDefinitions, nested));
Page<StreamDefinition> page = new PageImpl<>(result, pageable,
definitions.spliterator().getExactSizeIfKnown());
return assembler.toResource(page, new Assembler(page));
}
示例11: listMetrics
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@RequestMapping(
method = {RequestMethod.GET},
produces = "application/hal+json"
)
public ResponseEntity<PagedResources<MetricResource>> listMetrics(
@PathVariable Long projectId,
@PageableDefault Pageable pageable,
PagedResourcesAssembler pagedResourcesAssembler) {
projectVerifier.checkProjectExistsOrThrowException(projectId);
Page<String> metricsPage = metricValueRepository.findMetricsInProject(projectId, pageable);
MetricResourceAssembler assembler = new MetricResourceAssembler();
PagedResources<MetricResource> pagedResources =
pagedResourcesAssembler.toResource(metricsPage, assembler);
return new ResponseEntity<>(pagedResources, HttpStatus.OK);
}
示例12: getPropertiesByPage
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
/**
* ----------------------------------------------------------------------------------------------------------------
*
* GET - find "Pageable" properties
*
* ----------------------------------------------------------------------------------------------------------------
*
* Return a pageable list of Properties.
*
* @param pageable
* the page data. Page number and page size.
* @param assembler
* the assembler that will construct the property resource as a pageable resource.
* @return A pageable list of properties in json or xml format (default to json)
*
*/
@RequestMapping(value = "/location", method = RequestMethod.GET)
public HttpEntity<PagedResources<ResourceSupport>> getPropertiesByPage( //
@RequestParam(value = "longitude", required = true) final Double longitude, //
@RequestParam(value = "latitude", required = true) final Double latitude, //
@RequestParam(value = "distance", required = false, defaultValue = "1.0") final Double distance, //
@RequestParam(value = "sortOrder", required = false, defaultValue = "DESC") final String sortOrderAsString, //
PagedResourcesAssembler<Property> assembler //
) {
List<Property> properties = this.propertyService.findPropertiesByLocation(new GeoPoint(latitude, longitude), distance,
SortOrder.valueOf(sortOrderAsString.toUpperCase()));
return new ResponseEntity<PagedResources<ResourceSupport>>(assembler.toResource(new PageImpl<Property>(properties), this.propertyResourceAssembler),
HttpStatus.OK);
}
示例13: api
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.forCodeGeneration(false)
.alternateTypeRules(
getAlternateTypeRule(Collection.class, WildcardType.class, List.class,
WildcardType.class),
getAlternateTypeRule(Stream.class, WildcardType.class, List.class,
WildcardType.class),
getAlternateTypeRule(DeferredResult.class, List.class, WildcardType.class,
List.class, WildcardType.class))
.ignoredParameterTypes(PagedResourcesAssembler.class, Pageable.class)
.directModelSubstitute(MessageSourceResolvable.class, String.class)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/api/.*"))
.build()
.apiInfo(apiInfo());
}
示例14: add_infra_should_create_a_new_infra
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
@Before
public void add_infra_should_create_a_new_infra() {
Infrastructure infra = new Infrastructure();
infra.setDescription("Test description");
infra.setGroup("group");
HttpEntity<InfrastructureResource> resp = this.infrastructureController.addInfrastructure(infra);
Assert.assertNotNull(resp);
Assert.assertNotNull(resp.getBody());
InfrastructureResource infraReturned = resp.getBody();
Assert.assertNotNull(infraReturned);
Assert.assertNotNull(infraReturned.getId());
Assert.assertEquals(infra.getDescription(), infraReturned.getDescription());
Assert.assertEquals(infra.getCrm(), infraReturned.getCrm());
Assert.assertEquals(infra.getGroup(), infraReturned.getGroup());
infraId = infraReturned.getInfraId();
List<InfrastructureResource> infras = IterableUtils.toList(this.infrastructureController.getInfrastructures(null, null, new PagedResourcesAssembler<Infrastructure>(resolver, null)));
Assert.assertNotNull(infras);
Assert.assertEquals(1, infras.size());
}
示例15: update_zone_shouldnt_create_a_new_zone
import org.springframework.data.web.PagedResourcesAssembler; //导入依赖的package包/类
@Test
public void update_zone_shouldnt_create_a_new_zone() {
add_zone_should_create_a_new_zone();
Zone zone = new Zone();
zone.setDescription("Test description 2");
zone.setInfraId(infraId);
zone.setIp(0xC0A80101L);
zone.setId(id);
HttpEntity<ZoneResource> resp = this.controller.updateZone(infraId, id, zone);
Assert.assertNotNull(resp);
Assert.assertNotNull(resp.getBody());
ZoneResource zoneReturned = resp.getBody();
Assert.assertNotNull(zoneReturned);
Assert.assertNotNull(zoneReturned.getId());
Assert.assertEquals(zone.getDescription(), zoneReturned.getDescription());
Assert.assertEquals(zone.getInfraId(), zoneReturned.getInfraId());
Assert.assertEquals(zone.getIp(), zoneReturned.getIp());
Assert.assertEquals(3, zoneReturned.getLinks().size());
List<ZoneResource> zones = IterableUtils.toList(this.controller.getZones(infraId, null, new PagedResourcesAssembler<Zone>(resolver, null)));
Assert.assertNotNull(zones);
Assert.assertEquals(1, zones.size());
}