Using Lambda expression to check voided privileges

Good afternoon , In userServiceImpl.checkPrivileges, i would like to flatten the for-if-hierarchy and extract a constant called check checkedSuperUserPrivilege ®, taking role as an argument. And create an extracted checkSuperUserPrivilege method that returns void. forexample

private static final String ERROR_FORMAT = "You must have the following privileges in order to assign them: %s";
 private void checkSuperUserPrivilege(Role r) {
     if(r.getRole().equals(RoleConstants.SUPERUSER)
           && !Context.hasPrivilege(PrivilegeConstants.ASSIGN_SYSTEM_DEVELOPER_ROLE)) {
>          throw new APIException("User.you.must.have.role", new Object[] { RoleConstants.SUPERUSER });
>      }

Extracting this code would make the original more concise with the same functionality, but i was so disturbed since it may need other guidance before creating a pull request. Yes this will be against the ticket description ticket but to make the code more concise and use lambda expression ,i was thinking this can take us miles,Doing this wont make the work being finished because there is no usage of lambda expressions,Meaning i will again use lambda if this format is accepted,thanks more suggestion is highly appreciated. cc @dkayiwa, @ibacher,@mozzy

I fully support (finally) embracing Java 8 and using systematically Java streams and lambda expressions.

@sharif what’s your concern exactly?

1 Like

Thanks @mksd , Now we want to be able to use lambda expression in userServiceImpl class, so my concern was to first make similar code like this suggestedchanges. So if this is allowed , then i can go ahead and create a PR

Created a PR https://github.com/openmrs/openmrs-core/pull/3163