Source Code Cross Referenced for IterationService.java in  » Workflow-Engines » wilos » wilos » business » services » spem2 » iteration » 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 » Workflow Engines » wilos » wilos.business.services.spem2.iteration 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
003:         * Copyright (C) 2006-2007 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
004:         *
005:         * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
006:         * General Public License as published by the Free Software Foundation; either version 2 of the License,
007:         * or (at your option) any later version.
008:         *
009:         * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
010:         * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011:         * GNU General Public License for more details.
012:         *
013:         * You should have received a copy of the GNU General Public License along with this program; if not,
014:         * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
015:         */
016:
017:        package wilos.business.services.spem2.iteration;
018:
019:        import java.util.ArrayList;
020:        import java.util.HashMap;
021:        import java.util.HashSet;
022:        import java.util.List;
023:        import java.util.Set;
024:
025:        import org.springframework.transaction.annotation.Propagation;
026:        import org.springframework.transaction.annotation.Transactional;
027:
028:        import wilos.business.services.misc.concreteactivity.ConcreteActivityService;
029:        import wilos.business.services.misc.concreteworkbreakdownelement.ConcreteWorkOrderService;
030:        import wilos.business.services.spem2.activity.ActivityService;
031:        import wilos.business.services.spem2.breakdownelement.BreakdownElementService;
032:        import wilos.business.services.spem2.task.TaskDescriptorService;
033:        import wilos.hibernate.misc.concreteiteration.ConcreteIterationDao;
034:        import wilos.hibernate.misc.concretephase.ConcretePhaseDao;
035:        import wilos.hibernate.misc.project.ProjectDao;
036:        import wilos.hibernate.spem2.iteration.IterationDao;
037:        import wilos.model.misc.concreteactivity.ConcreteActivity;
038:        import wilos.model.misc.concretebreakdownelement.ConcreteBreakdownElement;
039:        import wilos.model.misc.concreteiteration.ConcreteIteration;
040:        import wilos.model.misc.concretephase.ConcretePhase;
041:        import wilos.model.misc.project.Project;
042:        import wilos.model.spem2.activity.Activity;
043:        import wilos.model.spem2.breakdownelement.BreakdownElement;
044:        import wilos.model.spem2.iteration.Iteration;
045:        import wilos.model.spem2.task.TaskDescriptor;
046:        import wilos.utils.Constantes;
047:
048:        /**
049:         * IterationManager is a transactional class, that manages operations about
050:         * Iteration
051:         * 
052:         */
053:        @Transactional(readOnly=false,propagation=Propagation.REQUIRED)
054:        public class IterationService {
055:
056:            private ConcreteIterationDao concreteIterationDao;
057:
058:            private IterationDao iterationDao;
059:
060:            private ConcretePhaseDao concretePhaseDao;
061:
062:            private ProjectDao projectDao;
063:
064:            private BreakdownElementService breakdownElementService;
065:
066:            private ActivityService activityService;
067:
068:            private ConcreteActivityService concreteActivityService;
069:
070:            private TaskDescriptorService taskDescriptorService;
071:
072:            private ConcreteWorkOrderService concreteWorkOrderService;
073:
074:            /**
075:             * 
076:             * Return all the Concrete iterations
077:             * 
078:             * @param _iteration
079:             * @return Set<ConcreteIteration>
080:             */
081:            public Set<ConcreteIteration> getAllConcreteIterations(
082:                    Iteration _iteration) {
083:                Set<ConcreteIteration> tmp = new HashSet<ConcreteIteration>();
084:                this .iterationDao.getSessionFactory().getCurrentSession()
085:                        .saveOrUpdate(_iteration);
086:                for (ConcreteIteration bde : _iteration.getConcreteIterations()) {
087:                    tmp.add(bde);
088:                }
089:                return tmp;
090:            }
091:
092:            /**
093:             * 
094:             * Return all the concrete activities of a project
095:             * 
096:             * @param _iteration
097:             * @param _project
098:             * @return Set<ConcreteIteration>
099:             */
100:            public Set<ConcreteIteration> getAllConcreteIterationsForAProject(
101:                    Iteration _iteration, Project _project) {
102:                Set<ConcreteIteration> tmp = new HashSet<ConcreteIteration>();
103:                this .iterationDao.getSessionFactory().getCurrentSession()
104:                        .saveOrUpdate(_iteration);
105:                this .projectDao.getSessionFactory().getCurrentSession()
106:                        .saveOrUpdate(_project);
107:                for (ConcreteIteration cit : _iteration.getConcreteIterations()) {
108:                    if (cit.getProject().getId().equals(_project.getId()))
109:                        tmp.add(cit);
110:                }
111:                return tmp;
112:            }
113:
114:            /**
115:             * Process an iteration for a project
116:             * 
117:             * @param _project
118:             *            project for which the iteration shall be processed
119:             * @param _phase
120:             *            iteration to instance
121:             */
122:            public void iterationInstanciation(Project _project,
123:                    Iteration _iteration, ConcreteActivity _cact,
124:                    List<HashMap<String, Object>> _list, int _occ,
125:                    boolean _isInstanciated, int _dispOrd) {
126:
127:                if (_occ > 0) {
128:                    this .concreteActivityService.getConcreteActivityDao()
129:                            .getSessionFactory().getCurrentSession()
130:                            .saveOrUpdate(_cact);
131:                    ArrayList<ConcreteIteration> concreteIterationsSisters = new ArrayList<ConcreteIteration>();
132:                    int nbExistingConcreteIterationChildren = 0;
133:                    for (ConcreteBreakdownElement tmp : _cact
134:                            .getConcreteBreakdownElements()) {
135:                        if (tmp instanceof  ConcreteIteration) {
136:                            if (((ConcreteIteration) tmp).getIteration()
137:                                    .getId().equals(_iteration.getId())) {
138:                                nbExistingConcreteIterationChildren++;
139:                                concreteIterationsSisters
140:                                        .add((ConcreteIteration) tmp);
141:                            }
142:                        }
143:                    }
144:                    int nbConcreteIterationSisters = nbExistingConcreteIterationChildren;
145:
146:                    for (int i = nbExistingConcreteIterationChildren + 1; i <= nbExistingConcreteIterationChildren
147:                            + _occ; i++) {
148:
149:                        ConcreteIteration ci = new ConcreteIteration();
150:
151:                        List<BreakdownElement> bdes = new ArrayList<BreakdownElement>();
152:                        bdes.addAll(this .activityService
153:                                .getAllBreakdownElements(_iteration));
154:
155:                        if (_occ != 1
156:                                || nbExistingConcreteIterationChildren != 0) {
157:                            if (_iteration.getPresentationName().equals(""))
158:                                ci.setConcreteName(_iteration.getName() + "#"
159:                                        + i);
160:                            else
161:                                ci.setConcreteName(_iteration
162:                                        .getPresentationName()
163:                                        + "#" + i);
164:                        } else {
165:                            if (_iteration.getPresentationName().equals(""))
166:                                ci.setConcreteName(_iteration.getName());
167:                            else
168:                                ci.setConcreteName(_iteration
169:                                        .getPresentationName());
170:                        }
171:
172:                        ci.addIteration(_iteration);
173:                        ci.setProject(_project);
174:                        ci.setBreakdownElement(_iteration);
175:                        ci.setInstanciationOrder(i);
176:                        ci.setWorkBreakdownElement(_iteration);
177:                        ci.setActivity(_iteration);
178:                        _cact
179:                                .setConcreteBreakdownElements(this .concreteActivityService
180:                                        .getConcreteBreakdownElements(_cact));
181:                        ci.addSuperConcreteActivity(_cact);
182:                        ci.setDisplayOrder(ci.getSuperConcreteActivity()
183:                                .getDisplayOrder()
184:                                + Integer.toString(_dispOrd + i));
185:
186:                        this .concreteIterationDao
187:                                .saveOrUpdateConcreteIteration(ci);
188:                        System.out.println("### ConcreteIteration vide sauve");
189:
190:                        int dispOrd = 0;
191:                        for (BreakdownElement bde : bdes) {
192:                            dispOrd++;
193:                            if (bde instanceof  Iteration) {
194:                                Iteration it = (Iteration) bde;
195:                                int occ = this .giveNbOccurences(it.getId(),
196:                                        _list, false);
197:                                if (occ == 0 && _occ > 0)
198:                                    occ = _occ;
199:                                this .iterationInstanciation(_project, it, ci,
200:                                        _list, occ, _isInstanciated, dispOrd);
201:                            } else {
202:                                if (bde instanceof  Activity) {
203:                                    Activity act = (Activity) bde;
204:                                    int occ = this .giveNbOccurences(
205:                                            act.getId(), _list, false);
206:                                    if (occ == 0 && _occ > 0)
207:                                        occ = _occ;
208:                                    this .activityService.activityInstanciation(
209:                                            _project, act, ci, _list, occ,
210:                                            _isInstanciated, dispOrd);
211:                                } else {
212:                                    if (bde instanceof  TaskDescriptor) {
213:                                        TaskDescriptor td = (TaskDescriptor) bde;
214:                                        int occ = this .giveNbOccurences(td
215:                                                .getId(), _list, false);
216:                                        if (occ == 0 && _occ > 0)
217:                                            occ = _occ;
218:                                        this .taskDescriptorService
219:                                                .taskDescriptorInstanciation(
220:                                                        _project, td, ci, occ,
221:                                                        _isInstanciated,
222:                                                        dispOrd);
223:                                    }
224:                                }
225:                            }
226:                        }
227:
228:                        this .concreteIterationDao
229:                                .saveOrUpdateConcreteIteration(ci);
230:                        System.out.println("### ConcreteIteration update");
231:
232:                        // if added ConcreteIteration has sisters, we add a FtS
233:                        // dependency between it and its predecessor
234:                        if (nbConcreteIterationSisters != 0) {
235:                            ConcreteIteration lastConcreteIteration = null;
236:                            for (ConcreteIteration tmp : concreteIterationsSisters) {
237:                                if (lastConcreteIteration == null
238:                                        || tmp.getInstanciationOrder() > lastConcreteIteration
239:                                                .getInstanciationOrder()) {
240:                                    lastConcreteIteration = tmp;
241:                                }
242:                            }
243:                            this .concreteWorkOrderService
244:                                    .saveConcreteWorkOrder(
245:                                            lastConcreteIteration.getId(),
246:                                            ci.getId(),
247:                                            Constantes.WorkOrderType.FINISH_TO_START,
248:                                            _project.getId());
249:                            System.out.println("### ConcreteWorkOrder added");
250:                        }
251:
252:                        nbConcreteIterationSisters++;
253:                        concreteIterationsSisters.add(ci);
254:                    }
255:                }
256:            }
257:
258:            /**
259:             * 
260:             * Update and actualize an iteration
261:             * 
262:             * @param _project
263:             * @param _it
264:             * @param _cacts
265:             * @param _list
266:             * @param _occ
267:             */
268:            public void iterationUpdate(Project _project, Iteration _it,
269:                    Set<ConcreteActivity> _cacts,
270:                    List<HashMap<String, Object>> _list, int _occ) {
271:
272:                // one concretephase at least to insert in all attached
273:                // concreteactivities of the parent of _phase
274:                if (_occ > 0) {
275:                    for (ConcreteActivity tmp : _cacts) {
276:                        String strDispOrd = this .concreteActivityService
277:                                .getMaxDisplayOrder(tmp);
278:                        int dispOrd = Integer.parseInt(strDispOrd) + 1;
279:                        this .iterationInstanciation(_project, _it, tmp, _list,
280:                                _occ, true, dispOrd);
281:
282:                        if (tmp instanceof  Project) {
283:                            Project pj = (Project) tmp;
284:                            this .projectDao.saveOrUpdateProject(pj);
285:                        } else {
286:                            if (tmp instanceof  ConcretePhase) {
287:                                ConcretePhase cph = (ConcretePhase) tmp;
288:                                this .concretePhaseDao
289:                                        .saveOrUpdateConcretePhase(cph);
290:                            } else {
291:                                if (tmp instanceof  ConcreteIteration) {
292:                                    ConcreteIteration cit = (ConcreteIteration) tmp;
293:                                    this .concreteIterationDao
294:                                            .saveOrUpdateConcreteIteration(cit);
295:                                }
296:                            }
297:                        }
298:                    }
299:                } else {
300:
301:                    // diving in all the concreteBreakdownElements to looking for update
302:                    Set<BreakdownElement> bdes = new HashSet<BreakdownElement>();
303:                    bdes.addAll(this .activityService
304:                            .getAllBreakdownElements(_it));
305:
306:                    Set<ConcreteActivity> cacts = new HashSet<ConcreteActivity>();
307:                    cacts.addAll(this .getAllConcreteIterationsForAProject(_it,
308:                            _project));
309:
310:                    for (BreakdownElement bde : bdes) {
311:                        if (bde instanceof  Iteration) {
312:                            Iteration it = (Iteration) bde;
313:                            int occ = this .giveNbOccurences(it.getId(), _list,
314:                                    true);
315:                            this .iterationUpdate(_project, it, cacts, _list,
316:                                    occ);
317:                        } else {
318:                            if (bde instanceof  Activity) {
319:                                Activity act = (Activity) bde;
320:                                int occ = this .giveNbOccurences(act.getId(),
321:                                        _list, true);
322:                                this .activityService.activityUpdate(_project,
323:                                        act, cacts, _list, occ);
324:                            } else {
325:                                if (bde instanceof  TaskDescriptor) {
326:                                    TaskDescriptor td = (TaskDescriptor) bde;
327:                                    int occ = this .giveNbOccurences(td.getId(),
328:                                            _list, true);
329:                                    this .taskDescriptorService
330:                                            .taskDescriptorUpdate(_project, td,
331:                                                    cacts, occ);
332:                                }
333:                            }
334:                        }
335:                    }
336:                }
337:            }
338:
339:            /**
340:             * 
341:             * Give(return) the number of occurrences
342:             * 
343:             * @param _id
344:             * @param list
345:             * @param _isInstanciated
346:             * @return int
347:             */
348:            private int giveNbOccurences(String _id,
349:                    List<HashMap<String, Object>> list, boolean _isInstanciated) {
350:
351:                int nb;
352:                if (!_isInstanciated)
353:                    nb = 1;
354:                else
355:                    nb = 0;
356:
357:                for (HashMap<String, Object> hashMap : list) {
358:                    if (((String) hashMap.get("id")).equals(_id)) {
359:                        nb = ((Integer) hashMap.get("nbOccurences")).intValue();
360:                        break;
361:                    }
362:                }
363:
364:                return nb;
365:            }
366:
367:            /**
368:             * Getter of concreteIterationDao
369:             * 
370:             * @return the concreteIterationDao
371:             */
372:            public ConcreteIterationDao getConcreteIterationDao() {
373:                return concreteIterationDao;
374:            }
375:
376:            /**
377:             * Setter of concreteIterationDao
378:             * 
379:             * @param concreteIterationDao
380:             *            the concreteIterationDao to set
381:             */
382:            public void setConcreteIterationDao(
383:                    ConcreteIterationDao concreteIterationDao) {
384:                this .concreteIterationDao = concreteIterationDao;
385:            }
386:
387:            /**
388:             * 
389:             * Getter of BreakdownElementService
390:             * 
391:             * @return the breakdownElementService
392:             */
393:            public BreakdownElementService getBreakdownElementService() {
394:                return breakdownElementService;
395:            }
396:
397:            /**
398:             * 
399:             * Setter of BreakdownElementService
400:             * 
401:             * @param breakdownElementService
402:             *            the breakdownElementService to set
403:             */
404:            public void setBreakdownElementService(
405:                    BreakdownElementService breakdownElementService) {
406:                this .breakdownElementService = breakdownElementService;
407:            }
408:
409:            /**
410:             * Getter of ActivityService
411:             * 
412:             * @return the activityService
413:             */
414:            public ActivityService getActivityService() {
415:                return activityService;
416:            }
417:
418:            /**
419:             * 
420:             * Setter of ActivityService
421:             * 
422:             * @param activityService
423:             *            the activityService to set
424:             */
425:            public void setActivityService(ActivityService activityService) {
426:                this .activityService = activityService;
427:            }
428:
429:            /**
430:             * 
431:             * GEtter of ConcreteActivityService
432:             * 
433:             * @return the concreteActivityService
434:             */
435:            public ConcreteActivityService getConcreteActivityService() {
436:                return this .concreteActivityService;
437:            }
438:
439:            /**
440:             * 
441:             * Setter of ConcreteActivityService
442:             * 
443:             * @param _concreteActivityService
444:             *            the concreteActivityService to set
445:             */
446:            public void setConcreteActivityService(
447:                    ConcreteActivityService _concreteActivityService) {
448:                this .concreteActivityService = _concreteActivityService;
449:            }
450:
451:            /**
452:             * Getter of TaskDescriptorService
453:             * 
454:             * @return the taskDescriptorService
455:             */
456:            public TaskDescriptorService getTaskDescriptorService() {
457:                return taskDescriptorService;
458:            }
459:
460:            /**
461:             * 
462:             * Setter of TaskDescriptorService
463:             * 
464:             * @param taskDescriptorService
465:             *            the taskDescriptorService to set
466:             */
467:            public void setTaskDescriptorService(
468:                    TaskDescriptorService taskDescriptorService) {
469:                this .taskDescriptorService = taskDescriptorService;
470:            }
471:
472:            /**
473:             * 
474:             * Getter of IterationDao
475:             * 
476:             * @return the iterationDao
477:             */
478:            public IterationDao getIterationDao() {
479:                return iterationDao;
480:            }
481:
482:            /**
483:             * 
484:             * Setter of IterationDao
485:             * 
486:             * @param iterationDao
487:             *            the iterationDao to set
488:             */
489:            public void setIterationDao(IterationDao iterationDao) {
490:                this .iterationDao = iterationDao;
491:            }
492:
493:            /**
494:             * Getter of ConcretePhaseDao
495:             * 
496:             * @return the concretePhaseDao
497:             */
498:            public ConcretePhaseDao getConcretePhaseDao() {
499:                return concretePhaseDao;
500:            }
501:
502:            /**
503:             * 
504:             * Setter of ConcretePhaseDao
505:             * 
506:             * @param concretePhaseDao
507:             *            the concretePhaseDao to set
508:             */
509:            public void setConcretePhaseDao(ConcretePhaseDao concretePhaseDao) {
510:                this .concretePhaseDao = concretePhaseDao;
511:            }
512:
513:            /**
514:             * 
515:             * Getter of ProjectDao
516:             * 
517:             * @return the projectDao
518:             */
519:            public ProjectDao getProjectDao() {
520:                return projectDao;
521:            }
522:
523:            /**
524:             * 
525:             * Setter of ProjectDao
526:             * 
527:             * @param projectDao
528:             *            the projectDao to set
529:             */
530:            public void setProjectDao(ProjectDao projectDao) {
531:                this .projectDao = projectDao;
532:            }
533:
534:            /**
535:             * 
536:             * Getter of ConcreteWorkOrderService
537:             * 
538:             * @return the concreteWorkOrderService
539:             */
540:            public ConcreteWorkOrderService getConcreteWorkOrderService() {
541:                return this .concreteWorkOrderService;
542:            }
543:
544:            /**
545:             * 
546:             * Setter of ConcreteWorkOrderService
547:             * 
548:             * @param _concreteWorkOrderService
549:             *            the concreteWorkOrderService to set
550:             */
551:            public void setConcreteWorkOrderService(
552:                    ConcreteWorkOrderService _concreteWorkOrderService) {
553:                this.concreteWorkOrderService = _concreteWorkOrderService;
554:            }
555:
556:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.