1 00:00:00,000 --> 00:00:02,350 [No Audio] 2 00:00:02,350 --> 00:00:03,920 In this video, we're going to develop the service 3 00:00:03,920 --> 00:00:05,372 a little bit more, so that we can pull 4 00:00:05,372 --> 00:00:07,294 back some users from the UserRepository. 5 00:00:07,294 --> 00:00:10,410 So let's get to this now, let's add another method now. 6 00:00:10,410 --> 00:00:12,868 [No Audio] 7 00:00:12,868 --> 00:00:14,840 Let's just say find all. 8 00:00:14,840 --> 00:00:16,748 Actually, we don't want this method here. 9 00:00:16,748 --> 00:00:18,581 Now think about it. What I'm going to do now is I'm 10 00:00:18,581 --> 00:00:19,989 going to put a method to find all the 11 00:00:19,989 --> 00:00:22,546 AdminUser or to find all the RegularUser. 12 00:00:22,546 --> 00:00:24,596 We could put that here, but instead let's put 13 00:00:24,596 --> 00:00:27,416 it higher up and introduce another service class. 14 00:00:27,416 --> 00:00:29,732 So in here we've got an AuthenticationService, 15 00:00:29,732 --> 00:00:32,326 which is responsible for authenticating users 16 00:00:32,326 --> 00:00:34,018 by checking username and password. 17 00:00:34,018 --> 00:00:36,650 Let's create another class. Actually, 18 00:00:36,650 --> 00:00:38,720 not let's not, we can put it in here for now. 19 00:00:38,720 --> 00:00:39,733 I was thinking we could create another 20 00:00:39,733 --> 00:00:41,876 class called for example, User Inquiry service. 21 00:00:41,876 --> 00:00:43,842 Maybe that's, you might want to 22 00:00:43,856 --> 00:00:46,078 create different service for this. It could be viewed. 23 00:00:46,078 --> 00:00:48,536 But like in our authentication is 24 00:00:48,536 --> 00:00:51,389 different from generally accessing users. 25 00:00:51,389 --> 00:00:54,270 [No Audio] 26 00:00:54,270 --> 00:00:55,656 We're not designing a full system here. 27 00:00:55,656 --> 00:00:57,360 So let's just put in AuthenticationService 28 00:00:57,360 --> 00:00:58,620 now for the sake of a demo. 29 00:00:58,620 --> 00:01:00,336 So inside AuthenticationService, 30 00:01:00,336 --> 00:01:02,737 [No Audio] 31 00:01:02,737 --> 00:01:04,670 let's add an extra method now, 32 00:01:04,670 --> 00:01:06,769 [No Audio] 33 00:01:06,769 --> 00:01:07,804 public list. 34 00:01:07,804 --> 00:01:10,350 Actually, let's make it public Set infact. 35 00:01:10,350 --> 00:01:13,096 Normally with JPA, Hibernate, those kind of 36 00:01:13,096 --> 00:01:15,186 things, when they're executed queries, you tend 37 00:01:15,198 --> 00:01:17,831 to get back a list. And that's because the execution 38 00:01:17,831 --> 00:01:20,490 of SQL might return a collection that's ordered. 39 00:01:20,490 --> 00:01:22,439 For example, if you have an order by clause, 40 00:01:22,439 --> 00:01:23,860 in general it won't. But it might do. 41 00:01:23,860 --> 00:01:25,804 And because it might do, it's important that 42 00:01:25,804 --> 00:01:28,984 the JPA and Hibernate libraries, JDBC libraries, those 43 00:01:28,984 --> 00:01:30,870 kind of things that they provide that facility. 44 00:01:30,870 --> 00:01:31,984 So that's in general where you'll always 45 00:01:31,984 --> 00:01:33,664 get things back into a list. 46 00:01:33,664 --> 00:01:34,960 But here, of course, in the service 47 00:01:34,960 --> 00:01:36,292 layer, we know better than that. 48 00:01:36,292 --> 00:01:37,876 We don't care about ordering, so we 49 00:01:37,876 --> 00:01:39,552 can just change it to a set. So let's just 50 00:01:39,552 --> 00:01:41,868 do that, which is something we probably do if we're 51 00:01:41,868 --> 00:01:44,404 writing proper production code anyhow. So here 52 00:01:44,404 --> 00:01:49,481 we've got a public set of let's say, user objects. 53 00:01:49,481 --> 00:01:54,481 Let's just say getRegularUsers. 54 00:01:54,481 --> 00:01:56,441 [No Audio] 55 00:01:56,441 --> 00:01:58,036 And to do this we're going to basically 56 00:01:58,036 --> 00:02:01,654 return the userRepository, 57 00:02:01,654 --> 00:02:03,054 find all, 58 00:02:03,054 --> 00:02:05,554 [No Audio] 59 00:02:05,554 --> 00:02:09,204 and then let's stream them using the Java Extremes API. 60 00:02:09,204 --> 00:02:12,420 Filter a predicate on a user object. 61 00:02:12,420 --> 00:02:15,171 I want to say that user is live, 62 00:02:15,171 --> 00:02:17,790 and user 63 00:02:17,790 --> 00:02:24,574 getUserType == User.UserType.REGULAR_USER. 64 00:02:24,574 --> 00:02:26,052 This is red. 65 00:02:26,052 --> 00:02:29,630 The reason this is red is because we need a 1.8 JDK. 66 00:02:29,630 --> 00:02:30,922 That's okay, let's go in here, make 67 00:02:30,936 --> 00:02:33,179 a 1.8 JDK reference for it. 68 00:02:33,179 --> 00:02:38,170 [No Audio] 69 00:02:38,170 --> 00:02:42,519 So Target bytecode 1.8, that's fine. 70 00:02:42,519 --> 00:02:46,552 And if we right click here and go into 71 00:02:46,552 --> 00:02:51,736 Module Settings, so the language level to 8 and 72 00:02:51,736 --> 00:02:54,957 then do okay, I should be fine then. 73 00:02:54,957 --> 00:02:57,298 But of course we haven't finished it. 74 00:02:57,298 --> 00:03:01,972 So we then need to, collect those results into a set. 75 00:03:01,972 --> 00:03:04,636 So we sat intelligent idea there very quickly 76 00:03:04,636 --> 00:03:06,942 to be able to use JDK 8 features. 77 00:03:06,942 --> 00:03:08,200 But a better way of doing this 78 00:03:08,200 --> 00:03:09,462 is to do it via configuring 79 00:03:09,462 --> 00:03:11,642 the Maven compiler plug-in and we'll see 80 00:03:11,656 --> 00:03:13,344 how to do that in the next video.