org.springframework.hateoas.RepresentationModel Java Examples
The following examples show how to use
org.springframework.hateoas.RepresentationModel.
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: StreamTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
StreamTemplate(RestTemplate restTemplate, RepresentationModel<?> resources, String dataFlowServerVersion) { Assert.notNull(resources, "URI CollectionModel can't be null"); Assert.notNull(resources.getLink(DEFINITIONS_REL), "Definitions relation is required"); Assert.notNull(resources.getLink(DEFINITION_REL), "Definition relation is required"); Assert.notNull(resources.getLink(DEPLOYMENTS_REL), "Deployments relation is required"); Assert.notNull(resources.getLink(DEPLOYMENT_REL), "Deployment relation is required"); if (VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion( VersionUtils.getThreePartVersion(dataFlowServerVersion), VALIDATION_RELATION_VERSION)) { Assert.notNull(resources.getLink(VALIDATION_REL), "Validation relation for streams is required"); } this.dataFlowServerVersion = dataFlowServerVersion; this.restTemplate = restTemplate; this.definitionsLink = resources.getLink(DEFINITIONS_REL).get(); this.deploymentsLink = resources.getLink(DEPLOYMENTS_REL).get(); this.definitionLink = resources.getLink(DEFINITION_REL).get(); this.deploymentLink = resources.getLink(DEPLOYMENT_REL).get(); this.validationLink = resources.getLink(VALIDATION_REL).get(); }
Example #2
Source File: JobTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
JobTemplate(RestTemplate restTemplate, RepresentationModel<?> resources) { Assert.notNull(resources, "URI CollectionModel 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).get(); this.executionLink = resources.getLink(EXECUTION_RELATION).get(); this.executionByNameLink = resources.getLink(EXECUTION_RELATION_BY_NAME).get(); this.instanceLink = resources.getLink(INSTANCE_RELATION).get(); this.instanceByNameLink = resources.getLink(INSTANCE_RELATION_BY_NAME).get(); this.stepExecutionsLink = resources.getLink(STEP_EXECUTION_RELATION_BY_ID).get(); this.stepExecutionProgressLink = resources.getLink(STEP_EXECUTION_PROGRESS_RELATION_BY_ID).get(); }
Example #3
Source File: SpringDocHateoasConfiguration.java From springdoc-openapi with Apache License 2.0 | 6 votes |
/** * Registers an OpenApiCustomiser and a jackson mixin to ensure the definition of `Links` matches the serialized * output. This is done because the customer serializer converts the data to a map before serializing it. * * @param halProvider the hal provider * @return the open api customiser * @see org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalLinkListSerializer#serialize(Links, JsonGenerator, SerializerProvider) org.springframework.hateoas.mediatype.hal.Jackson2HalModule.HalLinkListSerializer#serialize(Links, JsonGenerator, SerializerProvider) */ @Bean @ConditionalOnMissingBean @Lazy(false) OpenApiCustomiser linksSchemaCustomiser(HateoasHalProvider halProvider) { if (!halProvider.isHalEnabled()) { return openApi -> { }; } Json.mapper().addMixIn(RepresentationModel.class, RepresentationModelLinksOASMixin.class); ResolvedSchema resolvedLinkSchema = ModelConverters.getInstance() .resolveAsResolvedSchema(new AnnotatedType(Link.class)); return openApi -> openApi .schema("Link", resolvedLinkSchema.schema) .schema("Links", new MapSchema() .additionalProperties(new StringSchema()) .additionalProperties(new ObjectSchema().$ref(AnnotationsUtils.COMPONENTS_REF +"Link"))); }
Example #4
Source File: EmployeeController.java From spring-hateoas-examples with Apache License 2.0 | 5 votes |
@GetMapping("/") public RepresentationModel root() { RepresentationModel rootResource = new RepresentationModel(); rootResource.add( // linkTo(methodOn(EmployeeController.class).root()).withSelfRel(), // linkTo(methodOn(EmployeeController.class).findAll()).withRel("employees")); return rootResource; }
Example #5
Source File: TaskTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
TaskTemplate(RestTemplate restTemplate, RepresentationModel<?> resources, String dataFlowServerVersion) { Assert.notNull(resources, "URI CollectionModel 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"); Assert.notNull(dataFlowServerVersion, "dataFlowVersion must not be null"); Assert.notNull(resources.getLink(RETRIEVE_LOG), "Log relation is required"); this.dataFlowServerVersion = dataFlowServerVersion; if (VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion( VersionUtils.getThreePartVersion(dataFlowServerVersion), VALIDATION_RELATION_VERSION)) { Assert.notNull(resources.getLink(VALIDATION_REL), "Validiation relation for tasks is required"); } if (VersionUtils.isDataFlowServerVersionGreaterThanOrEqualToRequiredVersion( VersionUtils.getThreePartVersion(dataFlowServerVersion), EXECUTIONS_CURRENT_RELATION_VERSION)) { Assert.notNull(resources.getLink(EXECUTIONS_CURRENT_RELATION), "Executions current relation is required"); } this.restTemplate = restTemplate; this.definitionsLink = resources.getLink(DEFINITIONS_RELATION).get(); this.definitionLink = resources.getLink(DEFINITION_RELATION).get(); this.executionsLink = resources.getLink(EXECUTIONS_RELATION).get(); this.executionLink = resources.getLink(EXECUTION_RELATION).get(); this.executionByNameLink = resources.getLink(EXECUTION_RELATION_BY_NAME).get(); this.executionsCurrentLink = resources.getLink(EXECUTIONS_CURRENT_RELATION).get(); this.validationLink = resources.getLink(VALIDATION_REL).get(); this.platformListLink = resources.getLink(PLATFORM_LIST_RELATION).get(); this.retrieveLogLink = resources.getLink(RETRIEVE_LOG).get(); }
Example #6
Source File: SchedulerTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
SchedulerTemplate(RestTemplate restTemplate, RepresentationModel<?> resources) { Assert.notNull(resources, "URI CollectionModel must not be be null"); Assert.notNull(resources.getLink(SCHEDULES_RELATION), "Schedules relation is required"); Assert.notNull(resources.getLink(SCHEDULES_INSTANCE_RELATION), "Schedules instance relation is required"); Assert.notNull(restTemplate, "RestTemplate must not be null"); this.restTemplate = restTemplate; this.schedulesLink = resources.getLink(SCHEDULES_RELATION).get(); this.schedulesInstanceLink = resources.getLink(SCHEDULES_INSTANCE_RELATION).get(); }
Example #7
Source File: DataFlowTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
public Link getLink(RepresentationModel<?> resourceSupport, String rel) { Link link = resourceSupport.getLink(rel).get(); if (link == null) { throw new DataFlowServerException( "Server did not return a link for '" + rel + "', links: '" + resourceSupport + "'"); } return link; }
Example #8
Source File: AppRegistryTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
/** * Construct a {@code AppRegistryTemplate} object. * * @param restTemplate template for HTTP/rest commands * @param resourceSupport HATEOAS link support */ public AppRegistryTemplate(RestTemplate restTemplate, RepresentationModel<?> resourceSupport) { Assert.notNull(resourceSupport, "URI CollectionModel can't be null"); Assert.notNull(resourceSupport.getLink(APPS_REL), "Apps relation is required"); this.restTemplate = restTemplate; this.appsLink = resourceSupport.getLink(APPS_REL).get(); }
Example #9
Source File: ResourceDeserializer.java From bowman with Apache License 2.0 | 5 votes |
@Override public EntityModel<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { ObjectNode node = p.readValueAs(ObjectNode.class); ObjectMapper mapper = (ObjectMapper) p.getCodec(); RepresentationModel resource = mapper.convertValue(node, RepresentationModel.class); Links links = Links.of(resource.getLinks()); Object content = mapper.convertValue(node, getResourceDeserializationType(links)); return new EntityModel<>(content, links); }
Example #10
Source File: EmployeeController.java From spring-hateoas-examples with Apache License 2.0 | 5 votes |
@GetMapping("/") public RepresentationModel root() { RepresentationModel rootResource = new RepresentationModel(); rootResource.add( // linkTo(methodOn(EmployeeController.class).root()).withSelfRel(), // linkTo(methodOn(EmployeeController.class).findAll()).withRel("employees")); return rootResource; }
Example #11
Source File: RootController.java From spring-hateoas-examples with Apache License 2.0 | 5 votes |
@GetMapping("/") ResponseEntity<RepresentationModel> root() { RepresentationModel model = new RepresentationModel(); model.add(linkTo(methodOn(RootController.class).root()).withSelfRel()); model.add(linkTo(methodOn(EmployeeController.class).findAll()).withRel("employees")); model.add(linkTo(methodOn(EmployeeController.class).findAllDetailedEmployees()).withRel("detailedEmployees")); model.add(linkTo(methodOn(ManagerController.class).findAll()).withRel("managers")); return ResponseEntity.ok(model); }
Example #12
Source File: PageLinksAspect.java From taskana with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Around("@annotation(pro.taskana.resource.rest.PageLinks) && args(data, page, ..)") public <T extends RepresentationModel<? extends T> & ProceedingJoinPoint> RepresentationModel<T> addLinksToPageResource( ProceedingJoinPoint joinPoint, List<?> data, PageMetadata page) throws Throwable { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); Method method = ((MethodSignature) joinPoint.getSignature()).getMethod(); PageLinks pageLinks = method.getAnnotation(PageLinks.class); String relativeUrl = pageLinks.value(); UriComponentsBuilder original = originalUri(relativeUrl, request); RepresentationModel<T> resourceSupport = (RepresentationModel<T>) joinPoint.proceed(); resourceSupport.add(Link.of(original.toUriString()).withSelfRel()); if (page != null) { resourceSupport.add( Link.of(original.replaceQueryParam("page", 1).toUriString()) .withRel(IanaLinkRelations.FIRST)); resourceSupport.add( Link.of(original.replaceQueryParam("page", page.getTotalPages()).toUriString()) .withRel(IanaLinkRelations.LAST)); if (page.getNumber() > 1) { resourceSupport.add( Link.of(original.replaceQueryParam("page", page.getNumber() - 1).toUriString()) .withRel(IanaLinkRelations.PREV)); } if (page.getNumber() < page.getTotalPages()) { resourceSupport.add( Link.of(original.replaceQueryParam("page", page.getNumber() + 1).toUriString()) .withRel(IanaLinkRelations.NEXT)); } } return resourceSupport; }
Example #13
Source File: FeignHalAutoConfigurationContextTests.java From spring-cloud-openfeign with Apache License 2.0 | 5 votes |
@Test public void testHalJacksonHttpMessageConverterIsNotLoaded() { FilteredClassLoader filteredClassLoader = new FilteredClassLoader( RepositoryRestMvcConfiguration.class, RepresentationModel.class); contextRunner.withClassLoader(filteredClassLoader) .run(context -> assertThat(context) .doesNotHaveBean("halJacksonHttpMessageConverter")); }
Example #14
Source File: FeignHalAutoConfiguration.java From spring-cloud-openfeign with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean public TypeConstrainedMappingJackson2HttpMessageConverter halJacksonHttpMessageConverter( ObjectProvider<ObjectMapper> objectMapper, ObjectProvider<HalConfiguration> halConfiguration, ObjectProvider<MessageResolver> messageResolver, ObjectProvider<CurieProvider> curieProvider, ObjectProvider<LinkRelationProvider> linkRelationProvider) { ObjectMapper mapper = objectMapper.getIfAvailable(ObjectMapper::new).copy(); mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); HalConfiguration configuration = halConfiguration .getIfAvailable(HalConfiguration::new); CurieProvider curieProviderInstance = curieProvider .getIfAvailable(() -> new DefaultCurieProvider(Collections.emptyMap())); Jackson2HalModule.HalHandlerInstantiator halHandlerInstantiator = new Jackson2HalModule.HalHandlerInstantiator( linkRelationProvider.getIfAvailable(), curieProviderInstance, messageResolver.getIfAvailable(), configuration); mapper.setHandlerInstantiator(halHandlerInstantiator); if (!Jackson2HalModule.isAlreadyRegisteredIn(mapper)) { Jackson2HalModule halModule = new Jackson2HalModule(); mapper.registerModule(halModule); } TypeConstrainedMappingJackson2HttpMessageConverter converter = new TypeConstrainedMappingJackson2HttpMessageConverter( RepresentationModel.class); converter.setSupportedMediaTypes(Arrays.asList(HAL_JSON)); converter.setObjectMapper(mapper); return converter; }
Example #15
Source File: ComponentsController.java From springdoc-openapi with Apache License 2.0 | 5 votes |
@Operation(summary = "List the components") @PageableAsQueryParam @GetMapping public ResponseEntity<PagedModel<RepresentationModel<EntityModel<DemoComponentDto>>>> findAll(@Parameter(hidden = true) Pageable pageable) { Page<DemoComponent> results = componentsService.findAll(pageable); return ResponseEntity.ok(pagedResourcesAssembler.toModel(results, componentDtoModelAssembler)); }
Example #16
Source File: RuntimeTemplate.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
RuntimeTemplate(RestTemplate restTemplate, RepresentationModel<?> resources) { this.restTemplate = restTemplate; this.appStatusesUriTemplate = resources.getLink("runtime/apps").get(); this.appStatusUriTemplate = resources.getLink("runtime/apps/{appId}").get(); this.streamStatusUriTemplate = resources.getLink("runtime/streams/{streamNames}").get(); }
Example #17
Source File: ComponentDtoModelAssembler.java From springdoc-openapi with Apache License 2.0 | 4 votes |
@Override public RepresentationModel<EntityModel<DemoComponentDto>> toModel(DemoComponent entity) { return new EntityModel<DemoComponentDto>(toDtoConverter.convert(entity)); }