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: * Copyright (C) 2007 Sebastien BALARD <sbalard@wilos-project.org>
005: *
006: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
007: * General Public License as published by the Free Software Foundation; either version 2 of the License,
008: * or (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
011: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License along with this program; if not,
015: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
016: */
017:
018: package wilos.business.services.spem2.workbreakdownelement;
019:
020: import java.util.HashSet;
021: import java.util.Set;
022:
023: import org.springframework.transaction.annotation.Propagation;
024: import org.springframework.transaction.annotation.Transactional;
025:
026: import wilos.hibernate.misc.concreteworkbreakdownelement.ConcreteWorkBreakdownElementDao;
027: import wilos.hibernate.spem2.workbreakdownelement.WorkBreakdownElementDao;
028: import wilos.model.misc.concreteworkbreakdownelement.ConcreteWorkBreakdownElement;
029: import wilos.model.misc.project.Project;
030: import wilos.model.spem2.workbreakdownelement.WorkBreakdownElement;
031: import wilos.model.spem2.workbreakdownelement.WorkOrder;
032:
033: @Transactional(readOnly=false,propagation=Propagation.REQUIRED)
034: public class WorkBreakdownElementService {
035:
036: private ConcreteWorkBreakdownElementDao concreteWorkBreakdownElementDao;
037:
038: private WorkBreakdownElementDao workBreakdownElementDao;
039:
040: /**
041: *
042: * @param _project
043: * @param _wbde
044: */
045: public void workBreakdownElementInstanciation(Project _project,
046: WorkBreakdownElement _wbde) {
047:
048: ConcreteWorkBreakdownElement cwbe = new ConcreteWorkBreakdownElement();
049:
050: if (_wbde.getPresentationName() == null)
051: cwbe.setConcreteName(_wbde.getName());
052: else
053: cwbe.setConcreteName(_wbde.getPresentationName());
054:
055: cwbe.addBreakdownElement(_wbde);
056: cwbe.setProject(_project);
057:
058: this .concreteWorkBreakdownElementDao
059: .saveOrUpdateConcreteWorkBreakdownElement(cwbe);
060: }
061:
062: /**
063: *
064: * @param _wbde
065: * @return
066: */
067: public Set<WorkOrder> getPredecessors(WorkBreakdownElement _wbde) {
068: this .workBreakdownElementDao.getSessionFactory()
069: .getCurrentSession().saveOrUpdate(_wbde);
070: Set<WorkOrder> tmp = new HashSet<WorkOrder>();
071: for (WorkOrder wo : _wbde.getPredecessors()) {
072: tmp.add(wo);
073: }
074: return tmp;
075: }
076:
077: /**
078: *
079: * @param _wbde
080: * @return
081: */
082: public Set<WorkOrder> getSuccessors(WorkBreakdownElement _wbde) {
083: this .workBreakdownElementDao.getSessionFactory()
084: .getCurrentSession().saveOrUpdate(_wbde);
085: Set<WorkOrder> tmp = new HashSet<WorkOrder>();
086: for (WorkOrder wo : _wbde.getSuccessors()) {
087: tmp.add(wo);
088: }
089: return tmp;
090: }
091:
092: /**
093: * @param _wbde
094: * @return
095: */
096: public Set<ConcreteWorkBreakdownElement> getAllConcreteWorkBreakdownElementsFromWorkBreakdownElement(
097: WorkBreakdownElement _wbde) {
098:
099: this .workBreakdownElementDao.getSessionFactory()
100: .getCurrentSession().saveOrUpdate(_wbde);
101: Set<ConcreteWorkBreakdownElement> tmp = new HashSet<ConcreteWorkBreakdownElement>();
102: for (ConcreteWorkBreakdownElement cwbde : _wbde
103: .getConcreteWorkBreakdownElements()) {
104: tmp.add(cwbde);
105: }
106: return tmp;
107: }
108:
109: /**
110: * @param _predecessor
111: * @param _successor
112: * @return
113: */
114: public boolean canInstanciateConcreteWorkOrder(
115: WorkBreakdownElement _predecessor,
116: WorkBreakdownElement _successor) {
117:
118: this .workBreakdownElementDao.getSessionFactory()
119: .getCurrentSession().saveOrUpdate(_predecessor);
120: this .workBreakdownElementDao.getSessionFactory()
121: .getCurrentSession().saveOrUpdate(_predecessor);
122:
123: for (ConcreteWorkBreakdownElement cPred : _predecessor
124: .getConcreteWorkBreakdownElements()) {
125: if (cPred.getConcreteSuccessors().size() < _successor
126: .getConcreteWorkBreakdownElements().size())
127: return true;
128: else
129: return false;
130: }
131:
132: return true;
133:
134: }
135:
136: /**
137: * @return the concreteBreakdownElementDao
138: */
139: public ConcreteWorkBreakdownElementDao getConcreteWorkBreakdownElementDao() {
140: return concreteWorkBreakdownElementDao;
141: }
142:
143: /**
144: * @param concreteBreakdownElementDao
145: * the concreteBreakdownElementDao to set
146: */
147: public void setConcreteWorkBreakdownElementDao(
148: ConcreteWorkBreakdownElementDao concreteWorkBreakdownElementDao) {
149: this .concreteWorkBreakdownElementDao = concreteWorkBreakdownElementDao;
150: }
151:
152: public WorkBreakdownElementDao getWorkBreakdownElementDao() {
153: return workBreakdownElementDao;
154: }
155:
156: public void setWorkBreakdownElementDao(
157: WorkBreakdownElementDao workBreakdownElementDao) {
158: this.workBreakdownElementDao = workBreakdownElementDao;
159: }
160:
161: }
|