0

We have a VDM helper class as below

MmpurReqFluentHelper helper = (MmpurReqFluentHelper) valueHelpService.getAllMmpurReq();

helper.filter(FilterExpressionHelper<>); 

How can we convert a given StructuredQuery containing filters (structure attached in the picture) into a FilterExpressionHelper<> required by the helper class as given in the above line?

StructuredQuery structure

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

1

Edit: There actually is a convenience API:

final StructuredQuery query;
final MmpurReqFluentHelper helper;

ValueBoolean filter = query.getFilters().stream().reduce(ValueBoolean::and).orElse(null);
helper.filter(new UncheckedFilterExpression<>(filter));

It's not expected to use classes from Generic OData Client API (StructuredQuery) on the OData V2/V4 VDM API (MmpurReqFluentHelper). However you can apply the following workaround:

final StructuredQuery query;
final MmpurReqFluentHelper helper;

helper.filter(new FilterExpressionHelper<EntityT>() {
    @Override
    @Nullable
    FilterExpression toLegacyFilterExpression() {
        throw new IllegalStateException();
    }
    @Override
    @Nullable
    ValueBoolean toClientFilterExpression() {
        return query.getFilters().stream().reduce(ValueBoolean::and).orElse(null);
    }
});

Please replace EntityT with the respective entity type reference.

Alexander Dümont
  • 903
  • 1
  • 5
  • 9