class InviteUserServiceImpl extends BaseTransactionalService implements InviteUserService {

    @Override
    public ServiceResult<List<ExternalInviteResource>> findExternalInvites(String searchString, SearchCategory searchCategory) {
        String searchStringExpr = "%" + StringUtils.trim(searchString) + "%";
        return validateSearchString(searchString).andOnSuccess(() ->
                find(() -> findApplicationInvitesBySearchCriteria(searchStringExpr, searchCategory), () -> findProjectInvitesBySearchCriteria(searchStringExpr, searchCategory))
                        .andOnSuccess((appInvites, prjInvites) ->
                                serviceSuccess(sortByEmail(Stream.concat(
                                        getApplicationInvitesAsExternalInviteResource(appInvites).stream(),
                                        getProjectInvitesAsExternalInviteResource(prjInvites).stream()).collect(Collectors.toList())))
                        )
        );
    }

}