Request Validation and Filtering by Flags – Introduction
We are working on a service that should accept some kind of request.
The request has List of Items. In the response we need to tell the client whether the request is valid and also some information about each item: is it valid or not. If it’s valid, it will be persisted. If it’s not, it should be filtered out. So the response can have information of how many items are valid (and sent to be persisted) and list of information of the filtered out items.
The request has another metadata in it. It has collection (set) of flags. The filtering and validation is based on the flags of the request. So basically one request may be validated and filtered differently than the other, based on the flags of each request.
We might have general validations / filters that need to be applied to any request, whatever flags it has.
We’ll hold a mapping of flag-to-filters, and flag-to-validation.
Has flags and items.
Filter, Filter-Engine, Flags-MapperDevelopment Approach
We have a basic request already, as the service is up and running, but we don’t have any infrastructure for flags, flag-mapping, validation and filtering.
We’ll work bottom up; create the mechanism for filtering, enhance the request and then wire it up using Spring.
I’ll try to show the code using tests, and the development using some kind of TDD approach.
I am using eclipse’s EclEmma for coverage.
By looking at the code, you can see usage of JUnit, Mockito, Hamcrest, Google-Guava.
You can also see small classes, and interface development approach.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)