use of org.openlmis.stockmanagement.exception.ResourceNotFoundException in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryController method checkPermission.
private void checkPermission(UUID id) {
PhysicalInventory pi = repository.findOne(id);
if (pi == null) {
throw new ResourceNotFoundException(new Message(ERROR_PHYSICAL_INVENTORY_NOT_FOUND, id));
}
permissionService.canEditPhysicalInventory(pi.getProgramId(), pi.getFacilityId());
}
use of org.openlmis.stockmanagement.exception.ResourceNotFoundException in project openlmis-stockmanagement by OpenLMIS.
the class JasperReportService method getStockCardReportView.
/**
* Generate stock card report in PDF format.
*
* @param stockCardId stock card id
* @return generated stock card report.
*/
public ModelAndView getStockCardReportView(UUID stockCardId) {
StockCardDto stockCardDto = stockCardService.findStockCardById(stockCardId);
if (stockCardDto == null) {
throw new ResourceNotFoundException(new Message(ERROR_REPORT_ID_NOT_FOUND));
}
Collections.reverse(stockCardDto.getLineItems());
Map<String, Object> params = new HashMap<>();
params.put("datasource", singletonList(stockCardDto));
params.put("hasLot", stockCardDto.hasLot());
return generateReport(CARD_REPORT_URL, params);
}
use of org.openlmis.stockmanagement.exception.ResourceNotFoundException in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryService method deletePhysicalInventory.
/**
* Delete draft.
*
* @param id physical inventory id.
*/
public void deletePhysicalInventory(UUID id) {
PhysicalInventory foundInventory = physicalInventoriesRepository.findOne(id);
if (foundInventory != null) {
checkPermission(foundInventory.getProgramId(), foundInventory.getFacilityId());
if (!foundInventory.getIsDraft()) {
throw new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED);
}
physicalInventoriesRepository.delete(foundInventory);
} else {
throw new ResourceNotFoundException(new Message(ERROR_PHYSICAL_INVENTORY_NOT_FOUND, id));
}
}
use of org.openlmis.stockmanagement.exception.ResourceNotFoundException in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryControllerIntegrationTest method shouldReturnNotFoundWhenInventoryIsNotFound.
@Test
public void shouldReturnNotFoundWhenInventoryIsNotFound() {
// given
UUID physicalInventoryId = UUID.randomUUID();
doThrow(new ResourceNotFoundException(ERROR_PHYSICAL_INVENTORY_NOT_FOUND)).when(physicalInventoryService).deletePhysicalInventory(physicalInventoryId);
// when
restAssured.given().header(HttpHeaders.AUTHORIZATION, getTokenHeader()).contentType(APPLICATION_JSON).pathParam("id", physicalInventoryId).when().delete(ID_URL).then().statusCode(404);
// then
assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());
}
Aggregations