use of gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException in project qpp-conversion-tool by CMSgov.
the class ExceptionHandlerControllerV1Test method testFileNotFoundExceptionStatusCode.
@Test
void testFileNotFoundExceptionStatusCode() {
NoFileInDatabaseException exception = new NoFileInDatabaseException(CpcFileServiceImpl.FILE_NOT_FOUND);
ResponseEntity<String> responseEntity = objectUnderTest.handleFileNotFoundException(exception);
assertWithMessage("The response entity's status code must be 422.").that(responseEntity.getStatusCode()).isEquivalentAccordingToCompareTo(HttpStatus.NOT_FOUND);
}
use of gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException 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;
}
}
use of gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException 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;
}
}
use of gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException in project qpp-conversion-tool by CMSgov.
the class CpcFileServiceImplTest method testGetFileByIdNoFile.
@Test
void testGetFileByIdNoFile() {
when(dbService.getMetadataById(anyString())).thenReturn(null);
when(storageService.getFileByLocationId("test")).thenReturn(new ByteArrayInputStream("1337".getBytes()));
NoFileInDatabaseException expectedException = assertThrows(NoFileInDatabaseException.class, () -> objectUnderTest.getFileById("test"));
verify(dbService, times(1)).getMetadataById(anyString());
assertThat(expectedException).hasMessageThat().isEqualTo(CpcFileServiceImpl.FILE_NOT_FOUND);
}
use of gov.cms.qpp.conversion.api.exceptions.NoFileInDatabaseException in project qpp-conversion-tool by CMSgov.
the class CpcFileServiceImplTest method testUnprocessFileByIdFileNotFound.
@Test
void testUnprocessFileByIdFileNotFound() {
when(dbService.getMetadataById(anyString())).thenReturn(null);
NoFileInDatabaseException expectedException = assertThrows(NoFileInDatabaseException.class, () -> objectUnderTest.unprocessFileById("test"));
verify(dbService, times(1)).getMetadataById(anyString());
assertThat(expectedException).hasMessageThat().isEqualTo(CpcFileServiceImpl.FILE_NOT_FOUND);
}
Aggregations