Source Code Cross Referenced for AdministeringSearch.java in  » J2EE » Enhydra-Demos » projectmanagement » presentation » worksheets » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Enhydra Demos » projectmanagement.presentation.worksheets 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package projectmanagement.presentation.worksheets;
002:
003:        import projectmanagement.presentation.*;
004:        import projectmanagement.spec.timewage.*;
005:        import projectmanagement.spec.employee.*;
006:        import projectmanagement.spec.project.*;
007:        import com.lutris.appserver.server.httpPresentation.*;
008:        import org.enhydra.xml.xmlc.XMLObject;
009:
010:        import org.w3c.dom.*;
011:        import org.w3c.dom.html.*;
012:
013:        import java.util.Calendar;
014:        import java.util.GregorianCalendar;
015:        import java.sql.Date;
016:        import java.sql.Time;
017:        import java.lang.*;
018:
019:        /**
020:         * Shows a list of work sheets to administer.
021:         *
022:         * @author Sasa Bojanic, Nenad Stefanovic
023:         * @version 1.0
024:         */
025:        public class AdministeringSearch extends BasePO {
026:
027:            private static String EMPLOYEE = "employee";
028:            private static String PROJECT = "project";
029:            private static String FROMYEAR = "fromYear";
030:            private static String FROMMONTH = "fromMonth";
031:            private static String FROMDAY = "fromDay";
032:            private static String TOYEAR = "toYear";
033:            private static String TOMONTH = "toMonth";
034:            private static String TODAY = "toDay";
035:
036:            private static String IS_PERSONAL = "isPersonal";
037:
038:            /**
039:             * Superclass method override. Returns 1 or 2, depending on action.
040:             */
041:            protected int getRequiredAuthLevel() {
042:                String isPersonal = "";
043:                try {
044:                    isPersonal = this .getComms().request
045:                            .getParameter(IS_PERSONAL);
046:                } catch (Exception ex) {
047:                }
048:
049:                if (isPersonal != null && isPersonal.equalsIgnoreCase("true")) {
050:                    return 1;
051:                } else {
052:                    return 2;
053:                }
054:            }
055:
056:            /**
057:             *  Default event. Just show the page.
058:             */
059:            public XMLObject handleDefault() throws HttpPresentationException,
060:                    ClientPageRedirectException {
061:
062:                AdministeringHTML page = new AdministeringHTML();
063:                String employee = null;
064:                String project = null;
065:                boolean multiple = false;
066:                //for advanced search
067:                java.util.ArrayList employeeIDs = new java.util.ArrayList();
068:                ;
069:                int index = 0;
070:                String employeeID = EMPLOYEE + String.valueOf("0");
071:
072:                while (this .getComms().request.getParameter(employeeID) != null) {
073:                    employeeIDs.add(this .getComms().request
074:                            .getParameter(employeeID));
075:                    index++;
076:                    employeeID = EMPLOYEE + String.valueOf(index);
077:                }
078:
079:                //checking if there are multiple selection or is ALL selected
080:                try {
081:                    if (employeeIDs.size() == 1
082:                            || employeeIDs.get(0).toString().equals("")) {
083:                        employee = employeeIDs.get(0).toString();
084:                        if (employee != null && employee.length() == 0) {
085:                            employee = null;
086:                        }
087:                    } else {
088:                        multiple = true;
089:                    }
090:                } catch (IndexOutOfBoundsException e) {
091:                }
092:                java.util.ArrayList projectIDs = new java.util.ArrayList();
093:                index = 0;
094:                String projectID = PROJECT + String.valueOf("0");
095:                while (this .getComms().request.getParameter(projectID) != null) {
096:
097:                    projectIDs.add(this .getComms().request
098:                            .getParameter(projectID));
099:                    index++;
100:                    projectID = PROJECT + String.valueOf(index);
101:
102:                }
103:                //checking if there are multiple selection or is ALL selected
104:                if (projectIDs.size() == 1
105:                        || projectIDs.get(0).toString().equals("")) {
106:                    project = projectIDs.get(0).toString();
107:                    if (project != null && project.length() == 0) {
108:                        project = null;
109:                    }
110:                } else {
111:                    multiple = true;
112:                }
113:
114:                String fromYear = this .getComms().request
115:                        .getParameter(FROMYEAR);
116:                if (fromYear != null && fromYear.length() == 0) {
117:                    fromYear = null;
118:                }
119:                String fromMonth = this .getComms().request
120:                        .getParameter(FROMMONTH);
121:                if (fromMonth != null && fromMonth.length() == 0) {
122:                    fromMonth = null;
123:                }
124:                String fromDay = this .getComms().request.getParameter(FROMDAY);
125:                if (fromDay != null && fromDay.length() == 0) {
126:                    fromDay = null;
127:                }
128:
129:                String toYear = this .getComms().request.getParameter(TOYEAR);
130:                if (toYear != null && toYear.length() == 0) {
131:                    toYear = null;
132:                }
133:                String toMonth = this .getComms().request.getParameter(TOMONTH);
134:                if (toMonth != null && toMonth.length() == 0) {
135:                    toMonth = null;
136:                }
137:                String toDay = this .getComms().request.getParameter(TODAY);
138:                if (toDay != null && toDay.length() == 0) {
139:                    toDay = null;
140:                }
141:                boolean checkDates = true;
142:                String params = "";
143:                if (!checkDate(fromYear, fromMonth, fromDay)) {
144:                    params += "?checkFromDate=false";
145:                    checkDates = false;
146:                }
147:                if (!checkDate(toYear, toMonth, toDay)) {
148:                    if (!checkDates) {
149:                        params += "&checkToDate=false";
150:                    } else {
151:                        params += "?checkToDate=false";
152:                    }
153:                    checkDates = false;
154:                }
155:                if (!checkDates) {
156:                    throw new ClientPageRedirectException("Search.po" + params);
157:                }
158:
159:                HTMLFormElement form = page.getElementForm();
160:                form.setAttribute("target", "_self");
161:
162:                // fetches the table element from HTML document
163:                HTMLTableElement table = page.getElementTblWorkSheets();
164:                try {
165:                    WorkSheet[] workSheets = null;
166:                    WorkSheetManager workSheetManager = WorkSheetManagerFactory
167:                            .getWorkSheetManager("projectmanagement.business.timewage.WorkSheetManagerImpl");
168:
169:                    Calendar c1 = Calendar.getInstance();
170:                    Calendar c2 = Calendar.getInstance();
171:
172:                    if (fromYear != null && fromMonth != null
173:                            && fromDay != null && toYear != null
174:                            && toMonth != null && toDay != null) {
175:
176:                        c1.set(Integer.parseInt(fromYear), Integer
177:                                .parseInt(fromMonth) - 1, Integer
178:                                .parseInt(fromDay));
179:                        c2
180:                                .set(Integer.parseInt(toYear), Integer
181:                                        .parseInt(toMonth) - 1, Integer
182:                                        .parseInt(toDay));
183:
184:                        if (!multiple) {
185:                            workSheets = workSheetManager
186:                                    .getAllWorkSheetsForEmployeeProjectPairFromDate1ToDate2(
187:                                            employee, project, new Date(c1
188:                                                    .getTimeInMillis()),
189:                                            new Date(c2.getTimeInMillis()));
190:                        } else {
191:                            workSheets = workSheetManager
192:                                    .getAllWorksheetsForEmployeeArrayAndProjectArrayBetweenDates(
193:                                            employeeIDs, projectIDs, new Date(
194:                                                    c1.getTimeInMillis()),
195:                                            new Date(c2.getTimeInMillis()));
196:                        }
197:                    }
198:                    double sumOfHours = 0;
199:                    double sumOfMoney = 0;
200:                    if (workSheets != null) {
201:                        HoursAndMoney ham = new HoursAndMoney();
202:                        for (int i = 0; i < workSheets.length; i++) {
203:                            // creating row in HTML table which describes table properties
204:                            HTMLTableRowElement htmlRE = createNewRow(page,
205:                                    workSheets[i], ham);
206:                            // appending row at the end of table
207:                            table.appendChild(htmlRE);
208:                        }
209:                        sumOfHours = ham.getHours();
210:                        sumOfMoney = ham.getMoney();
211:                        sumOfMoney = (double) (Math.round(sumOfMoney * 100)) / 100;
212:                        sumOfHours = (double) (Math.round(sumOfHours * 100)) / 100;
213:                    }
214:                    page.setTextTxtSumOfHours(String.valueOf(sumOfHours));
215:                    page.setTextTxtSumOfMoney(String.valueOf(sumOfMoney));
216:
217:                    /* Catch Null pointer exception ( we canot make a instances of classes from business layer  when we run ProjectManagement_pres )
218:                     * We need  to allow ProjectManagement_pres to be functional ,  response
219:                     * will be default HTML page 
220:                     */
221:
222:                } catch (NullPointerException ex) {
223:                    return page;
224:                } catch (Exception ex) {
225:                    this .writeDebugMsg("Error populating list of work sheets: "
226:                            + ex);
227:                    throw new ProjectManagementPresentationException(
228:                            "Error getting list of work sheets: ", ex);
229:                }
230:
231:                //Remove template selection row from table
232:                table.removeChild(page.getElementTemplateRow());
233:
234:                String errorMsg = this .getSessionData()
235:                        .getAndClearUserMessage();
236:                /*if(null != errorMsg) {
237:                   page.setTextLblErrorText(errorMsg);
238:                } else {
239:                   page.getElementLblErrorText().getParentNode().removeChild(page.getElementLblErrorText());
240:                }*/
241:
242:                String isPersonal = this .getComms().request
243:                        .getParameter(IS_PERSONAL);
244:                if (isPersonal != null && isPersonal.equalsIgnoreCase("true")) {
245:                    HTMLInputElement ip = page.getElementIsPersonal();
246:                    ip.setValue("true");
247:                }
248:                // write out HTML
249:                return page;
250:            }
251:
252:            /**
253:             * Check if given date is OK
254:             */
255:            private boolean checkDate(String year, String month, String day) {
256:                GregorianCalendar cal = new GregorianCalendar();
257:                boolean retVal = true;
258:                cal.setLenient(false);
259:                cal.set(Integer.parseInt(year), Integer.parseInt(month) - 1, 1);
260:                if (cal.getActualMaximum(Calendar.DAY_OF_MONTH) < Integer
261:                        .parseInt(day)) {
262:                    retVal = false;
263:                } else if (cal.isLeapYear(Integer.parseInt(year))
264:                        && Integer.parseInt(month) == 1
265:                        && Integer.parseInt(day) == 29) {
266:                    retVal = true;
267:                } else {
268:                    retVal = true;
269:                }
270:                return retVal;
271:            }
272:
273:            /**
274:             * Creates the new row of HTML table element, based on given parameters.
275:             */
276:            private HTMLTableRowElement createNewRow(
277:                    AdministeringHTML administeringHTML, WorkSheet workSheet,
278:                    HoursAndMoney ham) {
279:
280:                String workSheetID = "";
281:
282:                try {
283:                    workSheetID = workSheet.getHandle();
284:                    PayRate pr = workSheet.getPayRate();
285:                    Employee emp = pr.getEmployee();
286:                    Project prj = pr.getProject();
287:                    Time timeStarted = workSheet.getTimeStarted();
288:                    Time timeFinished = workSheet.getTimeFinished();
289:                    administeringHTML.setTextTxtEmployee(emp.getFirstName()
290:                            + " " + emp.getLastName());
291:                    administeringHTML.setTextTxtProject(prj.getName());
292:                    Calendar cal = new GregorianCalendar();
293:                    cal.setTime(workSheet.getWorkingDate());
294:                    String wd = String.valueOf(cal.get(Calendar.YEAR)) + "-"
295:                            + String.valueOf(cal.get(Calendar.MONTH) + 1) + "-"
296:                            + String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
297:                    administeringHTML.setTextTxtWorkingDate(wd);
298:                    cal.setTime(timeStarted);
299:                    String tst = String.valueOf(cal.get(Calendar.HOUR)) + ":"
300:                            + String.valueOf(cal.get(Calendar.MINUTE));
301:                    administeringHTML.setTextTxtTimeStarted(tst);
302:                    cal.setTime(timeFinished);
303:                    String tfn = String.valueOf(cal.get(Calendar.HOUR)) + ":"
304:                            + String.valueOf(cal.get(Calendar.MINUTE));
305:                    administeringHTML.setTextTxtTimeFinished(tfn);
306:                    double mny = (double) (Math.round(ham.calculate(
307:                            calculateTimeDifferenceInHours(timeStarted,
308:                                    timeFinished), prj.getMoneyPerHour(), pr
309:                                    .getRate()) * 100)) / 100;
310:                    administeringHTML.setTextTxtMoney(String.valueOf(mny));
311:                } catch (Exception ex) {
312:                }
313:
314:                // image to get details on work sheet
315:                HTMLImageElement detailsImg = administeringHTML
316:                        .getElementImgDetails();
317:                detailsImg.setName(workSheetID);
318:
319:                // image to modify work sheet information
320:                HTMLImageElement modifyImg = administeringHTML
321:                        .getElementImgModify();
322:                modifyImg.setName(workSheetID);
323:
324:                // image to delete work sheet
325:                HTMLImageElement deleteImg = administeringHTML
326:                        .getElementImgDelete();
327:                deleteImg.setName(workSheetID);
328:
329:                HTMLTableRowElement row = (HTMLTableRowElement) administeringHTML
330:                        .getElementTemplateRow().cloneNode(true);
331:
332:                return row;
333:            }
334:
335:            private double calculateTimeDifferenceInHours(Time timeStarted,
336:                    Time timeFinished) {
337:                long ts = timeStarted.getTime();
338:                long tf = timeFinished.getTime();
339:                long diffInMilliseconds = tf - ts;
340:                double diffInHours = diffInMilliseconds / 3600000.0;
341:                return diffInHours;
342:            }
343:
344:            class HoursAndMoney {
345:                private double hours = 0;
346:                private double money = 0;
347:
348:                public double calculate(double hrs, double moneyPerHour,
349:                        double payRate) {
350:                    hours += hrs;
351:                    double dm = hrs * moneyPerHour * payRate;
352:                    money += dm;
353:                    return dm;
354:                }
355:
356:                public double getHours() {
357:                    return hours;
358:                }
359:
360:                public double getMoney() {
361:                    return money;
362:                }
363:            }
364:
365:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.