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);
}
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;
}
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));
}
}
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;
}
Aggregations