浏览代码

Modifed start page to view delivery history

Added style sheet (plain html css, not using SpringMVC theme)
Modified getters and setters to use getXXX and setXXX instead of xXX
jorgen_falk 18 年前
父节点
当前提交
604e60c2a7

+ 13
- 6
dddsample/src/main/java/se/citerus/dddsample/domain/Cargo.java 查看文件

@@ -1,5 +1,8 @@
1 1
 package se.citerus.dddsample.domain;
2 2
 
3
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
4
+import org.apache.commons.lang.builder.ToStringStyle;
5
+
3 6
 
4 7
 /**
5 8
  * A Cargo an entity identifed by TrackingId and is capable of getting its DeliveryHistory plus a number
@@ -19,7 +22,7 @@ public class Cargo {
19 22
     this.history = new DeliveryHistory();
20 23
   }
21 24
 
22
-  public DeliveryHistory deliveryHistory() {
25
+  public DeliveryHistory getDeliveryHistory() {
23 26
     return history;
24 27
   }
25 28
 
@@ -28,20 +31,24 @@ public class Cargo {
28 31
   }
29 32
 
30 33
   public boolean atFinalDestiation() {
31
-    return currentLocation().equals(finalDestination);
34
+    return getCurrentLocation().equals(finalDestination);
32 35
   }
33 36
 
34
-  public Location currentLocation() {
37
+  public Location getCurrentLocation() {
35 38
     HandlingEvent lastEvent = history.last();
36 39
     if (lastEvent == null) {
37 40
       return origin;
38 41
     }
39
-    CarrierMovement cm = lastEvent.getCarrierMovement();
40
-
41
-    return (lastEvent.type() == HandlingEvent.Type.LOAD) ? cm.from() : cm.to();
42
+    
43
+    return lastEvent.getLocation();
42 44
   }
43 45
 
44 46
   public TrackingId trackingId() {
45 47
     return trackingId;
46 48
   }
49
+
50
+  @Override
51
+  public String toString() {
52
+    return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
53
+  }
47 54
 }

+ 19
- 11
dddsample/src/main/java/se/citerus/dddsample/domain/DeliveryHistory.java 查看文件

@@ -3,19 +3,27 @@ package se.citerus.dddsample.domain;
3 3
 import java.util.SortedSet;
4 4
 import java.util.TreeSet;
5 5
 
6
+import org.apache.commons.lang.builder.ReflectionToStringBuilder;
7
+import org.apache.commons.lang.builder.ToStringStyle;
8
+
6 9
 public class DeliveryHistory {
7
-	
8
-	private final SortedSet<HandlingEvent> events = new TreeSet<HandlingEvent>();
9 10
 
10
-	public SortedSet<HandlingEvent> events() {
11
-		return events; 
12
-	}
11
+  private final SortedSet<HandlingEvent> events = new TreeSet<HandlingEvent>();
12
+
13
+  public SortedSet<HandlingEvent> getEvents() {
14
+    return events;
15
+  }
16
+
17
+  public void addEvent(HandlingEvent event) {
18
+    events.add(event);
19
+  }
13 20
 
14
-	public void addEvent(HandlingEvent event) {
15
-		events.add(event);
16
-	}
21
+  public HandlingEvent last() {
22
+    return events.isEmpty() ? null : events.last();
23
+  }
17 24
 
18
-	public HandlingEvent last() {
19
-		return events.isEmpty() ? null : events.last();
20
-	}
25
+  @Override
26
+  public String toString() {
27
+    return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
28
+  }
21 29
 }

+ 9
- 4
dddsample/src/main/java/se/citerus/dddsample/domain/HandlingEvent.java 查看文件

@@ -29,7 +29,7 @@ public class HandlingEvent implements Comparable<HandlingEvent> {
29 29
     this.carrierMovement = carrierMovement;
30 30
   }
31 31
 
32
-  public Type type() {
32
+  public Type getType() {
33 33
     return type;
34 34
   }
35 35
 
@@ -37,10 +37,15 @@ public class HandlingEvent implements Comparable<HandlingEvent> {
37 37
     return carrierMovement;
38 38
   }
39 39
 
40
-  public Date time() {
40
+  public Date getTime() {
41 41
     return time;
42 42
   }
43
-
43
+  
44
+  public Location getLocation() {
45
+    return (type == HandlingEvent.Type.LOAD) ? carrierMovement.from() : carrierMovement.to();
46
+  }
47
+  
48
+  
44 49
   @Override
45 50
   public boolean equals(Object obj) {
46 51
     return EqualsBuilder.reflectionEquals(this, obj);
@@ -52,6 +57,6 @@ public class HandlingEvent implements Comparable<HandlingEvent> {
52 57
   }
53 58
 
54 59
   public int compareTo(HandlingEvent o) {
55
-    return time.compareTo(o.time());
60
+    return time.compareTo(o.getTime());
56 61
   }
57 62
 }

+ 7
- 11
dddsample/src/main/java/se/citerus/dddsample/web/CargoTrackingController.java 查看文件

@@ -1,22 +1,20 @@
1 1
 package se.citerus.dddsample.web;
2 2
 
3
+import java.util.HashMap;
4
+import java.util.Map;
5
+
6
+import javax.servlet.http.HttpServletRequest;
7
+import javax.servlet.http.HttpServletResponse;
8
+
3 9
 import org.springframework.validation.BindException;
4 10
 import org.springframework.web.servlet.ModelAndView;
5 11
 import org.springframework.web.servlet.mvc.SimpleFormController;
6
-import org.springframework.web.servlet.view.RedirectView;
7 12
 
8 13
 import se.citerus.dddsample.domain.Cargo;
9 14
 import se.citerus.dddsample.domain.Location;
10 15
 import se.citerus.dddsample.service.CargoService;
11 16
 import se.citerus.dddsample.web.command.TrackCommand;
12 17
 
13
-import javax.servlet.ServletException;
14
-import javax.servlet.http.HttpServletRequest;
15
-import javax.servlet.http.HttpServletResponse;
16
-
17
-import java.util.HashMap;
18
-import java.util.Map;
19
-
20 18
 /**
21 19
  * Controller for tracking cargo.
22 20
  */
@@ -43,9 +41,7 @@ public class CargoTrackingController extends SimpleFormController {
43 41
     final Cargo cargo = cargoService.find(trackCommand.getTrackingId());
44 42
 
45 43
     if (cargo != null) {
46
-      final Location location = cargo.currentLocation();
47
-      logger.debug("Location of [" + trackCommand.getTrackingId() + "] is [" + location + "]");
48
-      model.put("location", location);
44
+      model.put("cargo", cargo);
49 45
       
50 46
       // Can't just return a new MaV instance when successView and FormView is the same. Binding will fail.
51 47
       // showForm will append our command and model to the request so that the form will bind successfully.

+ 7
- 0
dddsample/src/main/webapp/WEB-INF/jsp/dataAccessFailure.jsp 查看文件

@@ -1,6 +1,13 @@
1 1
 <%@ include file="/WEB-INF/jspf/include.jspf" %>
2 2
 
3 3
 <html>
4
+<head>
5
+	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
6
+	<script type="text/javascript"></script>
7
+	<style type="text/css" title="style" media="screen">
8
+		@import "/dddsample/style.css";
9
+	</style>
10
+</head>
4 11
 <body>
5 12
 <div>
6 13
 An DataAccessExcepton occured.

+ 27
- 11
dddsample/src/main/webapp/WEB-INF/jsp/start.jsp 查看文件

@@ -1,11 +1,17 @@
1 1
 <%@ include file="/WEB-INF/jspf/include.jspf" %>
2 2
 
3 3
 <html>
4
+<head>
5
+	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
6
+	<script type="text/javascript"></script>
7
+	<style type="text/css" title="style" media="screen">
8
+		@import "/dddsample/style.css";
9
+	</style>
10
+</head>
4 11
 <body>
5
-
6
-<div>
12
+<div id="form">
7 13
   <form:form method="post" commandName="trackCommand">
8
-    <table border="1" cellspacing="0" cellpadding="4">
14
+    <table cellspacing="0" cellpadding="4">
9 15
       <tr>
10 16
         <td align="right">
11 17
           Enter tracking id:
@@ -16,17 +22,27 @@
16 22
         <td>
17 23
           <form:errors path="trackingId" cssClass="error"/>
18 24
         </td>
25
+        <td>
26
+          <input type="submit" value="Track!">
27
+        </td>
19 28
       </tr>
20 29
     </table>
21
-    <br>
22
-    <input type="submit" value="Track!">
23
-    <c:choose>
24
-      <c:when test="${location ne null}">
25
-        <p>Your cargo is currently at: <b>${location}</b></p>
26
-      </c:when>
27
-    </c:choose>
28 30
   </form:form>
29 31
 </div>
30
-
32
+<div id="result">
33
+<c:choose>
34
+  <c:when test="${cargo ne null}">
35
+  	
36
+    <p>Your cargo is currently at: <span id="currentLocation">${cargo.currentLocation}</span></p>
37
+    
38
+    <table>
39
+      <c:forEach var="event" items="${cargo.deliveryHistory.events}">
40
+        <tr><td><c:out value="${event.type}"/> &nbsp; on &nbsp;</td><td><c:out value="${event.location}"/>&nbsp; at &nbsp;</td><td><c:out value="${event.time}"/></td></tr>
41
+      </c:forEach>
42
+    </table>
43
+    
44
+  </c:when>
45
+</c:choose>
46
+</div>
31 47
 </body>
32 48
 </html>

+ 7
- 0
dddsample/src/main/webapp/WEB-INF/jsp/unknownCargo.jsp 查看文件

@@ -1,6 +1,13 @@
1 1
 <%@ include file="/WEB-INF/jspf/include.jspf" %>
2 2
 
3 3
 <html>
4
+<head>
5
+	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
6
+	<script type="text/javascript"></script>
7
+	<style type="text/css" title="style" media="screen">
8
+		@import "/dddsample/style.css";
9
+	</style>
10
+</head>
4 11
 <body>
5 12
 
6 13
 <p>Unknown tracking id ${trackingId}</p>

+ 218
- 0
dddsample/src/main/webapp/style.css 查看文件

@@ -0,0 +1,218 @@
1
+/* css Zen Garden default style v1.02 */
2
+/* css released under Creative Commons License - http://creativecommons.org/licenses/by-nc-sa/1.0/  */
3
+
4
+/* This file based on 'Tranquille' by Dave Shea */
5
+/* You may use this file as a foundation for any new work, but you may find it easier to start from scratch. */
6
+/* Not all elements are defined in this file, so you'll most likely want to refer to the xhtml as well. */
7
+
8
+/* Your images should be linked as if the CSS file sits in the same folder as the images. ie. no paths. */
9
+
10
+
11
+/* basic elements */
12
+html {
13
+	margin: 0;
14
+	padding: 0;
15
+	}
16
+body { 
17
+	font: 75% georgia, sans-serif;
18
+	line-height: 1.88889;
19
+	color: #555753; 
20
+	background: #fff url(blossoms.jpg) no-repeat bottom right; 
21
+	margin: 0; 
22
+	padding: 0;
23
+	}
24
+p { 
25
+	margin-top: 0; 
26
+	text-align: justify;
27
+	}
28
+h3 { 
29
+	font: italic normal 1.4em georgia, sans-serif;
30
+	letter-spacing: 1px; 
31
+	margin-bottom: 0; 
32
+	color: #7D775C;
33
+	}
34
+a:link { 
35
+	font-weight: bold; 
36
+	text-decoration: none; 
37
+	color: #B7A5DF;
38
+	}
39
+a:visited { 
40
+	font-weight: bold; 
41
+	text-decoration: none; 
42
+	color: #D4CDDC;
43
+	}
44
+a:hover, a:active { 
45
+	text-decoration: underline; 
46
+	color: #9685BA;
47
+	}
48
+acronym {
49
+	border-bottom: none;
50
+	}
51
+
52
+
53
+/* specific divs */
54
+#container { 
55
+	background: url(zen-bg.jpg) no-repeat top left; 
56
+	padding: 0 175px 0 110px;  
57
+	margin: 0; 
58
+	position: relative;
59
+	}
60
+	
61
+#form {
62
+	padding: 0 175px 0 110px; 
63
+	font: 10pt/22pt georgia;
64
+	}	
65
+
66
+#intro { 
67
+	min-width: 470px;
68
+	}
69
+	
70
+#result {
71
+	padding: 0 175px 0 110px; 
72
+	font: italic 10pt/22pt georgia; 
73
+	text-align:right;
74
+	}
75
+#currentLocation{
76
+	font: bold 10pt/22pt georgia;
77
+	position: relative;
78
+	}
79
+#result table{
80
+	text-align:left;
81
+	font: 10pt/22pt georgia;
82
+	}
83
+
84
+/* using an image to replace text in an h1. This trick courtesy Douglas Bowman, http://www.stopdesign.com/articles/css/replace-text/ */
85
+#pageHeader h1 { 
86
+	background: transparent url(h1.gif) no-repeat top left; 
87
+	margin-top: 10px; 
88
+	width: 219px; 
89
+	height: 87px; 
90
+	float: left;
91
+	}
92
+#pageHeader h1 span {
93
+	display:none
94
+	}
95
+#pageHeader h2 { 
96
+	background: transparent url(h2.gif) no-repeat top left; 
97
+	margin-top: 58px; 
98
+	margin-bottom: 40px; 
99
+	width: 200px; 
100
+	height: 18px; 
101
+	float: right;
102
+	}
103
+#pageHeader h2 span {
104
+	display:none
105
+	}
106
+#pageHeader {
107
+	padding-top: 20px;
108
+}
109
+
110
+#quickSummary {
111
+	clear:both; 
112
+	margin: 20px 20px 20px 10px; 
113
+	width: 160px; 
114
+	float: left;
115
+	}
116
+#quickSummary p {
117
+	font: italic 10pt/22pt georgia; 
118
+	text-align:center;
119
+	}
120
+
121
+#preamble {
122
+	clear: right; 
123
+	padding: 0px 10px 0 10px;
124
+	}
125
+#supportingText {	
126
+	padding-left: 10px; 
127
+	margin-bottom: 40px;
128
+	}
129
+
130
+#footer { 
131
+	text-align: center; 
132
+	}
133
+#footer a:link, #footer a:visited { 
134
+	margin-right: 20px; 
135
+	}
136
+
137
+#linkList {
138
+	margin-left: 600px; 
139
+	position: absolute; 
140
+	top: 0; 
141
+	right: 0;
142
+	}
143
+#linkList2 { 
144
+	font: 10px verdana, sans-serif; 
145
+	background: transparent url(paper-bg.jpg) top left repeat-y; 
146
+	padding: 10px; 
147
+	margin-top: 150px; 
148
+	width: 130px; 
149
+	}
150
+#linkList h3.select { 
151
+	background: transparent url(h3.gif) no-repeat top left; 
152
+	margin: 10px 0 5px 0; 
153
+	width: 97px; 
154
+	height: 16px; 
155
+	}
156
+#linkList h3.select span {
157
+	display:none
158
+	}
159
+#linkList h3.favorites { 
160
+	background: transparent url(h4.gif) no-repeat top left; 
161
+	margin: 25px 0 5px 0; 
162
+	width: 60px; 
163
+	height: 18px; 
164
+	}
165
+#linkList h3.favorites span {
166
+	display:none
167
+	}
168
+#linkList h3.archives { 
169
+	background: transparent url(h5.gif) no-repeat top left; 
170
+	margin: 25px 0 5px 0; 
171
+	width:57px; 
172
+	height: 14px; 
173
+	}
174
+#linkList h3.archives span {
175
+	display:none
176
+	}
177
+#linkList h3.resources { 
178
+	background: transparent url(h6.gif) no-repeat top left; 
179
+	margin: 25px 0 5px 0; 
180
+	width:63px; 
181
+	height: 10px; 
182
+	}
183
+#linkList h3.resources span {
184
+	display:none
185
+	}
186
+
187
+
188
+#linkList ul {
189
+	margin: 0;
190
+	padding: 0;
191
+	}
192
+#linkList li {
193
+	line-height: 2.5ex; 
194
+	background: transparent url(cr1.gif) no-repeat top center; 
195
+	display: block; 
196
+	padding-top: 5px; 
197
+	margin-bottom: 5px;
198
+	list-style-type: none;
199
+	}
200
+#linkList li a:link {
201
+	color: #988F5E;
202
+	}
203
+#linkList li a:visited {
204
+	color: #B3AE94;
205
+	}
206
+
207
+
208
+#extraDiv1 {
209
+	background: transparent url(cr2.gif) top left no-repeat; 
210
+	position: absolute; 
211
+	top: 40px; 
212
+	right: 0; 
213
+	width: 148px; 
214
+	height: 110px;
215
+	}
216
+.accesskey {
217
+	text-decoration: underline;
218
+	}

+ 3
- 3
dddsample/src/test/java/se/citerus/dddsample/domain/CargoTest.java 查看文件

@@ -15,20 +15,20 @@ public class CargoTest extends TestCase{
15 15
     Location origin = new Location("SESTO");
16 16
     Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, destination);
17 17
 
18
-		assertEquals(origin, cargo.currentLocation());
18
+		assertEquals(origin, cargo.getCurrentLocation());
19 19
 	}
20 20
 
21 21
 
22 22
   public void testCurrentLocationUnloaded() throws Exception {
23 23
 		Cargo cargo = populateCargoOffHongKong();
24 24
 		
25
-		assertEquals(new Location("CNHGK"), cargo.currentLocation());
25
+		assertEquals(new Location("CNHGK"), cargo.getCurrentLocation());
26 26
 	}
27 27
 	
28 28
 	public void testCurrentLocationloaded() throws Exception {
29 29
 		Cargo cargo = populateCargoOnHamburg();
30 30
 		
31
-		assertEquals(new Location("DEHAM"), cargo.currentLocation());
31
+		assertEquals(new Location("DEHAM"), cargo.getCurrentLocation());
32 32
 	}
33 33
 	
34 34
 	public void testAtFinalLocation() throws Exception {

+ 4
- 4
dddsample/src/test/java/se/citerus/dddsample/domain/TrackingScenarioTest.java 查看文件

@@ -14,15 +14,15 @@ public class TrackingScenarioTest extends TestCase {
14 14
 
15 15
     Cargo cargo = populateCargo();
16 16
 
17
-    DeliveryHistory deliveryHistory = cargo.deliveryHistory();
17
+    DeliveryHistory deliveryHistory = cargo.getDeliveryHistory();
18 18
 
19
-    SortedSet<HandlingEvent> handlingEvents = deliveryHistory.events();
19
+    SortedSet<HandlingEvent> handlingEvents = deliveryHistory.getEvents();
20 20
 
21 21
     assertEquals(4, handlingEvents.size());
22 22
     final HandlingEvent event = handlingEvents.last();
23
-    assertSame(HandlingEvent.Type.UNLOAD, event.type());
23
+    assertSame(HandlingEvent.Type.UNLOAD, event.getType());
24 24
     assertFalse(cargo.atFinalDestiation());
25
-    assertEquals("CNHKG", cargo.currentLocation().unlocode());
25
+    assertEquals("CNHKG", cargo.getCurrentLocation().unlocode());
26 26
 
27 27
   }
28 28
 

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/web/CargoTrackingControllerTest.java 查看文件

@@ -73,8 +73,8 @@ public class CargoTrackingControllerTest extends TestCase {
73 73
 
74 74
     assertEquals("test-success", mav.getViewName());
75 75
     assertEquals(3, mav.getModel().size());
76
-    Location location = (Location) mav.getModel().get("location");
77
-    assertEquals("AAA", location.unlocode());
76
+    Cargo cargo = (Cargo) mav.getModel().get("cargo");
77
+    assertEquals("AAA", cargo.getCurrentLocation().unlocode());
78 78
   }
79 79
 
80 80
   public void testUnknownCargo() throws Exception {