use of org.openlmis.stockmanagement.dto.StockCardTemplateDto 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.StockCardTemplateDto 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.StockCardTemplateDto 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.StockCardTemplateDto 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.StockCardTemplateDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardTemplatesController method createStockCardTemplate.
/**
* Create stock card template.
*
* @param stockCardTemplate a stock card template bound to request body.
* @return The created stock card template.
*/
@RequestMapping(value = "/stockCardTemplates", method = POST)
public ResponseEntity<StockCardTemplateDto> createStockCardTemplate(@RequestBody StockCardTemplateDto stockCardTemplate) {
permissionService.canCreateStockCardTemplate();
StockCardTemplateDto savedTemplate = stockCardTemplateService.saveOrUpdate(stockCardTemplate);
return new ResponseEntity<>(savedTemplate, CREATED);
}
Aggregations