Search in sources :

Example 26 with Message

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;
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 27 with Message

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());
}
Also used : Organization(org.openlmis.stockmanagement.domain.sourcedestination.Organization) Message(org.openlmis.stockmanagement.util.Message) ResultActions(org.springframework.test.web.servlet.ResultActions) PermissionMessageException(org.openlmis.stockmanagement.exception.PermissionMessageException) Test(org.junit.Test)

Example 28 with Message

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with Message

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()));
        }
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) BufferedInputStream(java.io.BufferedInputStream) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) JasperTemplate(org.openlmis.stockmanagement.domain.JasperTemplate) FileInputStream(java.io.FileInputStream) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 30 with Message

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

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