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