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 Mathieu BENOIT <mathieu-benoit@hotmail.fr>
005: * Copyright (C) 2007 Sebastien BALARD <sbalard@wilos-project.org>
006: *
007: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
008: * General Public License as published by the Free Software Foundation; either version 2 of the License,
009: * or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
012: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * You should have received a copy of the GNU General Public License along with this program; if not,
016: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
017: */
018:
019: package wilos.business.services.spem2.guide;
020:
021: import java.io.File;
022: import java.util.Enumeration;
023: import java.util.HashSet;
024: import java.util.List;
025: import java.util.Set;
026: import java.util.StringTokenizer;
027:
028: import org.springframework.transaction.annotation.Propagation;
029: import org.springframework.transaction.annotation.Transactional;
030:
031: import wilos.business.services.spem2.process.ProcessService;
032: import wilos.hibernate.spem2.guide.GuidanceDao;
033: import wilos.model.spem2.activity.Activity;
034: import wilos.model.spem2.breakdownelement.BreakdownElement;
035: import wilos.model.spem2.guide.Guidance;
036: import wilos.model.spem2.process.Process;
037: import wilos.model.spem2.role.RoleDefinition;
038: import wilos.model.spem2.task.TaskDefinition;
039:
040: @Transactional(readOnly=false,propagation=Propagation.REQUIRED)
041: public class GuidanceService {
042:
043: private GuidanceDao guidanceDao;
044:
045: private ProcessService processService;
046:
047: public Guidance getGuidance(String _id) {
048: return this .guidanceDao.getGuidance(_id);
049: }
050:
051: public List<Guidance> getAllGuidances() {
052: return this .guidanceDao.getAllGuidances();
053: }
054:
055: public String saveGuidance(Guidance _guidance) {
056: return this .guidanceDao.saveOrUpdateGuidance(_guidance);
057: }
058:
059: public void deleteGuidance(Guidance _guidance) {
060: this .guidanceDao.deleteGuidance(_guidance);
061: }
062:
063: public Guidance getGuidanceFromGuid(String _guid) {
064: return this .guidanceDao.getGuidanceFromGuid(_guid);
065: }
066:
067: public String getAttachmentFilePath(String idGuidance, String file) {
068: String filePathToBeReturn = "";
069: String folder = "";
070: String attachment = "";
071: Guidance g = null;
072: String guidCurrentProcess = null;
073:
074: System.out.println("Id : " + idGuidance);
075:
076: g = this .getGuidanceFromGuid(idGuidance);
077:
078: BreakdownElement bde = null;
079:
080: if (g.getTaskDefinitions().size() != 0)
081: bde = g.getTaskDefinitions().iterator().next()
082: .getTaskDescriptors().iterator().next();
083: if (g.getRoleDefinitions().size() != 0)
084: bde = g.getRoleDefinitions().iterator().next()
085: .getRoleDescriptors().iterator().next();
086: if (g.getActivities().size() != 0)
087: bde = g.getActivities().iterator().next();
088: if (bde != null) {
089: while (bde.getSuperActivities().size() != 0) {
090: bde = bde.getSuperActivities().iterator().next();
091: }
092: if (bde instanceof Process) {
093: guidCurrentProcess = bde.getGuid();
094: }
095: }
096:
097: if (g != null && guidCurrentProcess != null) {
098:
099: Enumeration attachments = new StringTokenizer(g
100: .getAttachment(), "|", false);
101: while (attachments.hasMoreElements()) {
102: String currentAttachment = (String) attachments
103: .nextElement();
104: if (currentAttachment.matches(".*" + file)) {
105: attachment = new String(currentAttachment);
106: attachment = attachment
107: .replace("/", File.separator);
108: }
109: }
110:
111: folder = this .processService.getProcessFromGuid(
112: guidCurrentProcess).getFolderPath();
113: filePathToBeReturn = folder + File.separator
114: + guidCurrentProcess + File.separator + attachment;
115: System.out.println("FOLDER+ATTCH: " + filePathToBeReturn);
116: }
117: return filePathToBeReturn;
118: }
119:
120: /* Getters & Setters */
121:
122: public GuidanceDao getGuidanceDao() {
123: return this .guidanceDao;
124: }
125:
126: public void setGuidanceDao(GuidanceDao _guidanceDao) {
127: this .guidanceDao = _guidanceDao;
128: }
129:
130: public ProcessService getProcessService() {
131: return processService;
132: }
133:
134: public void setProcessService(ProcessService processService) {
135: this .processService = processService;
136: }
137:
138: /**
139: * @param _retrievedRd
140: * @return
141: */
142: public Set<TaskDefinition> getTaskDefinitions(Guidance _guidance) {
143: Set<TaskDefinition> tmp = new HashSet<TaskDefinition>();
144: this .guidanceDao.getSessionFactory().getCurrentSession()
145: .saveOrUpdate(_guidance);
146: for (TaskDefinition td : _guidance.getTaskDefinitions()) {
147: tmp.add(td);
148: }
149: return tmp;
150: }
151:
152: /**
153: * @param _retrievedRd
154: * @return
155: */
156: public Set<RoleDefinition> getRoleDefinitions(Guidance _guidance) {
157: Set<RoleDefinition> tmp = new HashSet<RoleDefinition>();
158: this .guidanceDao.getSessionFactory().getCurrentSession()
159: .saveOrUpdate(_guidance);
160: for (RoleDefinition td : _guidance.getRoleDefinitions()) {
161: tmp.add(td);
162: }
163: return tmp;
164: }
165:
166: /**
167: * @param _retrievedRd
168: * @return
169: */
170: public Set<Activity> getActivities(Guidance _guidance) {
171: Set<Activity> tmp = new HashSet<Activity>();
172: this .guidanceDao.getSessionFactory().getCurrentSession()
173: .saveOrUpdate(_guidance);
174: for (Activity act : _guidance.getActivities()) {
175: tmp.add(act);
176: }
177: return tmp;
178: }
179: }
|