org.springframework.hateoas.ResourceSupport Java Examples

The following examples show how to use org.springframework.hateoas.ResourceSupport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModuleRegistry.java    From moserp with Apache License 2.0 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example #2
Source File: AccountController.java    From service-block-samples with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: ProjectController.java    From service-block-samples with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: PageLinksAspect.java    From Showcase with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #5
Source File: RootController.java    From spring-cloud-dashboard with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: ConfigCommandTests.java    From spring-cloud-dashboard with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	MockitoAnnotations.initMocks(this);

	final CommandLine commandLine = Mockito.mock(CommandLine.class);

	when(commandLine.getArgs()).thenReturn(null);

	final List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
	messageConverters.add(new  MappingJackson2HttpMessageConverter());

	when(restTemplate.getMessageConverters()).thenReturn(messageConverters);
	final Exception e = new RestClientException("FooBar");
	when(restTemplate.getForObject(Mockito.any(URI.class), Mockito.eq(ResourceSupport.class))).thenThrow(e);

	configCommands.setTargetHolder(new TargetHolder());
	configCommands.setRestTemplate(restTemplate);
	configCommands.setDataFlowShell(dataFlowShell);
	configCommands.setServerUri("http://localhost:9393");
	configCommands.onApplicationEvent(null);
}
 
Example #7
Source File: DataFlowTemplate.java    From spring-cloud-dashboard with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example #8
Source File: ApplicationTemplate.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
ApplicationTemplate(RestTemplate restTemplate, ResourceSupport resources) {
	Assert.notNull(restTemplate, "RestTemplate can't be null");
	Assert.notNull(resources, "URI Resources can't be null");
	Assert.notNull(resources.getLink(DEFINITIONS_REL), "Definitions relation is required");
	Assert.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);
}
 
Example #9
Source File: DataFlowTemplate.java    From spring-cloud-dashboard with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #10
Source File: RestTmplApplicationTests.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
private MappingJackson2HttpMessageConverter getHalMessageConverter() {
	ObjectMapper objectMapper = new ObjectMapper();
	objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	objectMapper.registerModule(new Jackson2HalModule());
	MappingJackson2HttpMessageConverter halConverter = new TypeConstrainedMappingJackson2HttpMessageConverter(
			ResourceSupport.class);
	halConverter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
	halConverter.setObjectMapper(objectMapper);
	return halConverter;
}
 
Example #11
Source File: RestTmplApplicationTests.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
private MappingJackson2HttpMessageConverter getHalMessageConverter() {
	ObjectMapper objectMapper = new ObjectMapper();
	objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
	objectMapper.registerModule(new Jackson2HalModule());
	MappingJackson2HttpMessageConverter halConverter = new TypeConstrainedMappingJackson2HttpMessageConverter(
			ResourceSupport.class);
	halConverter.setSupportedMediaTypes(Arrays.asList(MediaTypes.HAL_JSON));
	halConverter.setObjectMapper(objectMapper);
	return halConverter;
}
 
Example #12
Source File: RuntimeTemplate.java    From spring-cloud-dashboard with Apache License 2.0 4 votes vote down vote up
RuntimeTemplate(RestTemplate restTemplate, ResourceSupport resources) {
	this.restTemplate = restTemplate;
	this.appStatusesUriTemplate = resources.getLink("runtime/apps");
	this.appStatusUriTemplate = resources.getLink("runtime/apps/app");
}
 
Example #13
Source File: TagsController.java    From restdocs-raml with MIT License 4 votes vote down vote up
@RequestMapping(value = "/{id}/notes", method = RequestMethod.GET)
ResourceSupport tagNotes(@PathVariable("id") long id) {
	Tag tag = findTagById(id);
	return new Resources<>(
			this.noteResourceAssembler.toResources(tag.getNotes()));
}
 
Example #14
Source File: NotesController.java    From restdocs-raml with MIT License 4 votes vote down vote up
@RequestMapping(value = "/{id}/tags", method = RequestMethod.GET)
ResourceSupport noteTags(@PathVariable("id") long id) {
	return new Resources<>(
			this.tagResourceAssembler.toResources(findNoteById(id).getTags()));
}
 
Example #15
Source File: NotesController.java    From restdocs-wiremock with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/{id}/tags", method = RequestMethod.GET)
ResourceSupport noteTags(@PathVariable("id") UUID id) {
	return new NestedContentResource<TagResource>(
			this.tagResourceAssembler.toResources(findNoteById(id).getTags()));
}
 
Example #16
Source File: TagsController.java    From restdocs-wiremock with Apache License 2.0 4 votes vote down vote up
@RequestMapping(value = "/{id}/notes", method = RequestMethod.GET)
ResourceSupport tagNotes(@PathVariable("id") long id) {
	Tag tag = findTagById(id);
	return new NestedContentResource<NoteResource>(
			this.noteResourceAssembler.toResources(tag.getNotes()));
}
 
Example #17
Source File: AppRegistryTemplate.java    From spring-cloud-dashboard with Apache License 2.0 2 votes vote down vote up
/**
 * Construct a {@code AppRegistryTemplate} object.
 *
 * @param restTemplate template for HTTP/rest commands
 * @param resourceSupport HATEOAS link support
 */
public AppRegistryTemplate(RestTemplate restTemplate, ResourceSupport resourceSupport) {
	this.restTemplate = restTemplate;
	this.uriTemplate = new UriTemplate(resourceSupport.getLink("apps").getHref());
}