本文整理汇总了Java中org.springframework.hateoas.Resources类的典型用法代码示例。如果您正苦于以下问题:Java Resources类的具体用法?Java Resources怎么用?Java Resources使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Resources类属于org.springframework.hateoas包,在下文中一共展示了Resources类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: accessServiceUsingRestTemplate
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@Test
public void accessServiceUsingRestTemplate() {
// Access root resource
URI uri = URI.create(String.format(SERVICE_URI, port));
RequestEntity<Void> request = RequestEntity.get(uri).accept(HAL_JSON).build();
Resource<Object> rootLinks = restOperations.exchange(request, new ResourceType<Object>() {}).getBody();
Links links = new Links(rootLinks.getLinks());
// Follow stores link
Link storesLink = links.getLink("stores").expand();
request = RequestEntity.get(URI.create(storesLink.getHref())).accept(HAL_JSON).build();
Resources<Store> stores = restOperations.exchange(request, new ResourcesType<Store>() {}).getBody();
stores.getContent().forEach(store -> log.info("{} - {}", store.name, store.address));
}
示例2: events
import org.springframework.hateoas.Resources; //导入依赖的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);
}
示例3: getAllIncidentsAsync
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@Override
public CompletableFuture<List<IncidentBean>> getAllIncidentsAsync() {
CompletableFuture<List<IncidentBean>> cf = new CompletableFuture<>();
CompletableFuture.runAsync(() -> {
LOG.info("Performing get {} web service", applicationProperties.getIncidentApiUrl() +"/incidents");
final String restUri = applicationProperties.getIncidentApiUrl() +"/incidents";
ResponseEntity<Resources<IncidentBean>> response = restTemplate.exchange(restUri, HttpMethod.GET, null,
new ParameterizedTypeReference<Resources<IncidentBean>>() {});
// LOG.info("Total Incidents {}", response.getBody().size());
Resources<IncidentBean> beanResources = response.getBody();
Collection<IncidentBean> beanCol = beanResources.getContent();
ArrayList<IncidentBean> beanList= new ArrayList<IncidentBean>(beanCol);
cf.complete( beanList );
LOG.info("Done getting incidents");
});
return cf;
}
示例4: search
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@Override
public Resources<PackageMetadata> search(String name, boolean details) {
ParameterizedTypeReference<Resources<PackageMetadata>> typeReference =
new ParameterizedTypeReference<Resources<PackageMetadata>>() { };
Traverson.TraversalBuilder traversalBuilder = this.traverson.follow("packageMetadata");
Map<String, Object> parameters = new HashMap<>();
parameters.put("size", 2000);
if (StringUtils.hasText(name)) {
parameters.put("name", name);
traversalBuilder.follow("search", "findByNameContainingIgnoreCase");
}
if (!details) {
parameters.put("projection", "summary");
parameters.put("sort", "name,asc");
// TODO semver sort..
}
return traversalBuilder.withTemplateParameters(parameters).toObject(typeReference);
}
示例5: findAudits
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@GetMapping("{id}/auditEntries")
@ApiOperation("Retrieves audits related to a Stored Document.")
public ResponseEntity<Object> findAudits(@PathVariable UUID id) {
StoredDocument storedDocument = storedDocumentService.findOne(id);
if (storedDocument == null) {
throw new StoredDocumentNotFoundException(id);
}
List<StoredDocumentAuditEntry> auditEntries = auditEntryService.findStoredDocumentAudits(storedDocument);
Resources<StoredDocumentAuditEntryHalResource> resources = new Resources<>(auditEntries
.stream()
.map(StoredDocumentAuditEntryHalResource::new).collect(Collectors.toList()));
return ResponseEntity.ok().contentType(V1MediaType.V1_HAL_AUDIT_ENTRY_COLLECTION_MEDIA_TYPE).body(resources);
}
示例6: listCSARs
import org.springframework.hateoas.Resources; //导入依赖的package包/类
/**
Responds with a list of csars stored on the transformer.
<p>
This always responds with HTTP-Code 200 (application/hal+json)
*/
@ApiOperation(
value = "List all CSARs stored on the server",
notes = "Returns a Hypermedia Resource containing all CSARs" +
" that have been uploaded to the server and did not get removed",
response = CsarResources.class,
produces = "application/hal+json"
)
@RequestMapping(
path = "",
method = RequestMethod.GET,
produces = "application/hal+json"
)
public ResponseEntity<Resources<CsarResponse>> listCSARs() {
Link selfLink = linkTo(methodOn(CsarController.class).listCSARs()).withSelfRel();
List<CsarResponse> responses = new ArrayList<>();
for (Csar csar : csarService.getCsars()) {
responses.add(new CsarResponse(csar.getIdentifier()));
}
Resources<CsarResponse> csarResources = new HiddenResources<>(responses, selfLink);
return ResponseEntity.ok().body(csarResources);
}
示例7: Platforms
import org.springframework.hateoas.Resources; //导入依赖的package包/类
/**
Lists all Supported Platforms (HTTP Response Method).
<p>
It handles the <code>/platforms</code> Request
<p>
Always responds with HTTP-Code 200 (application/hal+json)
*/
@ApiOperation(
value = "List all supported Platforms",
notes = "Returns a HAL resource (_embedded) containing all " +
"Platforms supported by this transformer",
code = 200,
response = PlatformResources.class
)
@RequestMapping(
path = "",
method = RequestMethod.GET,
produces = "application/hal+json"
)
public ResponseEntity<Resources<PlatformResponse>> getPlatforms() {
Link selfLink = linkTo(methodOn(PlatformController.class).getPlatforms()).withSelfRel();
ArrayList<PlatformResponse> responses = new ArrayList<>();
for (Platform platform : platformService.getSupportedPlatforms()) {
logger.info("Adding Platform {} to response ", platform.id);
PlatformResponse res = getPlatformResource(platform);
responses.add(res);
}
Resources<PlatformResponse> resources = new HiddenResources<>(responses, selfLink);
return ResponseEntity.ok(resources);
}
示例8: findAll
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@GetMapping("/employees")
ResponseEntity<Resources<Resource<Employee>>> findAll() {
List<Resource<Employee>> employeeResources = StreamSupport.stream(repository.findAll().spliterator(), false)
.map(employee -> new Resource<>(employee,
linkTo(methodOn(EmployeeController.class).findOne(employee.getId())).withSelfRel()
.andAffordance(afford(methodOn(EmployeeController.class).updateEmployee(null, employee.getId())))
.andAffordance(afford(methodOn(EmployeeController.class).deleteEmployee(employee.getId()))),
linkTo(methodOn(EmployeeController.class).findAll()).withRel("employees")
))
.collect(Collectors.toList());
return ResponseEntity.ok(new Resources<>(employeeResources,
linkTo(methodOn(EmployeeController.class).findAll()).withSelfRel()
.andAffordance(afford(methodOn(EmployeeController.class).newEmployee(null)))));
}
示例9: statuses
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@RequestMapping(method = RequestMethod.GET, value = ApiController.BASE_PATH + "/modules", produces = MediaTypes.HAL_JSON_VALUE)
public ResponseEntity<?> statuses(@RequestHeader("api") URL api,
@RequestHeader("org") String org,
@RequestHeader("space") String space,
@RequestHeader("email") String email,
@RequestHeader("password") String password,
@RequestHeader(value = "namespace", defaultValue = "") String namespace) {
return ResponseEntity.ok(new Resources<>(
moduleService.getStatuses(api, org, space, email, password, namespace)
.map(appStatus -> new Resource<>(
appStatus,
linkTo(methodOn(ModuleController.class).status(appStatus.getDeploymentId(), api, org, space, email, password, namespace)).withSelfRel(),
linkTo(methodOn(ModuleController.class).start(appStatus.getDeploymentId(), api, org, space, email, password, namespace)).withRel("start"),
linkTo(methodOn(ModuleController.class).stop(appStatus.getDeploymentId(), api, org, space, email, password, namespace)).withRel("stop"),
linkTo(methodOn(ModuleController.class).link(appStatus.getDeploymentId(), api, org, space, email, password, namespace)).withRel("link")))
.collect(Collectors.toList()),
linkTo(methodOn(ModuleController.class).statuses(api, org, space, email, password, namespace)).withSelfRel()
));
}
示例10: page
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "listback")
@GetMapping("/names")
ModelAndView page() {
ModelAndView model = new ModelAndView("tcloud");
Resources<Tcloud> tclouds = this.tcloudReader.read();
List<Object> data = new LinkedList<>();
tclouds.forEach(tcloud -> data.add(ImmutableMap.<String, Object>builder()
.put("id", tcloud.getId())
.put("tcloudName", tcloud.getTcloudName())
.build()));
model.addObject("tclouds", data);
model.addObject("message", this.tcloudMessageReader.read());
return model;
}
示例11: getProfileNamesForService
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "getProfileNamesFallback")
@RequestMapping(method=RequestMethod.GET, value="/names/{service}")
public Collection<String> getProfileNamesForService(@PathVariable("service") String service) {
ParameterizedTypeReference<Resources<SocialProfile>> typeReference = new ParameterizedTypeReference<Resources<SocialProfile>>() {};
ResponseEntity<Resources<SocialProfile>> profiles =
restTemplate.exchange(
"http://" + service + "/socialProfiles",
HttpMethod.GET,
null,
typeReference);
return profiles.getBody().getContent()
.stream()
.map(SocialProfile::getName)
.collect(Collectors.toList());
}
开发者ID:blibattre,项目名称:generator-spring-boot-microservices,代码行数:18,代码来源:SocialProfileApiGatewayController.java
示例12: getProjectsForUser
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@RequestMapping(value = PROJECTS_URL, method = RequestMethod.GET)
public ResponseEntity<Resources<Resource<Project>>> getProjectsForUser(OAuth2Authentication oAuth2Authentication) {
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
List<Project> projects = projectService.getProjectsForUser(sw360User);
List<Resource<Project>> projectResources = new ArrayList<>();
for (Project project : projects) {
// TODO Kai Tödter 2017-01-04
// Find better way to decrease details in list resources,
// e.g. apply projections or Jackson Mixins
project.setDescription(null);
project.setType(null);
project.setCreatedOn(null);
project.setReleaseIdToUsage(null);
project.setExternalIds(null);
project.setBusinessUnit(null);
Resource<Project> projectResource = new Resource<>(project);
projectResources.add(projectResource);
}
Resources<Resource<Project>> resources = new Resources<>(projectResources);
return new ResponseEntity<>(resources, HttpStatus.OK);
}
示例13: getLicenses
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@RequestMapping(value = LICENSES_URL)
public ResponseEntity<Resources<Resource<License>>> getLicenses(OAuth2Authentication oAuth2Authentication) {
List<License> licenses = licenseService.getLicenses();
List<Resource<License>> licenseResources = new ArrayList<>();
for (License license : licenses) {
// TODO Kai Tödter 2017-01-04
// Find better way to decrease details in list resources,
// e.g. apply projections or Jackson Mixins
license.setText(null);
license.setType(null);
license.setShortname(null);
Resource<License> licenseResource = new Resource<>(license);
licenseResources.add(licenseResource);
}
Resources<Resource<License>> resources = new Resources<>(licenseResources);
return new ResponseEntity<>(resources, HttpStatus.OK);
}
示例14: getReleasesForUser
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@RequestMapping(value = RELEASES_URL)
public ResponseEntity<Resources<Resource>> getReleasesForUser(OAuth2Authentication oAuth2Authentication) {
User sw360User = restControllerHelper.getSw360UserFromAuthentication(oAuth2Authentication);
List<Release> releases = releaseService.getReleasesForUser(sw360User);
List<Resource> releaseResources = new ArrayList<>();
for (Release release : releases) {
release.setComponentId(null);
release.setType(null);
release.setAttachments(null);
release.setReleaseDate(null);
release.setVendor(null);
release.setMainLicenseIds(null);
Resource<Release> releaseResource = new Resource<>(release);
releaseResources.add(releaseResource);
}
Resources<Resource> resources = new Resources<>(releaseResources);
return new ResponseEntity<>(resources, HttpStatus.OK);
}
示例15: getUsers
import org.springframework.hateoas.Resources; //导入依赖的package包/类
@RequestMapping(USERS_URL)
public ResponseEntity<Resources<Resource<User>>> getUsers() {
List<User> sw360Users = userService.getAllUsers();
List<Resource<User>> userResources = new ArrayList<>();
for (User sw360User : sw360Users) {
// TODO Kai Tödter 2017-01-04
// Find better way to decrease details in list resources,
// e.g. apply projections or Jackson Mixins
sw360User.setType(null);
sw360User.setFullname(null);
sw360User.setGivenname(null);
sw360User.setLastname(null);
sw360User.setDepartment(null);
Resource<User> userResource = new Resource<>(sw360User);
userResources.add(userResource);
}
Resources<Resource<User>> resources = new Resources<>(userResources);
return new ResponseEntity<>(resources, HttpStatus.OK);
}