Here are the examples of the java api org.springframework.hateoas.Link taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
124 Examples
19
View Source File : WebMvcMovieController.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
@PostMapping("/movies")
public ResponseEnreplacedy<?> newMovie(@RequestBody EnreplacedyModel<Movie> movie) {
int newMovieId = MOVIES.size() + 1;
String newMovieIdString = "" + newMovieId;
Movie movieContent = movie.getContent();
replacedert movieContent != null;
movieContent.setId(newMovieIdString);
MOVIES.put(newMovieId, movieContent);
Link link = linkTo(methodOn(getClreplaced()).findOne(newMovieId)).withSelfRel().expand();
return ResponseEnreplacedy.created(link.toUri()).build();
}
19
View Source File : JsonApiModelBuilder.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
/**
* Creates all pagination links.
* <p>
* Preconditions are:<ul>
* <li>the model has been added before
* <li>the model is a {@literal PagedModel}
* <li>the model contains {@literal PageMetadata}
* </ul>
*
* @param linkBase the prefix of all pagination links, e.g. the base URL of the collection resource
* @param pageNumberRequestParam the request parameter for page number
* @param pageSizeRequestParam the request parameter for page size
* @return will never be {@literal null}.
*/
public JsonApiModelBuilder pageLinks(String linkBase, String pageNumberRequestParam, String pageSizeRequestParam) {
replacedert.notNull(linkBase, "link base for paging must not be null!");
replacedert.notNull(pageNumberRequestParam, "page number request parameter must not be null!");
replacedert.notNull(pageSizeRequestParam, "page size request parameter must not be null!");
final PagedModel.PageMetadata metadata = getPageMetadata();
final long pageNumber = metadata.getNumber();
final long pageSize = metadata.getSize();
final long totalPages = metadata.getTotalPages();
List<Link> paginationLinks = new ArrayList<>();
String paramStart = "?";
try {
URL url = new URL(linkBase);
String query = url.getQuery();
if (query != null) {
paramStart = "&";
}
} catch (MalformedURLException e) {
throw new IllegalArgumentException("LinkBase parameter must be a valid URL.");
}
if (pageNumber > 0) {
Link firstLink = Link.of(linkBase + paramStart + pageNumberRequestParam + "=0&" + pageSizeRequestParam + "=" + pageSize).withRel(IreplacedinkRelations.FIRST);
paginationLinks.add(firstLink);
}
if (pageNumber > 0) {
Link prevLink = Link.of(linkBase + paramStart + pageNumberRequestParam + "=" + (pageNumber - 1) + "&" + pageSizeRequestParam + "=" + pageSize).withRel(IreplacedinkRelations.PREV);
paginationLinks.add(prevLink);
}
if (pageNumber < totalPages - 1) {
Link nextLink = Link.of(linkBase + paramStart + pageNumberRequestParam + "=" + (pageNumber + 1) + "&" + pageSizeRequestParam + "=" + (pageNumber + 1)).withRel(IreplacedinkRelations.NEXT);
paginationLinks.add(nextLink);
}
if (pageNumber < totalPages - 1) {
Link lastLink = Link.of(linkBase + paramStart + pageNumberRequestParam + "=" + (totalPages - 1) + "&" + pageSizeRequestParam + "=" + pageSize).withRel(IreplacedinkRelations.LAST);
paginationLinks.add(lastLink);
}
this.links = this.links.and(paginationLinks);
return this;
}
19
View Source File : JsonApiModelBuilder.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
/**
* Adds a {@link Link} to the {@link RepresentationModel} to be built.
* <p>
* NOTE: This adds it to the top level.
* If you need a link inside the model you added with {@link #model(RepresentationModel)} method,
* add it directly to the model.
*
* @param link must not be {@literal null}.
* @return will never be {@literal null}.
*/
public JsonApiModelBuilder link(Link link) {
this.links = links.and(link);
return this;
}
19
View Source File : JsonApiLinksSerializer.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
private boolean isSimpleLink(Link link) {
return "self".equals(link.getRel().value()) || getAttributes(link).size() == 0;
}
19
View Source File : MovieModelAssembler.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
public RepresentationModel<?> directorsToJsonApiModel(Movie movie) {
Link selfLink = linkTo(methodOn(MovieController.clreplaced).findDirectors(movie.getId())).withSelfRel();
JsonApiModelBuilder builder = jsonApiModel().model(CollectionModel.of(movie.getDirectors())).relationshipWithDataArray("movies").link(selfLink);
return builder.build();
}
19
View Source File : MovieModelAssembler.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
public RepresentationModel<?> toJsonApiModel(Movie movie, String[] fieldsMovies) {
Link selfLink = linkTo(methodOn(MovieController.clreplaced).findOne(movie.getId(), null)).withSelfRel();
String href = selfLink.getHref();
selfLink = selfLink.withHref(href.substring(0, href.indexOf("{")));
// TODO: Spring HATEOAS does not recognize templated links with square brackets
// Link templatedMoviesLink = Link.of(moviesLink.getHref() + "{?page[number],page[size]}").withRel("movies");
String relationshipSelfLink = selfLink.getHref() + "/relationships/" + DIRECTORS;
String relationshipRelatedLink = selfLink.getHref() + "/" + DIRECTORS;
JsonApiModelBuilder builder = jsonApiModel().model(movie).link(selfLink);
if (fieldsMovies != null) {
builder = builder.fields("movies", fieldsMovies);
}
if (fieldsMovies == null || Arrays.asList(fieldsMovies).contains("directors")) {
builder = builder.relationship(DIRECTORS, movie.getDirectors()).relationship(DIRECTORS, relationshipSelfLink, relationshipRelatedLink, null);
}
return builder.build();
}
19
View Source File : DirectorModelAssembler.java
License : Apache License 2.0
Project Creator : toedter
License : Apache License 2.0
Project Creator : toedter
public RepresentationModel<?> toJsonApiModel(Director director, String[] fieldsDirectors) {
Link selfLink = linkTo(methodOn(DirectorController.clreplaced).findOne(director.getId(), null)).withSelfRel();
Link directorsLink = linkTo(DirectorController.clreplaced).slash("directors").withRel("directors");
Link templatedDirectorsLink = Link.of(directorsLink.getHref() + "{?page[number],page[size]}").withRel("directors");
JsonApiModelBuilder builder = jsonApiModel().model(director).link(selfLink).link(templatedDirectorsLink);
if (fieldsDirectors != null) {
builder = builder.fields("directors", fieldsDirectors);
}
if (fieldsDirectors == null || Arrays.asList(fieldsDirectors).contains("movies")) {
builder = builder.relationship(MOVIES, director.getMovies());
}
return builder.build();
}
19
View Source File : EmployeeController.java
License : Apache License 2.0
Project Creator : springdoc
License : Apache License 2.0
Project Creator : springdoc
/**
* Update existing employee then return a Location header.
*
* @param employee
* @param id
* @return
*/
@PutMapping("/employees/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
ResponseEnreplacedy<Void> updateEmployee(@RequestBody Employee employee, @PathVariable long id) throws URISyntaxException {
Employee employeeToUpdate = employee;
employeeToUpdate.setId(id);
repository.save(employeeToUpdate);
Link newlyCreatedLink = linkTo(methodOn(EmployeeController.clreplaced).findOne(id)).withSelfRel();
return ResponseEnreplacedy.noContent().location(new URI(newlyCreatedLink.getHref())).build();
}
19
View Source File : EmployeeController.java
License : Apache License 2.0
Project Creator : springdoc
License : Apache License 2.0
Project Creator : springdoc
/**
* Update existing employee then return a Location header.
*
* @param employee
* @param id
* @return
*/
@PutMapping("/employees/{id}")
ResponseEnreplacedy<Void> updateEmployee(@RequestBody Employee employee, @PathVariable long id) throws URISyntaxException {
Employee employeeToUpdate = employee;
employeeToUpdate.setId(id);
repository.save(employeeToUpdate);
Link newlyCreatedLink = linkTo(methodOn(EmployeeController.clreplaced).findOne(id)).withSelfRel();
return ResponseEnreplacedy.noContent().location(new URI(newlyCreatedLink.getHref())).build();
}
19
View Source File : OrderProcessor.java
License : Apache License 2.0
Project Creator : spring-projects
License : Apache License 2.0
Project Creator : spring-projects
/**
* Adjust the {@link Link} such that it starts at {@literal basePath}.
*
* @param link - link presumably supplied via Spring HATEOAS
* @param basePath - base path provided by Spring Data REST
* @return new {@link Link} with these two values melded together
*/
private static Link applyBasePath(Link link, String basePath) {
URI uri = link.toUri();
URI newUri = null;
try {
newUri = new //
URI(//
uri.getScheme(), //
uri.getUserInfo(), //
uri.getHost(), uri.getPort(), basePath + uri.getPath(), uri.getQuery(), uri.getFragment());
} catch (URISyntaxException e) {
e.printStackTrace();
}
return new Link(newUri.toString(), link.getRel());
}
19
View Source File : EmployeeController.java
License : Apache License 2.0
Project Creator : spring-projects
License : Apache License 2.0
Project Creator : spring-projects
/**
* Update existing employee then return a Location header.
*
* @param employee
* @param id
* @return
*/
@PutMapping("/employees/{id}")
ResponseEnreplacedy<?> updateEmployee(@RequestBody Employee employee, @PathVariable long id) {
Employee employeeToUpdate = employee;
employeeToUpdate.setId(id);
repository.save(employeeToUpdate);
Link newlyCreatedLink = linkTo(methodOn(EmployeeController.clreplaced).findOne(id)).withSelfRel();
try {
return ResponseEnreplacedy.noContent().location(new URI(newlyCreatedLink.getHref())).build();
} catch (URISyntaxException e) {
return ResponseEnreplacedy.badRequest().body("Unable to update " + employeeToUpdate);
}
}
19
View Source File : PackageSummaryResourceProcessor.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
@Override
public EnreplacedyModel<PackageSummary> process(EnreplacedyModel<PackageSummary> packageSummaryResource) {
Link link = linkTo(methodOn(PackageController.clreplaced).install(Long.valueOf(packageSummaryResource.getContent().getId()), null)).withRel("install");
packageSummaryResource.add(link);
return packageSummaryResource;
}
19
View Source File : PackageMetadataResourceProcessor.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
@Override
public EnreplacedyModel<PackageMetadata> process(EnreplacedyModel<PackageMetadata> packageMetadataResource) {
Link installLink = linkTo(methodOn(PackageController.clreplaced).install(packageMetadataResource.getContent().getId(), null)).withRel("install");
packageMetadataResource.add(installLink);
return packageMetadataResource;
}
19
View Source File : FeignHalController.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
@GetMapping("/paged")
public CollectionModel<MarsRover> getPaged() {
MarsRover marsRover = new MarsRover();
marsRover.setName("Curiosity");
Link link = new Link("/paged", "self");
PagedModel.PageMetadata metadata = new PagedModel.PageMetadata(1, 1, 1);
return new PagedModel<>(Collections.singleton(marsRover), metadata, link);
}
19
View Source File : FeignHalController.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
@GetMapping("/collection")
public CollectionModel<MarsRover> getCollection() {
MarsRover marsRover = new MarsRover();
marsRover.setName("Opportunity");
Link link = new Link("/collection", "self");
return new CollectionModel<>(Collections.singleton(marsRover), link);
}
19
View Source File : FeignHalController.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
@GetMapping("/enreplacedy")
public EnreplacedyModel<MarsRover> getEnreplacedy() {
MarsRover marsRover = new MarsRover();
marsRover.setName("Sojourner");
Link link = new Link("/enreplacedy", "self");
return new EnreplacedyModel<>(marsRover, link);
}
19
View Source File : RootController.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
// Workaround https://github.com/spring-projects/spring-hateoas/issues/234
private Link unescapeTemplateVariables(Link raw) {
return new Link(raw.getHref().replace("%7B", "{").replace("%7D", "}"), raw.getRel());
}
19
View Source File : RuntimeTemplate.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
/**
* Implementation for {@link RuntimeOperations}.
*
* @author Eric Bottard
* @author Mark Fisher
*/
public clreplaced RuntimeTemplate implements RuntimeOperations {
private final RestTemplate restTemplate;
/**
* Uri template for accessing status of all apps.
*/
private final Link appStatusesUriTemplate;
/**
* Uri template for accessing status of a single app.
*/
private final Link appStatusUriTemplate;
RuntimeTemplate(RestTemplate restTemplate, ResourceSupport resources) {
this.restTemplate = restTemplate;
this.appStatusesUriTemplate = resources.getLink("runtime/apps");
this.appStatusUriTemplate = resources.getLink("runtime/apps/app");
}
@Override
public PagedResources<AppStatusResource> status() {
return restTemplate.getForObject(appStatusesUriTemplate.expand().getHref(), AppStatusResource.Page.clreplaced);
}
@Override
public AppStatusResource status(String deploymentId) {
return restTemplate.getForObject(appStatusUriTemplate.expand(deploymentId).getHref(), AppStatusResource.clreplaced);
}
}
19
View Source File : DataFlowTemplate.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
public Link getLink(ResourceSupport resourceSupport, String rel) {
Link link = resourceSupport.getLink(rel);
if (link == null) {
throw new DataFlowServerException("Server did not return a link for '" + rel + "', links: '" + resourceSupport + "'");
}
return link;
}
19
View Source File : ApplicationTemplate.java
License : Apache License 2.0
Project Creator : spring-cloud
License : Apache License 2.0
Project Creator : spring-cloud
/**
* Implementation for {@link ApplicationOperations}.
*
* @author Janne Valkealahti
*/
public clreplaced ApplicationTemplate implements ApplicationOperations {
public static final String DEFINITIONS_REL = "applications/definitions";
private static final String DEFINITION_REL = "applications/definitions/definition";
private static final String DEPLOYMENTS_REL = "applications/deployments";
private static final String DEPLOYMENT_REL = "applications/deployments/deployment";
private final RestTemplate restTemplate;
private final Link definitionsLink;
private final Link definitionLink;
private final Link deploymentsLink;
private final Link deploymentLink;
ApplicationTemplate(RestTemplate restTemplate, ResourceSupport resources) {
replacedert.notNull(restTemplate, "RestTemplate can't be null");
replacedert.notNull(resources, "URI Resources can't be null");
replacedert.notNull(resources.getLink(DEFINITIONS_REL), "Definitions relation is required");
replacedert.notNull(resources.getLink(DEFINITION_REL), "Definition relation is required");
this.restTemplate = restTemplate;
this.definitionsLink = resources.getLink(DEFINITIONS_REL);
this.definitionLink = resources.getLink(DEFINITION_REL);
this.deploymentsLink = resources.getLink(DEPLOYMENTS_REL);
this.deploymentLink = resources.getLink(DEPLOYMENT_REL);
}
@Override
public PagedResources<ApplicationDefinitionResource> list() {
String uriTemplate = definitionsLink.expand().getHref();
uriTemplate = uriTemplate + "?size=10000";
return restTemplate.getForObject(uriTemplate, ApplicationDefinitionResource.Page.clreplaced);
}
@Override
public ApplicationDefinitionResource createApplication(String name, String definition, boolean deploy) {
MultiValueMap<String, Object> values = new LinkedMultiValueMap<>();
values.add("name", name);
values.add("definition", definition);
values.add("deploy", Boolean.toString(deploy));
ApplicationDefinitionResource stream = restTemplate.postForObject(definitionsLink.expand().getHref(), values, ApplicationDefinitionResource.clreplaced);
return stream;
}
@Override
public void deploy(String name, Map<String, String> properties) {
MultiValueMap<String, Object> values = new LinkedMultiValueMap<>();
values.add("properties", DeploymentPropertiesUtils.format(properties));
restTemplate.postForObject(deploymentLink.expand(name).getHref(), values, Object.clreplaced);
}
@Override
public void undeploy(String name) {
restTemplate.delete(deploymentLink.expand(name).getHref());
}
@Override
public void undeployAll() {
restTemplate.delete(deploymentsLink.getHref());
}
@Override
public void destroy(String name) {
restTemplate.delete(definitionLink.expand(name).getHref());
}
@Override
public void destroyAll() {
restTemplate.delete(definitionsLink.getHref());
}
}
19
View Source File : OrganisationController.java
License : MIT License
Project Creator : Robinyo
License : MIT License
Project Creator : Robinyo
@PatchMapping("/organisations/{id}")
public ResponseEnreplacedy<OrganisationModel> update(@PathVariable("id") final Long id, @RequestBody Organisation organisation) throws ResponseStatusException {
log.info("OrganisationController PATCH /organisations/{id}");
logInfo(organisation, null);
try {
organisation.setId(id);
repository.save(organisation);
Link link = linkTo(methodOn(OrganisationController.clreplaced).findById(id)).withSelfRel();
return ResponseEnreplacedy.noContent().location(new URI(link.getHref())).build();
} catch (Exception e) {
log.error("{}", e.getLocalizedMessage());
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
}
}
19
View Source File : IndividualController.java
License : MIT License
Project Creator : Robinyo
License : MIT License
Project Creator : Robinyo
@PatchMapping("/individuals/{id}")
@PreAuthorize("hasAuthority('SCOPE_individual:patch')")
public ResponseEnreplacedy<IndividualModel> update(@PathVariable("id") final Long id, @RequestBody Individual individual) throws ResponseStatusException {
log.info("IndividualController PATCH /individuals/{id}");
logInfo(individual, null);
try {
individual.setId(id);
repository.save(individual);
Link link = linkTo(methodOn(IndividualController.clreplaced).findById(id)).withSelfRel();
return ResponseEnreplacedy.noContent().location(new URI(link.getHref())).build();
} catch (Exception e) {
log.error("{}", e.getLocalizedMessage());
throw new ResponseStatusException(HttpStatus.BAD_REQUEST);
}
}
19
View Source File : UserAccountController.java
License : MIT License
Project Creator : mariazevedo88
License : MIT License
Project Creator : mariazevedo88
/**
* Method that creates a relationship link to User object
*
* @author Mariana Azevedo
* @since 13/10/2020
*
* @param userTransaction
* @param userTransactionDTO
*/
private void createUserRelLink(UserAccount userTransaction, UserAccountDTO userTransactionDTO) {
Link relUserLink = WebMvcLinkBuilder.linkTo(UserController.clreplaced).slash(userTransaction.getUser().getId()).withRel("user");
userTransactionDTO.add(relUserLink);
}
19
View Source File : UserAccountController.java
License : MIT License
Project Creator : mariazevedo88
License : MIT License
Project Creator : mariazevedo88
/**
* Method that creates a relationship link to User Account object
*
* @author Mariana Azevedo
* @since 13/10/2020
*
* @param userAccount
* @param userAccountDTO
*/
private void createAccountRelLink(UserAccount userAccount, UserAccountDTO userAccountDTO) {
Link relTransactionLink = WebMvcLinkBuilder.linkTo(TravelController.clreplaced).slash(userAccount.getAccount().getId()).withRel("account");
userAccountDTO.add(relTransactionLink);
}
19
View Source File : RoleController.java
License : MIT License
Project Creator : lealceldeiro
License : MIT License
Project Creator : lealceldeiro
/**
* This method is intended to be used by the Spring framework and should not be overridden. Doing so may produce
* unexpected results.
*
* @param id {@link com.gms.domain.security.role.BRole} id.
* @param pageable {@link Pageable} bean injected by spring.
* @param pagereplacedembler {@link PagedResourcesreplacedembler} bean injected by spring.
* @return A {@link ResponseEnreplacedy} of {@link PagedResources} of {@link Resource} of {@link BPermission}
* containing the requested information.
*/
@GetMapping(path = ResourcePath.ROLE + "/{id}/" + ResourcePath.PERMISSION + "s", produces = "application/hal+json")
@ResponseBody
public ResponseEnreplacedy<PagedResources<Resource<BPermission>>> getAllPermissionsByRole(@PathVariable final long id, final Pageable pageable, final PagedResourcesreplacedembler<BPermission> pagereplacedembler) {
Page<BPermission> page = roleService.getAllPermissionsByRoleId(id, pageable);
Link link = linkTo(methodOn(RoleController.clreplaced).getAllPermissionsByRole(id, pageable, pagereplacedembler)).withSelfRel();
PagedResources<Resource<BPermission>> pagedResources = pagereplacedembler.toResource(page, link);
return ResponseEnreplacedy.ok(pagedResources);
}
19
View Source File : BasicEventService.java
License : Apache License 2.0
Project Creator : kbastani
License : Apache License 2.0
Project Creator : kbastani
public <S extends T> Boolean sendAsync(S event, Link... links) {
return eventSource.getChannel().send(MessageBuilder.withPayload(event).setHeader("contentType", MediaType.APPLICATION_JSON_UTF8_VALUE).build());
}
19
View Source File : SettlementController.java
License : Apache License 2.0
Project Creator : interledger4j
License : Apache License 2.0
Project Creator : interledger4j
/**
* <p>Called by the Settlement Engine when it detects an incoming settlement in order to notify this Connector's
* accounting system.</p>
*
* <p>This method allows the Settlement Engine to inform this Connector that money has been received on the
* underlying ledger so that ths Connector can properly update its balances.</p>
*
* <p>Note that the settlement engine MAY accrue incoming settlement acknowledgements without immediately informing
* this Connector.</p>
*
* <p>Caching Note: By setting `Cacheable.sync` to true, this ensures that only one request will be able
* to populate the cache, thus maintaining our idempotence requirements.</p>
*
* @param idempotencyKeyString The idempotence identifier defined in the SE RFC (typed as a {@link String}, but
* should always be a Type4 UUID).
* @param settlementEngineAccountId The {@link SettlementEngineAccountId} as supplied by the settlement engine. Note
* that settlement engines could theoretically store any type of identifier(either
* supplied by the Connector, or created by the engine). Thus, this implementation
* simply uses the settlement engines view of the world (i.e., a {@link
* SettlementEngineAccountId}) for communication.
* @param settlementQuanreplacedy A {@link SettlementQuanreplacedy}, as supplied by the Settlement Engine, that contains
* information about underlying money received for this account inside of the ledger
* that the settlement engine is tracking.
*
* @return A {@link SettlementQuanreplacedy} (in clearing units) that allows the clearing/accounting system indicate the
* amount it acknowledged receipt of so the settlement engine can track the amount leftover (e.g., if the
* accounting system uses a unit of account that is less-precise than the Settlement Engine).
*/
@RequestMapping(path = SLASH_ACCOUNTS + SLASH_SE_ACCOUNT_ID + SLASH_SETTLEMENTS, method = RequestMethod.POST, consumes = { APPLICATION_JSON_VALUE }, produces = { APPLICATION_JSON_VALUE, MediaTypes.PROBLEM_VALUE })
@Cacheable(cacheNames = SETTLEMENT_IDEMPOTENCE, sync = true)
public ResponseEnreplacedy<SettlementQuanreplacedy> creditIncomingSettlement(@RequestHeader(IDEMPOTENCY_KEY) final String idempotencyKeyString, @PathVariable(ACCOUNT_ID) final SettlementEngineAccountId settlementEngineAccountId, @RequestBody final SettlementQuanreplacedy settlementQuanreplacedy) {
this.requireIdempotenceId(idempotencyKeyString);
Objects.requireNonNull(settlementEngineAccountId);
Objects.requireNonNull(settlementQuanreplacedy);
final SettlementQuanreplacedy settledSettlementQuanreplacedy = settlementService.onIncomingSettlementPayment(SETTLEMENT_IDEMPOTENCE + ":" + idempotencyKeyString, settlementEngineAccountId, settlementQuanreplacedy);
final HttpHeaders headers = new HttpHeaders();
final Link selfRel = linkTo(SettlementController.clreplaced).slash(SLASH_ACCOUNTS).slash(settlementEngineAccountId).slash(SLASH_SETTLEMENTS).withSelfRel();
headers.setLocation(URI.create(selfRel.getHref()));
headers.put(IDEMPOTENCY_KEY, Lists.newArrayList(idempotencyKeyString));
headers.setContentType(APPLICATION_JSON);
return new ResponseEnreplacedy<>(settledSettlementQuanreplacedy, headers, HttpStatus.OK);
}
19
View Source File : AccountsController.java
License : Apache License 2.0
Project Creator : interledger4j
License : Apache License 2.0
Project Creator : interledger4j
private EnreplacedyModel<AccountSettings> toEnreplacedyModel(final AccountSettings accountSettings) {
Objects.requireNonNull(accountSettings);
final Link selfLink = linkTo(methodOn(AccountsController.clreplaced).getAccount(accountSettings.accountId())).withSelfRel();
return new EnreplacedyModel(accountSettings, selfLink);
}
19
View Source File : AccountsController.java
License : Apache License 2.0
Project Creator : interledger4j
License : Apache License 2.0
Project Creator : interledger4j
/**
* Create a new Account in this server.
*
* @param accountSettings The {@link AccountSettings} to create in this Connector.
*
* @return An {@link HttpEnreplacedy} that contains a {@link EnreplacedyModel} that contains the created {@link
* AccountSettings}.
*/
@RequestMapping(path = PathConstants.SLASH_ACCOUNTS, method = RequestMethod.POST, consumes = { APPLICATION_JSON_VALUE }, produces = { APPLICATION_JSON_VALUE, MediaTypes.PROBLEM_VALUE })
public HttpEnreplacedy<EnreplacedyModel<AccountSettings>> createAccount(@RequestBody final AccountSettings.AbstractAccountSettings accountSettings) {
Objects.requireNonNull(accountSettings);
final AccountSettings returnableAccountSettings = this.accountManager.createAccount(accountSettings);
final Link selfLink = linkTo(methodOn(AccountsController.clreplaced).getAccount(returnableAccountSettings.accountId())).withSelfRel();
final EnreplacedyModel resource = new EnreplacedyModel(returnableAccountSettings, selfLink);
final HttpHeaders headers = new HttpHeaders();
final Link selfRel = linkTo(AccountsController.clreplaced).slash(accountSettings.accountId().value()).withSelfRel();
headers.setLocation(URI.create(selfRel.getHref()));
return new ResponseEnreplacedy(resource, headers, HttpStatus.CREATED);
}
19
View Source File : WebMvcPersonController.java
License : Apache License 2.0
Project Creator : ingogriebsch
License : Apache License 2.0
Project Creator : ingogriebsch
@GetMapping("/persons/{id}")
public EnreplacedyModel<Person> findOne(@PathVariable Integer id) {
WebMvcPersonController controller = methodOn(WebMvcPersonController.clreplaced);
Link findOneLink = linkTo(controller.findOne(id)).withSelfRel();
Link personsLink = linkTo(controller.findAll()).withRel("persons");
return EnreplacedyModel.of(PERSONS.get(id), //
findOneLink.andAffordance(//
afford(controller.update(id, null))).andAffordance(//
afford(controller.patch(id, null))), personsLink);
}
19
View Source File : WebMvcPersonController.java
License : Apache License 2.0
Project Creator : ingogriebsch
License : Apache License 2.0
Project Creator : ingogriebsch
@GetMapping("/persons")
public CollectionModel<EnreplacedyModel<Person>> findAll() {
WebMvcPersonController controller = methodOn(WebMvcPersonController.clreplaced);
Link selfLink = //
linkTo(controller.findAll()).withSelfRel().andAffordance(//
afford(controller.insert(null))).andAffordance(afford(controller.search(null, null)));
return //
range(0, PERSONS.size()).mapToObj(//
this::findOne).collect(collectingAndThen(toList(), it -> CollectionModel.of(it, selfLink)));
}
19
View Source File : WebMvcPersonController.java
License : Apache License 2.0
Project Creator : ingogriebsch
License : Apache License 2.0
Project Creator : ingogriebsch
@GetMapping("/persons/search")
public CollectionModel<EnreplacedyModel<Person>> search(@RequestParam(value = "name", required = false) String name, @RequestParam(value = "age", required = false) Integer age) {
List<EnreplacedyModel<Person>> persons = new ArrayList<>();
for (int i = 0; i < PERSONS.size(); i++) {
EnreplacedyModel<Person> personModel = findOne(i);
boolean nameMatches = //
Optional.ofNullable(name).map(//
s -> personModel.getContent().getName().contains(s)).orElse(true);
boolean ageMatches = //
Optional.ofNullable(age).map(//
s -> personModel.getContent().getAge().equals(s)).orElse(true);
if (nameMatches && ageMatches) {
persons.add(personModel);
}
}
WebMvcPersonController controller = methodOn(WebMvcPersonController.clreplaced);
Link selfLink = //
linkTo(controller.findAll()).withSelfRel().andAffordance(//
afford(controller.insert(null))).andAffordance(afford(controller.search(null, null)));
return CollectionModel.of(persons, selfLink);
}
19
View Source File : SirenModelBuilder.java
License : Apache License 2.0
Project Creator : ingogriebsch
License : Apache License 2.0
Project Creator : ingogriebsch
/**
* Adds the given {@literal link} to the {@link RepresentationModel} to be built.
*
* @param link must not be {@literal null}.
* @return the current {@link SirenModelBuilder} instance.
* @see <a href="https://github.com/kevinswiber/siren#links-1" target="_blank">Siren Link</a>
* @see <a href="https://github.com/kevinswiber/siren#actions-1" target="_blank">Siren Action</a>
*/
public SirenModelBuilder linksAndActions(@NonNull Link link) {
return linksAndActions(of(link));
}
19
View Source File : SirenModelBuilder.java
License : Apache License 2.0
Project Creator : ingogriebsch
License : Apache License 2.0
Project Creator : ingogriebsch
/**
* Adds the given {@literal links} to the {@link RepresentationModel} to be built.
*
* @param links must not be {@literal null} and must not contain {@literal null} values.
* @return the current {@link SirenModelBuilder} instance.
* @see <a href="https://github.com/kevinswiber/siren#links-1" target="_blank">Siren Link</a>
* @see <a href="https://github.com/kevinswiber/siren#actions-1" target="_blank">Siren Action</a>
*/
public SirenModelBuilder linksAndActions(@NonNull Link... links) {
return linksAndActions(of(links));
}
19
View Source File : SirenLinkConverter.java
License : Apache License 2.0
Project Creator : ingogriebsch
License : Apache License 2.0
Project Creator : ingogriebsch
private List<SirenAction> actions(Link link) {
List<SirenAction> result = newArrayList();
for (SirenAffordanceModel model : affordanceModels(link)) {
if (!GET.equals(model.getHttpMethod())) {
result.add(action(model));
}
}
return result;
}
19
View Source File : SirenLinkConverter.java
License : Apache License 2.0
Project Creator : ingogriebsch
License : Apache License 2.0
Project Creator : ingogriebsch
private static List<SirenAffordanceModel> affordanceModels(Link link) {
return link.getAffordances().stream().map(a -> a.getAffordanceModel(SIREN_JSON)).map(SirenAffordanceModel.clreplaced::cast).collect(toList());
}
19
View Source File : SirenLinkConverter.java
License : Apache License 2.0
Project Creator : ingogriebsch
License : Apache License 2.0
Project Creator : ingogriebsch
private String replacedle(Link link) {
String replacedle = link.getreplacedle();
if (replacedle != null) {
return replacedle;
}
LinkRelation rel = link.getRel();
if (rel != null) {
return replacedle(SirenLink.replacedleResolvable.of(link.getRel()));
}
return null;
}
19
View Source File : SirenLinkConverter.java
License : Apache License 2.0
Project Creator : ingogriebsch
License : Apache License 2.0
Project Creator : ingogriebsch
SirenNavigables convert(Link link) {
return SirenNavigables.of(links(link), actions(link));
}
19
View Source File : SirenLinkConverter.java
License : Apache License 2.0
Project Creator : ingogriebsch
License : Apache License 2.0
Project Creator : ingogriebsch
private List<SirenLink> links(Link link) {
SirenLink sirenLink = //
SirenLink.builder().rel(//
link.getRel().value()).href(//
link.getHref()).replacedle(//
replacedle(link)).type(//
link.getType()).build();
return newArrayList(sirenLink);
}
19
View Source File : Person.java
License : Apache License 2.0
Project Creator : enr1c091
License : Apache License 2.0
Project Creator : enr1c091
public Person withLink(Link link) {
this.add(link);
return this;
}
19
View Source File : House.java
License : Apache License 2.0
Project Creator : enr1c091
License : Apache License 2.0
Project Creator : enr1c091
public House withLink(Link link) {
this.add(link);
return this;
}
19
View Source File : PageResourceAssembler.java
License : MIT License
Project Creator : cloudogu
License : MIT License
Project Creator : cloudogu
public PageResource toCommitFixedResource(Page page) {
PageResource resource = new PageResource(page.getPath().getValue(), page.getContent().getValue(), createCommitResource(page.getCommit()));
Link linkToPage = selfLink(page);
String href = linkToPage.getHref() + "?commit=" + page.getCommit().get().getId().get().getValue();
Link linkToPageCommitFixed = new Link(href, linkToPage.getRel());
resource.add(linkToPageCommitFixed);
resource.add(restoreLink(page));
return resource;
}
19
View Source File : HistoryResourceAssembler.java
License : MIT License
Project Creator : cloudogu
License : MIT License
Project Creator : cloudogu
private Link linkToPageAtCommit(History history, Commit commit) {
Link pageLink = pageLink(history).withRel("page");
String href = pageLink.getHref() + "?commit=" + commit.getId().get().getValue();
return new Link(href, pageLink.getRel());
}
19
View Source File : MethodLinkUriResolver.java
License : Apache License 2.0
Project Creator : BlackPepperSoftware
License : Apache License 2.0
Project Creator : BlackPepperSoftware
URI resolveForMethod(EnreplacedyModel<?> resource, String linkName, Object[] args) {
Link link = resource.getLink(linkName).orElseThrow(() -> new NoSuchLinkException(linkName));
return URI.create(link.expand(args).getHref());
}
19
View Source File : TaskVariablesResourceAssemblerTest.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Test
public void toResourceShouldReturnResourceWithSelfLinkContainingResourceId() {
// given
VariableInstance model = new VariableInstanceImpl<>("var", "string", "value", "procInstId");
((VariableInstanceImpl) model).setTaskId("my-identifier");
given(converter.from(model)).willReturn(new CloudVariableInstanceImpl<>(model));
// when
Resource<CloudVariableInstance> resource = resourcereplacedembler.toResource(model);
// then
Link globalVariablesLink = resource.getLink("variables");
replacedertThat(globalVariablesLink).isNotNull();
replacedertThat(globalVariablesLink.getHref()).contains("my-identifier");
}
19
View Source File : TaskResourceAssemblerTest.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Test
public void toResourceShouldReturnResourceWithSelfLinkContainingResourceId() {
Task model = new TaskImpl("my-identifier", "myTask", CREATED);
given(converter.from(model)).willReturn(new CloudTaskImpl(model));
Resource<CloudTask> resource = resourcereplacedembler.toResource(model);
Link selfResourceLink = resource.getLink("self");
replacedertThat(selfResourceLink).isNotNull();
replacedertThat(selfResourceLink.getHref()).contains("my-identifier");
}
19
View Source File : ProcessInstanceVariablesResourceAssemblerTest.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Test
public void toResourceShouldReturnResourceWithSelfLinkContainingResourceId() {
// given
VariableInstance model = new VariableInstanceImpl<>("var", "string", "value", "my-identifier");
given(converter.from(model)).willReturn(new CloudVariableInstanceImpl<>(model));
// when
Resource<CloudVariableInstance> resource = resourcereplacedembler.toResource(model);
// then
Link processVariablesLink = resource.getLink("processVariables");
replacedertThat(processVariablesLink).isNotNull();
replacedertThat(processVariablesLink.getHref()).contains("my-identifier");
}
19
View Source File : ProcessDefinitionMetaResourceAssemblerTest.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Test
public void toResourceShouldReturnResourceWithSelfLinkContainingResourceId() {
ProcessDefinitionMeta model = mock(ProcessDefinitionMeta.clreplaced);
when(model.getId()).thenReturn("my-identifier");
Resource<ProcessDefinitionMeta> resource = resourcereplacedembler.toResource(model);
Link selfResourceLink = resource.getLink("self");
replacedertThat(selfResourceLink).isNotNull();
replacedertThat(selfResourceLink.getHref()).contains("my-identifier");
Link metaResourceLink = resource.getLink("meta");
replacedertThat(metaResourceLink).isNotNull();
replacedertThat(metaResourceLink.getHref()).contains("my-identifier");
}
19
View Source File : TaskVariableInstanceResourceAssembler.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
@Override
public Resource<CloudVariableInstance> toResource(VariableInstance taskVariable) {
CloudVariableInstance cloudVariableInstance = converter.from(taskVariable);
Link globalVariables = linkTo(methodOn(TaskVariableControllerImpl.clreplaced).getVariables(cloudVariableInstance.getTaskId())).withRel("variables");
Link taskRel = linkTo(methodOn(TaskControllerImpl.clreplaced).getTaskById(cloudVariableInstance.getTaskId())).withRel("task");
Link homeLink = linkTo(HomeControllerImpl.clreplaced).withRel("home");
return new Resource<>(cloudVariableInstance, globalVariables, taskRel, homeLink);
}
19
View Source File : ResourcesAssembler.java
License : Apache License 2.0
Project Creator : Activiti
License : Apache License 2.0
Project Creator : Activiti
public <T, D extends ResourceSupport> Resources<D> toResources(List<T> enreplacedies, Resourcereplacedembler<T, D> resourcereplacedembler, Link... links) {
return new Resources<>(enreplacedies.stream().map(resourcereplacedembler::toResource).collect(Collectors.toList()), links);
}
See More Examples