org.springframework.boot.test.context.FilteredClassLoader#org.springframework.hateoas.RepresentationModel源码实例Demo

下面列出了org.springframework.boot.test.context.FilteredClassLoader#org.springframework.hateoas.RepresentationModel 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * 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")));
}
 
源代码2 项目: spring-cloud-dataflow   文件: JobTemplate.java
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();
}
 
源代码3 项目: spring-cloud-dataflow   文件: StreamTemplate.java
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();

}
 
源代码4 项目: springdoc-openapi   文件: ComponentsController.java
@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));
}
 
@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;
}
 
@Test
public void testHalJacksonHttpMessageConverterIsNotLoaded() {
	FilteredClassLoader filteredClassLoader = new FilteredClassLoader(
			RepositoryRestMvcConfiguration.class, RepresentationModel.class);
	contextRunner.withClassLoader(filteredClassLoader)
			.run(context -> assertThat(context)
					.doesNotHaveBean("halJacksonHttpMessageConverter"));
}
 
源代码7 项目: taskana   文件: PageLinksAspect.java
@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;
}
 
源代码8 项目: spring-hateoas-examples   文件: RootController.java
@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);
}
 
@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;
}
 
@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;
}
 
源代码11 项目: bowman   文件: ResourceDeserializer.java
@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);
}
 
/**
 * 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();
}
 
源代码13 项目: spring-cloud-dataflow   文件: DataFlowTemplate.java
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;
}
 
源代码14 项目: spring-cloud-dataflow   文件: SchedulerTemplate.java
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();

}
 
源代码15 项目: spring-cloud-dataflow   文件: TaskTemplate.java
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();
}
 
@Override
public RepresentationModel<EntityModel<DemoComponentDto>> toModel(DemoComponent entity) {
	return new EntityModel<DemoComponentDto>(toDtoConverter.convert(entity));
}
 
源代码17 项目: spring-cloud-dataflow   文件: RuntimeTemplate.java
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();
}