本文整理匯總了Java中org.springframework.hateoas.ResourceSupport類的典型用法代碼示例。如果您正苦於以下問題:Java ResourceSupport類的具體用法?Java ResourceSupport怎麽用?Java ResourceSupport使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ResourceSupport類屬於org.springframework.hateoas包,在下文中一共展示了ResourceSupport類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getStatusIndex
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
@RequestMapping(
value = {"/status/", "/status"},
method = RequestMethod.GET,
produces = "application/hal+json"
)
@ApiOperation(
value = "Hypermedia endpoint to get all supported Status operations",
notes = "Status operations are based on Spring Boot Actuator",
produces = "application/hal+json",
response = ResourceSupport.class
)
public ResourceSupport getStatusIndex(HttpServletRequest request) throws Exception {
String baseURL = request.getRequestURL().toString()
.replace("/api/status", "").replace("/api/status/", "");
ResourceSupport support = new HiddenResourceSupport();
support.add(new Link(baseURL + actuatorHealthPath, "health"));
support.add(new Link(baseURL + actuatorMetricsPath, "metrics"));
if (actuatorMappingsActive)
support.add(new Link(baseURL + actuatorMappingsPath, "mappings"));
support.add(linkTo(methodOn(CommonController.class).getStatusIndex(null)).withSelfRel());
return support;
}
示例2: getIndex
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
@RequestMapping(
value = {"/", ""},
method = RequestMethod.GET,
produces = "application/hal+json"
)
@ApiOperation(
value = "Hypermedia endpoint to get all resource endpoints",
notes = "The retuned links to the endpoints are: Csars, platforms and status",
produces = "application/hal+json",
response = ResourceSupport.class
)
public ResourceSupport getIndex() throws Exception {
ResourceSupport support = new HiddenResourceSupport();
support.add(linkTo(methodOn(CommonController.class).getIndex()).withSelfRel());
support.add(linkTo(methodOn(CommonController.class).getStatusIndex(null)).withRel("status"));
support.add(linkTo(methodOn(PlatformController.class).getPlatforms()).withRel("platforms"));
support.add(linkTo(methodOn(CsarController.class).listCSARs()).withRel("csars"));
return support;
}
示例3: getCommandsResource
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
private ResourceSupport getCommandsResource(Long id) {
Account account = new Account();
account.setIdentity(id);
CommandResources commandResources = new CommandResources();
// Add activate command link
commandResources.add(linkTo(AccountController.class)
.slash("accounts")
.slash(id)
.slash("commands")
.slash("activate")
.withRel("activate"));
// Add suspend command link
commandResources.add(linkTo(AccountController.class)
.slash("accounts")
.slash(id)
.slash("commands")
.slash("suspend")
.withRel("suspend"));
return new Resource<>(commandResources);
}
示例4: getCommandsResource
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
private ResourceSupport getCommandsResource(Long id) {
Project project = new Project();
project.setIdentity(id);
CommandResources commandResources = new CommandResources();
// Add suspend command link
commandResources.add(linkTo(ProjectController.class)
.slash("projects")
.slash(id)
.slash("commands")
.slash("commit")
.withRel("commit"));
return new Resource<>(commandResources);
}
示例5: DataFlowTemplate
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
/**
* Setup a {@link DataFlowTemplate} using the provide {@link RestTemplate}. Any missing Mixins for Jackson will be
* added implicitly. For more information, please see {@link #prepareRestTemplate(RestTemplate)}.
*
* @param baseURI Must not be null
* @param restTemplate Must not be null
*/
public DataFlowTemplate(URI baseURI, RestTemplate restTemplate) {
Assert.notNull(baseURI, "The provided baseURI must not be null.");
Assert.notNull(restTemplate, "The provided restTemplate must not be null.");
this.restTemplate = prepareRestTemplate(restTemplate);
final ResourceSupport resourceSupport = restTemplate.getForObject(baseURI, ResourceSupport.class);
this.runtimeOperations = new RuntimeTemplate(restTemplate, resourceSupport);
this.appRegistryOperations = new AppRegistryTemplate(restTemplate, resourceSupport);
this.completionOperations = new CompletionTemplate(restTemplate,
resourceSupport.getLink("completions/stream"),
resourceSupport.getLink("completions/task"));
if (resourceSupport.hasLink(ApplicationTemplate.DEFINITIONS_REL)) {
this.applicationOperations = new ApplicationTemplate(restTemplate, resourceSupport);
}
else {
this.applicationOperations = null;
}
}
示例6: info
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
/**
* Return a {@link ResourceSupport} object containing the resources
* served by the Data Flow server.
*
* @return {@code ResourceSupport} object containing the Data Flow server's resources
*/
@RequestMapping("/")
public ResourceSupport info() {
ResourceSupport resourceSupport = new ResourceSupport();
resourceSupport.add(new Link(dashboard(""), "dashboard"));
resourceSupport.add(entityLinks.linkToCollectionResource(AppRegistrationResource.class).withRel("apps"));
resourceSupport.add(entityLinks.linkToCollectionResource(AppStatusResource.class).withRel("runtime/apps"));
resourceSupport.add(unescapeTemplateVariables(entityLinks.linkForSingleResource(AppStatusResource.class, "{appId}").withRel("runtime/apps/app")));
resourceSupport.add(unescapeTemplateVariables(entityLinks.linkFor(AppInstanceStatusResource.class, UriComponents.UriTemplateVariables.SKIP_VALUE).withRel("runtime/apps/instances")));
resourceSupport.add(entityLinks.linkToCollectionResource(ApplicationDefinitionResource.class).withRel("applications/definitions"));
resourceSupport.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(ApplicationDefinitionResource.class, "{name}").withRel("applications/definitions/definition")));
resourceSupport.add(entityLinks.linkToCollectionResource(ApplicationDeploymentResource.class).withRel("applications/deployments"));
resourceSupport.add(unescapeTemplateVariables(entityLinks.linkToSingleResource(ApplicationDeploymentResource.class, "{name}").withRel("applications/deployments/deployment")));
String completionStreamTemplated = entityLinks.linkFor(CompletionProposalsResource.class).withSelfRel().getHref() + ("/stream{?start,detailLevel}");
resourceSupport.add(new Link(completionStreamTemplated).withRel("completions/stream"));
String completionTaskTemplated = entityLinks.linkFor(CompletionProposalsResource.class).withSelfRel().getHref() + ("/task{?start,detailLevel}");
resourceSupport.add(new Link(completionTaskTemplated).withRel("completions/task"));
return resourceSupport;
}
示例7: execution
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
@Around("@annotation(org.educama.common.api.resource.PageLinks) && execution(org.springframework.hateoas.ResourceSupport+ *(..)) && args(page, ..)")
public Object pageLinksAdvice(ProceedingJoinPoint joinPoint, Page<?> page) throws Throwable {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
PageLinks pageLinks = method.getAnnotation(PageLinks.class);
Class<?> controller = pageLinks.value();
UriComponentsBuilder original = originalUri(controller, request);
ResourceSupport resourceSupport = (ResourceSupport) joinPoint.proceed();
if (page.hasNext()) {
UriComponentsBuilder nextBuilder = replacePageParams(original, page.nextPageable());
resourceSupport.add(new Link(nextBuilder.toUriString()).withRel("next"));
}
if (page.hasPrevious()) {
UriComponentsBuilder prevBuilder = replacePageParams(original, page.previousPageable());
resourceSupport.add(new Link(prevBuilder.toUriString()).withRel("prev"));
}
return resourceSupport;
}
示例8: serialize
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
@Override
public void serialize(Collection<?> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonGenerationException {
Map<String, Object> embeddeds = embeddedMapper.map(value);
Object currentValue = jgen.getCurrentValue();
if (currentValue instanceof ResourceSupport) {
if (embeddedMapper.hasCuriedEmbed(value)) {
((ResourceSupport) currentValue).add(CURIES_REQUIRED_DUE_TO_EMBEDS);
}
}
provider.findValueSerializer(Map.class, property).serialize(embeddeds, jgen, provider);
}
示例9: JobTemplate
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
JobTemplate(RestTemplate restTemplate, ResourceSupport resources) {
Assert.notNull(resources, "URI Resources must not be be null");
Assert.notNull(restTemplate, "RestTemplate must not be null");
Assert.notNull(resources.getLink(EXECUTIONS_RELATION), "Executions relation is required");
Assert.notNull(resources.getLink(EXECUTION_RELATION), "Execution relation is required");
Assert.notNull(resources.getLink(EXECUTION_RELATION_BY_NAME), "Execution by name relation is required");
Assert.notNull(resources.getLink(INSTANCE_RELATION), "Instance relation is required");
Assert.notNull(resources.getLink(INSTANCE_RELATION_BY_NAME), "Instance by name relation is required");
Assert.notNull(resources.getLink(STEP_EXECUTION_RELATION_BY_ID), "Step Execution by id relation is required");
Assert.notNull(resources.getLink(STEP_EXECUTION_PROGRESS_RELATION_BY_ID),
"Step Execution Progress by id " + "relation is required");
Assert.notNull(resources.getLink(STEP_EXECUTION_PROGRESS_RELATION_BY_ID),
"Step Execution View by id relation" + " is required");
this.restTemplate = restTemplate;
this.executionsLink = resources.getLink(EXECUTIONS_RELATION);
this.executionLink = resources.getLink(EXECUTION_RELATION);
this.executionByNameLink = resources.getLink(EXECUTION_RELATION_BY_NAME);
this.instanceLink = resources.getLink(INSTANCE_RELATION);
this.instanceByNameLink = resources.getLink(INSTANCE_RELATION_BY_NAME);
this.stepExecutionsLink = resources.getLink(STEP_EXECUTION_RELATION_BY_ID);
this.stepExecutionProgressLink = resources.getLink(STEP_EXECUTION_PROGRESS_RELATION_BY_ID);
this.stepExecutionLink = resources.getLink(STEP_EXECUTION_PROGRESS_RELATION_BY_ID);
}
示例10: TaskTemplate
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
TaskTemplate(RestTemplate restTemplate, ResourceSupport resources) {
Assert.notNull(resources, "URI Resources must not be be null");
Assert.notNull(resources.getLink(EXECUTIONS_RELATION), "Executions relation is required");
Assert.notNull(resources.getLink(DEFINITIONS_RELATION), "Definitions relation is required");
Assert.notNull(resources.getLink(DEFINITION_RELATION), "Definition relation is required");
Assert.notNull(restTemplate, "RestTemplate must not be null");
Assert.notNull(resources.getLink(EXECUTIONS_RELATION), "Executions relation is required");
Assert.notNull(resources.getLink(EXECUTION_RELATION), "Execution relation is required");
Assert.notNull(resources.getLink(EXECUTION_RELATION_BY_NAME), "Execution by name relation is required");
this.restTemplate = restTemplate;
this.definitionsLink = resources.getLink(DEFINITIONS_RELATION);
this.definitionLink = resources.getLink(DEFINITION_RELATION);
this.executionsLink = resources.getLink(EXECUTIONS_RELATION);
this.executionLink = resources.getLink(EXECUTION_RELATION);
this.executionByNameLink = resources.getLink(EXECUTION_RELATION_BY_NAME);
}
示例11: loadResources
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
public void loadResources() {
for (String serviceId : discoveryClient.getServices()) {
log.debug("Analyzing service " + serviceId);
if(!serviceId.endsWith(MODULE_POST_FIX)) {
continue;
}
URI uri = getInstanceUri(serviceId);
if (uri == null) {
continue;
}
ParameterizedTypeReference<Map<String, ResourceSupport>> typeReference = new ParameterizedTypeReference<Map<String, ResourceSupport>>() {
};
String url = uri.toString() + "/structure";
ResponseEntity<Map<String, ResourceSupport>> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, typeReference);
Map<String, ResourceSupport> groupMap = responseEntity.getBody();
for (String group : groupMap.keySet()) {
ResourceSupport support = groupMap.get(group);
for (Link link : support.getLinks()) {
resourceToModuleMap.put(link.getRel(), serviceId);
}
}
}
}
示例12: toResource
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
@Override
public ResourceSupport toResource(Agent entity) {
// add link to itself ( rel = self )
Link selfLink = linkTo(methodOn(AgentRestEndpoint.class).getAgent(entity.getPrimaryKey().toString(), false)).withSelfRel();
entity.add(selfLink);
if( entity.getProperties() != null ){
entity.getProperties().forEach(p -> this.propertyResourceAssembler.toResource(p));
}
if( entity.getLeads() != null ){
entity.getLeads().forEach( l -> this.leadResourceAssembler.toResource(l) );
}
return entity;
}
示例13: getPropertiesByPage
import org.springframework.hateoas.ResourceSupport; //導入依賴的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);
}
示例14: toResource
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
@Override
public ResourceSupport toResource(Agent entity) {
// add link to itself ( rel = self )
// TODO: get the endpoint url that GET a property from micro-service CRUD. (using eureka). For now just hardcode the domain.
// add link to itself ( rel = self )
Link selfLink = linkTo( methodOn(AgentRestEndpoint.class).getAgent(entity.getPrimaryKey())).withSelfRel();
entity.add(selfLink);
Link propertiesLink = linkTo(
methodOn(AgentRestEndpoint.class).getAgentProperties(entity.getPrimaryKey().toString(), null, null)
).withRel( "properties" );
entity.add(propertiesLink);
if (entity.getProperties() != null) {
entity.getProperties().forEach(p -> this.propertyResourceAssembler.toResource(p));
}
if (entity.getLeads() != null) {
entity.getLeads().forEach(l -> this.leadResourceAssember.toResource(l));
}
return entity;
}
示例15: toResources_with_array_should_return_a_array
import org.springframework.hateoas.ResourceSupport; //導入依賴的package包/類
@Test
public void toResources_with_array_should_return_a_array() {
List<Range> list = new ArrayList<>();
Range range = new Range();
range.setId(1L);
range.setDescription("Test description");
range.setInfraId(1);
range.setZoneId(1L);
range.setSize(65535L);
range.setIp(0xC0A80001L);
list.add(range);
list.add(range);
list.add(range);
List<RangeResource> resources = this.assembler.toResources(list);
Assert.assertNotNull(resources);
Assert.assertEquals(list.size(), resources.size());
Assert.assertTrue(ResourceSupport.class.isAssignableFrom(resources.get(0).getClass()));
}