use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class StockCard method shallowCopy.
/**
* Creates a shallow copy of this stock card. Used during recalculation to avoid updates on
* existing stock cards and line items.
*/
public StockCard shallowCopy() {
StockCard clone = new StockCard();
clone.setId(getId());
clone.setLotId(lotId);
clone.setStockOnHand(stockOnHand);
clone.setOrderableId(orderableId);
clone.setProgramId(programId);
clone.setFacilityId(facilityId);
clone.setLineItems(new ArrayList<>());
try {
if (lineItems != null) {
for (StockCardLineItem lineItem : this.getLineItems()) {
clone.getLineItems().add((StockCardLineItem) cloneBean(lineItem));
}
}
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException ex) {
// this here to satisfy checkstyle/pmd and to make sure potential bug is not hidden.
throw new ValidationMessageException(new Message(SERVER_ERROR_SHALLOW_COPY, ex));
}
return clone;
}
use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class OrganizationControllerIntegrationTest method shouldReturn403WhenUserHasNoPermissionToManageOrganizations.
@Test
public void shouldReturn403WhenUserHasNoPermissionToManageOrganizations() throws Exception {
// given
doThrow(new PermissionMessageException(new Message("key"))).when(permissionService).canManageOrganizations();
Organization organization = createOrganization("Would Get 403");
// 1. try to create organization
ResultActions postResult = mvc.perform(post(ORGANIZATION_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(organization)));
postResult.andExpect(status().isForbidden());
// 2. try to update organization
ResultActions putResult = mvc.perform(put(ORGANIZATION_API + UUID.randomUUID().toString()).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(organization)));
putResult.andExpect(status().isForbidden());
// 3. try to retrieve organizations
ResultActions getResult = mvc.perform(get(ORGANIZATION_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON));
getResult.andExpect(status().isForbidden());
}
use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class ValidReasonAssignmentController method removeReasonAssignment.
/**
* Remove a reason assignment.
*
* @param assignmentId reason assignment id.
* @return No content status.
*/
@RequestMapping(value = "/validReasons/{id}", method = DELETE)
public ResponseEntity removeReasonAssignment(@PathVariable("id") UUID assignmentId) {
LOGGER.debug("Try to remove reason assignment {}", assignmentId);
permissionService.canManageReasons();
if (!reasonAssignmentRepository.exists(assignmentId)) {
throw new ValidationMessageException(new Message(ERROR_REASON_ASSIGNMENT_NOT_FOUND));
}
reasonAssignmentRepository.delete(assignmentId);
return new ResponseEntity<>(null, NO_CONTENT);
}
use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryTemplateController method downloadXmlTemplate.
/**
* Download report template with ".jrxml" format(extension) for Physical Inventory from database.
*
* @param response HttpServletResponse object.
*/
@GetMapping
@ResponseBody
public void downloadXmlTemplate(HttpServletResponse response) throws IOException {
LOGGER.debug("Checking right to view Physical Inventory template");
permissionService.canManageSystemSettings();
JasperTemplate piPrintTemplate = templateService.getByName(PRINT_PI);
if (piPrintTemplate == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Physical Inventory template does not exist.");
} else {
response.setContentType("application/xml");
response.addHeader("Content-Disposition", "attachment; filename=piPrint" + ".jrxml");
File file = templateService.convertJasperToXml(piPrintTemplate);
try (InputStream fis = new FileInputStream(file);
InputStream bis = new BufferedInputStream(fis)) {
IOUtils.copy(bis, response.getOutputStream());
response.flushBuffer();
} catch (IOException ex) {
throw new ValidationMessageException(ex, new Message(ERROR_IO, ex.getMessage()));
}
}
}
use of org.openlmis.stockmanagement.util.Message in project openlmis-stockmanagement by OpenLMIS.
the class StockoutNotifierTest method mockMessages.
private void mockMessages() {
Message.LocalizedMessage localizedMessage = new Message(TEST_KEY).new LocalizedMessage(SUBJECT);
when(messageService.localize(new Message(EMAIL_ACTION_REQUIRED_SUBJECT))).thenReturn(localizedMessage);
localizedMessage = new Message(TEST_KEY).new LocalizedMessage(CONTENT);
when(messageService.localize(new Message(EMAIL_ACTION_REQUIRED_CONTENT))).thenReturn(localizedMessage);
}
Aggregations