Search in sources :

Example 1 with StockCardLineItemFieldDto

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

the class StockCardTemplateServiceTest method shouldThrowExceptionWhenLineItemFieldsDuplicated.

@Test(expected = ValidationMessageException.class)
public void shouldThrowExceptionWhenLineItemFieldsDuplicated() throws Exception {
    StockCardTemplateDto dto = createTemplateDto();
    dto.getStockCardLineItemFields().add(new StockCardLineItemFieldDto("documentNo", true, 457));
    stockCardTemplateService.saveOrUpdate(dto);
}
Also used : StockCardTemplateDto(org.openlmis.stockmanagement.dto.StockCardTemplateDto) StockCardLineItemFieldDto(org.openlmis.stockmanagement.dto.StockCardLineItemFieldDto) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with StockCardLineItemFieldDto

use of org.openlmis.stockmanagement.dto.StockCardLineItemFieldDto 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 3 with StockCardLineItemFieldDto

use of org.openlmis.stockmanagement.dto.StockCardLineItemFieldDto 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 4 with StockCardLineItemFieldDto

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

the class StockCardTemplateDataBuilder method createTemplateDto.

/**
 * Create template dto.
 *
 * @return dto.
 */
public static StockCardTemplateDto createTemplateDto() {
    StockCardTemplateDto dto = new StockCardTemplateDto();
    dto.setFacilityTypeId(UUID.randomUUID());
    dto.setProgramId(UUID.randomUUID());
    dto.getStockCardFields().add(new StockCardFieldDto("packSize", true, 123));
    dto.getStockCardLineItemFields().add(new StockCardLineItemFieldDto("documentNumber", true, 456));
    return dto;
}
Also used : StockCardTemplateDto(org.openlmis.stockmanagement.dto.StockCardTemplateDto) StockCardLineItemFieldDto(org.openlmis.stockmanagement.dto.StockCardLineItemFieldDto) StockCardFieldDto(org.openlmis.stockmanagement.dto.StockCardFieldDto)

Aggregations

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