Search in sources :

Example 1 with OperationDefinition

use of com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition in project snow-owl by b2ihealthcare.

the class OperationDefinitionTest method deserialize.

@Test
public void deserialize() throws Exception {
    OperationDefinition readOperationDefinition = objectMapper.readValue(objectMapper.writeValueAsString(operationDefinition), OperationDefinition.class);
    validate(readOperationDefinition);
}
Also used : OperationDefinition(com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 2 with OperationDefinition

use of com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition in project snow-owl by b2ihealthcare.

the class FhirMetadataController method collectOperationDefinitions.

private Collection<OperationDefinition> collectOperationDefinitions(final OpenAPI openAPI) {
    final Paths paths = openAPI.getPaths();
    // Collect GET requests within the FHIR services hierarchy where the request path contains a '$' character
    return paths.entrySet().stream().filter(e -> {
        final String key = e.getKey();
        final PathItem value = e.getValue();
        return key.startsWith(config.getApiBaseUrl()) && key.contains("$") && (value.getGet() != null);
    }).map(e -> buildOperationDefinition(e.getKey(), e.getValue())).collect(Collectors.toList());
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Iterables(com.google.common.collect.Iterables) OpenApiWebMvcResource(org.springdoc.webmvc.api.OpenApiWebMvcResource) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Uri(com.b2international.snowowl.fhir.core.model.dt.Uri) SnowOwlOpenApiWebMvcResource(com.b2international.snowowl.core.rest.SnowOwlOpenApiWebMvcResource) OperationDefinition(com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition) Supplier(java.util.function.Supplier) FhirApiConfig(com.b2international.snowowl.core.rest.FhirApiConfig) Code(com.b2international.snowowl.fhir.core.model.dt.Code) Extension(io.swagger.v3.oas.annotations.extensions.Extension) Operation(io.swagger.v3.oas.annotations.Operation) StringUtils(com.b2international.commons.StringUtils) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) B2I_OPENAPI_PROFILE(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_PROFILE) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) GetMapping(org.springframework.web.bind.annotation.GetMapping) Suppliers(com.google.common.base.Suppliers) OperationKind(com.b2international.snowowl.fhir.core.codesystems.OperationKind) Schema(io.swagger.v3.oas.models.media.Schema) SnowOwlConfiguration(com.b2international.snowowl.core.config.SnowOwlConfiguration) NotFoundException(com.b2international.commons.exceptions.NotFoundException) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Collection(java.util.Collection) RestfulCapabilityMode(com.b2international.snowowl.fhir.core.codesystems.RestfulCapabilityMode) PathItem(io.swagger.v3.oas.models.PathItem) ExtensionProperty(io.swagger.v3.oas.annotations.extensions.ExtensionProperty) Paths(io.swagger.v3.oas.models.Paths) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) List(java.util.List) Tag(io.swagger.v3.oas.annotations.tags.Tag) CoreActivator(com.b2international.snowowl.core.CoreActivator) CapabilityStatementKind(com.b2international.snowowl.fhir.core.codesystems.CapabilityStatementKind) Platform(org.eclipse.core.runtime.Platform) Parameter(com.b2international.snowowl.fhir.core.model.operationdefinition.Parameter) B2I_OPENAPI_INTERACTION_READ(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_INTERACTION_READ) B2I_OPENAPI_X_NAME(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_NAME) PublicationStatus(com.b2international.snowowl.fhir.core.codesystems.PublicationStatus) Comparator(java.util.Comparator) ApplicationContext(com.b2international.snowowl.core.ApplicationContext) com.b2international.snowowl.fhir.core.model.capabilitystatement(com.b2international.snowowl.fhir.core.model.capabilitystatement) B2I_OPENAPI_X_INTERACTION(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_INTERACTION) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) PathItem(io.swagger.v3.oas.models.PathItem) Paths(io.swagger.v3.oas.models.Paths)

Example 3 with OperationDefinition

use of com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition in project snow-owl by b2ihealthcare.

the class FhirMetadataController method initCache.

private Holder initCache() {
    final Holder holder = new Holder();
    // XXX: we know that the subclass is instantiated (in SnowOwlApiConfig)
    final OpenAPI openAPI = ((SnowOwlOpenApiWebMvcResource) openApiWebMvcResource).getOpenApi();
    final Collection<Resource> resources = collectResources(openAPI);
    final Collection<OperationDefinition> operationDefinitions = collectOperationDefinitions(openAPI);
    final Rest.Builder restBuilder = Rest.builder().mode(RestfulCapabilityMode.SERVER).resources(resources);
    holder.operationMap = newHashMap();
    for (final OperationDefinition operationDefinition : operationDefinitions) {
        for (final Code code : operationDefinition.getResources()) {
            final String key = code.getCodeValue() + operationDefinition.getName();
            holder.operationMap.put(key, operationDefinition);
            restBuilder.addOperation(com.b2international.snowowl.fhir.core.model.capabilitystatement.Operation.builder().name(operationDefinition.getName()).definition(buildOperationUrl(code, operationDefinition)).build());
        }
    }
    final String serverVersion = Platform.getBundle(CoreActivator.PLUGIN_ID).getVersion().toString();
    String description = ApplicationContext.getServiceForClass(SnowOwlConfiguration.class).getDescription();
    holder.capabilityStatement = CapabilityStatement.builder().name("FHIR Capability statement for Snow Owl© Terminology Server").status(PublicationStatus.ACTIVE).experimental(false).kind(CapabilityStatementKind.INSTANCE.getCode()).fhirVersion("4.0.1").addInstantiate(new Uri("http://hl7.org/fhir/CapabilityStatement/terminology-server")).software(Software.builder().name("Snow Owl©").version(serverVersion).build()).implementation(Implementation.builder().url("https://b2i.sg").description(description).build()).addFormat(new Code(AbstractFhirController.APPLICATION_FHIR_JSON)).addRest(restBuilder.build()).build();
    return holder;
}
Also used : SnowOwlOpenApiWebMvcResource(com.b2international.snowowl.core.rest.SnowOwlOpenApiWebMvcResource) OpenApiWebMvcResource(org.springdoc.webmvc.api.OpenApiWebMvcResource) SnowOwlOpenApiWebMvcResource(com.b2international.snowowl.core.rest.SnowOwlOpenApiWebMvcResource) Code(com.b2international.snowowl.fhir.core.model.dt.Code) Uri(com.b2international.snowowl.fhir.core.model.dt.Uri) OpenAPI(io.swagger.v3.oas.models.OpenAPI) OperationDefinition(com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition) SnowOwlConfiguration(com.b2international.snowowl.core.config.SnowOwlConfiguration)

Example 4 with OperationDefinition

use of com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition in project snow-owl by b2ihealthcare.

the class FhirMetadataController method operationDefinition.

/**
 * Returns the {@link OperationDefinition} for a given operation.
 * @param operation
 * @return
 */
@Operation(summary = "Retrieve an operation definition by its name", description = "Retrieves an operation definition by its compound name (resource$operation).")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Operation definition not found") })
@GetMapping(value = "/OperationDefinition/{operation}")
public OperationDefinition operationDefinition(@PathVariable(value = "operation") final String operation) {
    final Map<String, OperationDefinition> operationMap = capabilityStatementSupplier.get().operationMap;
    final OperationDefinition operationDefinition = operationMap.get(operation);
    if (operationDefinition == null) {
        throw new NotFoundException("OperationDefinition", operation);
    }
    return operationDefinition;
}
Also used : NotFoundException(com.b2international.commons.exceptions.NotFoundException) OperationDefinition(com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition) GetMapping(org.springframework.web.bind.annotation.GetMapping) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

OperationDefinition (com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition)4 NotFoundException (com.b2international.commons.exceptions.NotFoundException)2 SnowOwlConfiguration (com.b2international.snowowl.core.config.SnowOwlConfiguration)2 SnowOwlOpenApiWebMvcResource (com.b2international.snowowl.core.rest.SnowOwlOpenApiWebMvcResource)2 Code (com.b2international.snowowl.fhir.core.model.dt.Code)2 Uri (com.b2international.snowowl.fhir.core.model.dt.Uri)2 Operation (io.swagger.v3.oas.annotations.Operation)2 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)2 OpenAPI (io.swagger.v3.oas.models.OpenAPI)2 OpenApiWebMvcResource (org.springdoc.webmvc.api.OpenApiWebMvcResource)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 StringUtils (com.b2international.commons.StringUtils)1 ApplicationContext (com.b2international.snowowl.core.ApplicationContext)1 CoreActivator (com.b2international.snowowl.core.CoreActivator)1 FhirApiConfig (com.b2international.snowowl.core.rest.FhirApiConfig)1 B2I_OPENAPI_INTERACTION_READ (com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_INTERACTION_READ)1 B2I_OPENAPI_PROFILE (com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_PROFILE)1 B2I_OPENAPI_X_INTERACTION (com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_INTERACTION)1 B2I_OPENAPI_X_NAME (com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_NAME)1 CapabilityStatementKind (com.b2international.snowowl.fhir.core.codesystems.CapabilityStatementKind)1