Rev 1310 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
857 | jmachado | 1 | package pt.estgp.estgweb.web.controllers.processes; |
2 | |||
3 | import jomm.dao.utils.HibernateUtils; |
||
4 | import jomm.utils.FilesUtils; |
||
5 | import org.apache.log4j.Logger; |
||
6 | import org.apache.struts.action.*; |
||
7 | import org.apache.struts.upload.FormFile; |
||
8 | import pt.estgp.estgweb.Globals; |
||
9 | import pt.estgp.estgweb.domain.MetaProcess; |
||
10 | import pt.estgp.estgweb.domain.dao.DaoFactory; |
||
11 | import pt.estgp.estgweb.filters.chains.ResourceAccessControlEnum; |
||
12 | import pt.estgp.estgweb.services.data.RepositoryService; |
||
13 | import pt.estgp.estgweb.utils.StringsUtils; |
||
14 | import pt.estgp.estgweb.web.UserSessionProxy; |
||
15 | import pt.estgp.estgweb.web.controllers.ApplicationDispatchController; |
||
16 | import pt.estgp.estgweb.web.form.processes.NewMetaProcessForm; |
||
17 | |||
18 | import javax.servlet.ServletException; |
||
19 | import javax.servlet.http.HttpServletRequest; |
||
20 | import javax.servlet.http.HttpServletResponse; |
||
21 | import java.util.ArrayList; |
||
22 | import java.util.Date; |
||
23 | import java.util.List; |
||
24 | |||
25 | /** |
||
26 | * @author Jorge Machado |
||
27 | * @date 26/Fev/2008 |
||
28 | * @time 18:01:54 |
||
29 | * @see pt.estgp.estgweb.web |
||
30 | */ |
||
31 | public class MetaProcessesController extends ApplicationDispatchController |
||
32 | { |
||
33 | |||
34 | private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(MetaProcessesController.class); |
||
35 | |||
36 | |||
37 | public ActionForward update(ActionMapping mapping, |
||
38 | ActionForm form, |
||
39 | HttpServletRequest request, |
||
40 | HttpServletResponse response) |
||
41 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException |
||
42 | { |
||
43 | try |
||
44 | { |
||
45 | |||
46 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isSuperuser() && UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole(Globals.ROLE_PROCESSES_ADMIN)) |
||
47 | return mapping.findForward("error401"); |
||
48 | NewMetaProcessForm f = (NewMetaProcessForm)form; |
||
49 | |||
50 | FormFile file = f.getFile(); |
||
51 | RepositoryService repositoryService = new RepositoryService(); |
||
52 | |||
53 | if(file != null && file.getFileSize()>0) |
||
54 | { |
||
55 | 1.5.0/docs/api/java/lang/System.html">System.out.println("FileName:"+file.getFileName()); |
||
56 | |||
57 | try { |
||
58 | HibernateUtils.getCurrentSession().beginTransaction(); |
||
59 | if(f.getMetaProcess().getRepositoryStream() == null || f.getMetaProcess().getRepositoryStream().length() == 0) |
||
60 | { |
||
61 | 1.5.0/docs/api/java/lang/System.html">System.out.println("AQUI"); |
||
1703 | jmachado | 62 | 1.5.0/docs/api/java/lang/String.html">String repositoryId = repositoryService.storeRepositoryFile(file.getInputStream(),file.getContentType(), FilesUtils.getExtension(file.getFileName()),file.getFileSize(),file.getFileName(),"MetaProcess Template file", ResourceAccessControlEnum.authenticatedDomain, null, UserSessionProxy.loadUserSessionFromRequest(request)); |
857 | jmachado | 63 | 1.5.0/docs/api/java/lang/System.html">System.out.println(repositoryId); |
64 | f.getMetaProcess().setRepositoryStream(repositoryId); |
||
65 | f.setFileName(file.getFileName()); |
||
66 | } |
||
67 | else |
||
68 | { |
||
69 | repositoryService.updateRepositoryFile(f.getMetaProcess().getRepositoryStream(),file.getInputStream(),file.getContentType(),FilesUtils.getExtension(file.getFileName()),file.getFileSize(),file.getFileName(),"MetaProcess Template file",ResourceAccessControlEnum.authenticatedDomain); |
||
70 | f.setFileName(file.getFileName()); |
||
71 | } |
||
72 | HibernateUtils.getCurrentSession().getTransaction().commit(); |
||
73 | |||
74 | }catch(1.5.0/docs/api/java/lang/Exception.html">Exception e) |
||
75 | { |
||
76 | logger.error(e,e); |
||
77 | } |
||
78 | } |
||
79 | 1.5.0/docs/api/java/lang/String.html">String personToAdd = f.getPersonToAdd(); |
||
80 | |||
81 | if(personToAdd.trim().length() > 0) |
||
82 | { |
||
83 | if(f.getMetaProcess().getPossiblePersons() == null) |
||
84 | f.getMetaProcess().setPossiblePersons(""); |
||
85 | List<String> persons = StringsUtils.getStringsFromSerial(f.getMetaProcess().getPossiblePersons(), ";"); |
||
86 | if(persons == null) |
||
87 | persons = new ArrayList<String>(); |
||
88 | if(!persons.contains(personToAdd)) |
||
89 | { |
||
90 | f.getMetaProcess().setPossiblePersons(f.getMetaProcess().getPossiblePersons() + personToAdd + ";"); |
||
91 | } |
||
92 | |||
93 | } |
||
94 | |||
95 | 1.5.0/docs/api/java/lang/String.html">String roleToAdd = f.getRoleToAdd(); |
||
96 | |||
97 | if(roleToAdd.trim().length() > 0) |
||
98 | { |
||
99 | if(f.getMetaProcess().getPossibleTargets() == null) |
||
100 | f.getMetaProcess().setPossibleTargets(""); |
||
101 | List<String> roles = StringsUtils.getStringsFromSerial(f.getMetaProcess().getPossibleTargets(), ";"); |
||
102 | if(roles == null) |
||
103 | roles = new ArrayList<String>(); |
||
104 | if(!roles.contains(roleToAdd)) |
||
105 | { |
||
106 | f.getMetaProcess().setPossibleTargets(f.getMetaProcess().getPossibleTargets() + roleToAdd + ";"); |
||
107 | } |
||
108 | } |
||
109 | f.setRoleToRemove(""); |
||
110 | f.setRoleToAdd(""); |
||
111 | f.setPersonToRemove(""); |
||
112 | f.setPersonToAdd(""); |
||
113 | |||
114 | return mapping.getInputForward(); |
||
115 | |||
116 | } |
||
117 | //catch (FilterChainFailedException e) |
||
118 | //{ |
||
119 | // return mapping.findForward("error401"); |
||
120 | //} |
||
121 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
122 | { |
||
123 | logger.error(e, e); |
||
124 | throw e; |
||
125 | } |
||
126 | } |
||
127 | |||
128 | |||
129 | public ActionForward create(ActionMapping mapping, |
||
130 | ActionForm form, |
||
131 | HttpServletRequest request, |
||
132 | HttpServletResponse response) |
||
133 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException |
||
134 | { |
||
135 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isSuperuser() && UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole(Globals.ROLE_PROCESSES_ADMIN)) |
||
136 | return mapping.findForward("error401"); |
||
137 | try |
||
138 | { |
||
139 | NewMetaProcessForm f = (NewMetaProcessForm)form; |
||
140 | HibernateUtils.getCurrentSession().beginTransaction(); |
||
141 | |||
142 | ActionMessages errors = f.validate(mapping,request); |
||
143 | if(!errors.isEmpty()) |
||
144 | { |
||
145 | saveErrors(request, errors); |
||
146 | return mapping.getInputForward(); |
||
147 | } |
||
148 | |||
149 | MetaProcess metaProcess = f.getMetaProcess(); |
||
150 | if(metaProcess.getId() == 0) |
||
151 | { |
||
152 | metaProcess.setSaveDate(new 5+0%2Fdocs%2Fapi+Date">Date()); |
||
153 | DaoFactory.getMetaProcessDaoImpl().save(metaProcess); |
||
154 | } |
||
155 | else |
||
156 | { |
||
157 | MetaProcess db = DaoFactory.getMetaProcessDaoImpl().load(metaProcess.getId()); |
||
158 | db.setCategory(metaProcess.getCategory()); |
||
159 | db.setSubCategory(metaProcess.getSubCategory()); |
||
160 | db.setRepositoryStream(f.getMetaProcess().getRepositoryStream()); |
||
161 | db.setDescription(metaProcess.getDescription()); |
||
162 | db.setPossiblePersons(metaProcess.getPossiblePersons()); |
||
163 | db.setPossibleTargets(metaProcess.getPossibleTargets()); |
||
164 | db.setName(metaProcess.getName()); |
||
165 | db.setSrcRole(metaProcess.getSrcRole()); |
||
166 | db.setTargetRole(metaProcess.getTargetRole()); |
||
167 | } |
||
168 | |||
169 | |||
170 | HibernateUtils.getCurrentSession().getTransaction().commit(); |
||
171 | addMessage(request,"metaprocess.created",metaProcess.getName()); |
||
172 | return mapping.findForward("process.submited"); |
||
173 | } |
||
174 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
175 | { |
||
176 | logger.error(e, e); |
||
177 | throw e; |
||
178 | } |
||
179 | } |
||
180 | |||
181 | public ActionForward delete(ActionMapping mapping, |
||
182 | ActionForm form, |
||
183 | HttpServletRequest request, |
||
184 | HttpServletResponse response) |
||
185 | throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException |
||
186 | { |
||
187 | if(!UserSessionProxy.loadUserSessionFromRequest(request).getUser().isSuperuser() && UserSessionProxy.loadUserSessionFromRequest(request).getUser().hasRole(Globals.ROLE_PROCESSES_ADMIN)) |
||
188 | return mapping.findForward("error401"); |
||
189 | try |
||
190 | { |
||
191 | |||
192 | NewMetaProcessForm f = (NewMetaProcessForm)form; |
||
193 | |||
194 | 1.5.0/docs/api/java/lang/String.html">String personToRemove = f.getPersonToRemove(); |
||
195 | |||
196 | |||
197 | if(personToRemove.trim().length() > 0) |
||
198 | { |
||
199 | if(f.getMetaProcess().getPossiblePersons() == null) |
||
200 | f.getMetaProcess().setPossiblePersons(""); |
||
201 | List<String> persons = StringsUtils.getStringsFromSerial(f.getMetaProcess().getPossiblePersons(), ";"); |
||
202 | if(persons == null) |
||
203 | persons = new ArrayList<String>(); |
||
204 | if(persons.contains(personToRemove)) |
||
205 | { |
||
206 | persons.remove(personToRemove); |
||
207 | f.getMetaProcess().setPossiblePersons(""); |
||
208 | for(1.5.0/docs/api/java/lang/String.html">String p: persons) |
||
209 | f.getMetaProcess().setPossiblePersons(f.getMetaProcess().getPossiblePersons() + p + ";"); |
||
210 | } |
||
211 | |||
212 | } |
||
213 | |||
214 | 1.5.0/docs/api/java/lang/String.html">String roleToRemove = f.getRoleToRemove(); |
||
215 | |||
216 | if(roleToRemove.trim().length() > 0) |
||
217 | { |
||
218 | if(f.getMetaProcess().getPossibleTargets() == null) |
||
219 | f.getMetaProcess().setPossibleTargets(""); |
||
220 | List<String> roles = StringsUtils.getStringsFromSerial(f.getMetaProcess().getPossibleTargets(), ";"); |
||
221 | if(roles == null) |
||
222 | roles = new ArrayList<String>(); |
||
223 | if(roles.contains(roleToRemove)) |
||
224 | { |
||
225 | roles.remove(roleToRemove); |
||
226 | f.getMetaProcess().setPossibleTargets(""); |
||
227 | for(1.5.0/docs/api/java/lang/String.html">String r: roles) |
||
228 | f.getMetaProcess().setPossibleTargets(f.getMetaProcess().getPossibleTargets() + r + ";"); |
||
229 | } |
||
230 | } |
||
231 | |||
232 | f.setRoleToRemove(""); |
||
233 | f.setRoleToAdd(""); |
||
234 | f.setPersonToRemove(""); |
||
235 | f.setPersonToAdd(""); |
||
236 | return mapping.getInputForward(); |
||
237 | |||
238 | } |
||
239 | //catch (FilterChainFailedException e) |
||
240 | //{ |
||
241 | // return mapping.findForward("error401"); |
||
242 | //} |
||
243 | catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e) |
||
244 | { |
||
245 | logger.error(e, e); |
||
246 | throw e; |
||
247 | } |
||
248 | } |
||
249 | |||
250 | |||
251 | |||
252 | } |