Skip to content
Browse files

Persisting time

  • Loading branch information...
1 parent 17063fe commit 710d88c96aec30bb8ec9c10aa48c75d7ed8f84d9 @matthewmccullough committed Apr 22, 2010
View
2 ExerciseGAE/build.xml
@@ -82,7 +82,7 @@
<javac srcdir="src" destdir="${war.dir}/WEB-INF/classes">
<classpath>
<fileset dir="${appengine.sdk}/lib/user">
- <include name="*.jar"/>
+ <include name="**/*.jar"/>
</fileset>
<fileset dir="${appengine.sdk}/lib/shared">
<include name="*.jar"/>
View
11 ExerciseGAE/src/WEB-INF/web.xml
@@ -14,6 +14,17 @@ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet-name>Quota</servlet-name>
<url-pattern>/quota</url-pattern>
</servlet-mapping>
+
+ <servlet>
+ <servlet-name>AddTime</servlet-name>
+ <servlet-class>com.ambientideas.invoicetimetracking.AddTimeServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>AddTime</servlet-name>
+ <url-pattern>/addtime</url-pattern>
+ </servlet-mapping>
+
+
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
View
50 ExerciseGAE/src/com/ambientideas/invoicetimetracking/AddTimeServlet.java
@@ -0,0 +1,50 @@
+package com.ambientideas.invoicetimetracking;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.logging.Logger;
+import javax.jdo.PersistenceManager;
+import javax.servlet.http.*;
+import com.google.appengine.api.users.User;
+import com.google.appengine.api.users.UserService;
+import com.google.appengine.api.users.UserServiceFactory;
+
+public class AddTimeServlet extends HttpServlet {
+ private static final long serialVersionUID = -547355420609921703L;
+ private static final Logger log = Logger.getLogger(AddTimeServlet.class
+ .getName());
+
+ public void doPost(HttpServletRequest req, HttpServletResponse resp)
+ throws IOException {
+ UserService userService = UserServiceFactory.getUserService();
+ User user = userService.getCurrentUser();
+
+ String hoursWorked = req.getParameter("hoursWorked");
+ log.warning("Hours Worked: " + hoursWorked);
+ log.warning("Hours Worked as Float: " + new Float(hoursWorked));
+ String workComments = req.getParameter("workComments");
+ log.warning("Work Comments: " + workComments);
+
+ Date date = new Date();
+ log.warning("Date: " + date);
+
+ String employeeName = "Anonymous";
+ if (user != null && user.getEmail() != null) {
+ employeeName = user.getEmail();
+ }
+
+ TimeTracked timetracked = new TimeTracked(new Float(hoursWorked),
+ workComments, date, employeeName);
+
+ log.info("Creating time for: " + timetracked);
+
+ PersistenceManager pm = PMF.get().getPersistenceManager();
+ try {
+ pm.makePersistent(timetracked);
+ } finally {
+ pm.close();
+ }
+
+ resp.sendRedirect("/listtime.jsp");
+ }
+}
View
20 ExerciseGAE/src/com/ambientideas/invoicetimetracking/TimeTracked.java
@@ -26,6 +26,14 @@
@Persistent
private String employeeName;
+ public TimeTracked(Float hoursWorked, String workComments, Date date,
+ String employeeName) {
+ super();
+ this.hoursWorked = hoursWorked;
+ this.workComments = workComments;
+ this.date = date;
+ this.employeeName = employeeName;
+ }
public Long getId() {
return id;
@@ -66,4 +74,16 @@ public String getEmployeeName() {
public void setEmployeeName(String employeeName) {
this.employeeName = employeeName;
}
+
+ @Override
+ public String toString() {
+ return "TimeTracked ["
+ + (date != null ? "date=" + date + ", " : "")
+ + (employeeName != null ? "employeeName=" + employeeName + ", "
+ : "")
+ + (hoursWorked != null ? "hoursWorked=" + hoursWorked + ", "
+ : "") + (id != null ? "id=" + id + ", " : "")
+ + (workComments != null ? "workComments=" + workComments : "")
+ + "]";
+ }
}
View
2 ExerciseGAE/war/WEB-INF/appengine-generated/datastore-indexes-auto.xml
@@ -1,4 +1,4 @@
-<!-- Indices written at Thu, 22 Apr 2010 19:45:27 UTC -->
+<!-- Indices written at Thu, 22 Apr 2010 20:00:51 UTC -->
<datastore-indexes/>
View
BIN ExerciseGAE/war/WEB-INF/appengine-generated/local_db.bin
Binary file not shown.
View
11 ExerciseGAE/war/WEB-INF/classes/WEB-INF/web.xml
@@ -14,6 +14,17 @@ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet-name>Quota</servlet-name>
<url-pattern>/quota</url-pattern>
</servlet-mapping>
+
+ <servlet>
+ <servlet-name>AddTime</servlet-name>
+ <servlet-class>com.ambientideas.invoicetimetracking.AddTimeServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>AddTime</servlet-name>
+ <url-pattern>/addtime</url-pattern>
+ </servlet-mapping>
+
+
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
View
11 ExerciseGAE/war/WEB-INF/web.xml
@@ -14,6 +14,17 @@ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet-name>Quota</servlet-name>
<url-pattern>/quota</url-pattern>
</servlet-mapping>
+
+ <servlet>
+ <servlet-name>AddTime</servlet-name>
+ <servlet-class>com.ambientideas.invoicetimetracking.AddTimeServlet</servlet-class>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>AddTime</servlet-name>
+ <url-pattern>/addtime</url-pattern>
+ </servlet-mapping>
+
+
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

0 comments on commit 710d88c

Please sign in to comment.
Something went wrong with that request. Please try again.