Source Code Cross Referenced for ProjectController.java in  » Project-Management » EmForce » org » emforge » projectmanager » web » bean » 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 » Project Management » EmForce » org.emforge.projectmanager.web.bean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.emforge.projectmanager.web.bean;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collection;
005:        import java.util.GregorianCalendar;
006:        import java.util.LinkedList;
007:        import java.util.TimeZone;
008:
009:        import javax.faces.context.FacesContext;
010:        import javax.servlet.http.HttpServletRequest;
011:
012:        import org.apache.commons.lang.StringUtils;
013:        import org.emforge.BpmService;
014:        import org.emforge.CommentService;
015:        import org.emforge.EmForgeException;
016:        import org.emforge.projectmanager.ProjectService;
017:        import org.emforge.projectmanager.base.MilestoneDO;
018:        import org.emforge.projectmanager.base.ProjectDO;
019:        import org.emforge.xfer.CommentTO;
020:        import org.emforge.xfer.TaskStatus;
021:
022:        import ru.emdev.EmForge.web.bean.BaseControllerImpl;
023:        import ru.emdev.EmForge.web.bean.EditTextController;
024:        import ru.emdev.EmForge.web.bean.MainMenuController.MainMenuItem;
025:        import ru.emdev.EmForge.wiki.web.bean.Crumb;
026:
027:        import com.ecyrd.jspwiki.WikiContext;
028:        import com.ecyrd.jspwiki.WikiPage;
029:        import com.ecyrd.jspwiki.attachment.Attachment;
030:        import com.ecyrd.jspwiki.providers.ProviderException;
031:
032:        /**
033:         * Controller for processing editing of project
034:         *
035:         * @author mchirkov
036:         */
037:        public class ProjectController extends BaseControllerImpl {
038:            public static final String PROJECT_PAGE_NAME = "project";
039:            public static final String PROJECT_ID_ATTR = "id";
040:            public static final String PROJECT_PAGE_ATTR = "page";
041:
042:            protected ProjectService m_projectService;
043:
044:            private ProjectDO m_project;
045:
046:            BpmService m_bpmService;
047:
048:            CommentService m_commentService;
049:            EditTextController m_editTextController;
050:
051:            Collection<MilestoneData> m_openedMilestones;
052:            Collection<MilestoneData> m_closedMilestones;
053:
054:            public void setProjectService(ProjectService i_projectService) {
055:                m_projectService = i_projectService;
056:            }
057:
058:            public void setBpmService(BpmService i_bpmService) {
059:                m_bpmService = i_bpmService;
060:            }
061:
062:            public void setCommentService(CommentService i_commentService) {
063:                m_commentService = i_commentService;
064:            }
065:
066:            public void setEditTextController(
067:                    EditTextController i_editTextController) {
068:                m_editTextController = i_editTextController;
069:            }
070:
071:            @Override
072:            public MainMenuItem getSelectionItemOnMainMenu() {
073:                return MainMenuItem.PROJECTS;
074:            }
075:
076:            public String getTitleImpl() {
077:                return m_project.getDisplayName();
078:            }
079:
080:            @Override
081:            public Crumb getTrailCrumbInfo() {
082:                if (m_project == null) {
083:                    return null;
084:                }
085:                String displayName;
086:                String url;
087:                try {
088:                    displayName = m_project.getName();
089:                    url = PROJECT_PAGE_NAME + "/" + m_project.getName();
090:                } catch (Exception ex) {
091:                    logger.debug("Cannot get trail crumb info: ", ex);
092:                    return null;
093:                }
094:                return new Crumb(displayName, url);
095:            }
096:
097:            @Override
098:            protected void init() {
099:                if (m_appContext != null && m_projectService != null) {
100:                    HttpServletRequest request = (HttpServletRequest) FacesContext
101:                            .getCurrentInstance().getExternalContext()
102:                            .getRequest();
103:
104:                    String id = request.getParameter(PROJECT_ID_ATTR);
105:                    String name = null;
106:
107:                    if (StringUtils.isNotEmpty(id)) {
108:                        try {
109:                            m_project = m_projectService.getProject(Long
110:                                    .valueOf(id));
111:                        } catch (Exception ex) {
112:                            // just ignore it here
113:                        }
114:                    }
115:
116:                    if (m_project != null) {
117:                        name = m_project.getName();
118:                    } else if (StringUtils.isNotEmpty(request
119:                            .getParameter(PROJECT_PAGE_ATTR))) {
120:                        name = request.getParameter(PROJECT_PAGE_ATTR);
121:                        m_project = m_projectService.getProject(name);
122:
123:                    } else {
124:                        m_project = new ProjectDO("");
125:                    }
126:
127:                    if (name != null) {
128:                        // set it into editTextController
129:                        m_editTextController.setPageName(name);
130:                    }
131:                }
132:            }
133:
134:            public String save() {
135:                Boolean wasNew = isNewProject();
136:
137:                try {
138:                    m_projectService.saveProject(m_project);
139:
140:                    if (wasNew) {
141:                        addInfoMessage("New Project Created", null);
142:                    } else {
143:                        addInfoMessage("Project Changes Saved", null);
144:                    }
145:
146:                    // navigate to edit window - if it was new project
147:                    if (wasNew) {
148:                        redirect("edit/" + m_project.getName());
149:                        return null;
150:                    } else {
151:                        // returns to the project page
152:                        return "project";
153:                    }
154:                } catch (Exception ex) {
155:                    logger.error("Cannot save project", ex);
156:
157:                    if (wasNew) {
158:                        addErrorMessage("Cannot Created Project", ex
159:                                .getMessage());
160:                    } else {
161:                        addErrorMessage("Cannot Save Changes", ex.getMessage());
162:                    }
163:
164:                    return null;
165:                }
166:            }
167:
168:            public boolean isNewProject() {
169:                if (m_project != null) {
170:                    return (m_project.getId() == null);
171:                }
172:                return false;
173:            }
174:
175:            public ProjectDO getProject() {
176:                return m_project;
177:            }
178:
179:            @SuppressWarnings("unchecked")
180:            public Collection getOpenedMilestones() throws EmForgeException {
181:                if (m_openedMilestones == null) {
182:                    m_openedMilestones = new ArrayList<MilestoneData>();
183:
184:                    Collection<MilestoneDO> milestones = m_projectService
185:                            .getOpenedMilestones(m_project);
186:                    for (MilestoneDO milestone : milestones) {
187:                        int opened = m_bpmService.findTasks(
188:                                milestone.getName(), TaskStatus.OPENED, true)
189:                                .size();
190:                        int closed = m_bpmService.findTasks(
191:                                milestone.getName(), TaskStatus.CLOSED, true)
192:                                .size();
193:
194:                        m_openedMilestones.add(new MilestoneData(milestone,
195:                                opened, closed));
196:                    }
197:                }
198:
199:                return m_openedMilestones;
200:            }
201:
202:            @SuppressWarnings("unchecked")
203:            public Collection getClosedMilestones() throws EmForgeException {
204:                if (m_closedMilestones == null) {
205:                    m_closedMilestones = new ArrayList<MilestoneData>();
206:
207:                    Collection<MilestoneDO> milestones = m_projectService
208:                            .getClosedMilestones(m_project);
209:                    for (MilestoneDO milestone : milestones) {
210:                        int opened = m_bpmService.findTasks(
211:                                milestone.getName(), TaskStatus.OPENED, true)
212:                                .size();
213:                        int closed = m_bpmService.findTasks(
214:                                milestone.getName(), TaskStatus.CLOSED, true)
215:                                .size();
216:
217:                        m_closedMilestones.add(new MilestoneData(milestone,
218:                                opened, closed));
219:                    }
220:                }
221:
222:                return m_closedMilestones;
223:            }
224:
225:            /** 
226:             * @deprecated We should found some other solution to work with time-zones
227:             * @return
228:             */
229:            public TimeZone getTimeZone() {
230:                return new GregorianCalendar().getTimeZone();
231:            }
232:
233:            public Long getProjectId() {
234:                if (m_project != null) {
235:                    return m_project.getId();
236:                }
237:
238:                return null;
239:            }
240:
241:            public void setProjectId(Long id) {
242:                if (id != null) {
243:                    m_project = m_projectService.getProject(id);
244:                } else {
245:                    m_project = new ProjectDO("");
246:                }
247:            }
248:
249:            public boolean getCanAddMilestone() {
250:                return m_projectService.canCreateMilestone(m_project);
251:            }
252:
253:            public boolean getCanAddProject() {
254:                return m_projectService.canCreateProject();
255:            }
256:
257:            public boolean getCanSaveProject() {
258:                return m_projectService.canChangeProject(m_project);
259:            }
260:
261:            public boolean getCanViewProjectRoles() {
262:                return !getCurrentUser().isAnonymous();
263:            }
264:
265:            public class MilestoneData {
266:
267:                MilestoneDO m_milestone;
268:                int m_openedProcessesCount;
269:                int m_closedProcessesCount;
270:
271:                public MilestoneData(MilestoneDO i_milestone,
272:                        int i_openedProcessesCount, int i_closedProcessesCount) {
273:                    m_milestone = i_milestone;
274:                    m_openedProcessesCount = i_openedProcessesCount;
275:                    m_closedProcessesCount = i_closedProcessesCount;
276:                }
277:
278:                public int getClosedProcessesCount() {
279:                    return m_closedProcessesCount;
280:                }
281:
282:                public MilestoneDO getMilestone() {
283:                    return m_milestone;
284:                }
285:
286:                public int getOpenedProcessesCount() {
287:                    return m_openedProcessesCount;
288:                }
289:
290:                public int getOpenedProcessesPercentage() {
291:                    return 100 * m_openedProcessesCount
292:                            / (m_openedProcessesCount + m_closedProcessesCount);
293:                }
294:
295:                public int getClosedProcessesPercentage() {
296:                    return 100 - getOpenedProcessesPercentage();
297:                }
298:            }
299:
300:            /** Returns Attachments for Project
301:             * 
302:             * @return
303:             */
304:            @SuppressWarnings("unchecked")
305:            public Collection<Attachment> getAttachments() {
306:                if (isNewProject()) {
307:                    // return empty list
308:                    return new LinkedList<Attachment>();
309:                }
310:
311:                // attachments for project are stored in wiki-engine
312:                Collection<Attachment> result = new ArrayList<Attachment>();
313:
314:                WikiContext wikiContext = getWikiContext();
315:                if (wikiContext != null) {
316:                    try {
317:                        WikiPage page = wikiContext.getPage();
318:                        if (page != null) {
319:                            result = wikiContext.getEngine()
320:                                    .getAttachmentManager().listAttachments(
321:                                            page);
322:                        }
323:                    } catch (ProviderException e) {
324:                        logger.error("Cannot get attachment list: ", e);
325:                        return result;
326:                    }
327:                }
328:                return result;
329:
330:            }
331:
332:            private WikiContext getWikiContext() {
333:                if (StringUtils.isEmpty(getProject().getName())) {
334:                    return null;
335:                }
336:
337:                WikiPage page = m_wikiEngine
338:                        .getPage(getProject().getName(), -1);
339:                if (page != null) {
340:                    return new WikiContext(m_wikiEngine, page);
341:                }
342:
343:                return null;
344:            }
345:
346:            public CommentTO[] getComments() throws EmForgeException {
347:                return m_commentService.getComments(getProject().getName());
348:            }
349:
350:            /** Logged-In user can add comments for project
351:             * 
352:             */
353:            public boolean isCanAddComment() {
354:                return !m_appContext.getUserService().getCurrentUser()
355:                        .isAnonymous()
356:                        && !isNewProject();
357:            }
358:
359:            public String addComment() {
360:                String comment = m_editTextController.getWikiText();
361:
362:                if (StringUtils.isNotEmpty(comment)) {
363:                    try {
364:                        m_commentService.addComment(getProject().getName(),
365:                                comment);
366:                    } catch (EmForgeException ex) {
367:                        logger.error("Cannot add comment for project: "
368:                                + getProject().getName(), ex);
369:                        addErrorMessage("Cannot add comment: "
370:                                + ex.getMessage(), "Cannot add comment: "
371:                                + ex.getMessage());
372:                    }
373:
374:                }
375:
376:                return null;
377:            }
378:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.