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