use of org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity in project openlmis-stockmanagement by OpenLMIS.
the class StockCardSummariesServiceTest method shouldCreateDummyCards.
@Test
public void shouldCreateDummyCards() throws Exception {
// given
UUID orderable1Id = randomUUID();
UUID orderable2Id = randomUUID();
UUID orderable3Id = randomUUID();
UUID orderable4Id = randomUUID();
OrderableDto orderable1 = createOrderableDto(orderable1Id, "1");
OrderableDto orderable2 = createOrderableDto(orderable2Id, "2");
orderable2.getIdentifiers().put("tradeItem", randomUUID().toString());
OrderableDto orderable3 = createOrderableDto(orderable3Id, "3");
OrderableDto orderable4 = createOrderableDto(orderable4Id, "4");
UUID programId = randomUUID();
UUID facilityId = randomUUID();
// 1,2,3,4 all approved
when(orderableReferenceDataService.findAll()).thenReturn(asList(orderable1, orderable2, orderable3, orderable4));
// but only 1, 3 have cards. 2, 4 don't have cards.
when(cardRepository.getIdentitiesBy(programId, facilityId)).thenReturn(asList(new OrderableLotIdentity(orderable1Id, null), new OrderableLotIdentity(orderable3Id, null)));
LotDto lotDto = new LotDto();
lotDto.setId(randomUUID());
// 2 has a lot
when(lotReferenceDataService.getAllLotsOf(fromString(orderable2.getIdentifiers().get("tradeItem")))).thenReturn(singletonList(lotDto));
// when
List<StockCardDto> cardDtos = stockCardSummariesService.createDummyStockCards(programId, facilityId);
// then
assertThat(cardDtos.size(), is(3));
String orderablePropertyName = "orderable";
String lotPropertyName = "lot";
String idPropertyName = "id";
String lineItemsPropertyName = "lineItems";
String stockOnHandPropertyName = "stockOnHand";
String lastUpdatePropertyName = "lastUpdate";
// 2 and lot
assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable2)), hasProperty(lotPropertyName, is(lotDto)), hasProperty(idPropertyName, nullValue()), hasProperty(stockOnHandPropertyName, nullValue()), hasProperty(lineItemsPropertyName, nullValue()))));
// 2 and no lot
assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable2)), hasProperty(lotPropertyName, is(nullValue())), hasProperty(idPropertyName, nullValue()), hasProperty(stockOnHandPropertyName, nullValue()), hasProperty(lastUpdatePropertyName, nullValue()), hasProperty(lineItemsPropertyName, nullValue()))));
// 4 and no lot
assertThat(cardDtos, hasItem(allOf(hasProperty(orderablePropertyName, is(orderable4)), hasProperty(lotPropertyName, is(nullValue())), hasProperty(idPropertyName, nullValue()), hasProperty(stockOnHandPropertyName, nullValue()), hasProperty(lastUpdatePropertyName, nullValue()), hasProperty(lineItemsPropertyName, nullValue()))));
}
use of org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity in project openlmis-stockmanagement by OpenLMIS.
the class StockEventNotificationProcessorTest method shouldCallStockoutNotifierForEveryCard.
@Test
public void shouldCallStockoutNotifierForEveryCard() throws Exception {
// given
UUID anotherStockCardId = UUID.randomUUID();
UUID anotherOrderableId = UUID.randomUUID();
UUID anotherLotId = UUID.randomUUID();
StockCard anotherStockCard = new StockCard(null, facilityId, programId, orderableId, lotId, null, 0);
anotherStockCard.setId(anotherStockCardId);
StockEventLineItemDto secondLineItem = createStockEventLineItem();
secondLineItem.setOrderableId(anotherOrderableId);
secondLineItem.setLotId(anotherLotId);
secondLineItem.setQuantity(0);
stockEventDto.setLineItems(Arrays.asList(firstLineItem, secondLineItem));
when(context.findCard(new OrderableLotIdentity(orderableId, lotId))).thenReturn(stockCard);
when(context.findCard(new OrderableLotIdentity(anotherOrderableId, anotherLotId))).thenReturn(anotherStockCard);
// when
stockEventNotificationProcessor.callAllNotifications(stockEventDto);
// then
verify(stockoutNotifier, times(2)).notifyStockEditors(any(StockCard.class));
}
use of org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryService method submitPhysicalInventory.
/**
* Persist physical inventory, with an event id.
*
* @param inventoryDto inventoryDto.
* @param eventId eventId.
*/
void submitPhysicalInventory(PhysicalInventoryDto inventoryDto, UUID eventId) {
LOGGER.info("submit physical inventory");
PhysicalInventory inventory = inventoryDto.toPhysicalInventoryForSubmit();
if (null != eventId) {
StockEvent event = new StockEvent();
event.setId(eventId);
inventory.setStockEvent(event);
}
Map<OrderableLotIdentity, StockCard> cards = stockCardRepository.findByProgramIdAndFacilityId(inventory.getProgramId(), inventory.getFacilityId()).stream().collect(toMap(OrderableLotIdentity::identityOf, card -> card));
for (PhysicalInventoryLineItem line : inventory.getLineItems()) {
StockCard foundCard = cards.get(OrderableLotIdentity.identityOf(line));
// modified during recalculation, this will avoid persistence of those modified models
if (foundCard != null) {
StockCard stockCard = foundCard.shallowCopy();
stockCard.calculateStockOnHand();
line.setPreviousStockOnHandWhenSubmitted(stockCard.getStockOnHand());
}
}
physicalInventoriesRepository.save(inventory);
}
use of org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity in project openlmis-stockmanagement by OpenLMIS.
the class StockCardService method findOrCreateCard.
private StockCard findOrCreateCard(StockEventDto eventDto, StockEventLineItemDto eventLineItem, UUID savedEventId, List<StockCard> cardsToUpdate) {
OrderableLotIdentity identity = identityOf(eventLineItem);
StockCard card = eventDto.getContext().findCard(identity);
if (null == card) {
card = cardsToUpdate.stream().filter(elem -> identityOf(elem).equals(identity)).findFirst().orElse(null);
}
if (null == card) {
card = createStockCardFrom(eventDto, eventLineItem, savedEventId);
}
if (cardsToUpdate.stream().noneMatch(elem -> identityOf(elem).equals(identity))) {
cardsToUpdate.add(card);
}
return card;
}
use of org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity in project openlmis-stockmanagement by OpenLMIS.
the class StockCardSummariesService method createOrderableLots.
private Map<OrderableLotIdentity, OrderableLot> createOrderableLots(List<OrderableDto> orderableDtos) {
Stream<OrderableLot> orderableLots = orderableDtos.stream().flatMap(this::lotsOfOrderable);
Stream<OrderableLot> orderablesOnly = orderableDtos.stream().map(orderableDto -> new OrderableLot(orderableDto, null));
return concat(orderableLots, orderablesOnly).collect(toMap(OrderableLotIdentity::identityOf, orderableLot -> orderableLot));
}
Aggregations