Search in sources :

Example 36 with Metadata

use of gov.cms.qpp.conversion.api.model.Metadata 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 37 with Metadata

use of gov.cms.qpp.conversion.api.model.Metadata in project qpp-conversion-tool by CMSgov.

the class AuditServiceImpl method initMetadata.

/**
 * Initializes {@link Metadata} from the {@link ConversionReport} and conversion outcome
 *
 * @param report Object containing metadata information
 * @param outcome Status of the conversion
 * @return Constructed metadata
 */
private Metadata initMetadata(ConversionReport report, MetadataHelper.Outcome outcome) {
    Metadata metadata = MetadataHelper.generateMetadata(report.getDecoded(), outcome);
    metadata.setFileName(report.getQrdaSource().getName());
    metadata.setPurpose(report.getPurpose());
    return metadata;
}
Also used : Metadata(gov.cms.qpp.conversion.api.model.Metadata)

Example 38 with Metadata

use of gov.cms.qpp.conversion.api.model.Metadata in project qpp-conversion-tool by CMSgov.

the class CpcApiAcceptance method createDatedCpcMetadata.

private Metadata createDatedCpcMetadata(String parsableDate) {
    Metadata metadata = new Metadata();
    metadata.setApm("T3STV47U3");
    metadata.setTin("0001233212");
    metadata.setNpi("012123123");
    metadata.setCpc(Constants.CPC_DYNAMO_PARTITION_START + "15");
    metadata.setCpcProcessed(false);
    metadata.setFileName("acceptance_test.xml");
    metadata.setConversionStatus(true);
    metadata.setOverallStatus(true);
    metadata.setValidationStatus(true);
    metadata.setQppLocator("not-here?");
    metadata.setValidationErrorLocator("not-there?");
    metadata.setConversionErrorLocator("not-anywhere?");
    metadata.setCreatedDate(Instant.parse(parsableDate));
    return metadata;
}
Also used : Metadata(gov.cms.qpp.conversion.api.model.Metadata)

Example 39 with Metadata

use of gov.cms.qpp.conversion.api.model.Metadata 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 40 with Metadata

use of gov.cms.qpp.conversion.api.model.Metadata in project qpp-conversion-tool by CMSgov.

the class MetadataHelper method generateMetadata.

/**
 * Generates a {@link Metadata} object from a {@link Node}.
 * This {@link Metadata} does not contain data not found in a standard {@link Node}.
 *
 * @param node from which to extract metadata
 * @param outcome to update with metadata
 * @return metadata
 */
public static Metadata generateMetadata(Node node, Outcome outcome) {
    Objects.requireNonNull(outcome, "outcome");
    Metadata metadata = new Metadata();
    if (node != null) {
        metadata.setApm(findApm(node));
        metadata.setTin(findTin(node));
        metadata.setNpi(findNpi(node));
        metadata.setCpc(deriveCpcHash(node));
        metadata.setCpcProcessed(false);
    }
    outcome.setStatus(metadata);
    return metadata;
}
Also used : Metadata(gov.cms.qpp.conversion.api.model.Metadata)

Aggregations

Metadata (gov.cms.qpp.conversion.api.model.Metadata)40 Test (org.junit.jupiter.api.Test)24 Node (gov.cms.qpp.conversion.model.Node)16 Source (gov.cms.qpp.conversion.Source)5 ConversionReport (gov.cms.qpp.conversion.ConversionReport)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ResponseEntity (org.springframework.http.ResponseEntity)3 InvalidFileTypeException (gov.cms.qpp.conversion.api.exceptions.InvalidFileTypeException)2 NoFileInDatabaseException (gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException)2 Outcome (gov.cms.qpp.conversion.api.helper.MetadataHelper.Outcome)2 AcceptanceTest (gov.cms.qpp.test.annotations.AcceptanceTest)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 InputStreamSupplierSource (gov.cms.qpp.conversion.InputStreamSupplierSource)1 AuditException (gov.cms.qpp.conversion.api.exceptions.AuditException)1 InvalidPurposeException (gov.cms.qpp.conversion.api.exceptions.InvalidPurposeException)1 UncheckedInterruptedException (gov.cms.qpp.conversion.api.exceptions.UncheckedInterruptedException)1 MetadataHelper (gov.cms.qpp.conversion.api.helper.MetadataHelper)1 Constants (gov.cms.qpp.conversion.api.model.Constants)1 UnprocessedCpcFileData (gov.cms.qpp.conversion.api.model.UnprocessedCpcFileData)1 InputStream (java.io.InputStream)1