Revision: 8118
Author: [email protected]
Date: Wed May 12 14:52:17 2010
Log: The employee records now have a supervisorId that is propagated to the
reports. Plus, minor cleanup.
Patch by: amitmanjhi
Review by: rjrjr (tbr)
Review at http://gwt-code-reviews.appspot.com/518801
http://code.google.com/p/google-web-toolkit/source/detail?r=8118
Added:
/branches/2.1/bikeshed/scripts/expensesJsonData_small.txt
Modified:
/branches/2.1/bikeshed/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
/branches/2.1/bikeshed/src/com/google/gwt/requestfactory/shared/impl/RequestDataManager.java
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/server/DataGenerator.java
=======================================
--- /dev/null
+++ /branches/2.1/bikeshed/scripts/expensesJsonData_small.txt Wed May 12
14:52:17 2010
@@ -0,0 +1,443 @@
+{"CREATE": [
+ {"EmployeeRecord": {
+ "id": "1",
+ "department": "Sales",
+ "userName": "dluminous",
+ "displayName": "Dave Luminous"
+ }},
+ {"ReportRecord": {
+ "id": "2",
+ "created": 1267662990534,
+ "reporterKey": 1,
+ "department": "Sales",
+ "purpose": "Visting Miami",
+ "notes": ""
+ }},
+ {"ExpenseRecord": {
+ "amount": 223.74,
+ "id": "3",
+ "category": "Local Transportation",
+ "created": 1268397466537,
+ "description": "Train fare",
+ "reportId": 2
+ }},
+ {"ReportRecord": {
+ "id": "4",
+ "created": 1269746087537,
+ "reporterKey": 1,
+ "department": "Sales",
+ "purpose": "Paid vacation in Chicago",
+ "notes": "Need approval by Monday"
+ }},
+ {"ExpenseRecord": {
+ "amount": 64.39,
+ "id": "5",
+ "category": "Local Transportation",
+ "created": 1270791569537,
+ "description": "Bus ticket",
+ "reportId": 4
+ }},
+ {"EmployeeRecord": {
+ "id": "6",
+ "supervisorKey": "1",
+ "department": "Marketing",
+ "userName": "cperfect",
+ "displayName": "Catherine Perfect"
+ }},
+ {"ReportRecord": {
+ "id": "7",
+ "created": 1268750893537,
+ "approvedSupervisorKey": "1",
+ "reporterKey": 6,
+ "department": "Marketing",
+ "purpose": "Travelling to Zurich",
+ "notes": "Need approval by Monday"
+ }},
+ {"ExpenseRecord": {
+ "amount": 90.13,
+ "id": "8",
+ "category": "Office Supplies",
+ "created": 1271192214537,
+ "description": "Paperclips",
+ "reportId": 7
+ }},
+ {"EmployeeRecord": {
+ "id": "9",
+ "supervisorKey": "1",
+ "department": "Engineering",
+ "userName": "sluminous",
+ "displayName": "Sally Luminous"
+ }},
+ {"ReportRecord": {
+ "id": "10",
+ "created": 1268855245537,
+ "approvedSupervisorKey": "1",
+ "reporterKey": 9,
+ "department": "Engineering",
+ "purpose": "Paid vacation in Miami",
+ "notes": "Please bill to the Widgets project"
+ }},
+ {"ExpenseRecord": {
+ "amount": 106.19,
+ "id": "11",
+ "category": "Office Supplies",
+ "created": 1271298705537,
+ "description": "Paperclips",
+ "reportId": 10
+ }},
+ {"ExpenseRecord": {
+ "amount": 155.1,
+ "id": "12",
+ "category": "Office Supplies",
+ "created": 1267514069537,
+ "description": "Scissors",
+ "reportId": 10
+ }},
+ {"ReportRecord": {
+ "id": "13",
+ "created": 1268344663537,
+ "approvedSupervisorKey": "1",
+ "reporterKey": 9,
+ "department": "Engineering",
+ "purpose": "Having fun in Bangalore",
+ "notes": "Please bill to the Widgets project"
+ }},
+ {"ExpenseRecord": {
+ "amount": 117.64,
+ "id": "14",
+ "category": "Office Supplies",
+ "created": 1269771680537,
+ "description": "Stapler",
+ "reportId": 13
+ }},
+ {"EmployeeRecord": {
+ "id": "15",
+ "supervisorKey": "1",
+ "department": "Operations",
+ "userName": "hperfect",
+ "displayName": "Harriot Perfect"
+ }},
+ {"ReportRecord": {
+ "id": "16",
+ "created": 1273352534537,
+ "approvedSupervisorKey": "1",
+ "reporterKey": 15,
+ "department": "Operations",
+ "purpose": "Paid vacation in Atlanta",
+ "notes": "Show me the money"
+ }},
+ {"ExpenseRecord": {
+ "amount": 78.66,
+ "id": "17",
+ "category": "Local Transportation",
+ "created": 1266686806537,
+ "description": "Bus ticket",
+ "reportId": 16
+ }},
+ {"ExpenseRecord": {
+ "amount": 5.23,
+ "id": "18",
+ "category": "Office Supplies",
+ "created": 1269234622537,
+ "description": "Stapler",
+ "reportId": 16
+ }},
+ {"EmployeeRecord": {
+ "id": "19",
+ "supervisorKey": "9",
+ "department": "Finance",
+ "userName": "wstellar",
+ "displayName": "Wes Stellar"
+ }},
+ {"ReportRecord": {
+ "id": "20",
+ "created": 1266646885537,
+ "approvedSupervisorKey": "9",
+ "reporterKey": 19,
+ "department": "Finance",
+ "purpose": "Travelling to San Francisco",
+ "notes": "High priority"
+ }},
+ {"ExpenseRecord": {
+ "amount": 163.63,
+ "id": "21",
+ "category": "Local Transportation",
+ "created": 1267653390537,
+ "description": "Bus ticket",
+ "reportId": 20
+ }},
+ {"ExpenseRecord": {
+ "amount": 172.09,
+ "id": "22",
+ "category": "Office Supplies",
+ "created": 1273426519537,
+ "description": "Scissors",
+ "reportId": 20
+ }},
+ {"ExpenseRecord": {
+ "amount": 162.63,
+ "id": "23",
+ "category": "Lodging",
+ "created": 1270129391537,
+ "description": "Bed & Breakfast",
+ "reportId": 20
+ }},
+ {"EmployeeRecord": {
+ "id": "24",
+ "supervisorKey": "1",
+ "department": "Sales",
+ "userName": "ocool",
+ "displayName": "Owen Cool"
+ }},
+ {"ReportRecord": {
+ "id": "25",
+ "created": 1268528258537,
+ "approvedSupervisorKey": "1",
+ "reporterKey": 24,
+ "department": "Sales",
+ "purpose": "Work related visit to Atlanta",
+ "notes": "Show me the money"
+ }},
+ {"ExpenseRecord": {
+ "amount": 86.96,
+ "id": "26",
+ "category": "Office Supplies",
+ "created": 1269348517537,
+ "description": "Paste",
+ "reportId": 25
+ }},
+ {"EmployeeRecord": {
+ "id": "27",
+ "supervisorKey": "1",
+ "department": "Marketing",
+ "userName": "jstellar",
+ "displayName": "John Stellar"
+ }},
+ {"ReportRecord": {
+ "id": "28",
+ "created": 1271090354537,
+ "approvedSupervisorKey": "1",
+ "reporterKey": 27,
+ "department": "Marketing",
+ "purpose": "Having fun in New York",
+ "notes": "Need approval by Monday"
+ }},
+ {"ExpenseRecord": {
+ "amount": 122.04,
+ "id": "29",
+ "category": "Office Supplies",
+ "created": 1266438351537,
+ "description": "Paperclips",
+ "reportId": 28
+ }},
+ {"ExpenseRecord": {
+ "amount": 228.39,
+ "id": "30",
+ "category": "Local Transportation",
+ "created": 1268510017537,
+ "description": "Train fare",
+ "reportId": 28
+ }},
+ {"EmployeeRecord": {
+ "id": "31",
+ "supervisorKey": "27",
+ "department": "Engineering",
+ "userName": "fperfect",
+ "displayName": "Flin Perfect"
+ }},
+ {"ReportRecord": {
+ "id": "32",
+ "created": 1270982927537,
+ "approvedSupervisorKey": "27",
+ "reporterKey": 31,
+ "department": "Engineering",
+ "purpose": "Work related visit to Sydney",
+ "notes": "Please bill to the Widgets project"
+ }},
+ {"ExpenseRecord": {
+ "amount": 48.88,
+ "id": "33",
+ "category": "Dining",
+ "created": 1273254143537,
+ "description": "Dinner",
+ "reportId": 32
+ }},
+ {"ReportRecord": {
+ "id": "34",
+ "created": 1266536604537,
+ "approvedSupervisorKey": "27",
+ "reporterKey": 31,
+ "department": "Engineering",
+ "purpose": "Visting Istanbul",
+ "notes": "Need approval by Monday"
+ }},
+ {"ExpenseRecord": {
+ "amount": 110.32,
+ "id": "35",
+ "category": "Dining",
+ "created": 1273430771537,
+ "description": "Dinner",
+ "reportId": 34
+ }},
+ {"EmployeeRecord": {
+ "id": "36",
+ "supervisorKey": "1",
+ "department": "Operations",
+ "userName": "icool",
+ "displayName": "Ingrid Cool"
+ }},
+ {"ReportRecord": {
+ "id": "37",
+ "created": 1267304957537,
+ "approvedSupervisorKey": "1",
+ "reporterKey": 36,
+ "department": "Operations",
+ "purpose": "Work related visit to Los Angeles",
+ "notes": "Need approval by Monday"
+ }},
+ {"ExpenseRecord": {
+ "amount": 85.92,
+ "id": "38",
+ "category": "Air Travel",
+ "created": 1267519758537,
+ "description": "Flight from ATL to SFO",
+ "reportId": 37
+ }},
+ {"ExpenseRecord": {
+ "amount": 64.28,
+ "id": "39",
+ "category": "Office Supplies",
+ "created": 1268699796537,
+ "description": "Scissors",
+ "reportId": 37
+ }},
+ {"ReportRecord": {
+ "id": "40",
+ "created": 1270926097537,
+ "approvedSupervisorKey": "1",
+ "reporterKey": 36,
+ "department": "Operations",
+ "purpose": "Travelling to Miami",
+ "notes": "Need approval by Monday"
+ }},
+ {"ExpenseRecord": {
+ "amount": 157.25,
+ "id": "41",
+ "category": "Air Travel",
+ "created": 1270907118537,
+ "description": "Flight from ATL to SFO",
+ "reportId": 40
+ }},
+ {"EmployeeRecord": {
+ "id": "42",
+ "supervisorKey": "27",
+ "department": "Finance",
+ "userName": "foutstanding",
+ "displayName": "Flin Outstanding"
+ }},
+ {"ReportRecord": {
+ "id": "43",
+ "created": 1271459622537,
+ "approvedSupervisorKey": "27",
+ "reporterKey": 42,
+ "department": "Finance",
+ "purpose": "Travelling to Sydney",
+ "notes": "Show me the money"
+ }},
+ {"ExpenseRecord": {
+ "amount": 114.72,
+ "id": "44",
+ "category": "Lodging",
+ "created": 1267108281537,
+ "description": "Hotel",
+ "reportId": 43
+ }},
+ {"ExpenseRecord": {
+ "amount": 46.26,
+ "id": "45",
+ "category": "Office Supplies",
+ "created": 1266457109537,
+ "description": "Paperclips",
+ "reportId": 43
+ }},
+ {"ExpenseRecord": {
+ "amount": 100.51,
+ "id": "46",
+ "category": "Lodging",
+ "created": 1270482398537,
+ "description": "Bed & Breakfast",
+ "reportId": 43
+ }},
+ {"EmployeeRecord": {
+ "id": "47",
+ "supervisorKey": "1",
+ "department": "Sales",
+ "userName": "dterrific",
+ "displayName": "Dave Terrific"
+ }},
+ {"ReportRecord": {
+ "id": "48",
+ "created": 1266648017537,
+ "approvedSupervisorKey": "1",
+ "reporterKey": 47,
+ "department": "Sales",
+ "purpose": "Having fun in Frankfurt",
+ "notes": "Need approval by Monday"
+ }},
+ {"ExpenseRecord": {
+ "amount": 193.7,
+ "id": "49",
+ "category": "Air Travel",
+ "created": 1267182442537,
+ "description": "Flight from SFO to ATL",
+ "reportId": 48
+ }},
+ {"ExpenseRecord": {
+ "amount": 114.56,
+ "id": "50",
+ "category": "Local Transportation",
+ "created": 1268749600537,
+ "description": "Bus ticket",
+ "reportId": 48
+ }},
+ {"ExpenseRecord": {
+ "amount": 234.51,
+ "id": "51",
+ "category": "Lodging",
+ "created": 1272794433537,
+ "description": "Bed & Breakfast",
+ "reportId": 48
+ }},
+ {"EmployeeRecord": {
+ "id": "52",
+ "supervisorKey": "27",
+ "department": "Marketing",
+ "userName": "rradical",
+ "displayName": "Reece Radical"
+ }},
+ {"ReportRecord": {
+ "id": "53",
+ "created": 1273177476537,
+ "approvedSupervisorKey": "27",
+ "reporterKey": 52,
+ "department": "Marketing",
+ "purpose": "Travelling to Honolulu",
+ "notes": "Review A.S.A.P."
+ }},
+ {"ExpenseRecord": {
+ "amount": 30.39,
+ "id": "54",
+ "category": "Local Transportation",
+ "created": 1270186281537,
+ "description": "Taxi fare",
+ "reportId": 53
+ }},
+ {"ExpenseRecord": {
+ "amount": 198.2,
+ "id": "55",
+ "category": "Dining",
+ "created": 1273223135537,
+ "description": "Dinner",
+ "reportId": 53
+ }}
+]}
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
Tue May 11 20:06:57 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/requestfactory/server/SampleDataPopulator.java
Wed May 12 14:52:17 2010
@@ -18,6 +18,7 @@
import com.google.gwt.dev.util.Util;
import com.google.gwt.requestfactory.shared.RequestFactory;
import com.google.gwt.requestfactory.shared.RequestFactory.WriteOperation;
+import com.google.gwt.requestfactory.shared.impl.RequestDataManager;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
@@ -81,8 +82,8 @@
IOException, JSONException {
PostMethod post = new PostMethod(url);
JSONObject request = new JSONObject();
- request.put("operation", RequestFactory.SYNC);
- request.put("contentData", contentData);
+ request.put(RequestDataManager.OPERATION_TOKEN, RequestFactory.SYNC);
+ request.put(RequestDataManager.CONTENT_TOKEN, contentData);
post.setRequestBody(request.toString());
HttpClient client = new HttpClient();
int status = client.executeMethod(post);
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/requestfactory/shared/impl/RequestDataManager.java
Fri Apr 9 11:25:51 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/requestfactory/shared/impl/RequestDataManager.java
Wed May 12 14:52:17 2010
@@ -27,7 +27,6 @@
public class RequestDataManager {
public static final String CONTENT_TOKEN = "contentData";
- public static final String METHOD_TOKEN = "methodName";
public static final String OPERATION_TOKEN = "operation";
public static final String PARAM_TOKEN = "param";
=======================================
---
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/server/DataGenerator.java
Wed May 12 04:54:10 2010
+++
/branches/2.1/bikeshed/src/com/google/gwt/sample/expenses/server/DataGenerator.java
Wed May 12 14:52:17 2010
@@ -35,6 +35,10 @@
*
*/
public class DataGenerator {
+
+ // add support later. currently, it can be only zero.
+ private static final long ID_START = 0;
+
// Must be in sync with DESCRIPTIONS
private static final String[] CATEGORIES = {
"Dining", "Dining", "Dining", "Lodging", "Lodging",
@@ -43,7 +47,7 @@
"Office Supplies", "Office Supplies",};
private static final String[] DEPARTMENTS = {
- "Sales", "Marketing", "Engineering", "Operations"};
+ "Sales", "Marketing", "Engineering", "Operations", "Finance"};
// Must be in sync with CATEGORIES
private static final String[] DESCRIPTIONS = {
@@ -66,11 +70,15 @@
"", "Need approval by Monday", "Show me the money",
"Please bill to the Widgets project", "High priority", "Review
A.S.A.P."};
- private static final String[] PURPOSES = {
- "Spending lots of money", "Team building diamond cutting offsite",
- "Visit to Istanbul", "ISDN modem for telecommuting", "Sushi offsite",
- "Baseball card research", "Potato chip cooking offsite",
- "Money laundering", "Donut day"};
+ private static final String[] PURPOSES1 = {
+ "Visting", "Travelling to", "Having fun in", "Paid vacation in",
+ "Work related visit to"};
+
+ private static final String[] PURPOSES2 = {
+ "Istanbul", "Delhi", "Honolulu", "San Francisco", "Atlanta", "Miami",
+ "Los Angeles", "Sydney", "Dortmund", "Dusseldorf", "Melbourne",
+ "New York", "Chicago", "Mountain View", "Zurich", "Frankfurt",
+ "Bangalore"};
public static void main(String args[]) throws JSONException {
if (args.length < 2) {
@@ -93,7 +101,9 @@
List<Object> objectList = new ArrayList<Object>();
// TODO: hacky, assuming that id is assigned sequentially.
- long id = 1;
+ long id = ID_START + 1;
+ int employeeCount = 0;
+ List<Long> supervisors = new ArrayList<Long>();
List<Object> generateData(int numEmployees) {
// Initialize the database.
@@ -113,16 +123,26 @@
String username = (firstName.charAt(0) + lastName).toLowerCase();
abc.setUserName(username);
abc.setDisplayName(firstName + " " + lastName);
- String department = nextValue(DEPARTMENTS);
+ String department = DEPARTMENTS[employeeCount % DEPARTMENTS.length];
abc.setDepartment(department);
- abc.setId(id++);
+ long employeeId = id++;
+ abc.setId(employeeId);
objectList.add(abc);
-
- addReports(abc.getId(), department);
+ employeeCount++;
+ Long supervisorKey = nextValue(supervisors);
+ if (supervisorKey != null) {
+ abc.setSupervisorKey(supervisorKey);
+ }
+
+ if (supervisors.isEmpty() || rand.nextInt(3) == 0) {
+ supervisors.add(employeeId);
+ }
+
+ addReports(abc.getId(), department, supervisorKey);
}
private void addExpenses(Long reportId) {
- int num = rand.nextInt(5) + 1;
+ int num = rand.nextInt(3) + 1;
for (int i = 0; i < num; i++) {
int index = rand.nextInt(DESCRIPTIONS.length);
Expense detail = new Expense();
@@ -143,16 +163,19 @@
*
* @param employeeId the id of the employee who created the report
*/
- private void addReports(Long employeeId, String department) {
+ private void addReports(Long employeeId, String department, Long
supervisorKey) {
// Add 1-20 expense reports.
- int reportCount = 1 + rand.nextInt(20);
+ int reportCount = 1 + rand.nextInt(2);
for (int i = 0; i < reportCount; i++) {
Report report = new Report();
report.setCreated(getDate());
report.setDepartment(department);
report.setReporterKey(employeeId);
- report.setPurpose(nextValue(PURPOSES));
+ report.setPurpose(nextValue(PURPOSES1) + " " + nextValue(PURPOSES2));
report.setNotes(nextValue(NOTES));
+ if (supervisorKey != null) {
+ report.setApprovedSupervisorKey(supervisorKey);
+ }
report.setId(id++);
objectList.add(report);
@@ -173,6 +196,10 @@
jsonObject.put("userName", employee.getUserName());
jsonObject.put("displayName", employee.getDisplayName());
jsonObject.put("department", employee.getDepartment());
+ Long supervisorKey = employee.getSupervisorKey();
+ if (supervisorKey != null) {
+ jsonObject.put("supervisorKey", "" + employee.getSupervisorKey());
+ }
return jsonObject;
}
@@ -215,8 +242,19 @@
jsonObject.put("reporterKey", report.getReporterKey());
jsonObject.put("purpose", report.getPurpose());
jsonObject.put("notes", report.getNotes());
+ Long approvedSupervisorKey = report.getApprovedSupervisorKey();
+ if (approvedSupervisorKey != null) {
+ jsonObject.put("approvedSupervisorKey", "" +
report.getApprovedSupervisorKey());
+ }
return jsonObject;
}
+
+ private Long nextValue(List<Long> supervisors) {
+ if (supervisors.isEmpty()) {
+ return null;
+ }
+ return supervisors.get(rand.nextInt(supervisors.size()));
+ }
/**
* Get the next random value from an array.
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors