use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.
the class StockEventDataBuilder method build.
/**
* Creates stock event based on parameters from the builder.
*/
public StockEvent build() {
StockEvent event = new StockEvent(facilityId, programId, userId, processedDate, signature, documentNumber, lineItems);
event.setId(id);
return event;
}
use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.
the class StockCardSummariesV2DtoBuilderTest method before.
@Before
public void before() {
ReflectionTestUtils.setField(builder, "serviceUrl", "https://openlmis/");
orderable1 = new OrderableDtoDataBuilder().build();
orderable2 = new OrderableDtoDataBuilder().build();
orderable3 = new OrderableDtoDataBuilder().build();
StockEvent event = new StockEventDataBuilder().withFacility(facilityId).withProgram(programId).build();
stockCard = new StockCardDataBuilder(event).buildWithStockOnHandAndLineItemAndOrderableId(12, new StockCardLineItemDataBuilder().buildWithStockOnHand(16), orderable1.getId());
stockCard1 = new StockCardDataBuilder(event).buildWithStockOnHandAndLineItemAndOrderableId(26, new StockCardLineItemDataBuilder().buildWithStockOnHand(30), orderable3.getId());
stockCard2 = new StockCardDataBuilder(event).withLot(UUID.randomUUID()).buildWithStockOnHandAndLineItemAndOrderableId(22, new StockCardLineItemDataBuilder().buildWithStockOnHand(10), orderable3.getId());
fulfillMap = new HashMap<>();
fulfillMap.put(orderable1.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(asList(orderable2.getId(), orderable3.getId())).build());
fulfillMap.put(orderable2.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(Collections.singletonList(orderable1.getId())).build());
}
use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.
the class StockEventDto method toEvent.
/**
* Convert dto to jpa model.
*
* @return the converted jpa model object.
*/
public StockEvent toEvent() {
List<StockEventLineItem> domainLines = this.lineItems.stream().map(StockEventLineItemDto::toEventLineItem).collect(Collectors.toList());
StockEvent event = new StockEvent(facilityId, programId, context.getCurrentUserId(), // processed date generated by server side
now(), signature, documentNumber, domainLines);
domainLines.forEach(lineItem -> {
lineItem.setStockAdjustments(lineItem.stockAdjustments());
lineItem.setStockEvent(event);
});
return event;
}
use of org.openlmis.stockmanagement.domain.event.StockEvent 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.event.StockEvent 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