use of com.b2international.snowowl.fhir.core.exceptions.BadRequestException in project snow-owl by b2ihealthcare.
the class ExceptionTest method testException.
@Test
public void testException() throws Exception {
Issue expectedIssue = builder.addLocation("LookupRequest.system").detailsWithDisplay(OperationOutcomeCode.MSG_PARAM_INVALID, "Parameter 'LookupRequest.system' content is invalid").build();
BadRequestException bre = new BadRequestException("No system specified", "LookupRequest.system");
exception.expect(FhirException.class);
exception.expectMessage("No system specified");
exception.expect(FhirExceptionIssueMatcher.issue(expectedIssue));
throw bre;
}
use of com.b2international.snowowl.fhir.core.exceptions.BadRequestException in project snow-owl by b2ihealthcare.
the class SnomedUri method fromUriString.
/**
* Factory method to create a new SNOMED CT URI from a valid URI String.
* @param uriString
* @param parameterName for reporting purposes
* @return new SNOMED CT URI instance
*/
public static SnomedUri fromUriString(String uriString, String parameterName) {
Builder builder = builder();
if (!uriString.startsWith(SNOMED_BASE_URI_STRING)) {
throw new BadRequestException(String.format("URI '%s' is not a valid SNOMED CT URI. It should start as '%s'.", uriString, SNOMED_BASE_URI_STRING), parameterName);
}
String extensionString = uriString.replaceFirst(SNOMED_BASE_URI_STRING, "");
String[] splitUri = extensionString.split("\\?");
if (splitUri.length > 2) {
throw new BadRequestException(String.format("Invalid SNOMED CT URI [%s].", uriString), parameterName);
}
if (splitUri.length == 2) {
parseQueryPart(builder, uriString, splitUri[1], parameterName);
}
StringTokenizer tokenizer = new StringTokenizer(splitUri[0], "/");
// this should not happen
if (!tokenizer.hasMoreTokens())
return builder.build();
// extension
String pathSegment = tokenizer.nextToken();
// No extension or version definition provided - SNOMED CT INT Edition
if (StringUtils.isEmpty(pathSegment))
return builder.build();
if (!SnomedIdentifiers.isValid(pathSegment)) {
throw new BadRequestException(String.format("Invalid SNOMED CT extension module ID [%s] defined.", pathSegment), parameterName);
} else {
builder.extensionModuleId(pathSegment);
}
// version parameter
if (!tokenizer.hasMoreTokens())
return builder.build();
String versionParameterKeySegment = tokenizer.nextToken();
if (!VERSION_PATH_SEGMENT.equals(versionParameterKeySegment)) {
throw new BadRequestException(String.format("Invalid path segment [%s], 'version' expected.", versionParameterKeySegment), parameterName);
}
// Version tag
if (!tokenizer.hasMoreTokens()) {
throw new BadRequestException(String.format("No version tag is specified after the 'version' parameter."), parameterName);
}
String versionTag = tokenizer.nextToken();
// to validate
try {
EffectiveTimes.parse(versionTag, DateFormats.SHORT);
} catch (RuntimeException re) {
throw new BadRequestException(String.format("Could not parse version date [%s].", versionTag), parameterName);
}
return builder.version(versionTag).build();
}
use of com.b2international.snowowl.fhir.core.exceptions.BadRequestException in project snow-owl by b2ihealthcare.
the class FhirCodeSystemValidateCodeOperationController method validateCode.
/**
* POST-based $validate-code end-point.
* All parameters are in the request body, except the codeSystemId
* @param body - FHIR parameters
* @return out - FHIR parameters
*/
@Operation(summary = "Validate a code in a code system", description = "Validate that a coded value is in a code system.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "400", description = "Bad request") })
@PostMapping(value = "/{codeSystemId:**}/$validate-code", consumes = AbstractFhirController.APPLICATION_FHIR_JSON)
public Promise<Parameters.Fhir> validateCode(@Parameter(description = "The id of the code system to validate against") @PathVariable("codeSystemId") String codeSystemId, @Parameter(description = "The validate-code request parameters") @RequestBody Parameters.Fhir body) {
final ValidateCodeRequest request = toRequest(body, ValidateCodeRequest.class);
// Validate for parameters that are not allowed on the instance level
if (request.getUrl() != null) {
throw new BadRequestException("Parameter 'url' cannot be specified when the code system ID is set.", "ValidateCodeRequest.url");
}
if (request.getCoding() != null) {
throw new BadRequestException("Parameter 'coding' cannot be specified when the code system ID is set.", "ValidateCodeRequest.coding");
}
if (request.getCodeableConcept() != null) {
throw new BadRequestException("Parameter 'codeableConcept' cannot be specified when the code system ID is set.", "ValidateCodeRequest.codeableConcept");
}
if (request.getCodeSystem() != null) {
throw new BadRequestException("Validation against external code systems is not supported", "ValidateCodeRequest.codeSystem");
}
// before execution set the codesystem to the path variable
request.setUrl(new Uri(codeSystemId));
return FhirRequests.codeSystems().prepareValidateCode().setRequest(request).buildAsync().execute(getBus()).then(this::toResponse);
}
use of com.b2international.snowowl.fhir.core.exceptions.BadRequestException in project snow-owl by b2ihealthcare.
the class ExceptionTest method testException2.
@Test
public void testException2() throws Exception {
Issue expectedIssue = Issue.builder().code(IssueType.INVALID).severity(IssueSeverity.ERROR).diagnostics("No system specified [null]").addLocation("LookupRequest.system").detailsWithDisplay(OperationOutcomeCode.MSG_PARAM_INVALID, "Parameter 'LookupRequest.system' content is invalid").build();
BadRequestException bre = new BadRequestException("No system specified [null]", "LookupRequest.system");
exception.expect(FhirException.class);
exception.expectMessage("No system specified [null]");
exception.expect(FhirExceptionIssueMatcher.issue(expectedIssue));
throw bre;
}
Aggregations