Search in sources :

Example 1 with StockEventLineItem

use of org.openlmis.stockmanagement.domain.event.StockEventLineItem 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;
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockEventLineItem(org.openlmis.stockmanagement.domain.event.StockEventLineItem)

Example 2 with StockEventLineItem

use of org.openlmis.stockmanagement.domain.event.StockEventLineItem in project openlmis-stockmanagement by OpenLMIS.

the class StockEventLineItemDtoTest method shouldConvertFromDtoToJpaModel.

@Test
public void shouldConvertFromDtoToJpaModel() throws Exception {
    // given
    StockEventLineItemDto lineItemDto = StockEventDtoDataBuilder.createStockEventLineItem();
    // when
    StockEventLineItem lineItem = lineItemDto.toEventLineItem();
    // then
    assertThat(lineItem.getReasonFreeText(), is(lineItemDto.getReasonFreeText()));
    assertThat(lineItem.getReasonId(), is(lineItemDto.getReasonId()));
    assertThat(lineItem.getQuantity(), is(lineItemDto.getQuantity()));
    assertThat(lineItem.getOrderableId(), is(lineItemDto.getOrderableId()));
    assertThat(lineItem.getOccurredDate(), is(lineItemDto.getOccurredDate()));
    assertThat(lineItem.getSourceId(), is(lineItemDto.getSourceId()));
    assertThat(lineItem.getDestinationId(), is(lineItemDto.getDestinationId()));
    assertThat(lineItem.getSourceFreeText(), is(lineItemDto.getSourceFreeText()));
    assertThat(lineItem.getDestinationFreeText(), is(lineItemDto.getDestinationFreeText()));
}
Also used : StockEventLineItem(org.openlmis.stockmanagement.domain.event.StockEventLineItem) Test(org.junit.Test)

Aggregations

StockEventLineItem (org.openlmis.stockmanagement.domain.event.StockEventLineItem)2 Test (org.junit.Test)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1