use of org.openlmis.stockmanagement.domain.common.VvmApplicable 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);
}
}
}
use of org.openlmis.stockmanagement.domain.common.VvmApplicable in project openlmis-stockmanagement by OpenLMIS.
the class VvmValidatorTest method shouldRejectIfOrderableDisabledVvmAndLineItemHasVvmStatus.
@Test(expected = ValidationMessageException.class)
public void shouldRejectIfOrderableDisabledVvmAndLineItemHasVvmStatus() {
OrderableDto orderable = generateOrderable();
orderable.setExtraData(Collections.singletonMap("useVVM", "false"));
VvmApplicable lineItem = generateVvmApplicable(orderable);
lineItem.setExtraData(Collections.singletonMap("vvmStatus", "status"));
validator.validate(Collections.singletonList(lineItem), ERROR_MESSAGE, false);
}
use of org.openlmis.stockmanagement.domain.common.VvmApplicable in project openlmis-stockmanagement by OpenLMIS.
the class VvmValidatorTest method shouldNotRejectIfOrderableDisabledVvmAndLineItemHasNoVvmStatus.
@Test
public void shouldNotRejectIfOrderableDisabledVvmAndLineItemHasNoVvmStatus() {
OrderableDto orderable = generateOrderable();
orderable.setExtraData(Collections.singletonMap("useVVM", "false"));
VvmApplicable lineItem = generateVvmApplicable(orderable);
validator.validate(Collections.singletonList(lineItem), ERROR_MESSAGE, false);
}
use of org.openlmis.stockmanagement.domain.common.VvmApplicable in project openlmis-stockmanagement by OpenLMIS.
the class VvmValidatorTest method shouldNotRejectIfOrderableEnabledVvmAndLineItemHasVvmStatus.
@Test
public void shouldNotRejectIfOrderableEnabledVvmAndLineItemHasVvmStatus() {
OrderableDto orderable = generateOrderable();
orderable.setExtraData(Collections.singletonMap("useVVM", "true"));
VvmApplicable lineItem = generateVvmApplicable(orderable);
lineItem.setExtraData(Collections.singletonMap("vvmStatus", "status"));
validator.validate(Collections.singletonList(lineItem), ERROR_MESSAGE, false);
}
use of org.openlmis.stockmanagement.domain.common.VvmApplicable in project openlmis-stockmanagement by OpenLMIS.
the class VvmValidatorTest method shouldRejectIfOrderableNotConfiguredVvmAndLineItemHasVvmStatus.
@Test(expected = ValidationMessageException.class)
public void shouldRejectIfOrderableNotConfiguredVvmAndLineItemHasVvmStatus() {
OrderableDto orderable = generateOrderable();
VvmApplicable lineItem = generateVvmApplicable(orderable);
lineItem.setExtraData(Collections.singletonMap("vvmStatus", "status"));
validator.validate(Collections.singletonList(lineItem), ERROR_MESSAGE, false);
}
Aggregations