Search in sources :

Example 1 with StockEventLineItemDto

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));
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID(java.util.UUID) Test(org.junit.Test)

Example 2 with StockEventLineItemDto

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);
    }
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto)

Example 3 with StockEventLineItemDto

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;
}
Also used : FacilityReferenceDataService(org.openlmis.stockmanagement.service.referencedata.FacilityReferenceDataService) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) OrderableReferenceDataService(org.openlmis.stockmanagement.service.referencedata.OrderableReferenceDataService) OrganizationRepository(org.openlmis.stockmanagement.repository.OrganizationRepository) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) CollectionUtils.isEmpty(org.apache.commons.collections4.CollectionUtils.isEmpty) OrderableLotIdentity.identityOf(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity.identityOf) Collections.singletonList(java.util.Collections.singletonList) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) HashSet(java.util.HashSet) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) Lists(com.google.common.collect.Lists) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) LotReferenceDataService(org.openlmis.stockmanagement.service.referencedata.LotReferenceDataService) Service(org.springframework.stereotype.Service) PHYSICAL_INVENTORY(org.openlmis.stockmanagement.domain.reason.ReasonCategory.PHYSICAL_INVENTORY) Pageable(org.springframework.data.domain.Pageable) StockCardRepository(org.openlmis.stockmanagement.repository.StockCardRepository) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) STOCK_CARDS_VIEW(org.openlmis.stockmanagement.service.PermissionService.STOCK_CARDS_VIEW) Node(org.openlmis.stockmanagement.domain.sourcedestination.Node) StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) Logger(org.slf4j.Logger) PermissionStrings(org.openlmis.stockmanagement.service.referencedata.PermissionStrings) UserDto(org.openlmis.stockmanagement.dto.referencedata.UserDto) Collection(java.util.Collection) Set(java.util.Set) Pagination(org.openlmis.stockmanagement.web.Pagination) UUID(java.util.UUID) NotNull(javax.validation.constraints.NotNull) Page(org.springframework.data.domain.Page) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) PermissionStringDto(org.openlmis.stockmanagement.service.referencedata.PermissionStringDto) List(java.util.List) MessageService(org.openlmis.stockmanagement.i18n.MessageService) AuthenticationHelper(org.openlmis.stockmanagement.util.AuthenticationHelper) Message(org.openlmis.stockmanagement.util.Message) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) StockCardLineItem.createLineItemFrom(org.openlmis.stockmanagement.domain.card.StockCardLineItem.createLineItemFrom) StockCard.createStockCardFrom(org.openlmis.stockmanagement.domain.card.StockCard.createStockCardFrom) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) StockCard(org.openlmis.stockmanagement.domain.card.StockCard)

Example 4 with StockEventLineItemDto

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;
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto)

Example 5 with StockEventLineItemDto

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;
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID)

Aggregations

StockEventLineItemDto (org.openlmis.stockmanagement.dto.StockEventLineItemDto)16 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)8 UUID (java.util.UUID)5 Test (org.junit.Test)4 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)3 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)3 UUID.randomUUID (java.util.UUID.randomUUID)2 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 Lists (com.google.common.collect.Lists)1 ZonedDateTime (java.time.ZonedDateTime)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 NotNull (javax.validation.constraints.NotNull)1 CollectionUtils.isEmpty (org.apache.commons.collections4.CollectionUtils.isEmpty)1 StockCard.createStockCardFrom (org.openlmis.stockmanagement.domain.card.StockCard.createStockCardFrom)1 StockCardLineItem.createLineItemFrom (org.openlmis.stockmanagement.domain.card.StockCardLineItem.createLineItemFrom)1