use of gov.cms.qpp.conversion.api.exceptions.InvalidPurposeException in project qpp-conversion-tool by CMSgov.
the class ExceptionHandlerControllerV1Test method testHandleInvalidPurposeExceptionExceptionResponseBody.
@Test
void testHandleInvalidPurposeExceptionExceptionResponseBody() {
InvalidPurposeException exception = new InvalidPurposeException("some message");
ResponseEntity<String> response = objectUnderTest.handleInvalidPurposeException(exception);
Truth.assertThat(response.getBody()).contains("some message");
}
use of gov.cms.qpp.conversion.api.exceptions.InvalidPurposeException in project qpp-conversion-tool by CMSgov.
the class QrdaControllerV1 method uploadQrdaFile.
/**
* Endpoint to transform an uploaded file into a valid or error json response
*
* @param file Uploaded file
* @param purpose the purpose for the conversion
* @return Valid json or error json content
*/
@PostMapping(headers = { "Accept=" + Constants.V1_API_ACCEPT })
public ResponseEntity<String> uploadQrdaFile(@RequestParam(name = "file") MultipartFile file, @RequestHeader(required = false, name = "Purpose") String purpose) {
String originalFilename = file.getOriginalFilename();
if (!StringUtils.isEmpty(purpose)) {
if (purpose.length() > MAX_PURPOSE_LENGTH) {
throw new InvalidPurposeException("Given Purpose (header) is too large. Max length is " + MAX_PURPOSE_LENGTH + ", yours was " + purpose.length());
}
API_LOG.info("Conversion request received for " + purpose);
} else {
// if it's an empty string, make it null
purpose = null;
API_LOG.info("Conversion request received");
}
ConversionReport conversionReport = qrdaService.convertQrda3ToQpp(new InputStreamSupplierSource(originalFilename, inputStream(file), purpose));
validationService.validateQpp(conversionReport);
Metadata metadata = audit(conversionReport);
API_LOG.info("Conversion request succeeded");
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
if (metadata != null) {
httpHeaders.add("Location", metadata.getUuid());
}
return new ResponseEntity<>(conversionReport.getEncoded().toString(), httpHeaders, HttpStatus.CREATED);
}
Aggregations