Search in sources :

Example 1 with ERROR_EVENT_ORDERABLE_LOT_DUPLICATION

use of org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_EVENT_ORDERABLE_LOT_DUPLICATION in project openlmis-stockmanagement by OpenLMIS.

the class OrderableLotDuplicationValidator method validate.

@Override
public void validate(StockEventDto stockEventDto) {
    // duplication is not allow in physical inventory, but is allowed in adjustment
    if (!stockEventDto.hasLineItems() || !stockEventDto.isPhysicalInventory()) {
        return;
    }
    Set<OrderableLotIdentity> nonDuplicates = new HashSet<>();
    Set<OrderableLotIdentity> duplicates = stockEventDto.getLineItems().stream().map(OrderableLotIdentity::identityOf).filter(lotIdentity -> !nonDuplicates.add(lotIdentity)).collect(toSet());
    if (duplicates.size() > 0) {
        throw new ValidationMessageException(new Message(ERROR_EVENT_ORDERABLE_LOT_DUPLICATION, duplicates));
    }
}
Also used : HashSet(java.util.HashSet) ERROR_EVENT_ORDERABLE_LOT_DUPLICATION(org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_EVENT_ORDERABLE_LOT_DUPLICATION) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) Message(org.openlmis.stockmanagement.util.Message) Component(org.springframework.stereotype.Component) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) Set(java.util.Set) Collectors.toSet(java.util.stream.Collectors.toSet) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Message(org.openlmis.stockmanagement.util.Message) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)1 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)1 ERROR_EVENT_ORDERABLE_LOT_DUPLICATION (org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_EVENT_ORDERABLE_LOT_DUPLICATION)1 Message (org.openlmis.stockmanagement.util.Message)1 Component (org.springframework.stereotype.Component)1