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


001:        package org.emforge.projectmanager.impl;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collection;
005:        import java.util.List;
006:
007:        import org.acegisecurity.AccessDeniedException;
008:        import org.acegisecurity.userdetails.UserDetails;
009:        import org.acegisecurity.userdetails.UsernameNotFoundException;
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:        import org.emforge.projectmanager.ProjectService;
013:        import org.emforge.projectmanager.ProjectServiceException;
014:        import org.emforge.projectmanager.base.MilestoneDO;
015:        import org.emforge.projectmanager.base.ProjectDO;
016:        import org.emforge.projectmanager.base.ProjectRole;
017:        import org.emforge.projectmanager.base.ProjectUserRole;
018:        import org.emforge.projectmanager.dao.MilestoneDAO;
019:        import org.emforge.projectmanager.dao.ProjectDAO;
020:        import org.springframework.beans.factory.InitializingBean;
021:
022:        import ru.emdev.EmForge.security.EmForgeUserDetails;
023:        import ru.emdev.EmForge.security.UserFactory;
024:        import ru.emdev.EmForge.security.dao.Role;
025:        import ru.emdev.EmForge.security.dao.UserDao;
026:        import ru.emdev.EmForge.security.web.SiteRole;
027:
028:        /**
029:         * Implementation of Project Service
030:         * 
031:         * @todo I do not like fact that we are using UserDao for getting information about Roles... Actually, roles may be
032:         *       stored somethere else (like in LDAP) - and we will need to be able to work with it But for now it is ok
033:         */
034:        public class ProjectServiceImpl implements  ProjectService,
035:                InitializingBean {
036:
037:            protected final Log logger = LogFactory.getLog(getClass());
038:
039:            ProjectDAO m_projectDao;
040:            MilestoneDAO m_milestoneDao;
041:            UserDao m_userDao;
042:            UserFactory m_userFactory;
043:
044:            /**
045:             * @param i_projectDao
046:             */
047:            public void setProjectDao(ProjectDAO i_projectDao) {
048:
049:                m_projectDao = i_projectDao;
050:            }
051:
052:            /**
053:             * @param i_milestoneDao
054:             */
055:            public void setMilestoneDao(MilestoneDAO i_milestoneDao) {
056:
057:                m_milestoneDao = i_milestoneDao;
058:            }
059:
060:            /**
061:             * @param i_userDao
062:             */
063:            public void setUserDao(UserDao i_userDao) {
064:
065:                m_userDao = i_userDao;
066:            }
067:
068:            /**
069:             * @param i_userFactory
070:             */
071:            public void setUserFactory(UserFactory i_userFactory) {
072:
073:                m_userFactory = i_userFactory;
074:            }
075:
076:            /**
077:             * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
078:             */
079:            public void afterPropertiesSet() throws Exception {
080:
081:                if (m_projectDao == null) {
082:                    throw new IllegalArgumentException(
083:                            "projectDao should be specified for projectService bean");
084:                }
085:                if (m_milestoneDao == null) {
086:                    throw new IllegalArgumentException(
087:                            "milestoneDao should be specified for projectService bean");
088:                }
089:                if (m_userDao == null) {
090:                    throw new IllegalArgumentException(
091:                            "userDao should be specified for projectService bean");
092:                }
093:                if (m_userFactory == null) {
094:                    throw new IllegalArgumentException(
095:                            "userFactory should be specified for projectService bean");
096:                }
097:
098:                initData();
099:            }
100:
101:            /**
102:             * Get all projects avialable for current user
103:             * 
104:             * @todo Currently list returns all prjojects. Later we should return only projects, used really can see
105:             */
106:            public Collection<ProjectDO> getAllProjects()
107:                    throws AccessDeniedException, ProjectServiceException {
108:
109:                try {
110:                    return m_projectDao.getProjects();
111:                } catch (Exception ex) {
112:                    throw new ProjectServiceException(
113:                            "Cannot get list of projects", ex);
114:                }
115:            }
116:
117:            /**
118:             * @see org.emforge.projectmanager.ProjectService#getProject(java.lang.Long)
119:             */
120:            public ProjectDO getProject(Long i_projectId)
121:                    throws AccessDeniedException, ProjectServiceException {
122:
123:                if (!canGetProject(i_projectId)) {
124:                    throw new AccessDeniedException(
125:                            "You are not allowed to view this project");
126:                }
127:
128:                try {
129:                    ProjectDO project = m_projectDao
130:                            .getProjectById(i_projectId);
131:
132:                    return project;
133:                } catch (Exception ex) {
134:                    throw new ProjectServiceException("Cannot get project"
135:                            + i_projectId, ex);
136:                }
137:            }
138:
139:            /**
140:             * @see org.emforge.projectmanager.ProjectService#getProject(java.lang.String)
141:             */
142:            public ProjectDO getProject(String i_projectWikiName)
143:                    throws AccessDeniedException, ProjectServiceException {
144:
145:                if (!canGetProject(i_projectWikiName)) {
146:                    throw new AccessDeniedException(
147:                            "You are not allowed to view this project");
148:                }
149:
150:                try {
151:                    ProjectDO project = m_projectDao
152:                            .getProjectByName(i_projectWikiName);
153:
154:                    return project;
155:                } catch (Exception ex) {
156:                    throw new ProjectServiceException("Cannot get project "
157:                            + i_projectWikiName, ex);
158:                }
159:            }
160:
161:            /**
162:             * @see org.emforge.projectmanager.ProjectService#saveProject(org.emforge.projectmanager.base.Project)
163:             */
164:            public void saveProject(ProjectDO i_project)
165:                    throws AccessDeniedException, ProjectServiceException {
166:
167:                boolean wasNew = false;
168:                // security checks
169:                if (i_project.getId() == null) {
170:                    wasNew = true;
171:                    if (!canCreateProject()) {
172:                        throw new AccessDeniedException(
173:                                "You are not allowed to create new project");
174:                    }
175:                } else if (!canChangeProject(i_project)) {
176:                    throw new AccessDeniedException(
177:                            "You are not allowed to change project");
178:                }
179:
180:                try {
181:                    m_projectDao.saveProject(i_project);
182:
183:                    // For current moment we have no sysadmin role, allowed to create
184:                    // new projects.
185:                    // So, to allow user to have configuration access for created
186:                    // project we should add him as manager
187:                    // for created project
188:                    if (wasNew) {
189:                        EmForgeUserDetails currentUser = m_userFactory
190:                                .getCurrentUser();
191:                        if (currentUser != null) {
192:                            Role adminRole = m_userDao
193:                                    .getRoleByName(ROLE_MANAGER);
194:                            if (adminRole == null) {
195:                                throw new ProjectServiceException(
196:                                        "Cannot get admin role");
197:                            }
198:                            m_projectDao.addUser(i_project, currentUser,
199:                                    adminRole);
200:                        }
201:                        initProjectRoles(i_project);
202:                    }
203:                } catch (Exception ex) {
204:                    throw new ProjectServiceException("Cannot save project"
205:                            + i_project.getName(), ex);
206:                }
207:            }
208:
209:            /**
210:             * @see org.emforge.projectmanager.ProjectService#deleteProject(org.emforge.projectmanager.base.Project)
211:             */
212:            public void deleteProject(ProjectDO i_project)
213:                    throws AccessDeniedException, ProjectServiceException {
214:
215:                if (!canDeleteProject(i_project)) {
216:                    throw new AccessDeniedException(
217:                            "You are not allowed to delete project");
218:                }
219:
220:                try {
221:                    m_projectDao.deleteProject(i_project);// Should here be delegation to deleteProject?
222:                } catch (Exception ex) {
223:                    throw new ProjectServiceException("Cannot delete project"
224:                            + i_project.getName(), ex);
225:                }
226:            }
227:
228:            /** Add User into Project with specified Role */
229:            public void addUser(ProjectDO i_project, UserDetails i_user,
230:                    Role i_role) throws AccessDeniedException,
231:                    ProjectServiceException {
232:
233:                if (!canChangeProject(i_project)) {
234:                    throw new AccessDeniedException(
235:                            "You are not allowed to change project");
236:                }
237:
238:                try {
239:                    m_projectDao.addUser(i_project, i_user, i_role);
240:                } catch (Exception ex) {
241:                    throw new ProjectServiceException(
242:                            "Cannot add user role to project", ex);
243:                }
244:            }
245:
246:            /** Delete User's Role from Project */
247:            public void deleteUserRole(ProjectDO i_project, UserDetails i_user,
248:                    Role i_role) throws AccessDeniedException,
249:                    ProjectServiceException {
250:
251:                if (!canChangeProject(i_project)) {
252:                    throw new AccessDeniedException(
253:                            "You are not allowed to change project");
254:                }
255:
256:                try {
257:                    m_projectDao.deleteUserRole(i_project, i_user, i_role);
258:                } catch (Exception ex) {
259:                    throw new ProjectServiceException(
260:                            "Cannot delete user role to project", ex);
261:                }
262:            }
263:
264:            /**
265:             * Returns true - if specified user has specified role in project
266:             */
267:            public boolean hasRole(ProjectDO i_project, UserDetails i_user,
268:                    Role i_role) throws AccessDeniedException,
269:                    ProjectServiceException {
270:
271:                try {
272:                    return m_projectDao.hasRole(i_project, i_user, i_role);
273:                } catch (Exception ex) {
274:                    throw new ProjectServiceException(
275:                            "Cannot get user role information", ex);
276:                }
277:            }
278:
279:            /**
280:             * @see org.emforge.projectmanager.ProjectService#hasRole(org.emforge.projectmanager.base.Project,
281:             *      org.acegisecurity.userdetails.UserDetails, java.lang.String)
282:             */
283:            public boolean hasRole(ProjectDO i_project, UserDetails i_user,
284:                    String i_role) throws AccessDeniedException,
285:                    ProjectServiceException {
286:
287:                try {
288:                    Role role = m_userDao.getRoleByName(i_role);
289:                    return m_projectDao.hasRole(i_project, i_user, role);
290:                } catch (Exception ex) {
291:                    throw new ProjectServiceException(
292:                            "Cannot get user role information", ex);
293:                }
294:            }
295:
296:            /**
297:             * Returns Users with specified role
298:             * 
299:             * @see org.emforge.projectmanager.ProjectService#getUsers(org.emforge.projectmanager.base.Project, java.lang.String)
300:             */
301:            public Collection<EmForgeUserDetails> getUsers(ProjectDO i_project,
302:                    String i_roleName) throws AccessDeniedException,
303:                    ProjectServiceException {
304:
305:                Collection<EmForgeUserDetails> result = null;
306:                Role role = m_userDao.getRoleByName(i_roleName);
307:                if (role != null) {
308:                    result = getUsers(i_project, role);
309:                }
310:                return result;
311:            }
312:
313:            /**
314:             * Returns Users with specified role
315:             * 
316:             * @see org.emforge.projectmanager.ProjectService#getUsers(org.emforge.projectmanager.base.Project,
317:             *      ru.emdev.EmForge.security.dao.Role)
318:             */
319:            public Collection<EmForgeUserDetails> getUsers(ProjectDO i_project,
320:                    Role i_role) throws AccessDeniedException,
321:                    ProjectServiceException {
322:
323:                try {
324:                    Collection<ProjectUserRole> roles = m_projectDao.getUsers(
325:                            i_project, i_role);
326:
327:                    List<EmForgeUserDetails> result = new ArrayList<EmForgeUserDetails>();
328:                    for (ProjectUserRole projectUserRole : roles) {
329:
330:                        try {
331:                            EmForgeUserDetails user = m_userFactory
332:                                    .getUser(projectUserRole.getName());
333:                            // todo: can getUser return null value?
334:                            if (user != null) {
335:                                result.add(user);
336:                            }
337:                        } catch (UsernameNotFoundException ex) {
338:                            // catch the cases then user does not exist
339:                            logger.warn("Cannot find user for role + "
340:                                    + i_role.getName() + " :"
341:                                    + projectUserRole.getName());
342:                        }
343:                    }
344:
345:                    return result;
346:                } catch (Exception ex) {
347:                    throw new ProjectServiceException(
348:                            "Cannot get user roles information", ex);
349:                }
350:            }
351:
352:            /**
353:             * @see org.emforge.projectmanager.ProjectService#getAllProjectUsers(org.emforge.projectmanager.base.Project)
354:             */
355:            public Collection<EmForgeUserDetails> getAllProjectUsers(
356:                    ProjectDO i_project) throws AccessDeniedException,
357:                    ProjectServiceException {
358:
359:                try {
360:                    Collection<String> users = m_projectDao
361:                            .getAllProjectUsers(i_project);
362:
363:                    List<EmForgeUserDetails> result = new ArrayList<EmForgeUserDetails>();
364:                    for (String userName : users) {
365:
366:                        try {
367:                            EmForgeUserDetails user = m_userFactory
368:                                    .getUser(userName);
369:                            // todo: can getUser return null value?
370:                            if (user != null) {
371:                                result.add(user);
372:                            }
373:                        } catch (UsernameNotFoundException ex) {
374:                            // catch the cases then user does not exist
375:                            logger.warn("Cannot find users for project + "
376:                                    + i_project.getDisplayName());
377:                        }
378:                    }
379:
380:                    return result;
381:                } catch (Exception ex) {
382:                    throw new ProjectServiceException(
383:                            "Cannot get user roles information", ex);
384:                }
385:            }
386:
387:            /**
388:             * Returns Avialable Roles for specified Project
389:             * 
390:             * @param i_project
391:             * @return
392:             */
393:            public Collection<Role> getAvialableRoles(ProjectDO i_project)
394:                    throws AccessDeniedException, ProjectServiceException {
395:
396:                try {
397:                    return m_projectDao.getAvialableRoles(i_project);
398:                } catch (Exception ex) {
399:                    throw new ProjectServiceException(
400:                            "Cannot get project roles information", ex);
401:                }
402:            }
403:
404:            /**
405:             * Currently everybody get get any project
406:             * 
407:             * @todo Implement flag private for project - that will means - only users, has any role in project allowed to get
408:             *       any information about it
409:             */
410:            public boolean canGetProject(Long i_projectId) {
411:
412:                return true;
413:            }
414:
415:            /**
416:             * Currently everybody get get any project
417:             * 
418:             * @todo Implement flag private for project - that will means - only users, has any role in project allowed to get
419:             *       any information about it
420:             */
421:            public boolean canGetProject(String i_projectWikiName) {
422:
423:                return true;
424:            }
425:
426:            /**
427:             * Is user allowed to create new project? Only site admins allowed to create new projects
428:             */
429:            public boolean canCreateProject() {
430:
431:                return m_userFactory.hasRole(SiteRole.ADMIN.getId());
432:            }
433:
434:            /**
435:             * Is current user allowed to change project? Only Project Administrators may change project
436:             */
437:            public boolean canChangeProject(ProjectDO i_project) {
438:
439:                return m_userFactory.hasRole(SiteRole.ADMIN.getId())
440:                        || hasRole(i_project, ROLE_MANAGER);
441:            }
442:
443:            /**
444:             * Is current user allowed to delete project? Only Site Administrators may delete project
445:             */
446:            public boolean canDeleteProject(ProjectDO i_project) {
447:
448:                return m_userFactory.hasRole(SiteRole.ADMIN.getId());
449:            }
450:
451:            /**
452:             * 
453:             */
454:            public MilestoneDO getMilestone(Long i_milestoneId)
455:                    throws AccessDeniedException, ProjectServiceException {
456:
457:                if (!canGetMilestone(i_milestoneId)) {
458:                    throw new AccessDeniedException(
459:                            "You are not allowed to view milestone "
460:                                    + i_milestoneId);
461:                }
462:
463:                try {
464:                    return m_milestoneDao.getMilestoneById(i_milestoneId);
465:                } catch (Exception ex) {
466:                    throw new ProjectServiceException("Cannot get milestone "
467:                            + i_milestoneId, ex);
468:                }
469:            }
470:
471:            /**
472:             * @see org.emforge.projectmanager.ProjectService#getMilestone(java.lang.String)
473:             */
474:            public MilestoneDO getMilestone(String i_name)
475:                    throws AccessDeniedException, ProjectServiceException {
476:
477:                if (!canGetMilestone(i_name)) {
478:                    throw new AccessDeniedException(
479:                            "You are not allowed to view milestone " + i_name);
480:                }
481:
482:                try {
483:                    return m_milestoneDao.getMilestoneByName(i_name);
484:                } catch (Exception ex) {
485:                    throw new ProjectServiceException("Cannot get milestone "
486:                            + i_name, ex);
487:                }
488:            }
489:
490:            /**
491:             * @see org.emforge.projectmanager.ProjectService#getMilestones(org.emforge.projectmanager.base.Project)
492:             */
493:            public Collection<MilestoneDO> getMilestones(ProjectDO i_project)
494:                    throws AccessDeniedException, ProjectServiceException {
495:
496:                if (!canGetMilestones(i_project)) {
497:                    throw new AccessDeniedException(
498:                            "You are not allowed to view milestones for project "
499:                                    + i_project.getDisplayName());
500:                }
501:
502:                try {
503:                    Collection<MilestoneDO> milestones = m_milestoneDao
504:                            .getMilestonesByProject(i_project);
505:
506:                    if (milestones == null) {
507:                        throw new ProjectServiceException(
508:                                "Cannot get milestones for project "
509:                                        + i_project.getDisplayName());
510:                    }
511:
512:                    return milestones;
513:                } catch (Exception ex) {
514:                    throw new ProjectServiceException(
515:                            "Cannot get milestones for project "
516:                                    + i_project.getDisplayName(), ex);
517:                }
518:            }
519:
520:            /**
521:             * @see org.emforge.projectmanager.ProjectService#getOpenedMilestones(org.emforge.projectmanager.base.Project)
522:             */
523:            public Collection<MilestoneDO> getOpenedMilestones(
524:                    ProjectDO i_project) throws AccessDeniedException,
525:                    ProjectServiceException {
526:
527:                if (!canGetMilestones(i_project)) {
528:                    throw new AccessDeniedException(
529:                            "You are not allowed to view milestones for project "
530:                                    + i_project.getDisplayName());
531:                }
532:
533:                try {
534:                    Collection<MilestoneDO> milestones = m_milestoneDao
535:                            .getOpenedMilestonesByProject(i_project);
536:
537:                    if (milestones == null) {
538:                        throw new ProjectServiceException(
539:                                "Cannot get milestones for project "
540:                                        + i_project.getDisplayName());
541:                    }
542:
543:                    return milestones;
544:                } catch (Exception ex) {
545:                    throw new ProjectServiceException(
546:                            "Cannot get milestones for project "
547:                                    + i_project.getDisplayName(), ex);
548:                }
549:            }
550:
551:            /**
552:             * @see org.emforge.projectmanager.ProjectService#getClosedMilestones(org.emforge.projectmanager.base.Project)
553:             */
554:            public Collection<MilestoneDO> getClosedMilestones(
555:                    ProjectDO i_project) throws AccessDeniedException,
556:                    ProjectServiceException {
557:
558:                if (!canGetMilestones(i_project)) {
559:                    throw new AccessDeniedException(
560:                            "You are not allowed to view milestones for project "
561:                                    + i_project.getDisplayName());
562:                }
563:
564:                try {
565:                    Collection<MilestoneDO> milestones = m_milestoneDao
566:                            .getClosedMilestonesByProject(i_project);
567:
568:                    if (milestones == null) {
569:                        throw new ProjectServiceException(
570:                                "Cannot get milestones for project "
571:                                        + i_project.getDisplayName());
572:                    }
573:
574:                    return milestones;
575:                } catch (Exception ex) {
576:                    throw new ProjectServiceException(
577:                            "Cannot get milestones for project "
578:                                    + i_project.getDisplayName(), ex);
579:                }
580:            }
581:
582:            /**
583:             * @see org.emforge.projectmanager.ProjectService#saveMilestone(org.emforge.projectmanager.base.Milestone)
584:             */
585:            public void saveMilestone(MilestoneDO i_milestone)
586:                    throws AccessDeniedException, ProjectServiceException {
587:
588:                // security checks
589:                if (i_milestone.getId() == null) {
590:                    if (!canCreateMilestone(i_milestone.getProject())) {
591:                        throw new AccessDeniedException(
592:                                "You are not allowed to create new milestone");
593:                    }
594:                } else if (!canChangeMilestone(i_milestone)) {
595:                    throw new AccessDeniedException(
596:                            "You are not allowed to change milestone");
597:                }
598:
599:                try {
600:                    m_milestoneDao.saveMilestone(i_milestone);
601:
602:                } catch (Exception ex) {
603:                    throw new ProjectServiceException("Cannot save milestone"
604:                            + i_milestone.getName(), ex);
605:                }
606:            }
607:
608:            /**
609:             * @see org.emforge.projectmanager.ProjectService#deleteMilestone(org.emforge.projectmanager.base.Milestone)
610:             */
611:            public void deleteMilestone(MilestoneDO i_milestone)
612:                    throws AccessDeniedException, ProjectServiceException {
613:
614:                if (!canDeleteMilestone(i_milestone)) {
615:                    throw new AccessDeniedException(
616:                            "You are not allowed to delete milestone");
617:                }
618:
619:                try {
620:                    m_milestoneDao.saveMilestone(i_milestone);
621:                } catch (Exception ex) {
622:                    throw new ProjectServiceException("Cannot save milestone "
623:                            + i_milestone.getName(), ex);
624:                }
625:            }
626:
627:            /**
628:             * @see org.emforge.projectmanager.ProjectService#canGetMilestone(java.lang.Long)
629:             */
630:            public boolean canGetMilestone(Long i_milestoneId) {
631:
632:                // to check - can we get milestone - we should check - can we get
633:                // project:
634:                MilestoneDO milestone = m_milestoneDao
635:                        .getMilestoneById(i_milestoneId);
636:
637:                if (milestone == null) {
638:                    // milestone does not exists - so, we have no any access rules on it
639:                    return true;
640:                }
641:
642:                return canGetProject(milestone.getProject().getId());
643:            }
644:
645:            /**
646:             * @see org.emforge.projectmanager.ProjectService#canGetMilestone(java.lang.String)
647:             */
648:            public boolean canGetMilestone(String i_name) {
649:
650:                // to check - can we get milestone - we should check - can we get
651:                // project:
652:                MilestoneDO milestone = m_milestoneDao
653:                        .getMilestoneByName(i_name);
654:
655:                if (milestone == null) {
656:                    // milestone does not exists - so, we have no any access rules on it
657:                    return true;
658:                }
659:
660:                return canGetProject(milestone.getProject().getId());
661:            }
662:
663:            /**
664:             * @see org.emforge.projectmanager.ProjectService#canGetMilestones(org.emforge.projectmanager.base.Project)
665:             */
666:            public boolean canGetMilestones(ProjectDO i_project) {
667:
668:                if (i_project == null) {
669:                    return true;
670:                }
671:
672:                return canGetProject(i_project.getId());
673:            }
674:
675:            /**
676:             * Is current user allowed to create milestone?
677:             */
678:            public boolean canCreateMilestone(ProjectDO i_project) {
679:
680:                return canChangeProject(i_project);
681:            }
682:
683:            /**
684:             * @see org.emforge.projectmanager.ProjectService#canChangeMilestone(org.emforge.projectmanager.base.Milestone)
685:             */
686:            public boolean canChangeMilestone(MilestoneDO i_milestone) {
687:
688:                return canChangeProject(i_milestone.getProject());
689:            }
690:
691:            /**
692:             * @see org.emforge.projectmanager.ProjectService#canDeleteMilestone(org.emforge.projectmanager.base.Milestone)
693:             */
694:            public boolean canDeleteMilestone(MilestoneDO i_milestone) {
695:
696:                return canChangeProject(i_milestone.getProject());
697:            }
698:
699:            /**
700:             * Initialize default data (default project roles)
701:             */
702:            protected void initData() {
703:
704:                initDefaultProjectRoles();
705:            }
706:
707:            /**
708:             * Initialize Default Project Roles
709:             * 
710:             * @todo Move these roles into Spring Definition for easily changing it
711:             */
712:            protected void initDefaultProjectRoles() {
713:
714:                // initialize role Admin
715:                initializeRole(ROLE_MANAGER, "Manager");
716:                initializeRole(ROLE_DEVELOPER, "Developer");
717:                initializeRole(ROLE_TESTER, "Tester");
718:                initializeRole(ROLE_USER, "User");
719:            }
720:
721:            /**
722:             * public for migrating needs
723:             * 
724:             * @param project
725:             */
726:            public void initProjectRoles(ProjectDO project) {
727:
728:                initializeProjectRoleEmail(m_userDao
729:                        .getRoleByName(ROLE_MANAGER), project);
730:                initializeProjectRoleEmail(m_userDao
731:                        .getRoleByName(ROLE_DEVELOPER), project);
732:                initializeProjectRoleEmail(
733:                        m_userDao.getRoleByName(ROLE_TESTER), project);
734:                initializeProjectRoleEmail(m_userDao.getRoleByName(ROLE_USER),
735:                        project);
736:
737:                m_userDao.getHibernateTemplate().flush();
738:            }
739:
740:            /**
741:             * Initialize Role with specified name and display name
742:             * 
743:             * @param i_roleName
744:             * @param i_roleDisplayName
745:             */
746:            protected void initializeProjectRoleEmail(Role role,
747:                    ProjectDO project) {
748:
749:                if (m_userDao.getEmailByRoleNameAndProjectId(role.getName(),
750:                        project.getId()) == null) {
751:                    ProjectRole projectRole = new ProjectRole();
752:                    projectRole.setRole(role);
753:                    projectRole.setProject(project);
754:                    projectRole.setEmail("");
755:
756:                    m_userDao.saveProjectRole(projectRole);
757:                }
758:            }
759:
760:            /**
761:             * @param i_roleName
762:             * @param i_roleDisplayName
763:             */
764:            protected void initializeRole(String i_roleName,
765:                    String i_roleDisplayName) {
766:
767:                if (m_userDao.getRoleByName(i_roleName) == null) {
768:                    Role role = new Role();
769:                    role.setName(i_roleName);
770:                    role.setDisplayName(i_roleDisplayName);
771:                    role.setRoleType(Role.ROLE_TYPE_PROJECT);
772:
773:                    m_userDao.saveRole(role);
774:                }
775:            }
776:
777:            /**
778:             * @param i_project
779:             * @param i_roleName
780:             * @return
781:             */
782:            protected boolean hasRole(ProjectDO i_project, String i_roleName) {
783:
784:                try {
785:                    Role role = m_userDao.getRoleByName(i_roleName);
786:
787:                    if (role == null) {
788:                        logger.warn("Cannot read role " + role);
789:                        return false;
790:                    }
791:
792:                    // get current user
793:                    EmForgeUserDetails currentUser = m_userFactory
794:                            .getCurrentUser();
795:                    if (currentUser == null) {
796:                        logger.warn("Cannot get current user information");
797:                        return false;
798:                    }
799:
800:                    return m_projectDao.hasRole(i_project, currentUser, role);
801:
802:                } catch (Exception ex) {
803:                    logger.error("Cannot check role " + i_roleName
804:                            + " on project " + i_project.getName(), ex);
805:                    return false;
806:                }
807:            }
808:
809:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.