Search in sources :

Example 11 with OrderableLotIdentity

use of org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity in project openlmis-stockmanagement by OpenLMIS.

the class ActiveStockCardsValidator method checkAllStockCardsCovered.

private void checkAllStockCardsCovered(StockEventDto stockEventDto) {
    List<OrderableLotIdentity> coveredIdentities = stockEventDto.getLineItems().stream().map(OrderableLotIdentity::identityOf).collect(toList());
    boolean anyMissing = stockCardRepository.getIdentitiesBy(stockEventDto.getProgramId(), stockEventDto.getFacilityId()).stream().anyMatch(identity -> !coveredIdentities.contains(identity));
    if (anyMissing) {
        throw new ValidationMessageException(new Message(ERROR_PHYSICAL_INVENTORY_NOT_INCLUDE_ACTIVE_STOCK_CARD));
    }
}
Also used : Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)

Example 12 with OrderableLotIdentity

use of org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity in project openlmis-stockmanagement by OpenLMIS.

the class ActiveStockCardsValidatorTest method shouldThrowExceptionIfExistingCardLotNotCovered.

@Test
public void shouldThrowExceptionIfExistingCardLotNotCovered() throws Exception {
    expectedEx.expectMessage(ERROR_PHYSICAL_INVENTORY_NOT_INCLUDE_ACTIVE_STOCK_CARD);
    // given
    StockEventDto stockEventDto = createNoSourceDestinationStockEventDto();
    stockEventDto.getLineItems().get(0).setReasonId(null);
    stockEventDto.getLineItems().get(0).setLotId(randomUUID());
    when(stockCardRepository.getIdentitiesBy(stockEventDto.getProgramId(), stockEventDto.getFacilityId())).thenReturn(singletonList(new OrderableLotIdentity(randomUUID(), randomUUID())));
    // when
    activeStockCardsValidator.validate(stockEventDto);
}
Also used : OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createNoSourceDestinationStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test)

Aggregations

OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)12 UUID (java.util.UUID)6 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)6 Test (org.junit.Test)5 List (java.util.List)4 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)4 Message (org.openlmis.stockmanagement.util.Message)4 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)3 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)3 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)3 StockCardRepository (org.openlmis.stockmanagement.repository.StockCardRepository)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Service (org.springframework.stereotype.Service)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Set (java.util.Set)2 Collectors.toMap (java.util.stream.Collectors.toMap)2