Search in sources :

Example 6 with StockCardTemplate

use of org.openlmis.stockmanagement.domain.template.StockCardTemplate in project openlmis-stockmanagement by OpenLMIS.

the class StockCardTemplateDto method toModel.

/**
 * Convert to DB model object.
 *
 * @param availableCardFields     will be used to match stock card fields
 * @param availableLineItemFields will be use to match line item fields
 * @return DB model object.
 */
public StockCardTemplate toModel(List<AvailableStockCardFields> availableCardFields, List<AvailableStockCardLineItemFields> availableLineItemFields) {
    StockCardTemplate template = new StockCardTemplate();
    template.setFacilityTypeId(this.getFacilityTypeId());
    template.setProgramId(this.getProgramId());
    template.setStockCardFields(stockCardFields.stream().distinct().map(cardFieldDto -> cardFieldDto.toModel(template, availableCardFields)).collect(toList()));
    template.setStockCardLineItemFields(stockCardLineItemFields.stream().map(lineItemFieldDto -> lineItemFieldDto.toModel(template, availableLineItemFields)).collect(toList()));
    return template;
}
Also used : StockCardTemplate(org.openlmis.stockmanagement.domain.template.StockCardTemplate)

Example 7 with StockCardTemplate

use of org.openlmis.stockmanagement.domain.template.StockCardTemplate in project openlmis-stockmanagement by OpenLMIS.

the class StockCardTemplatesControllerIntegrationTest method shouldReturn201WhenCreateTemplate.

@Test
public void shouldReturn201WhenCreateTemplate() throws Exception {
    // given
    Mockito.doNothing().when(permissionService).canCreateStockCardTemplate();
    when(stockCardTemplateService.saveOrUpdate(any(StockCardTemplateDto.class))).thenReturn(createTemplateDto());
    // when
    ResultActions resultActions = mvc.perform(post(STOCK_CARD_TEMPLATE_API).param(ACCESS_TOKEN, ACCESS_TOKEN_VALUE).contentType(MediaType.APPLICATION_JSON).content(objectToJsonString(new StockCardTemplate())));
    // then
    resultActions.andExpect(status().isCreated());
}
Also used : StockCardTemplateDto(org.openlmis.stockmanagement.dto.StockCardTemplateDto) StockCardTemplate(org.openlmis.stockmanagement.domain.template.StockCardTemplate) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test)

Example 8 with StockCardTemplate

use of org.openlmis.stockmanagement.domain.template.StockCardTemplate in project openlmis-stockmanagement by OpenLMIS.

the class StockCardTemplateDataBuilder method createTemplate.

/**
 * Create test object for stock card template.
 *
 * @return created object.
 */
public static StockCardTemplate createTemplate() {
    StockCardTemplate template = new StockCardTemplate();
    template.setFacilityTypeId(UUID.randomUUID());
    template.setProgramId(UUID.randomUUID());
    AvailableStockCardFields packSize = new AvailableStockCardFields();
    packSize.setId(UUID.fromString("7663b4d2-d6da-11e6-bf26-cec0c932ce01"));
    AvailableStockCardLineItemFields docNumber = new AvailableStockCardLineItemFields();
    docNumber.setId(UUID.fromString("b15ad020-d6da-11e6-bf26-cec0c932ce01"));
    template.getStockCardFields().add(new StockCardFields(template, packSize, true, 123));
    template.getStockCardLineItemFields().add(new StockCardLineItemFields(template, docNumber, true, 456));
    return template;
}
Also used : StockCardTemplate(org.openlmis.stockmanagement.domain.template.StockCardTemplate) StockCardLineItemFields(org.openlmis.stockmanagement.domain.template.StockCardLineItemFields) AvailableStockCardLineItemFields(org.openlmis.stockmanagement.domain.template.AvailableStockCardLineItemFields) AvailableStockCardFields(org.openlmis.stockmanagement.domain.template.AvailableStockCardFields) AvailableStockCardLineItemFields(org.openlmis.stockmanagement.domain.template.AvailableStockCardLineItemFields) AvailableStockCardFields(org.openlmis.stockmanagement.domain.template.AvailableStockCardFields) StockCardFields(org.openlmis.stockmanagement.domain.template.StockCardFields)

Aggregations

StockCardTemplate (org.openlmis.stockmanagement.domain.template.StockCardTemplate)8 Test (org.junit.Test)4 ResultActions (org.springframework.test.web.servlet.ResultActions)4 AvailableStockCardFields (org.openlmis.stockmanagement.domain.template.AvailableStockCardFields)2 AvailableStockCardLineItemFields (org.openlmis.stockmanagement.domain.template.AvailableStockCardLineItemFields)2 Message (org.openlmis.stockmanagement.util.Message)2 Transactional (javax.transaction.Transactional)1 StockCardFields (org.openlmis.stockmanagement.domain.template.StockCardFields)1 StockCardLineItemFields (org.openlmis.stockmanagement.domain.template.StockCardLineItemFields)1 StockCardTemplateDto (org.openlmis.stockmanagement.dto.StockCardTemplateDto)1 AuthenticationException (org.openlmis.stockmanagement.exception.AuthenticationException)1 PermissionMessageException (org.openlmis.stockmanagement.exception.PermissionMessageException)1 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1