Search in sources :

Example 1 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class StockCardSummariesServiceTest method shouldThrowExceptionIfNoPermission.

@Test(expected = PermissionMessageException.class)
public void shouldThrowExceptionIfNoPermission() {
    StockCardSummariesV2SearchParams params = new StockCardSummariesV2SearchParamsDataBuilder().build();
    doThrow(new PermissionMessageException(new Message("no permission"))).when(permissionService).canViewStockCard(params.getProgramId(), params.getFacilityId());
    stockCardSummariesService.findStockCards(params);
}
Also used : Message(org.openlmis.stockmanagement.util.Message) StockCardSummariesV2SearchParamsDataBuilder(org.openlmis.stockmanagement.testutils.StockCardSummariesV2SearchParamsDataBuilder) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Example 2 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryController method print.

/**
 * Print out physical inventory as a PDF file.
 *
 * @param id The UUID of the stock event to print
 * @param format The report format
 * @return ResponseEntity with the "#200 OK" HTTP response status and PDF file on success, or
 *     ResponseEntity containing the error description status.
 */
@GetMapping(value = ID_PATH_VARIABLE, params = "format")
@ResponseBody
public ModelAndView print(@PathVariable("id") UUID id, @RequestParam String format) throws JasperReportViewException {
    checkPermission(id);
    checkFormat(format.toLowerCase());
    JasperTemplate printTemplate = templateService.getByName(PRINT_PI);
    if (printTemplate == null) {
        throw new ValidationMessageException(new Message(ERROR_REPORTING_TEMPLATE_NOT_FOUND_WITH_NAME, PRINT_PI));
    }
    JasperReportsMultiFormatView jasperView = jasperReportService.getJasperReportsView(printTemplate);
    return new ModelAndView(jasperView, getParams(id, format));
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) ModelAndView(org.springframework.web.servlet.ModelAndView) JasperReportsMultiFormatView(org.springframework.web.servlet.view.jasperreports.JasperReportsMultiFormatView) JasperTemplate(org.openlmis.stockmanagement.domain.JasperTemplate) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with Message

use of org.openlmis.stockmanagement.util.Message 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 4 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class ReportsControllerIntegrationTest method return403WhenUserHasNoPermissionToViewStockCard.

@Test
public void return403WhenUserHasNoPermissionToViewStockCard() throws Exception {
    // given
    UUID programId = UUID.randomUUID();
    UUID facilityId = UUID.randomUUID();
    doThrow(new PermissionMessageException(new Message("key"))).when(permissionService).canViewStockCard(programId, facilityId);
    // when
    ResultActions resultActions = mvc.perform(get(CARD_SUMMARY_REPORT).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).param("program", programId.toString()).param("facility", facilityId.toString()));
    // then
    resultActions.andExpect(status().isForbidden());
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ResultActions(org.springframework.test.web.servlet.ResultActions) UUID(java.util.UUID) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Example 5 with Message

use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.

the class StockCardLineItemReasonControllerIntegrationTest method shouldReturn403WhenUserHasNoPermissionToManageReasons.

@Test
public void shouldReturn403WhenUserHasNoPermissionToManageReasons() throws Exception {
    doThrow(new PermissionMessageException(new Message("key"))).when(permissionService).canManageReasons();
    // 1.create reason
    ResultActions postResults = mvc.perform(MockMvcRequestBuilders.post(STOCK_CARD_LINE_ITEM_REASON_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockCardLineItemReason())));
    postResults.andExpect(status().isForbidden());
    // 2.update reason
    ResultActions putResults = mvc.perform(MockMvcRequestBuilders.put(STOCK_CARD_LINE_ITEM_REASON_API + "/" + UUID.randomUUID().toString()).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockCardLineItemReason())));
    putResults.andExpect(status().isForbidden());
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) Message(org.openlmis.stockmanagement.util.Message) ResultActions(org.springframework.test.web.servlet.ResultActions) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Aggregations

Message (org.openlmis.stockmanagement.util.Message)35 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)19 Test (org.junit.Test)13 PermissionMessageException (org.openlmis.stockmanagement.exception.PermissionMessageException)13 ResultActions (org.springframework.test.web.servlet.ResultActions)9 UUID (java.util.UUID)8 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)6 StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto)4 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)4 ResourceNotFoundException (org.openlmis.stockmanagement.exception.ResourceNotFoundException)3 IOException (java.io.IOException)2 JasperTemplate (org.openlmis.stockmanagement.domain.JasperTemplate)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)2 StockCardTemplate (org.openlmis.stockmanagement.domain.template.StockCardTemplate)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1