001: /*
002: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
003: * Copyright (C) 2007 Sebastien BALARD <sbalard@wilos-project.org>
004: * Copyright (C) 2007-2008 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
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: package wilos.business.services.misc.concreteworkbreakdownelement;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021: import java.util.List;
022:
023: import org.springframework.transaction.annotation.Propagation;
024: import org.springframework.transaction.annotation.Transactional;
025:
026: import wilos.business.services.spem2.workbreakdownelement.WorkBreakdownElementService;
027: import wilos.hibernate.misc.concreteworkbreakdownelement.ConcreteWorkBreakdownElementDao;
028: import wilos.hibernate.misc.project.ProjectDao;
029: import wilos.model.misc.concreteworkbreakdownelement.ConcreteWorkBreakdownElement;
030: import wilos.model.misc.concreteworkbreakdownelement.ConcreteWorkOrder;
031: import wilos.model.misc.project.Project;
032: import wilos.model.spem2.workbreakdownelement.WorkBreakdownElement;
033: import wilos.model.spem2.workbreakdownelement.WorkOrder;
034:
035: /**
036: * @author Sebastien
037: *
038: */
039: @Transactional(readOnly=false,propagation=Propagation.REQUIRED)
040: public class ConcreteWorkBreakdownElementService {
041:
042: private ConcreteWorkBreakdownElementDao concreteWorkBreakdownElementDao;
043:
044: private WorkBreakdownElementService workBreakdownElementService;
045:
046: private ConcreteWorkOrderService concreteWorkOrderService;
047:
048: private ProjectDao projectDao;
049:
050: /**
051: * Get the ConcreteWorkBreakdownElements list having at least one successor
052: *
053: * @return List<ConcreteWorkBreakdownElement>
054: */
055: public List<ConcreteWorkBreakdownElement> getAllConcreteWorkBreakdownElementsWithAtLeastOneSuccessor(
056: Project _project) {
057:
058: this .projectDao.getSessionFactory().getCurrentSession()
059: .saveOrUpdate(_project);
060:
061: List<ConcreteWorkBreakdownElement> tmp = new ArrayList<ConcreteWorkBreakdownElement>();
062:
063: for (ConcreteWorkBreakdownElement cwbde : this .concreteWorkBreakdownElementDao
064: .getAllConcreteWorkBreakdownElements()) {
065: WorkBreakdownElement wbde = cwbde.getWorkBreakdownElement();
066: if (!(cwbde instanceof Project) && (wbde != null)) {
067: String id = cwbde.getProject().getId();
068: if (id.equals(_project.getId())
069: && wbde.getSuccessors().size() != 0) {
070: tmp.add(cwbde);
071: }
072: }
073: }
074: return tmp;
075: }
076:
077: /**
078: * Allows to get the list of all concreteBreakdownElements for a project
079: *
080: * @param _project
081: * @return the list of all concreteBreakdownElements
082: */
083: public List<ConcreteWorkBreakdownElement> getAllConcreteWorkBreakdownElements(
084: Project _project) {
085: this .projectDao.getSessionFactory().getCurrentSession()
086: .saveOrUpdate(_project);
087:
088: List<ConcreteWorkBreakdownElement> tmp = new ArrayList<ConcreteWorkBreakdownElement>();
089:
090: for (ConcreteWorkBreakdownElement cwbde : this .concreteWorkBreakdownElementDao
091: .getAllConcreteWorkBreakdownElements()) {
092: WorkBreakdownElement wbde = cwbde.getWorkBreakdownElement();
093: if (!(cwbde instanceof Project) && (wbde != null)) {
094: String id = cwbde.getProject().getId();
095: if (id.equals(_project.getId())) {
096: tmp.add(cwbde);
097: }
098: }
099: }
100: return tmp;
101: }
102:
103: /**
104: * Allows to get the list of super concretActivities from a
105: * concreteWorkBreakdownElement
106: *
107: * @param _cwbde
108: * @return the list of super concretActivities
109: */
110: public List<ConcreteWorkBreakdownElement> getSuperConcreteActivitiesFromConcreteWorkBreakdownElement(
111: ConcreteWorkBreakdownElement _cwbde) {
112:
113: this .concreteWorkBreakdownElementDao.getSessionFactory()
114: .getCurrentSession().saveOrUpdate(_cwbde);
115:
116: List<ConcreteWorkBreakdownElement> tmp = new ArrayList<ConcreteWorkBreakdownElement>();
117:
118: for (ConcreteWorkBreakdownElement cwbde : _cwbde
119: .getSuperConcreteActivities()) {
120: tmp.add(cwbde);
121: }
122: return tmp;
123:
124: }
125:
126: /**
127: * Allows to check if a concreteWorkBreakdownElement's predecessor is
128: * instanciable
129: *
130: * @param _cwbde
131: * @return true if the predecessor is instanciable, false in the other case
132: */
133: public boolean isInstanciablePredecessor(
134: ConcreteWorkBreakdownElement _cwbde) {
135:
136: boolean instanciable = false;
137:
138: this .concreteWorkBreakdownElementDao.getSessionFactory()
139: .getCurrentSession().saveOrUpdate(_cwbde);
140:
141: // getting of spem predecessor
142: WorkBreakdownElement pred = _cwbde.getWorkBreakdownElement();
143: // for each spem successor
144: int s = 0;
145: for (WorkOrder wo : pred.getSuccessors()) {
146: WorkBreakdownElement succ = wo.getSuccessor();
147: // if ConcreteSuccessors number is less inferior than succesor
148: // ConcreteWbdes number
149: int p = _cwbde.getConcreteSuccessors().size();
150: s += this .workBreakdownElementService
151: .getAllConcreteWorkBreakdownElementsFromWorkBreakdownElement(
152: succ).size();
153: if (p < s) {
154: instanciable = true;
155: }
156: }
157: return instanciable;
158: }
159:
160: /**
161: * Allows to get a concreteWorkBrreakdownElement with its id
162: *
163: * @param _id
164: * @return the concreteWorkBrreakdownElement
165: */
166: public ConcreteWorkBreakdownElement getConcreteWorkBreakdownElement(
167: String _id) {
168: return this .concreteWorkBreakdownElementDao
169: .getConcreteWorkBreakdownElement(_id);
170: }
171:
172: /**
173: * Allows to get the concreteWorkBreakdownElementDao
174: *
175: * @return the concreteWorkBreakdownElementDao
176: */
177: public ConcreteWorkBreakdownElementDao getConcreteWorkBreakdownElementDao() {
178: return this .concreteWorkBreakdownElementDao;
179: }
180:
181: /**
182: * Allows to set the concreteWorkBreakdownElementDao
183: *
184: * @param _concreteWorkBreakdownElementDao
185: */
186: public void setConcreteWorkBreakdownElementDao(
187: ConcreteWorkBreakdownElementDao _concreteWorkBreakdownElementDao) {
188: this .concreteWorkBreakdownElementDao = _concreteWorkBreakdownElementDao;
189: }
190:
191: /**
192: * Allows to get the projectDao
193: *
194: * @return the projectDao
195: */
196: public ProjectDao getProjectDao() {
197: return this .projectDao;
198: }
199:
200: /**
201: * Allows to set the projectDao
202: *
203: * @param _projectDao
204: */
205: public void setProjectDao(ProjectDao _projectDao) {
206: this .projectDao = _projectDao;
207: }
208:
209: /**
210: * Allows to get the workBreakdownElementService
211: *
212: * @return the workBreakdownElementService
213: */
214: public WorkBreakdownElementService getWorkBreakdownElementService() {
215: return this .workBreakdownElementService;
216: }
217:
218: /**
219: * Allows to set the workBreakdownElementService
220: *
221: * @param _workBreakdownElementService
222: */
223: public void setWorkBreakdownElementService(
224: WorkBreakdownElementService _workBreakdownElementService) {
225: this .workBreakdownElementService = _workBreakdownElementService;
226: }
227:
228: /**
229: * Allows to get the concreteWorkOrderService
230: *
231: * @return the concreteWorkOrderService
232: */
233: public ConcreteWorkOrderService getConcreteWorkOrderService() {
234: return this .concreteWorkOrderService;
235: }
236:
237: /**
238: * Allows to set the concreteWorkOrderService
239: *
240: * @param _concreteWorkOrderService
241: *
242: */
243: public void setConcreteWorkOrderService(
244: ConcreteWorkOrderService _concreteWorkOrderService) {
245: this .concreteWorkOrderService = _concreteWorkOrderService;
246: }
247:
248: /**
249: * Allows to get the list of concretePredecessor by hashMap
250: *
251: * @param _cwbde
252: * @return the list of concretePredecessor by hashMap
253: */
254: public List<HashMap<String, Object>> getConcretePredecessorHashMap(
255: ConcreteWorkBreakdownElement _cwbde) {
256:
257: this .concreteWorkBreakdownElementDao.getSessionFactory()
258: .getCurrentSession().saveOrUpdate(_cwbde);
259:
260: List<HashMap<String, Object>> predecessorHashMap = new ArrayList<HashMap<String, Object>>();
261:
262: for (ConcreteWorkOrder cwo : _cwbde.getConcretePredecessors()) {
263:
264: HashMap<String, Object> hm = new HashMap<String, Object>();
265: ConcreteWorkBreakdownElement cPred = this
266: .getConcreteWorkBreakdownElementDao()
267: .getConcreteWorkBreakdownElement(
268: cwo.getConcreteWorkOrderId()
269: .getConcretePredecessorId());
270:
271: hm.put("pred", cPred.getConcreteName());
272: hm.put("linkType", cwo.getConcreteLinkType());
273:
274: predecessorHashMap.add(hm);
275: }
276:
277: return predecessorHashMap;
278: }
279:
280: /**
281: * Allows to get the list of concreteSuccessors by hashMap
282: *
283: * @param _cwbde
284: * @return the list of concreteSuccessors by hashMap
285: */
286: public List<HashMap<String, Object>> getConcreteSuccessorHashMap(
287: ConcreteWorkBreakdownElement _cwbde) {
288:
289: this .concreteWorkBreakdownElementDao.getSessionFactory()
290: .getCurrentSession().saveOrUpdate(_cwbde);
291:
292: List<HashMap<String, Object>> successorHashMap = new ArrayList<HashMap<String, Object>>();
293:
294: for (ConcreteWorkOrder cwo : _cwbde.getConcreteSuccessors()) {
295:
296: HashMap<String, Object> hm = new HashMap<String, Object>();
297: ConcreteWorkBreakdownElement cSucc = this
298: .getConcreteWorkBreakdownElementDao()
299: .getConcreteWorkBreakdownElement(
300: cwo.getConcreteWorkOrderId()
301: .getConcreteSuccessorId());
302:
303: hm.put("succ", cSucc.getConcreteName());
304: hm.put("linkType", cwo.getConcreteLinkType());
305:
306: successorHashMap.add(hm);
307: }
308:
309: return successorHashMap;
310: }
311: }
|