Search in sources :

Example 1 with ResourceNotFoundException

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());
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) Message(org.openlmis.stockmanagement.util.Message) ResourceNotFoundException(org.openlmis.stockmanagement.exception.ResourceNotFoundException)

Example 2 with ResourceNotFoundException

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);
}
Also used : Message(org.openlmis.stockmanagement.util.Message) HashMap(java.util.HashMap) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) ResourceNotFoundException(org.openlmis.stockmanagement.exception.ResourceNotFoundException)

Example 3 with ResourceNotFoundException

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));
    }
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) ResourceNotFoundException(org.openlmis.stockmanagement.exception.ResourceNotFoundException)

Example 4 with ResourceNotFoundException

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());
}
Also used : UUID(java.util.UUID) ResourceNotFoundException(org.openlmis.stockmanagement.exception.ResourceNotFoundException) Test(org.junit.Test)

Aggregations

ResourceNotFoundException (org.openlmis.stockmanagement.exception.ResourceNotFoundException)4 Message (org.openlmis.stockmanagement.util.Message)3 PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)2 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 Test (org.junit.Test)1 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)1 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)1