Search in sources :

Example 1 with StockCardTemplateDto

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

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);
}
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 3 with StockCardTemplateDto

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"));
}
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 4 with StockCardTemplateDto

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;
}
Also used : StockCardTemplateDto(org.openlmis.stockmanagement.dto.StockCardTemplateDto) StockCardLineItemFieldDto(org.openlmis.stockmanagement.dto.StockCardLineItemFieldDto) StockCardFieldDto(org.openlmis.stockmanagement.dto.StockCardFieldDto)

Example 5 with StockCardTemplateDto

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);
}
Also used : StockCardTemplateDto(org.openlmis.stockmanagement.dto.StockCardTemplateDto) ResponseEntity(org.springframework.http.ResponseEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

StockCardTemplateDto (org.openlmis.stockmanagement.dto.StockCardTemplateDto)12 Test (org.junit.Test)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 StockCardFieldDto (org.openlmis.stockmanagement.dto.StockCardFieldDto)5 StockCardLineItemFieldDto (org.openlmis.stockmanagement.dto.StockCardLineItemFieldDto)3 UUID (java.util.UUID)2 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)1 ResponseEntity (org.springframework.http.ResponseEntity)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1