use of org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_EVENT_ORDERABLE_INVALID in project openlmis-stockmanagement by OpenLMIS.
the class VvmValidator method validate.
/**
* Validates whether the vvm applicables have proper vvm status (if applicable).
* Throws ValidationMessageException if any of items is in invalid state.
* @param vvmApplicables list of items to test
* @param messageKey error message key for exception
* @param ignoreMissingOrderable whether should
*/
public void validate(List<? extends VvmApplicable> vvmApplicables, String messageKey, boolean ignoreMissingOrderable) {
Set<UUID> orderableIds = vvmApplicables.stream().map(VvmApplicable::getOrderableId).collect(Collectors.toSet());
List<OrderableDto> orderables = orderableReferenceDataService.findByIds(orderableIds);
Map<UUID, OrderableDto> groupById = orderables.stream().collect(Collectors.toMap(OrderableDto::getId, orderable -> orderable));
for (VvmApplicable item : vvmApplicables) {
OrderableDto orderable = groupById.get(item.getOrderableId());
if (null == orderable) {
if (ignoreMissingOrderable) {
continue;
} else {
throw new ValidationMessageException(ERROR_EVENT_ORDERABLE_INVALID);
}
}
boolean useVvm = false;
boolean hasVvmStatus = false;
if (orderable.getExtraData() != null) {
useVvm = Boolean.parseBoolean(orderable.getExtraData().get(USE_VVM));
}
if (item.getExtraData() != null) {
hasVvmStatus = item.getExtraData().get(VVM_STATUS) != null;
}
if (!useVvm && hasVvmStatus) {
throw new ValidationMessageException(messageKey);
}
}
}
Aggregations