1

00:00:01,140  -->  00:00:03,870
Now it's time to have some real fun.

2

00:00:04,060  -->  00:00:12,270
We've been similar user bookmarking process that is use at bookmarking a particular item will be writing

3

00:00:12,270  -->  00:00:17,580
code that touches most of the classes we wrote so far and this simulation.

4

00:00:17,760  -->  00:00:24,210
Each user will be associated with five random bookmarks only user may get associated with duplicate

5

00:00:24,220  -->  00:00:25,120
bookmarks.

6

00:00:25,560  -->  00:00:28,650
But let's not worry about duplications for now.

7

00:00:28,830  -->  00:00:33,100
We will first write a new class code view within com not semantics.

8

00:00:33,120  -->  00:00:37,150
We're not really a package in a real world application.

9

00:00:37,260  -->  00:00:42,240
Dishcloths would correspond to the user interface and that's the reason why we would call this class

10

00:00:42,270  -->  00:00:43,410
as a view.

11

00:00:44,070  -->  00:00:51,300
So the class what similar UI actions taken by a single user that is each method in this class would

12

00:00:51,300  -->  00:00:57,050
correspond to one or more actions that a single user takes within the web browser.

13

00:00:57,720  -->  00:01:05,010
Examples would be a particular user bookmarking few items or an editor marking one or more bookmarks

14

00:01:05,220  -->  00:01:11,430
as kid friendly under Methot in this class would be invoked from the launch class.

15

00:01:11,430  -->  00:01:14,400
So let's get started now and create the Buca us

16

00:01:14,400  -->  00:01:27,990
.

17

00:01:27,990  -->  00:01:30,990
So that's the class in your package.

18

00:01:31,590  -->  00:01:39,460
And first let's create since this is about bookmarking let's create the method called bookmark or block

19

00:01:39,480  -->  00:01:39,550
.

20

00:01:39,700  -->  00:01:43,900
Let's keep all the methods static.

21

00:01:46,380  -->  00:01:51,530
And since this is about a user bookmarking some bookmarks.

22

00:01:51,600  -->  00:01:53,760
So one of the parameters would be user.

23

00:01:54,210  -->  00:02:00,720
And let's just a humor that the user is presented with all the bookmarks in the system and the user

24

00:02:01,050  -->  00:02:06,840
then looks at all those bookmarks and selects five of them.

25

00:02:06,850  -->  00:02:07,490
OK.

26

00:02:07,950  -->  00:02:12,890
But we will be doing it randomly right now.

27

00:02:12,930  -->  00:02:15,240
So that's the bookmark signature.

28

00:02:15,270  -->  00:02:17,010
So let's just import here

29

00:02:20,850  -->  00:02:25,440
now this motard will be invoked from the launch class.

30

00:02:25,560  -->  00:02:33,520
So here let's call this as dark bookmarking So we are just launching the process.

31

00:02:33,600  -->  00:02:39,270
So that's the simulation part of simulation and let's create this matter

32

00:02:43,480  -->  00:02:45,120
Sculpey this over

33

00:02:48,630  -->  00:02:49,770
here.

34

00:02:50,520  -->  00:02:52,560
And so that's the second step.

35

00:02:52,620  -->  00:02:52,870
Right.

36

00:02:52,890  -->  00:02:54,880
The first step is loaded data.

37

00:02:55,260  -->  00:02:56,790
So let's just go with this

38

00:03:04,610  -->  00:03:06,700
and that's him bookmarking.

39

00:03:07,080  -->  00:03:15,330
And from here we will invoke the bookmark method and we will have to do that for all of the users so

40

00:03:15,330  -->  00:03:19,310
the users are maintained and this data structure users we know that.

41

00:03:19,560  -->  00:03:30,090
So let's just iterate over all the users and invoke the method and the view class so to users.

42

00:03:30,120  -->  00:03:42,670
And from here we're going to call view door mark and we're going to pass this user and the bookmarks

43

00:03:42,720  -->  00:03:43,470
.

44

00:03:43,470  -->  00:03:47,580
So that's about start bookmarking matter.

45

00:03:47,610  -->  00:03:50,280
So let's go back here and further this method.

46

00:03:50,850  -->  00:03:56,880
So first let's print who the user is who's who who is the user.

47

00:03:56,880  -->  00:04:05,720
So in a controlled space the new line here can make use of the e-mail motard here

48

00:04:10,080  -->  00:04:15,320
and we can say these bookmarking So this will show up in the output.

49

00:04:16,050  -->  00:04:26,830
Now each user bookmarks five of them five bookmarks and so we can see why less than five.

50

00:04:27,180  -->  00:04:34,410
But indeed a store class we have this method called user bookmarklet which means that a user can bookmark

51

00:04:34,800  -->  00:04:36,640
at most five of them.

52

00:04:36,720  -->  00:04:42,060
So we have this thing here but we need to make it public because it's private and so it's inaccessible

53

00:04:42,150  -->  00:04:45,500
outside that will actually make all of these public

54

00:04:50,910  -->  00:04:52,710
disclose this.

55

00:04:52,860  -->  00:04:54,150
So let's see

56

00:05:03,620  -->  00:05:10,620
so the user is browsing through all the book marks no user selects.

57

00:05:10,640  -->  00:05:12,310
Max FEIBEL Max.

58

00:05:12,700  -->  00:05:21,290
OK so first thing is we need to randomly select five off them and five off 15 bookmarks because there

59

00:05:21,290  -->  00:05:23,670
are three more pipes on each of them have five.

60

00:05:23,870  -->  00:05:27,450
So we need to randomly select one of the bookmarks from here.

61

00:05:27,830  -->  00:05:33,920
So let's we need to randomly select the index.

62

00:05:33,920  -->  00:05:37,250
So we need to indexes your first to get the type.

63

00:05:37,760  -->  00:05:44,100
And second to get the particular bookmark within a particular type.

64

00:05:44,120  -->  00:05:46,630
So first one we call it just type offset.

65

00:05:46,700  -->  00:05:47,440
So we are.

66

00:05:47,480  -->  00:05:49,460
So it's Carlist type offset.

67

00:05:49,730  -->  00:05:54,710
So that way we are going to get one of the bookmark apps and the second one within that particular type

68

00:05:54,720  -->  00:05:54,930
.

69

00:05:55,250  -->  00:06:00,760
We want to select a particular bookmark so we see its bookmark offset.

70

00:06:00,770  -->  00:06:04,990
Now you randomly select We can use the math function here.

71

00:06:05,030  -->  00:06:10,760
So in some mad dog around them which would read return a value between 0 and 1.

72

00:06:10,760  -->  00:06:14,700
So anywhere from zero to point nine now.

73

00:06:15,140  -->  00:06:16,630
So there are three of them.

74

00:06:16,640  -->  00:06:20,170
So or of three we need to get one random value.

75

00:06:20,330  -->  00:06:22,600
So it's a data store dot.

76

00:06:23,140  -->  00:06:25,100
We have more types.

77

00:06:25,160  -->  00:06:27,240
So which is three.

78

00:06:27,740  -->  00:06:30,350
OK so let's just go ahead.

79

00:06:31,100  -->  00:06:37,500
We need to call done I guess here and let's do the same thing here.

80

00:06:37,560  -->  00:06:45,250
And this value will be five you because each type has five round the variables five random bookmarks

81

00:06:45,550  -->  00:06:46,970
bookmarks.

82

00:06:48,410  -->  00:06:50,960
And it could be bookmarks count bar type.

83

00:06:50,960  -->  00:06:52,970
So this is disvalue is fine.

84

00:06:53,330  -->  00:07:01,450
So now we how the nexus we just need to select the bookmark now.

85

00:07:02,000  -->  00:07:16,290
So really when said more marks and the first one is type of said and this is a nice book mark offset

86

00:07:16,300  -->  00:07:16,480
.

87

00:07:16,550  -->  00:07:24,130
So sick so we how randomly selected one and next thing we need to do is so the.

88

00:07:24,190  -->  00:07:31,040
So in real world a user has randomly selected a bookmark and he's going to say Rick and once he's said

89

00:07:31,700  -->  00:07:37,670
that information will be passed to the backend server and it will reset the controller and from the

90

00:07:37,680  -->  00:07:41,460
controller to agree we passed to the book to the service on and so on.

91

00:07:41,690  -->  00:07:46,230
So we need to send this to the controller and we still haven't written any controllers.

92

00:07:46,340  -->  00:07:49,070
So that's right a controller that's introduced a controller now.

93

00:07:49,340  -->  00:07:51,550
So let's create a package for controllers

94

00:07:53,990  -->  00:07:55,280
let's call it as

95

00:07:58,520  -->  00:07:59,530
semantic.

96

00:07:59,570  -->  00:08:04,610
square dot or rollers

97

00:08:07,610  -->  00:08:09,140
and within the controllers.

98

00:08:09,140  -->  00:08:12,320
Let's introduce one called bookmark controller

99

00:08:15,830  -->  00:08:24,230
also controller will be a singleton even framework's NBC even spring for example if you pick up spring

100

00:08:24,530  -->  00:08:31,550
spring has a MVC framework and it has controllers in the framework and all the controllers over there

101

00:08:31,550  -->  00:08:33,900
are also by default singleton.

102

00:08:34,190  -->  00:08:35,830
So lets be consistent with that.

103

00:08:35,850  -->  00:08:38,160
And let's create a single controller.

104

00:08:38,390  -->  00:08:45,580
So for that we need to have a private constructor we know that.

105

00:08:46,920  -->  00:08:48,450
OK.

106

00:08:48,530  -->  00:08:50,090
Now we also need to create

107

00:08:53,030  -->  00:08:56,660
a variable that would hold the instance psycho-BS static

108

00:08:59,240  -->  00:09:03,520
instance.

109

00:09:07,480  -->  00:09:08,650
OK.

110

00:09:09,110  -->  00:09:15,200
Now we need to provide a public global access point.

111

00:09:15,290  -->  00:09:29,750
So it will be static Skop is here see your instance.

112

00:09:30,080  -->  00:09:34,160
So thats the controller related code and we need to

113

00:09:37,520  -->  00:09:40,480
know that.

114

00:09:40,950  -->  00:09:53,860
Also this and car create a method called Save user bookwork because its a user's bookmark and that's

115

00:09:53,870  -->  00:10:00,390
past user and the bookmark that was randomly selected.

116

00:10:02,360  -->  00:10:12,100
But since we don't have that method there will be using the suggestion here not a creation tradition

117

00:10:12,120  -->  00:10:12,170
.

118

00:10:12,190  -->  00:10:16,730
So that's what we have now so the control is in control now.

119

00:10:16,960  -->  00:10:25,350
And from the controller we need to invoke the manager so manager as the service layer part of service

120

00:10:25,510  -->  00:10:25,600
.

121

00:10:25,620  -->  00:10:28,550
And it has a real business logic.

122

00:10:28,690  -->  00:10:29,620
So yes.

123

00:10:29,920  -->  00:10:34,570
And let's go into the same user bookmark.

124

00:10:34,560  -->  00:10:39,130
So same signature as this particular matter and user

125

00:10:41,490  -->  00:10:42,930
bookmark.

126

00:10:43,600  -->  00:10:45,260
So this matter is also not there.

127

00:10:45,280  -->  00:10:50,120
So we're going to auto created now.

128

00:10:50,230  -->  00:10:54,950
So we have this now within bookmark manager.

129

00:10:55,180  -->  00:10:57,470
So we need Guerard the real business logic right.

130

00:10:57,490  -->  00:11:03,910
And if you recall we already have this matter on this entity called user bookmark so it maintains the

131

00:11:03,910  -->  00:11:08,830
association between a user and bookmarks so we're going to instantiate that

132

00:11:12,990  -->  00:11:19,280
gay and user bookmark has a second method called user.

133

00:11:19,300  -->  00:11:31,990
So I'm going to use that and new user bookmark also has a certain method for bookmarks so you are also

134

00:11:31,990  -->  00:11:33,420
using that.

135

00:11:34,360  -->  00:11:39,040
And from here we need to pass this particular object to doll.

136

00:11:39,250  -->  00:11:42,310
So we have the bookmark doll and this class.

137

00:11:42,310  -->  00:11:45,940
Here are the top bookmark down.

138

00:11:46,000  -->  00:11:52,230
So we are just going to pass it to a new method called C..

139

00:11:52,380  -->  00:11:53,140
Bookmark

140

00:11:55,940  -->  00:11:57,980
Missee user bookmark.

141

00:11:58,600  -->  00:12:05,090
But it will accept this parameter called user bookmark.

142

00:12:05,290  -->  00:12:08,480
So that's the entity.

143

00:12:08,650  -->  00:12:15,340
So let's just use auto create feature once again and discreate has created this method.

144

00:12:15,400  -->  00:12:24,670
Now from here the dollar typically we have some SU l r r r which Q R in higher which is a query language

145

00:12:24,670  -->  00:12:25,480
for hibernate.

146

00:12:25,630  -->  00:12:28,770
So one of those queries to insert into the database.

147

00:12:28,840  -->  00:12:36,070
So since we don't have that we need to use this data storage right and we can either create a new method

148

00:12:36,100  -->  00:12:43,610
call add and we can pass this thing with matter use or bookmark.

149

00:12:43,630  -->  00:12:47,400
So it's like adding to the database inserting in the database.

150

00:12:47,410  -->  00:12:48,550
So and since it's not there.

151

00:12:48,580  -->  00:12:53,050
Once again let's go ahead and nicely auto created.

152

00:12:53,410  -->  00:12:57,940
Now this value will be added can be stored.

153

00:12:58,000  -->  00:13:07,960
And this are they do this optical use or bookmarks but we need to slow the user a particular user will

154

00:13:07,960  -->  00:13:15,490
be will be bookmarking bookmarks and other users will also be bookmarking bookmarks in a similar way

155

00:13:15,500  -->  00:13:15,740
.

156

00:13:15,970  -->  00:13:22,010
So we need to have an index on that index needs to be incremented right with each added bookmark.

157

00:13:22,210  -->  00:13:24,240
So if you need an index over there.

158

00:13:24,250  -->  00:13:27,040
So let's just create an index.

159

00:13:27,060  -->  00:13:36,820
It's a great read static and since it's a bookmark index it's going to just bookmark and next and it's

160

00:13:36,820  -->  00:13:38,860
initialized with zero.

161

00:13:38,860  -->  00:13:51,430
Now let's go back to the matter and let's see user marks and bookmark next.

162

00:13:51,490  -->  00:14:01,690
Now you add this value here user bookmarks are not stored but many do also increment bookmark index

163

00:14:03,340  -->  00:14:06,870
so that it's ready for the next bookmark.

164

00:14:07,240  -->  00:14:10,980
OK so that's all there is to this.

165

00:14:10,990  -->  00:14:16,200
So from controller you're passing to manager from Manager we are passing it or door from door we're

166

00:14:16,220  -->  00:14:17,110
passing it.

167

00:14:17,200  -->  00:14:20,760
We are inserting it in the database now and the view.

168

00:14:20,800  -->  00:14:26,980
Let's actually print this matter let's have six out.

169

00:14:27,590  -->  00:14:36,460
Sorry controlled space and that's read this bookmark which means this user is printing this bookmark

170

00:14:37,570  -->  00:14:44,310
and launches here that sort of code and you line statement here.

171

00:14:44,440  -->  00:14:49,010
So that's it I guess let's just go ahead and run this program launch.

172

00:14:49,010  -->  00:14:50,790
And there you go.

173

00:14:51,790  -->  00:14:53,350
So you have this.

174

00:14:53,380  -->  00:14:56,350
So this is the loading data step.

175

00:14:56,380  -->  00:14:57,640
We have already seen that.

176

00:14:57,640  -->  00:15:02,130
So this is the bookmarking step and user Zillah's bookmarking here.

177

00:15:02,170  -->  00:15:07,810
So these are the firewall marks that are randomly associated assigned to this user.

178

00:15:07,990  -->  00:15:11,080
And here is a rambling book about blink blink blink.

179

00:15:11,170  -->  00:15:13,220
And this is where the second user.

180

00:15:14,080  -->  00:15:17,530
And third for first users.

181

00:15:18,130  -->  00:15:20,830
So that's about it and everything is done randomly.

182

00:15:20,830  -->  00:15:27,670
So if we run this again you'll see that it's a different output because of the randomization that we

183

00:15:27,670  -->  00:15:28,360
are using.

184

00:15:28,360  -->  00:15:32,790
So this time it's two more weeks two books and one movie for the first user.

185

00:15:33,610  -->  00:15:36,470
So that's the thing.

186

00:15:36,550  -->  00:15:39,440
So that's some good functionality that we want.

187

00:15:39,820  -->  00:15:43,000
I hope you implemented it with me in parallel.

188

00:15:43,210  -->  00:15:47,480
If not please go ahead and do it as soon as you get a chance.

189

00:15:47,710  -->  00:15:48,510
OK.

190

00:15:48,820  -->  00:15:53,890
OK then see you in the next lesson and we will continue extending the project.
