Search in sources :

Example 11 with Metadata

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

the class CpcApiAcceptance method testMarkFileProcessedNotCPC.

@AcceptanceTest
void testMarkFileProcessedNotCPC() {
    Metadata metadata = createDatedCpcMetadata("2018-01-02T05:00:00.000Z");
    metadata.setCpc(null);
    mapper.save(metadata);
    String responseBody = markFileAsProcessed(metadata.getUuid(), 404);
    assertThat(responseBody).isEqualTo("The file was not a CPC+ file.");
}
Also used : Metadata(gov.cms.qpp.conversion.api.model.Metadata) AcceptanceTest(gov.cms.qpp.test.annotations.AcceptanceTest)

Example 12 with Metadata

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

the class CpcApiAcceptance method testUnprocessedFilesDates.

@AcceptanceTest
void testUnprocessedFilesDates() {
    Metadata afterJanuarySecondMetadata = createDatedCpcMetadata("2018-01-02T05:00:00.000Z");
    Metadata beforeJanuarySecondMetadata = createDatedCpcMetadata(DbServiceImpl.START_OF_UNALLOWED_CONVERSION_TIME);
    Metadata anotherAllowedMetadata = createDatedCpcMetadata("2018-02-26T14:36:43.723Z");
    Metadata anotherUnallowedMetadata = createDatedCpcMetadata("2017-12-25T00:00:00.000Z");
    mapper.batchSave(afterJanuarySecondMetadata, beforeJanuarySecondMetadata, anotherAllowedMetadata, anotherUnallowedMetadata);
    List<Map> responseBody = getUnprocessedFiles();
    responseBody.stream().forEach(map -> assertThat(Instant.parse((String) map.get("conversionDate"))).isGreaterThan(Instant.parse(DbServiceImpl.START_OF_UNALLOWED_CONVERSION_TIME)));
}
Also used : Metadata(gov.cms.qpp.conversion.api.model.Metadata) Map(java.util.Map) AcceptanceTest(gov.cms.qpp.test.annotations.AcceptanceTest)

Example 13 with Metadata

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

the class AuditServiceImpl method failConversion.

/**
 * Audit a failed QPP conversion.
 *
 * @param conversionReport report of the conversion
 * @return future
 */
@Override
public CompletableFuture<Void> failConversion(ConversionReport conversionReport) {
    if (noAudit()) {
        return null;
    }
    API_LOG.info("Writing audit information for a conversion failure scenario");
    Metadata metadata = initMetadata(conversionReport, Outcome.CONVERSION_ERROR);
    Source qrdaSource = conversionReport.getQrdaSource();
    Source validationErrorSource = conversionReport.getValidationErrorsSource();
    CompletableFuture<Void> allWrites = CompletableFuture.allOf(storeContent(validationErrorSource).thenAccept(metadata::setConversionErrorLocator), storeContent(qrdaSource).thenAccept(metadata::setSubmissionLocator));
    return allWrites.whenComplete((ignore, thrown) -> persist(metadata, thrown));
}
Also used : Metadata(gov.cms.qpp.conversion.api.model.Metadata) Source(gov.cms.qpp.conversion.Source)

Example 14 with Metadata

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

the class CpcFileServiceImpl method unprocessFileById.

/**
 * Process to ensure the file is a processed cpc+ file and marks the file as unprocessed
 *
 * @param fileId Identifier of the CPC+ file
 * @return Success or failure message.
 */
@Override
public String unprocessFileById(String fileId) {
    Metadata metadata = dbService.getMetadataById(fileId);
    if (metadata == null) {
        throw new NoFileInDatabaseException(FILE_NOT_FOUND);
    } else if (metadata.getCpc() == null) {
        throw new InvalidFileTypeException(INVALID_FILE);
    } else if (!metadata.getCpcProcessed()) {
        return FILE_FOUND_UNPROCESSED;
    } else {
        metadata.setCpcProcessed(false);
        CompletableFuture<Metadata> metadataFuture = dbService.write(metadata);
        metadataFuture.join();
        return FILE_FOUND_UNPROCESSED;
    }
}
Also used : InvalidFileTypeException(gov.cms.qpp.conversion.api.exceptions.InvalidFileTypeException) Metadata(gov.cms.qpp.conversion.api.model.Metadata) NoFileInDatabaseException(gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException)

Example 15 with Metadata

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

the class CpcFileServiceImpl method processFileById.

/**
 * Process to ensure the file is an unprocessed cpc+ file and marks the file as processed
 *
 * @param fileId Identifier of the CPC+ file
 * @return Success or failure message.
 */
@Override
public String processFileById(String fileId) {
    Metadata metadata = dbService.getMetadataById(fileId);
    if (metadata == null) {
        throw new NoFileInDatabaseException(FILE_NOT_FOUND);
    } else if (metadata.getCpc() == null) {
        throw new InvalidFileTypeException(INVALID_FILE);
    } else if (metadata.getCpcProcessed()) {
        return FILE_FOUND_PROCESSED;
    } else {
        metadata.setCpcProcessed(true);
        CompletableFuture<Metadata> metadataFuture = dbService.write(metadata);
        metadataFuture.join();
        return FILE_FOUND_PROCESSED;
    }
}
Also used : InvalidFileTypeException(gov.cms.qpp.conversion.api.exceptions.InvalidFileTypeException) Metadata(gov.cms.qpp.conversion.api.model.Metadata) NoFileInDatabaseException(gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException)

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