Search in sources :

Example 21 with StockCard

use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.

the class StockEventNotificationProcessor method callNotifications.

private void callNotifications(StockEventDto event, StockEventLineItemDto eventLine) {
    XLOGGER.entry(event, eventLine);
    Profiler profiler = new Profiler("CALL_NOTIFICATION_FOR_LINE_ITEM");
    profiler.setLogger(XLOGGER);
    profiler.start("COPY_STOCK_CARD");
    OrderableLotIdentity identity = OrderableLotIdentity.identityOf(eventLine);
    StockCard card = event.getContext().findCard(identity);
    StockCard copy = card.shallowCopy();
    for (StockCardLineItem line : copy.getLineItems()) {
        StockCardLineItemReason reason = line.getReason();
        if (null != reason) {
            line.setReason(event.getContext().findCardReason(reason.getId()));
        }
    }
    profiler.start("CALCULATE_STOCK_ON_HAND");
    copy.calculateStockOnHand();
    profiler.start("NOTIFY_STOCK_CARD_EDITORS");
    if (copy.getStockOnHand() == 0) {
        stockoutNotifier.notifyStockEditors(copy);
    }
    profiler.stop().log();
    XLOGGER.exit();
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) Profiler(org.slf4j.profiler.Profiler) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) StockCard(org.openlmis.stockmanagement.domain.card.StockCard)

Example 22 with StockCard

use of org.openlmis.stockmanagement.domain.card.StockCard 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 23 with StockCard

use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.

the class StockCardRepositoryIntegrationTest method findByIds.

@Test
public void findByIds() throws Exception {
    pageable = new PageRequest(0, 10);
    stockCard1 = stockCardRepository.save(generateInstance());
    stockCard2 = stockCardRepository.save(generateInstance());
    stockCardRepository.save(generateInstance());
    stockCardRepository.save(generateInstance());
    Page<StockCard> result = stockCardRepository.findByIdIn(asList(stockCard1.getId(), stockCard2.getId()), pageable);
    assertEquals(10, result.getSize());
    assertEquals(0, result.getNumber());
    assertThat(result.getContent(), hasItems(stockCard1, stockCard2));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) Test(org.junit.Test)

Example 24 with StockCard

use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceIntegrationTest method shouldSaveLineItemsWithProgramFacilityOrderableForNonFirstMovement.

@Test
public void shouldSaveLineItemsWithProgramFacilityOrderableForNonFirstMovement() throws Exception {
    // given
    // 1. there is an existing event that caused a stock card to exist
    StockEventDto existingEventDto = createStockEventDto();
    final StockEvent existingEvent = save(existingEventDto, randomUUID());
    UUID orderableId = existingEventDto.getLineItems().get(0).getOrderableId();
    // 2. and there is a new event coming
    StockEventDto newEventDto = createStockEventDto();
    newEventDto.setProgramId(existingEventDto.getProgramId());
    newEventDto.setFacilityId(existingEventDto.getFacilityId());
    newEventDto.getLineItems().get(0).setOrderableId(orderableId);
    // when
    long cardAmountBeforeSave = stockCardRepository.count();
    UUID userId = randomUUID();
    StockEvent savedNewEvent = save(newEventDto, userId);
    long cardAmountAfterSave = stockCardRepository.count();
    // then
    StockCard savedCard = stockCardRepository.findByOriginEvent(existingEvent);
    List<StockCardLineItem> lineItems = savedCard.getLineItems();
    lineItems.sort(Comparator.comparing(StockCardLineItem::getProcessedDate));
    StockCardLineItem latestLineItem = lineItems.get(lineItems.size() - 1);
    assertThat(cardAmountAfterSave, is(cardAmountBeforeSave));
    assertThat(latestLineItem.getOriginEvent().getId(), is(savedNewEvent.getId()));
    assertThat(latestLineItem.getStockCard().getId(), is(savedCard.getId()));
    assertThat(latestLineItem.getUserId(), is(userId));
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with StockCard

use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceIntegrationTest method shouldSaveStockCardLineItemsAndCreateStockCardForFirstMovement.

@Test
public void shouldSaveStockCardLineItemsAndCreateStockCardForFirstMovement() throws Exception {
    // given
    UUID userId = randomUUID();
    StockEventDto stockEventDto = createStockEventDto();
    StockEvent savedEvent = save(stockEventDto, userId);
    // when
    stockCardService.saveFromEvent(stockEventDto, savedEvent.getId());
    // then
    StockCard savedCard = stockCardRepository.findByOriginEvent(savedEvent);
    StockCardLineItem firstLineItem = savedCard.getLineItems().get(0);
    assertThat(firstLineItem.getUserId(), is(userId));
    assertThat(firstLineItem.getSource().isRefDataFacility(), is(true));
    assertThat(firstLineItem.getDestination().isRefDataFacility(), is(false));
    assertThat(firstLineItem.getStockCard().getOriginEvent().getId(), is(savedEvent.getId()));
    assertThat(firstLineItem.getStockCard().getFacilityId(), is(savedEvent.getFacilityId()));
    assertThat(firstLineItem.getStockCard().getProgramId(), is(savedEvent.getProgramId()));
    UUID orderableId = savedEvent.getLineItems().get(0).getOrderableId();
    assertThat(firstLineItem.getStockCard().getOrderableId(), is(orderableId));
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

StockCard (org.openlmis.stockmanagement.domain.card.StockCard)35 Test (org.junit.Test)20 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)12 UUID (java.util.UUID)11 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)11 LocalDate (java.time.LocalDate)10 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)9 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)6 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)6 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)6 List (java.util.List)5 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)5 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)5 UUID.randomUUID (java.util.UUID.randomUUID)4 StockEventLineItemDto (org.openlmis.stockmanagement.dto.StockEventLineItemDto)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)3 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)3 ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)3