Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to KiwiResources to validate parameters from MultivaluedMaps #604

Closed
sleberknight opened this issue Sep 4, 2021 · 1 comment · Fixed by #667
Closed

Add methods to KiwiResources to validate parameters from MultivaluedMaps #604

sleberknight opened this issue Sep 4, 2021 · 1 comment · Fixed by #667
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

Add new parameter validation methods in KiwiResources that accept MultivaluedMap. Even though MultivaluedMap extends Map we have run into problems in which the method resolution picks the "wrong" method. See #571 for details, and specifically the @implNote in the Javadocs in WebTargetHelper for why having separate methods from the existing validateXxxParameter methods is the right thing to do (despite it being annoying).

So, in addition to the validateIntParameter and validateLongParameter methods which take a Map<String, V> (or will, once #603 is implemented), these new methods will specifically accept MultivaluedMap<String, V> where V is a type parameter.

Since MultivaluedMap by definition permits more than one value for a key, we will want to have separate methods to handle the cases when you know you only want one parameter (e.g. /url?n=42), and when it's OK to have one or more (e.g. /url?n=42&n=84). So, the new method signatures might look like:

// Validates there is exactly one parameter with the given name
// whose type is an int, and return as an int
public static <V> int validateOneIntParameter(MultivaluedMap<String, V> parameters, String parameterName)

// Validate that there are one or more parameters with the given name
// whose types are all ints, and return as a list of Integer
public static <V> List<Integer> validateManyIntParameters(MultivaluedMap<String, V> parameters, String parameterName)

// Validates there is exactly one parameter with the given name
// whose type is an long, and return as a long
public static <V> long validateOneLongParameter(MultivaluedMap<String, V> parameters, String parameterName)

// Validate that there are one or more parameters with the given name
// whose types are all longs, and return as a list of Long
public static <V> List<Long> validateManyLongParameters(MultivaluedMap<String, V> parameters, String parameterName)

One question is whether the validateOne methods should throw an exception if there is more than one parameter with the given name? Or, should there be separate validateExactlyOne methods in addition which would be the ones that throw exceptions, whereas the regular validateOne methods just grab the first query parameter with the given name?

@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Sep 4, 2021
@sleberknight
Copy link
Member Author

@sleberknight sleberknight self-assigned this Jan 30, 2022
@sleberknight sleberknight added this to the 1.3.0 milestone Jan 30, 2022
@sleberknight sleberknight added the in progress A task that is actively being worked on label Jan 31, 2022
sleberknight added a commit that referenced this issue Feb 1, 2022
* Add validateOneIntParameter
* Add validateExactlyOneIntParameter
* Add validateOneOrMoreIntParameters
* Add validateOneLongParameter
* Add validateExactlyOneLongParameter
* Add validateOneOrMoreLongParameters
* Modify existing validateIntParameter and validateLongParameter to
  throw IllegalArgumentException if given a null parameter map (#666)

Closes #604
Closes #666
@sleberknight sleberknight removed the in progress A task that is actively being worked on label Feb 1, 2022
chrisrohr pushed a commit that referenced this issue Feb 2, 2022
* Add validateOneIntParameter
* Add validateExactlyOneIntParameter
* Add validateOneOrMoreIntParameters
* Add validateOneLongParameter
* Add validateExactlyOneLongParameter
* Add validateOneOrMoreLongParameters
* Modify existing validateIntParameter and validateLongParameter to
  throw IllegalArgumentException if given a null parameter map (#666)

Closes #604
Closes #666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant