Search in sources :

Example 1 with StockCardFieldDto

use of org.openlmis.stockmanagement.dto.StockCardFieldDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardTemplateServiceTest method shouldThrowExceptionWhenCardFieldsDuplicated.

@Test(expected = ValidationMessageException.class)
public void shouldThrowExceptionWhenCardFieldsDuplicated() throws Exception {
    StockCardTemplateDto dto = createTemplateDto();
    dto.getStockCardFields().add(new StockCardFieldDto("packSize", true, 124));
    stockCardTemplateService.saveOrUpdate(dto);
}
Also used : StockCardTemplateDto(org.openlmis.stockmanagement.dto.StockCardTemplateDto) StockCardFieldDto(org.openlmis.stockmanagement.dto.StockCardFieldDto) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with StockCardFieldDto

use of org.openlmis.stockmanagement.dto.StockCardFieldDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardTemplateServiceTest method shouldUpdateExistingTemplate.

@Test
public void shouldUpdateExistingTemplate() {
    // given: there is an existing template
    StockCardTemplateDto savedTemplate = stockCardTemplateService.saveOrUpdate(createTemplateDto());
    UUID facilityTypeId = savedTemplate.getFacilityTypeId();
    UUID programId = savedTemplate.getProgramId();
    // when: try to save a template with the same program and facility type
    StockCardTemplateDto newTemplate = createTemplateDto();
    newTemplate.setFacilityTypeId(facilityTypeId);
    newTemplate.setProgramId(programId);
    newTemplate.getStockCardFields().get(0).setDisplayOrder(321);
    stockCardTemplateService.saveOrUpdate(newTemplate);
    StockCardTemplateDto updatedTemplate = stockCardTemplateService.findByProgramIdAndFacilityTypeId(programId, facilityTypeId);
    // then
    assertThat(updatedTemplate.getStockCardFields().size(), is(1));
    StockCardFieldDto firstFields = updatedTemplate.getStockCardFields().get(0);
    assertThat(firstFields.getDisplayOrder(), is(321));
    assertThat(firstFields.getName(), is("packSize"));
}
Also used : StockCardTemplateDto(org.openlmis.stockmanagement.dto.StockCardTemplateDto) UUID(java.util.UUID) StockCardFieldDto(org.openlmis.stockmanagement.dto.StockCardFieldDto) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with StockCardFieldDto

use of org.openlmis.stockmanagement.dto.StockCardFieldDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardTemplateService method getDefaultStockCardTemplate.

/**
 * Get default stock card template, with all fields set to false.
 *
 * @return default stock card template.
 */
public StockCardTemplateDto getDefaultStockCardTemplate() {
    List<StockCardFieldDto> cardFieldDtos = convertAllFieldsToDto(cardFieldsRepo, this::convertModelToDefaultDto);
    List<StockCardLineItemFieldDto> lineItemFieldDtos = convertAllFieldsToDto(lineItemFieldsRepo, this::convertModelToDefaultDto);
    StockCardTemplateDto dto = new StockCardTemplateDto();
    dto.setStockCardFields(cardFieldDtos);
    dto.setStockCardLineItemFields(lineItemFieldDtos);
    return dto;
}
Also used : StockCardTemplateDto(org.openlmis.stockmanagement.dto.StockCardTemplateDto) StockCardLineItemFieldDto(org.openlmis.stockmanagement.dto.StockCardLineItemFieldDto) StockCardFieldDto(org.openlmis.stockmanagement.dto.StockCardFieldDto)

Example 4 with StockCardFieldDto

use of org.openlmis.stockmanagement.dto.StockCardFieldDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardTemplateService method checkFieldsDuplication.

private void checkFieldsDuplication(StockCardTemplateDto templateDto) {
    List<StockCardFieldDto> cardFields = templateDto.getStockCardFields();
    long cardFieldCount = cardFields.stream().map(StockCardFieldDto::getName).distinct().count();
    List<StockCardLineItemFieldDto> lineItemFields = templateDto.getStockCardLineItemFields();
    long lineItemFieldCount = lineItemFields.stream().map(StockCardLineItemFieldDto::getName).distinct().count();
    if (cardFieldCount < cardFields.size() || lineItemFieldCount < lineItemFields.size()) {
        throw new ValidationMessageException(new Message(ERROR_STOCK_CARD_FIELD_DUPLICATED));
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) StockCardLineItemFieldDto(org.openlmis.stockmanagement.dto.StockCardLineItemFieldDto) StockCardFieldDto(org.openlmis.stockmanagement.dto.StockCardFieldDto)

Example 5 with StockCardFieldDto

use of org.openlmis.stockmanagement.dto.StockCardFieldDto in project openlmis-stockmanagement by OpenLMIS.

the class StockCardTemplateServiceTest method shouldNotSaveTemplateWithUnavailableField.

@Test(expected = ValidationMessageException.class)
public void shouldNotSaveTemplateWithUnavailableField() {
    // given
    StockCardTemplateDto templateDto = createTemplateDto();
    templateDto.getStockCardFields().add(new StockCardFieldDto("i do not exist", false, 1));
    // when
    stockCardTemplateService.saveOrUpdate(templateDto);
}
Also used : StockCardTemplateDto(org.openlmis.stockmanagement.dto.StockCardTemplateDto) StockCardFieldDto(org.openlmis.stockmanagement.dto.StockCardFieldDto) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

StockCardFieldDto (org.openlmis.stockmanagement.dto.StockCardFieldDto)6 StockCardTemplateDto (org.openlmis.stockmanagement.dto.StockCardTemplateDto)5 Test (org.junit.Test)3 StockCardLineItemFieldDto (org.openlmis.stockmanagement.dto.StockCardLineItemFieldDto)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 UUID (java.util.UUID)1 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)1 Message (org.openlmis.stockmanagement.util.Message)1