Search in sources :

Example 6 with ProgramDto

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

the class StockCardBaseService method createDtos.

protected List<StockCardDto> createDtos(List<StockCard> stockCards) {
    if (stockCards.isEmpty()) {
        return emptyList();
    }
    StockCard firstCard = stockCards.get(0);
    LOGGER.debug("Calling ref data to retrieve facility info for card");
    FacilityDto facility = facilityRefDataService.findOne(firstCard.getFacilityId());
    LOGGER.debug("Calling ref data to retrieve program info for card");
    ProgramDto program = programRefDataService.findOne(firstCard.getProgramId());
    return stockCards.stream().map(card -> cardToDto(facility, program, card)).collect(toList());
}
Also used : CollectionUtils.isEmpty(org.springframework.util.CollectionUtils.isEmpty) FacilityReferenceDataService(org.openlmis.stockmanagement.service.referencedata.FacilityReferenceDataService) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) Logger(org.slf4j.Logger) Collections.emptyList(java.util.Collections.emptyList) ProgramReferenceDataService(org.openlmis.stockmanagement.service.referencedata.ProgramReferenceDataService) LoggerFactory(org.slf4j.LoggerFactory) LotDto(org.openlmis.stockmanagement.dto.referencedata.LotDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ProgramDto(org.openlmis.stockmanagement.dto.referencedata.ProgramDto) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) Service(org.springframework.stereotype.Service) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) StockCardLineItemDto(org.openlmis.stockmanagement.dto.StockCardLineItemDto) ProgramDto(org.openlmis.stockmanagement.dto.referencedata.ProgramDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto)

Example 7 with ProgramDto

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

the class StockEventProcessContextBuilderTest method testBuildContext.

private void testBuildContext(StockEventDto stockEventDto) {
    // given
    UUID lotId = UUID.randomUUID();
    LotDto lot = new LotDto();
    lot.setId(lotId);
    StockEventDtoDataBuilder.createStockEventDto();
    stockEventDto.getLineItems().get(0).setLotId(lotId);
    ProgramDto programDto = new ProgramDto();
    FacilityDto facilityDto = new FacilityDto();
    ArrayList<OrderableDto> approvedProductDtos = new ArrayList<>();
    when(programService.findOne(stockEventDto.getProgramId())).thenReturn(programDto);
    when(facilityService.findOne(stockEventDto.getFacilityId())).thenReturn(facilityDto);
    when(orderableReferenceDataService.findAll()).thenReturn(approvedProductDtos);
    when(lotReferenceDataService.findOne(lotId)).thenReturn(lot);
    // when
    StockEventProcessContext context = contextBuilder.buildContext(stockEventDto);
    // then
    assertThat(context.getCurrentUserId(), is(userDto.getId()));
    assertThat(context.getProgram(), is(programDto));
    assertThat(context.getFacility(), is(facilityDto));
    assertThat(context.getAllApprovedProducts(), is(approvedProductDtos));
    assertThat(context.findLot(lotId), is(lot));
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) ProgramDto(org.openlmis.stockmanagement.dto.referencedata.ProgramDto) ArrayList(java.util.ArrayList) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) UUID(java.util.UUID) LotDto(org.openlmis.stockmanagement.dto.referencedata.LotDto) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext)

Aggregations

ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)7 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)5 UUID (java.util.UUID)4 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)4 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)4 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)3 List (java.util.List)2 UUID.randomUUID (java.util.UUID.randomUUID)2 Before (org.junit.Before)2 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)2 StockCardLineItemDto (org.openlmis.stockmanagement.dto.StockCardLineItemDto)2 FacilityTypeDto (org.openlmis.stockmanagement.dto.referencedata.FacilityTypeDto)2 StockEventProcessContext (org.openlmis.stockmanagement.util.StockEventProcessContext)2 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 Collectors.toList (java.util.stream.Collectors.toList)1 Test (org.junit.Test)1 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1