Search in sources :

Example 1 with InputStreamSupplierSource

use of gov.cms.qpp.conversion.InputStreamSupplierSource in project qpp-conversion-tool by CMSgov.

the class MarkupManipulationHandler method executeScenario.

public List<Detail> executeScenario(String xpath, boolean remove) {
    InputStream inStream = manipulator.upsetTheNorm(xpath, remove);
    Converter converter = new Converter(new InputStreamSupplierSource(xpath, inStream));
    try {
        converter.transform();
    } catch (TransformException exception) {
        AllErrors errors = exception.getDetails();
        return errors.getErrors().stream().map(Error::getDetails).flatMap(List::stream).collect(Collectors.toList());
    }
    return Collections.emptyList();
}
Also used : InputStream(java.io.InputStream) AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) TransformException(gov.cms.qpp.conversion.model.error.TransformException) Converter(gov.cms.qpp.conversion.Converter) InputStreamSupplierSource(gov.cms.qpp.conversion.InputStreamSupplierSource) List(java.util.List)

Example 2 with InputStreamSupplierSource

use of gov.cms.qpp.conversion.InputStreamSupplierSource 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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) Metadata(gov.cms.qpp.conversion.api.model.Metadata) InvalidPurposeException(gov.cms.qpp.conversion.api.exceptions.InvalidPurposeException) ConversionReport(gov.cms.qpp.conversion.ConversionReport) InputStreamSupplierSource(gov.cms.qpp.conversion.InputStreamSupplierSource) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 3 with InputStreamSupplierSource

use of gov.cms.qpp.conversion.InputStreamSupplierSource in project qpp-conversion-tool by CMSgov.

the class QualityMeasureIdMultiRoundTripTest method executeScenario.

private List<Detail> executeScenario(String path, boolean remove) {
    InputStream modified = manipulator.upsetTheNorm(path, remove);
    Converter converter = new Converter(new InputStreamSupplierSource(JUNK_QRDA3_FILE.toString(), modified));
    List<Detail> details = new ArrayList<>();
    try {
        converter.transform();
    } catch (TransformException exception) {
        AllErrors errors = exception.getDetails();
        details.addAll(errors.getErrors().get(0).getDetails());
    }
    return details;
}
Also used : InputStream(java.io.InputStream) AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) ArrayList(java.util.ArrayList) TransformException(gov.cms.qpp.conversion.model.error.TransformException) Converter(gov.cms.qpp.conversion.Converter) InputStreamSupplierSource(gov.cms.qpp.conversion.InputStreamSupplierSource) Detail(gov.cms.qpp.conversion.model.error.Detail)

Aggregations

InputStreamSupplierSource (gov.cms.qpp.conversion.InputStreamSupplierSource)3 Converter (gov.cms.qpp.conversion.Converter)2 AllErrors (gov.cms.qpp.conversion.model.error.AllErrors)2 TransformException (gov.cms.qpp.conversion.model.error.TransformException)2 InputStream (java.io.InputStream)2 ConversionReport (gov.cms.qpp.conversion.ConversionReport)1 InvalidPurposeException (gov.cms.qpp.conversion.api.exceptions.InvalidPurposeException)1 Metadata (gov.cms.qpp.conversion.api.model.Metadata)1 Detail (gov.cms.qpp.conversion.model.error.Detail)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1