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