[No Audio]
In this video, we're going to develop the service
a little bit more, so that we can pull
back some users from the UserRepository.
So let's get to this now, let's add another method now.
[No Audio]
Let's just say find all.
Actually, we don't want this method here.
Now think about it. What I'm going to do now is I'm
going to put a method to find all the
AdminUser or to find all the RegularUser.
We could put that here, but instead let's put
it higher up and introduce another service class.
So in here we've got an AuthenticationService,
which is responsible for authenticating users
by checking username and password.
Let's create another class. Actually,
not let's not, we can put it in here for now.
I was thinking we could create another
class called for example, User Inquiry service.
Maybe that's, you might want to
create different service for this. It could be viewed.
But like in our authentication is
different from generally accessing users.
[No Audio]
We're not designing a full system here.
So let's just put in AuthenticationService
now for the sake of a demo.
So inside AuthenticationService,
[No Audio]
let's add an extra method now,
[No Audio]
public list.
Actually, let's make it public Set infact.
Normally with JPA, Hibernate, those kind of
things, when they're executed queries, you tend
to get back a list. And that's because the execution
of SQL might return a collection that's ordered.
For example, if you have an order by clause,
in general it won't. But it might do.
And because it might do, it's important that
the JPA and Hibernate libraries, JDBC libraries, those
kind of things that they provide that facility.
So that's in general where you'll always
get things back into a list.
But here, of course, in the service
layer, we know better than that.
We don't care about ordering, so we
can just change it to a set. So let's just
do that, which is something we probably do if we're
writing proper production code anyhow. So here
we've got a public set of let's say, user objects.
Let's just say getRegularUsers.
[No Audio]
And to do this we're going to basically
return the userRepository,
find all,
[No Audio]
and then let's stream them using the Java Extremes API.
Filter a predicate on a user object.
I want to say that user is live,
and user
getUserType == User.UserType.REGULAR_USER.
This is red.
The reason this is red is because we need a 1.8 JDK.
That's okay, let's go in here, make
a 1.8 JDK reference for it.
[No Audio]
So Target bytecode 1.8, that's fine.
And if we right click here and go into
Module Settings, so the language level to 8 and
then do okay, I should be fine then.
But of course we haven't finished it.
So we then need to, collect those results into a set.
So we sat intelligent idea there very quickly
to be able to use JDK 8 features.
But a better way of doing this
is to do it via configuring
the Maven compiler plug-in and we'll see
how to do that in the next video.