use of org.openlmis.stockmanagement.dto.StockEventLineItemDto 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.dto.StockEventLineItemDto in project openlmis-stockmanagement by OpenLMIS.
the class FreeTextValidator method validate.
@Override
public void validate(StockEventDto stockEventDto) {
LOGGER.debug("Validate free text");
if (!stockEventDto.hasLineItems()) {
return;
}
for (StockEventLineItemDto eventLineItem : stockEventDto.getLineItems()) {
checkSourceDestinationFreeTextBothPresent(eventLineItem);
checkNodeFreeText(stockEventDto, eventLineItem.getSourceId(), eventLineItem.getSourceFreeText(), ERROR_SOURCE_FREE_TEXT_NOT_ALLOWED);
checkNodeFreeText(stockEventDto, eventLineItem.getDestinationId(), eventLineItem.getDestinationFreeText(), ERROR_DESTINATION_FREE_TEXT_NOT_ALLOWED);
checkReasonFreeText(stockEventDto, eventLineItem);
}
}
use of org.openlmis.stockmanagement.dto.StockEventLineItemDto 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.dto.StockEventLineItemDto in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryAdjustmentReasonsValidatorTest method generateLineItem.
private StockEventLineItemDto generateLineItem(StockEventAdjustmentDto adjustment) {
StockEventLineItemDto lineItem = new StockEventLineItemDto();
if (null == adjustment) {
return lineItem;
}
lineItem.setStockAdjustments(Lists.newArrayList(adjustment));
return lineItem;
}
use of org.openlmis.stockmanagement.dto.StockEventLineItemDto in project openlmis-stockmanagement by OpenLMIS.
the class OrderableLotDuplicationValidatorTest method createStockEventDtoWithDuplicateOrderableLot.
private StockEventDto createStockEventDtoWithDuplicateOrderableLot(UUID reasonId) {
// given: an event with orderable appear twice
StockEventLineItemDto eventLineItem1 = new StockEventLineItemDto();
StockEventLineItemDto eventLineItem2 = new StockEventLineItemDto();
eventLineItem1.setReasonId(reasonId);
eventLineItem2.setReasonId(reasonId);
UUID orderableId = randomUUID();
UUID lotId = randomUUID();
eventLineItem1.setOrderableId(orderableId);
// same uuid string, different object, make sure the code recognize them as same uuid
eventLineItem2.setOrderableId(fromString(orderableId.toString()));
eventLineItem1.setLotId(lotId);
eventLineItem2.setLotId(fromString(lotId.toString()));
StockEventDto eventDto = new StockEventDto();
eventDto.setLineItems(Arrays.asList(eventLineItem1, eventLineItem2));
return eventDto;
}
Aggregations