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);
}
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));
}
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());
}
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());
}
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());
}
Aggregations