Search in sources :

Example 1 with ConversionReport

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

the class QrdaServiceImplTest method successConverter.

private Converter successConverter() {
    Converter mockConverter = mock(Converter.class);
    JsonWrapper qpp = new JsonWrapper();
    qpp.putString(KEY, MOCK_SUCCESS_QPP_STRING);
    ConversionReport report = mock(ConversionReport.class);
    when(report.getEncoded()).thenReturn(qpp);
    when(mockConverter.getReport()).thenReturn(report);
    return mockConverter;
}
Also used : JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) Converter(gov.cms.qpp.conversion.Converter) ConversionReport(gov.cms.qpp.conversion.ConversionReport)

Example 2 with ConversionReport

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

the class ValidationServiceImplTest method before.

@BeforeEach
void before() throws NoSuchFieldException, IllegalAccessException {
    ValidationServiceImpl meep = new ValidationServiceImpl(environment);
    Field rt = meep.getClass().getDeclaredField("restTemplate");
    rt.setAccessible(true);
    rt.set(meep, restTemplate);
    rt.setAccessible(false);
    objectUnderTest = spy(meep);
    ConversionReport report = mock(ConversionReport.class);
    when(report.getEncoded()).thenReturn(qppWrapper);
    when(converter.getReport()).thenReturn(report);
}
Also used : Field(java.lang.reflect.Field) ConversionReport(gov.cms.qpp.conversion.ConversionReport) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with ConversionReport

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

the class QrdaServiceImplTest method errorConverter.

private Converter errorConverter() {
    Converter mockConverter = mock(Converter.class);
    AllErrors allErrors = new AllErrors();
    allErrors.addError(new Error(MOCK_ERROR_SOURCE_IDENTIFIER, null));
    ConversionReport report = mock(ConversionReport.class);
    when(report.getReportDetails()).thenReturn(allErrors);
    TransformException transformException = new TransformException("mock problem", new NullPointerException(), report);
    when(mockConverter.transform()).thenThrow(transformException);
    return mockConverter;
}
Also used : AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) TransformException(gov.cms.qpp.conversion.model.error.TransformException) Converter(gov.cms.qpp.conversion.Converter) Error(gov.cms.qpp.conversion.model.error.Error) ConversionReport(gov.cms.qpp.conversion.ConversionReport)

Example 4 with ConversionReport

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

the class AuditServiceImpl method success.

/**
 * Audit a successful conversion.
 *
 * @param conversionReport report of the conversion
 * @return future
 */
@Override
public CompletableFuture<Metadata> success(ConversionReport conversionReport) {
    if (noAudit()) {
        return null;
    }
    API_LOG.info("Writing success audit information");
    Metadata metadata = initMetadata(conversionReport, Outcome.SUCCESS);
    Source qrdaSource = conversionReport.getQrdaSource();
    Source qppSource = conversionReport.getQppSource();
    CompletableFuture<Void> allWrites = CompletableFuture.allOf(storeContent(qrdaSource).thenAccept(metadata::setSubmissionLocator), storeContent(qppSource).thenAccept(metadata::setQppLocator));
    return allWrites.whenComplete((nada, thrown) -> persist(metadata, thrown)).thenApply(ignore -> metadata);
}
Also used : ConversionReport(gov.cms.qpp.conversion.ConversionReport) Logger(org.slf4j.Logger) AuditException(gov.cms.qpp.conversion.api.exceptions.AuditException) Metadata(gov.cms.qpp.conversion.api.model.Metadata) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) Outcome(gov.cms.qpp.conversion.api.helper.MetadataHelper.Outcome) MetadataHelper(gov.cms.qpp.conversion.api.helper.MetadataHelper) Environment(org.springframework.core.env.Environment) Service(org.springframework.stereotype.Service) Source(gov.cms.qpp.conversion.Source) Constants(gov.cms.qpp.conversion.api.model.Constants) InputStream(java.io.InputStream) Metadata(gov.cms.qpp.conversion.api.model.Metadata) Source(gov.cms.qpp.conversion.Source)

Example 5 with ConversionReport

use of gov.cms.qpp.conversion.ConversionReport 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)

Aggregations

ConversionReport (gov.cms.qpp.conversion.ConversionReport)5 Converter (gov.cms.qpp.conversion.Converter)2 Metadata (gov.cms.qpp.conversion.api.model.Metadata)2 InputStreamSupplierSource (gov.cms.qpp.conversion.InputStreamSupplierSource)1 Source (gov.cms.qpp.conversion.Source)1 AuditException (gov.cms.qpp.conversion.api.exceptions.AuditException)1 InvalidPurposeException (gov.cms.qpp.conversion.api.exceptions.InvalidPurposeException)1 MetadataHelper (gov.cms.qpp.conversion.api.helper.MetadataHelper)1 Outcome (gov.cms.qpp.conversion.api.helper.MetadataHelper.Outcome)1 Constants (gov.cms.qpp.conversion.api.model.Constants)1 JsonWrapper (gov.cms.qpp.conversion.encode.JsonWrapper)1 AllErrors (gov.cms.qpp.conversion.model.error.AllErrors)1 Error (gov.cms.qpp.conversion.model.error.Error)1 TransformException (gov.cms.qpp.conversion.model.error.TransformException)1 InputStream (java.io.InputStream)1 Field (java.lang.reflect.Field)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Logger (org.slf4j.Logger)1