1
00:00:00,003 --> 00:00:05,006
(upbeat music)

2
00:00:05,006 --> 00:00:07,003
- [Instructor] In this challenge you want to take

3
00:00:07,003 --> 00:00:10,007
the compare use case from requirement to release,

4
00:00:10,007 --> 00:00:12,007
so this is how I did it.

5
00:00:12,007 --> 00:00:15,004
First, let us see its user story.

6
00:00:15,004 --> 00:00:17,009
As a user I want to look up food products,

7
00:00:17,009 --> 00:00:21,003
so that I can compare their nutritional values.

8
00:00:21,003 --> 00:00:23,009
Now this user story does not specify

9
00:00:23,009 --> 00:00:27,004
how many products the user wants to compare at a time.

10
00:00:27,004 --> 00:00:31,008
But let us assume that user wants to compare two products.

11
00:00:31,008 --> 00:00:35,004
And with that assumption, here is the UI mock up.

12
00:00:35,004 --> 00:00:38,004
From home page I go to compare.

13
00:00:38,004 --> 00:00:40,008
It shows two search boxes.

14
00:00:40,008 --> 00:00:44,009
I can enter two different strings or same string in both

15
00:00:44,009 --> 00:00:47,003
like I have done it here in this mock-up.

16
00:00:47,003 --> 00:00:50,004
When I compare, it shows two sets of products.

17
00:00:50,004 --> 00:00:52,003
To start with both lists

18
00:00:52,003 --> 00:00:54,008
will have their first product selected.

19
00:00:54,008 --> 00:00:56,008
Here I have shown a scenario

20
00:00:56,008 --> 00:01:00,005
where the left box has first product selected

21
00:01:00,005 --> 00:01:05,006
and the user has selected third product in the second box.

22
00:01:05,006 --> 00:01:08,006
Accordingly, the nutrient lists show different sets

23
00:01:08,006 --> 00:01:11,008
of nutrients just below these two products.

24
00:01:11,008 --> 00:01:14,008
As you can see, this functionality is very similar

25
00:01:14,008 --> 00:01:17,001
to what we had in search use case

26
00:01:17,001 --> 00:01:19,001
except that we are dealing with two sets

27
00:01:19,001 --> 00:01:21,002
of products and nutrients here.

28
00:01:21,002 --> 00:01:25,004
So with that understanding, let us move to sequence diagram.

29
00:01:25,004 --> 00:01:30,006
To start with, user chooses to compare an index GSB

30
00:01:30,006 --> 00:01:34,001
which forwards a request to compare controller.

31
00:01:34,001 --> 00:01:38,000
Compare controller forwards it to comparison inputs GSB

32
00:01:38,000 --> 00:01:41,004
which shows the options to enter search strings.

33
00:01:41,004 --> 00:01:44,002
User provides two search strings,

34
00:01:44,002 --> 00:01:46,009
and search inputs GSB forwards them

35
00:01:46,009 --> 00:01:51,001
to another servlet, comparer on product need.

36
00:01:51,001 --> 00:01:54,007
This servlet gets the session from request object,

37
00:01:54,007 --> 00:01:58,009
and saves search streams as session attributes.

38
00:01:58,009 --> 00:02:01,008
Then, one by one, it sends them to Dao,

39
00:02:01,008 --> 00:02:03,005
to look for products that have

40
00:02:03,005 --> 00:02:06,003
these search strings on their names,

41
00:02:06,003 --> 00:02:08,006
gets the two product lists,

42
00:02:08,006 --> 00:02:11,006
and then asks Dao to search for nutrients for

43
00:02:11,006 --> 00:02:14,006
first products in both the lists.

44
00:02:14,006 --> 00:02:16,008
Once it gets all these things,

45
00:02:16,008 --> 00:02:19,003
it saves them as session attributes,

46
00:02:19,003 --> 00:02:23,006
and forwards them to comparison as GSP to display results.

47
00:02:23,006 --> 00:02:26,007
Now, like we had it in searching case,

48
00:02:26,007 --> 00:02:30,001
the user can select different products from the two lists,

49
00:02:30,001 --> 00:02:33,008
which will require nutrient lists to be refreshed.

50
00:02:33,008 --> 00:02:36,009
And that would create another interloop

51
00:02:36,009 --> 00:02:38,009
where users select a product,

52
00:02:38,009 --> 00:02:42,000
displayed by comparison results GSP,

53
00:02:42,000 --> 00:02:44,007
and then the ABC ID of selected product

54
00:02:44,007 --> 00:02:49,006
is forwarded to another servlet comparer on FDC ID.

55
00:02:49,006 --> 00:02:52,004
The servlet asks Dao to get nutrients

56
00:02:52,004 --> 00:02:56,003
for the selected product, Dao sends the list,

57
00:02:56,003 --> 00:02:59,004
and then the new list of nutrients is displayed.

58
00:02:59,004 --> 00:03:01,007
As you can see, tracing this flow

59
00:03:01,007 --> 00:03:04,008
has helped us identify three servlets,

60
00:03:04,008 --> 00:03:08,002
compares our controller, comparer, or product name,

61
00:03:08,002 --> 00:03:12,008
and comparer on FDC ID, and to GSPs,

62
00:03:12,008 --> 00:03:15,008
compares and inputs, and compares and resolves.

63
00:03:15,008 --> 00:03:19,009
Our class diagram for compare use case looks like this.

64
00:03:19,009 --> 00:03:23,004
There are three new servlets that were introduced.

65
00:03:23,004 --> 00:03:26,005
Thanks to object-oriented design,

66
00:03:26,005 --> 00:03:28,001
no other classes had to change.

67
00:03:28,001 --> 00:03:30,009
And finally, our FOIL class diagram,

68
00:03:30,009 --> 00:03:33,002
for all functionalities and Red30

69
00:03:33,002 --> 00:03:35,005
so far looks like this.

70
00:03:35,005 --> 00:03:37,007
Here, you can see three packages,

71
00:03:37,007 --> 00:03:44,004
search, compare, and beings inside (mumbles).

72
00:03:44,004 --> 00:03:47,000
Now, time to look at the code.

73
00:03:47,000 --> 00:03:50,000
Starting with head of GSP, that has the link

74
00:03:50,000 --> 00:03:54,005
for user to initiate compare functionality in line 19.

75
00:03:54,005 --> 00:03:57,006
Here, you can see that it goes to compare servlet,

76
00:03:57,006 --> 00:04:00,003
which is compare controller.

77
00:04:00,003 --> 00:04:03,002
All the other classes related to compare use case

78
00:04:03,002 --> 00:04:05,005
are in compare package here.

79
00:04:05,005 --> 00:04:08,008
Compare controller has doGet and doPost

80
00:04:08,008 --> 00:04:10,005
as usual, and it takes us to

81
00:04:10,005 --> 00:04:13,007
compares and inputs GSP.

82
00:04:13,007 --> 00:04:15,008
Compares and inputs is in a folder

83
00:04:15,008 --> 00:04:18,008
named "compare inside GSP folder".

84
00:04:18,008 --> 00:04:21,005
It has a form in line 12.

85
00:04:21,005 --> 00:04:24,003
That takes two inputs per search.

86
00:04:24,003 --> 00:04:27,001
Line 18 for search string one,

87
00:04:27,001 --> 00:04:30,007
and line 23 for search string two.

88
00:04:30,007 --> 00:04:33,008
Once user enters these two search strings,

89
00:04:33,008 --> 00:04:36,000
control goes to compare name,

90
00:04:36,000 --> 00:04:39,008
which is the URL for comparer on, product name.

91
00:04:39,008 --> 00:04:43,006
Comparer on product name, first,

92
00:04:43,006 --> 00:04:46,002
gets the session from request object,

93
00:04:46,002 --> 00:04:50,004
and saves search strings in line 28 to 30,

94
00:04:50,004 --> 00:04:54,009
then in line 33 to 36, it gets products lists

95
00:04:54,009 --> 00:04:57,002
for first string searched in Dao.

96
00:04:57,002 --> 00:05:00,009
In line 40 to 43, it gets products lists

97
00:05:00,009 --> 00:05:03,000
for second search string.

98
00:05:03,000 --> 00:05:06,000
Then in line 47 to 53, it gets nutrients

99
00:05:06,000 --> 00:05:09,000
for first product in first list,

100
00:05:09,000 --> 00:05:13,001
and in line 56 to 62, it gets nutrients

101
00:05:13,001 --> 00:05:15,008
for first product in second list.

102
00:05:15,008 --> 00:05:18,006
While doing so, it saves all these results

103
00:05:18,006 --> 00:05:21,003
as session attributes and forwards the request

104
00:05:21,003 --> 00:05:23,002
to compare and results.

105
00:05:23,002 --> 00:05:28,005
In line 64, let us look at compares and results now.

106
00:05:28,005 --> 00:05:32,004
In compares and results, the approach is same as

107
00:05:32,004 --> 00:05:35,003
what we had in search results.

108
00:05:35,003 --> 00:05:37,008
In line 16 through 26, we pull

109
00:05:37,008 --> 00:05:41,006
all session attributes in local (mumbles).

110
00:05:41,006 --> 00:05:44,001
There are several forms here,

111
00:05:44,001 --> 00:05:47,004
at the top, there is a form in line 29,

112
00:05:47,004 --> 00:05:50,000
for changing the search string to get

113
00:05:50,000 --> 00:05:52,002
a different product to compare.

114
00:05:52,002 --> 00:05:54,003
Any change here will take the control

115
00:05:54,003 --> 00:05:56,006
to comparer on product name servlet,

116
00:05:56,006 --> 00:05:58,008
which we just looked at.

117
00:05:58,008 --> 00:06:02,002
Then in line 39, onwards, there's a table

118
00:06:02,002 --> 00:06:05,004
that has two columns and two rows.

119
00:06:05,004 --> 00:06:08,001
Top row has two lists of products,

120
00:06:08,001 --> 00:06:11,004
you can see this row starting in line 41,

121
00:06:11,004 --> 00:06:13,009
it displays the first product list

122
00:06:13,009 --> 00:06:17,000
in the first column, and it goes on

123
00:06:17,000 --> 00:06:21,002
to line 90, and then second list from

124
00:06:21,002 --> 00:06:26,005
line 107 to line 147.

125
00:06:26,005 --> 00:06:31,007
The bottom row starts in line 156,

126
00:06:31,007 --> 00:06:34,007
where in left side, you have

127
00:06:34,007 --> 00:06:37,000
first nutrient list until line 200.

128
00:06:37,000 --> 00:06:40,009
And then second cells starting in line 208,

129
00:06:40,009 --> 00:06:45,004
showing second nutrients list up to line 255.

130
00:06:45,004 --> 00:06:47,003
Lastly, when the user chooses

131
00:06:47,003 --> 00:06:49,000
a different product from the list,

132
00:06:49,000 --> 00:06:51,000
using radio button selection,

133
00:06:51,000 --> 00:06:54,001
the control goes to the third servlet

134
00:06:54,001 --> 00:06:58,001
comparer on FDC ID.

135
00:06:58,001 --> 00:07:00,004
Comparer on FDC ID as usual,

136
00:07:00,004 --> 00:07:02,009
first gets the session and requests

137
00:07:02,009 --> 00:07:08,000
parameters from request option in line 25 to 27,

138
00:07:08,000 --> 00:07:12,003
then in line 32 to 39, finds the product with

139
00:07:12,003 --> 00:07:15,003
selected FDC ID from product map,

140
00:07:15,003 --> 00:07:18,006
gets its nutrients from Dao's search nutrients

141
00:07:18,006 --> 00:07:22,003
for product matter, and sets nutrient list

142
00:07:22,003 --> 00:07:24,002
one attribute.

143
00:07:24,002 --> 00:07:31,006
Same thing for second product in lines 42 to 49.

144
00:07:31,006 --> 00:07:34,000
Finally, forward all these results to compare

145
00:07:34,000 --> 00:07:37,000
to last year's B4 display.

146
00:07:37,000 --> 00:07:40,004
Now, that we have seen all (mumbles) functionalities,

147
00:07:40,004 --> 00:07:44,008
so now, let's run the application.

148
00:07:44,008 --> 00:07:48,005
I go into 'run as', then 'all server',

149
00:07:48,005 --> 00:07:51,007
you can see the product data is being loaded,

150
00:07:51,007 --> 00:07:54,009
and our application is running,

151
00:07:54,009 --> 00:07:57,005
I can go into compare products from here,

152
00:07:57,005 --> 00:08:01,004
or let's go to the browser.

153
00:08:01,004 --> 00:08:07,005
Here, I can say local host 8082 Red30,

154
00:08:07,005 --> 00:08:10,005
and compare products. Let's say I say

155
00:08:10,005 --> 00:08:15,009
apple pie, and compare it with apple crisp.

156
00:08:15,009 --> 00:08:20,002
And you can see two sets of products and nutrients,

157
00:08:20,002 --> 00:08:22,003
I can select a different product,

158
00:08:22,003 --> 00:08:25,004
and you can see the nutrient changing for that product.

159
00:08:25,004 --> 00:08:29,000
So now, on the writing side, I can choose

160
00:08:29,000 --> 00:08:30,000
a different product, and the nutrient list

161
00:08:30,000 --> 00:08:31,006
is changing here as well.

162
00:08:31,006 --> 00:08:35,000
Now I need to move all these changes to production.

163
00:08:35,000 --> 00:08:37,005
So, for that, I'll go to eclipse,

164
00:08:37,005 --> 00:08:40,003
and in my (mumble), I can see all my new

165
00:08:40,003 --> 00:08:43,004
compare functionality files are unstaged,

166
00:08:43,004 --> 00:08:46,006
which I can stage now, and I can come

167
00:08:46,006 --> 00:08:50,009
like this, I am commenting it to 0306.

168
00:08:50,009 --> 00:08:55,004
Compare use case completed.

169
00:08:55,004 --> 00:09:00,004
Comment and push, and next.

170
00:09:00,004 --> 00:09:01,006
And finish.

171
00:09:01,006 --> 00:09:04,009
Now, I am in Jenkins, I have already merged

172
00:09:04,009 --> 00:09:07,007
the new changes to master, like I did before

173
00:09:07,007 --> 00:09:09,009
for Jenkins to pick up from.

174
00:09:09,009 --> 00:09:13,004
So, all I need here is to build,

175
00:09:13,004 --> 00:09:17,006
you can see the build has begun,

176
00:09:17,006 --> 00:09:22,003
and, I can go to my production URL,

177
00:09:22,003 --> 00:09:26,001
refresh, and then compare.

178
00:09:26,001 --> 00:09:29,003
Use the same products just to compare here,

179
00:09:29,003 --> 00:09:33,001
Apple pie and apple crisp, and

180
00:09:33,001 --> 00:09:35,000
we are all good.

