本文整理汇总了Java中org.springframework.hateoas.Link类的典型用法代码示例。如果您正苦于以下问题:Java Link类的具体用法?Java Link怎么用?Java Link使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Link类属于org.springframework.hateoas包,在下文中一共展示了Link类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: accessServiceUsingRestTemplate
import org.springframework.hateoas.Link; //导入依赖的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: updateEmployee
import org.springframework.hateoas.Link; //导入依赖的package包/类
@PutMapping("/employees/{id}")
ResponseEntity<?> updateEmployee(@RequestBody Employee employee, @PathVariable long id) {
Employee employeeToUpdate = employee;
employeeToUpdate.setId(id);
Employee updatedEmployee = repository.save(employeeToUpdate);
return new Resource<>(updatedEmployee,
linkTo(methodOn(EmployeeController.class).findOne(updatedEmployee.getId())).withSelfRel()
.andAffordance(afford(methodOn(EmployeeController.class).updateEmployee(null, updatedEmployee.getId())))
.andAffordance(afford(methodOn(EmployeeController.class).deleteEmployee(updatedEmployee.getId()))),
linkTo(methodOn(EmployeeController.class).findAll()).withRel("employees")
).getId()
.map(Link::getHref)
.map(href -> {
try {
return new URI(href);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
})
.map(uri -> ResponseEntity.noContent().location(uri).build())
.orElse(ResponseEntity.badRequest().body("Unable to update " + employeeToUpdate));
}
示例3: getOtherTitleContribution
import org.springframework.hateoas.Link; //导入依赖的package包/类
@ApiOperation(value = "Get the contribution of titles")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No contribution found") })
@GetMapping(value = "/contributions/{id}/othertitles", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
ContributionResource<OtherTitle> getOtherTitleContribution(
@ApiParam(value = "The contribution ID", required = true)
@PathVariable("id") final Long id
) {
log.info("Called with id {}", id);
final Contribution<OtherTitle> otherTitleContribution = this.movieContributionSearchService.getOtherTitleContribution(id);
final Link self = linkTo(
methodOn(MovieContributionRestController.class).getOtherTitleContribution(id)
).withSelfRel();
return new ContributionResource<>(otherTitleContribution, self);
}
示例4: getReleaseDateContribution
import org.springframework.hateoas.Link; //导入依赖的package包/类
@ApiOperation(value = "Get the contribution of release dates")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No contribution found") })
@GetMapping(value = "/contributions/{id}/releasedates", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
ContributionResource<ReleaseDate> getReleaseDateContribution(
@ApiParam(value = "The contribution ID", required = true) @PathVariable("id") final Long id
) {
log.info("Called with id {}", id);
final Contribution<ReleaseDate> releaseDateContribution = this.movieContributionSearchService.getReleaseDateContribution(id);
final Link self = linkTo(
methodOn(MovieContributionRestController.class).getReleaseDateContribution(id)
).withSelfRel();
return new ContributionResource<>(releaseDateContribution, self);
}
示例5: getStorylineContribution
import org.springframework.hateoas.Link; //导入依赖的package包/类
@ApiOperation(value = "Get the contribution of storylines")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No contribution found") })
@GetMapping(value = "/contributions/{id}/storylines", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
ContributionResource<Storyline> getStorylineContribution(
@ApiParam(value = "The contribution ID", required = true)
@PathVariable("id") final Long id
) {
log.info("Called with id {}", id);
final Contribution<Storyline> storylineContribution = this.movieContributionSearchService.getStorylineContribution(id);
final Link self = linkTo(
methodOn(MovieContributionRestController.class).getStorylineContribution(id)
).withSelfRel();
return new ContributionResource<>(storylineContribution, self);
}
示例6: getBoxOfficeContribution
import org.springframework.hateoas.Link; //导入依赖的package包/类
@ApiOperation(value = "Get the contribution of box offices")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No contribution found") })
@GetMapping(value = "/contributions/{id}/boxoffices", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
ContributionResource<BoxOffice> getBoxOfficeContribution(
@ApiParam(value = "The contribution ID", required = true)
@PathVariable("id") final Long id
) {
log.info("Called with id {}", id);
final Contribution<BoxOffice> boxOfficeContribution = this.movieContributionSearchService.getBoxOfficeContribution(id);
final Link self = linkTo(
methodOn(MovieContributionRestController.class).getBoxOfficeContribution(id)
).withSelfRel();
return new ContributionResource<>(boxOfficeContribution, self);
}
示例7: getSiteContribution
import org.springframework.hateoas.Link; //导入依赖的package包/类
@ApiOperation(value = "Get the contribution of sites")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No contribution found") })
@GetMapping(value = "/contributions/{id}/sites", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
ContributionResource<Site> getSiteContribution(
@ApiParam(value = "The contribution ID", required = true)
@PathVariable("id") final Long id
) {
log.info("Called with id {}", id);
final Contribution<Site> siteContribution = this.movieContributionSearchService.getSiteContribution(id);
final Link self = linkTo(
methodOn(MovieContributionRestController.class).getSiteContribution(id)
).withSelfRel();
return new ContributionResource<>(siteContribution, self);
}
示例8: getCountryContribution
import org.springframework.hateoas.Link; //导入依赖的package包/类
@ApiOperation(value = "Get the contribution of countries")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No contribution found") })
@GetMapping(value = "/contributions/{id}/countries", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
ContributionResource<Country> getCountryContribution(
@ApiParam(value = "The contribution ID", required = true)
@PathVariable("id") final Long id
) {
log.info("Called with id {}", id);
final Contribution<Country> countryContribution = this.movieContributionSearchService.getCountryContribution(id);
final Link self = linkTo(
methodOn(MovieContributionRestController.class).getCountryContribution(id)
).withSelfRel();
return new ContributionResource<>(countryContribution, self);
}
示例9: getLanguageContribution
import org.springframework.hateoas.Link; //导入依赖的package包/类
@ApiOperation(value = "Get the contribution of languages")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No contribution found") })
@GetMapping(value = "/contributions/{id}/languages", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
ContributionResource<Language> getLanguageContribution(
@ApiParam(value = "The contribution ID", required = true)
@PathVariable("id") final Long id
) {
log.info("Called with id {}", id);
final Contribution<Language> languageContribution = this.movieContributionSearchService.getLanguageContribution(id);
final Link self = linkTo(
methodOn(MovieContributionRestController.class).getLanguageContribution(id)
).withSelfRel();
return new ContributionResource<>(languageContribution, self);
}
示例10: getGenreContribution
import org.springframework.hateoas.Link; //导入依赖的package包/类
@ApiOperation(value = "Get the contribution of genres")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No contribution found") })
@GetMapping(value = "/contributions/{id}/genres", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
ContributionResource<Genre> getGenreContribution(
@ApiParam(value = "The contribution ID", required = true)
@PathVariable("id") final Long id
) {
log.info("Called with id {}", id);
final Contribution<Genre> genreContribution = this.movieContributionSearchService.getGenreContribution(id);
final Link self = linkTo(
methodOn(MovieContributionRestController.class).getGenreContribution(id)
).withSelfRel();
return new ContributionResource<>(genreContribution, self);
}
示例11: getReviewContribution
import org.springframework.hateoas.Link; //导入依赖的package包/类
@ApiOperation(value = "Get the contribution of reviews")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No contribution found") })
@GetMapping(value = "/contributions/{id}/reviews", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
ContributionResource<Review> getReviewContribution(
@ApiParam(value = "The contribution ID", required = true)
@PathVariable("id") final Long id
) {
log.info("Called with id {}", id);
final Contribution<Review> reviewContribution = this.movieContributionSearchService.getReviewContribution(id);
final Link self = linkTo(
methodOn(MovieContributionRestController.class).getReviewContribution(id)
).withSelfRel();
return new ContributionResource<>(reviewContribution, self);
}
示例12: getPhotoContribution
import org.springframework.hateoas.Link; //导入依赖的package包/类
@ApiOperation(value = "Get the contribution of photos")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No contribution found") })
@GetMapping(value = "/contributions/{id}/photos", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
ContributionResource<ImageResponse> getPhotoContribution(
@ApiParam(value = "The contribution ID", required = true)
@PathVariable("id") final Long id
) {
log.info("Called with id {}", id);
final Contribution<ImageResponse> photoContribution = this.movieContributionSearchService.getPhotoContribution(id);
final Link self = linkTo(
methodOn(MovieContributionRestController.class).getPhotoContribution(id)
).withSelfRel();
return new ContributionResource<>(photoContribution, self);
}
示例13: getPosterContribution
import org.springframework.hateoas.Link; //导入依赖的package包/类
@ApiOperation(value = "Get the contribution of posters")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No contribution found") })
@GetMapping(value = "/contributions/{id}/posters", produces = MediaTypes.HAL_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public
ContributionResource<ImageResponse> getPosterContribution(
@ApiParam(value = "The contribution ID", required = true)
@PathVariable("id") final Long id
) {
log.info("Called with id {}", id);
final Contribution<ImageResponse> posterContribution = this.movieContributionSearchService.getPosterContribution(id);
final Link self = linkTo(
methodOn(MovieContributionRestController.class).getPosterContribution(id)
).withSelfRel();
return new ContributionResource<>(posterContribution, self);
}
示例14: testInvalidTaskName
import org.springframework.hateoas.Link; //导入依赖的package包/类
@Test
@DirtiesContext
public void testInvalidTaskName() throws Exception {
String exceptionMessage = null;
final String ERROR_MESSAGE =
"Could not find task definition named " + TASK_NAME;
VndErrors errors = new VndErrors("message", ERROR_MESSAGE, new Link("ref"));
Mockito.doThrow(new DataFlowClientException(errors))
.when(this.taskOperations)
.launch(Matchers.anyString(),
(Map<String, String>) Matchers.any(),
(List<String>) Matchers.any());
TaskLauncherTasklet taskLauncherTasklet = getTaskExecutionTasklet();
ChunkContext chunkContext = chunkContext();
try {
taskLauncherTasklet.execute(null, chunkContext);
}
catch (DataFlowClientException dfce) {
exceptionMessage = dfce.getMessage();
}
assertEquals(ERROR_MESSAGE+"\n", exceptionMessage);
}
开发者ID:spring-cloud-task-app-starters,项目名称:composed-task-runner,代码行数:23,代码来源:TaskLauncherTaskletTests.java
示例15: testCreate
import org.springframework.hateoas.Link; //导入依赖的package包/类
/**
* Check that {@link PedigreeResourceFactory#create(Pedigree)} instantiates the
* {@link PedigreeResource} with the {@link Pedigree} and Link.
*/
@Test
public void testCreate() {
// Given
Link link = mock(Link.class);
when(hateoasFactory.createResourceLink(pedigree)).thenReturn(link);
// When
PedigreeResource resource = pedigreeResourceFactory.create(pedigree);
// Then
assertNotNull("Expecting an instance", resource);
assertSame("Expecting the pedigree passed as argument", pedigree, resource.getPedigree());
assertEquals("Expecting one link", 1, resource.getLinks().size());
assertSame("Expecting the Link instance for the Link factory", link, resource.getLinks().get(0));
}