Subversion Repositories bacoAlunos

Rev

Rev 1310 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
109 fvelez 1
package pt.estgp.estgweb.web.controllers.profile;
2
 
1054 jmachado 3
import org.apache.log4j.Logger;
4
import org.apache.struts.action.ActionErrors;
5
import org.apache.struts.action.ActionForm;
6
import org.apache.struts.action.ActionForward;
7
import org.apache.struts.action.ActionMapping;
8
import pt.estgp.estgweb.Globals;
9
import pt.estgp.estgweb.domain.DomainObjectFactory;
10
import pt.estgp.estgweb.domain.User;
11
import pt.estgp.estgweb.domain.UserSessionImpl;
12
import pt.estgp.estgweb.domain.views.RecordView;
13
import pt.estgp.estgweb.domain.views.UserView;
14
import pt.estgp.estgweb.services.expceptions.AlreadyExistsException;
15
import pt.estgp.estgweb.web.UserSessionProxy;
132 fvelez 16
import pt.estgp.estgweb.web.controllers.AddRolesController;
175 jmachado 17
import pt.estgp.estgweb.web.exceptions.NoCookiesException;
1054 jmachado 18
import pt.estgp.estgweb.web.form.AddRolesForm;
113 fvelez 19
import pt.estgp.estgweb.web.form.profile.ProfileForm;
1054 jmachado 20
import pt.estgp.estgweb.web.utils.RequestUtils;
21
import pt.utl.ist.berserk.logic.filterManager.exceptions.FilterRetrieveException;
22
import pt.utl.ist.berserk.logic.filterManager.exceptions.IncompatibleFilterException;
23
import pt.utl.ist.berserk.logic.filterManager.exceptions.InvalidFilterException;
24
import pt.utl.ist.berserk.logic.filterManager.exceptions.InvalidFilterExpressionException;
109 fvelez 25
import pt.utl.ist.berserk.logic.serviceManager.IServiceManager;
26
import pt.utl.ist.berserk.logic.serviceManager.ServiceManager;
113 fvelez 27
import pt.utl.ist.berserk.logic.serviceManager.exceptions.FilterChainFailedException;
175 jmachado 28
import pt.utl.ist.berserk.logic.serviceManager.exceptions.ServiceManagerException;
109 fvelez 29
 
1054 jmachado 30
import javax.servlet.ServletException;
109 fvelez 31
import javax.servlet.http.HttpServletRequest;
32
import javax.servlet.http.HttpServletResponse;
1054 jmachado 33
import java.io.Serializable;
113 fvelez 34
import java.util.List;
168 fvelez 35
 
109 fvelez 36
/**
37
 * @author Jorge Machado
38
 * @date 26/Fev/2008
39
 * @time 18:01:54
40
 * @see pt.estgp.estgweb.web
41
 */
168 fvelez 42
public class ProfileController extends AddRolesController
43
{
109 fvelez 44
 
45
    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(ProfileController.class);
141 fvelez 46
    private static final 1.5.0/docs/api/java/lang/String.html">String TARGET_ROLES_KEY = AddRolesForm.TARGET_ROLES_KEY;
109 fvelez 47
 
148 fvelez 48
 
109 fvelez 49
    public ActionForward editUser(ActionMapping mapping,
168 fvelez 50
                                  ActionForm form,
113 fvelez 51
                                  HttpServletRequest request,
52
                                  HttpServletResponse response)
168 fvelez 53
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
54
    {
55
        ProfileForm profileForm = (ProfileForm) form;
175 jmachado 56
        ActionErrors errors = profileForm.validate(mapping, request);
57
        if (!errors.isEmpty())
58
        {
338 jmachado 59
            if(profileForm.getUserView().getId() > 0)
60
            {
61
                UserView uV = loadUser(profileForm.getUserView().getId(), request, response);
62
                profileForm.getUserView().setPasswordLocal(uV.isPasswordLocal());
344 jmachado 63
                UserSessionImpl userSession = (UserSessionImpl) UserSessionProxy.loadUserSession(request, response);
64
                uV.setUserRoles((List<String>) userSession.get(TARGET_ROLES_KEY));
65
                profileForm.setSelectedRoles(uV.getUserRoles());
338 jmachado 66
            }
175 jmachado 67
            saveMessages(request, errors);
68
            return mapping.getInputForward();
69
        }
168 fvelez 70
        UserView userView = profileForm.getUserView();
109 fvelez 71
        try
72
        {
168 fvelez 73
            UserSessionImpl userSession = (UserSessionImpl) UserSessionProxy.loadUserSession(request, response);
141 fvelez 74
            userView.setUserRoles((List<String>) userSession.get(TARGET_ROLES_KEY));
109 fvelez 75
            IServiceManager sm = ServiceManager.getInstance();
113 fvelez 76
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"object"};
168 fvelez 77
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{userView, profileForm.getTypeClass()};
338 jmachado 78
            try
79
            {
80
                userView = (UserView) sm.execute(RequestUtils.getRequester(request, response), "SubmitUser", args, names);
81
            }
82
            catch (AlreadyExistsException e)
83
            {
84
                if(profileForm.getUserView().getId() > 0)
85
                {
86
                    UserView uV = loadUser(profileForm.getUserView().getId(), request, response);
87
                    profileForm.getUserView().setPasswordLocal(uV.isPasswordLocal());
88
                }
89
                addErrorWithKeys(request,"user.exists",e.getMessage());
90
                return mapping.getInputForward();
91
            }
215 jmachado 92
            profileForm.setUserView(userView);
93
            if (userSession.getUser().getId() == userView.getId())
168 fvelez 94
            {
215 jmachado 95
                userSession.setUser(userView.getUser());
168 fvelez 96
                request.setAttribute(Globals.USER_SESSION_KEY, userSession);
215 jmachado 97
                logger.info("Puting new user info in session:" + userView.getId());
132 fvelez 98
            }
168 fvelez 99
            addMessage(request, "profile.edited.sucess");
113 fvelez 100
            return mapping.findForward("success");
101
        }
168 fvelez 102
        catch (FilterChainFailedException e)
113 fvelez 103
        {
104
            return mapping.findForward("error401");
105
        }
106
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
107
        {
168 fvelez 108
            logger.error(e, e);
113 fvelez 109
            throw e;
110
        }
111
    }
109 fvelez 112
 
168 fvelez 113
    public ActionForward newTeacher(ActionMapping mapping,
114
                                    ActionForm form,
115
                                    HttpServletRequest request,
116
                                    HttpServletResponse response)
117
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
118
    {
119
        return newGenericUser(mapping, form, request, response, DomainObjectFactory.createTeacherImpl());
120
    }
121
 
122
    public ActionForward newStudent(ActionMapping mapping,
123
                                    ActionForm form,
124
                                    HttpServletRequest request,
125
                                    HttpServletResponse response)
126
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
127
    {
128
        return newGenericUser(mapping, form, request, response, DomainObjectFactory.createStudentImpl());
129
    }
130
 
131
    public ActionForward newUser(ActionMapping mapping,
132
                                 ActionForm form,
133
                                 HttpServletRequest request,
134
                                 HttpServletResponse response)
135
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
136
    {
137
        return newGenericUser(mapping, form, request, response, DomainObjectFactory.createUserImpl());
138
    }
139
 
140
    public ActionForward newGenericUser(ActionMapping mapping,
141
                                        ActionForm form,
142
                                        HttpServletRequest request,
143
                                        HttpServletResponse response,
144
                                        User u)
145
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
146
    {
147
        try
148
        {
149
            ProfileForm pF = (ProfileForm) form;
150
            UserSessionImpl userSession = (UserSessionImpl) UserSessionProxy.loadUserSession(request, response);
151
 
152
            UserView uV = new UserView(u);
153
            pF.setUserView(uV);
154
            pF.setTypeClass(u.getClass().getName());
155
            pF.setSelectedRoles(uV.getUserRoles());
156
            userSession.put(TARGET_ROLES_KEY, (1.5.0/docs/api/java/io/Serializable.html">Serializable) uV.getUserRoles());
157
            userSession.serialize(request, response);
215 jmachado 158
            return mapping.findForward("personalData");
168 fvelez 159
        }
160
        catch (FilterChainFailedException e)
161
        {
162
            return mapping.findForward("error401");
163
        }
164
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
165
        {
166
            logger.error(e, e);
167
            throw e;
168
        }
169
    }
170
 
113 fvelez 171
    public ActionForward changeProfile(ActionMapping mapping,
168 fvelez 172
                                       ActionForm form,
113 fvelez 173
                                       HttpServletRequest request,
174
                                       HttpServletResponse response)
168 fvelez 175
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
176
    {
113 fvelez 177
        try
178
        {
140 fvelez 179
            ProfileForm pF = (ProfileForm) form;
168 fvelez 180
            UserSessionImpl userSession = (UserSessionImpl) UserSessionProxy.loadUserSession(request, response);
132 fvelez 181
            1.5.0/docs/api/java/lang/String.html">String id = request.getParameter("id");
182
            long userToLoad;
183
 
168 fvelez 184
            if (id != null)
185
                userToLoad = 1.5.0/docs/api/java/lang/Long.html">Long.valueOf(id);
132 fvelez 186
            else
168 fvelez 187
                userToLoad = userSession.getUser().getId();
175 jmachado 188
            UserView uV = loadUser(userToLoad, request, response);
140 fvelez 189
            pF.setUserView(uV);
190
            pF.setSelectedRoles(uV.getUserRoles());
141 fvelez 191
            userSession.put(TARGET_ROLES_KEY, (1.5.0/docs/api/java/io/Serializable.html">Serializable) uV.getUserRoles());
168 fvelez 192
            userSession.serialize(request, response);
215 jmachado 193
            return mapping.findForward("personalData");
109 fvelez 194
        }
168 fvelez 195
        catch (FilterChainFailedException e)
109 fvelez 196
        {
113 fvelez 197
            return mapping.findForward("error401");
109 fvelez 198
        }
199
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
200
        {
168 fvelez 201
            logger.error(e, e);
113 fvelez 202
            throw e;
109 fvelez 203
        }
204
    }
338 jmachado 205
 
215 jmachado 206
    public ActionForward home(ActionMapping mapping,
207
                              ActionForm form,
208
                              HttpServletRequest request,
209
                              HttpServletResponse response)
210
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
211
    {
212
        try
213
        {
214
            ProfileForm pF = (ProfileForm) form;
215
            UserSessionImpl userSession = (UserSessionImpl) UserSessionProxy.loadUserSession(request, response);
216
            long userToLoad;
1338 jmachado 217
            if (request.getParameter("id")!=null)
218
                userToLoad = 1.5.0/docs/api/java/lang/Long.html">Long.parseLong(request.getParameter("id"));
219
            else if (pF.getUserView() != null && pF.getUserView().getId() > 0)
215 jmachado 220
                userToLoad = pF.getUserView().getId();
221
            else
222
                userToLoad = userSession.getUser().getId();
223
            UserView uV = loadUserWithRecords(userToLoad, request, response);
224
            pF.setUserView(uV);
225
            return mapping.findForward("home");
226
        }
227
        catch (FilterChainFailedException e)
228
        {
229
            return mapping.findForward("error401");
230
        }
231
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
232
        {
233
            logger.error(e, e);
234
            throw e;
235
        }
236
    }
338 jmachado 237
 
219 jmachado 238
    public ActionForward grades(ActionMapping mapping,
338 jmachado 239
                                ActionForm form,
240
                                HttpServletRequest request,
241
                                HttpServletResponse response)
219 jmachado 242
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
243
    {
244
        try
245
        {
246
            ProfileForm pF = (ProfileForm) form;
247
            UserSessionImpl userSession = (UserSessionImpl) UserSessionProxy.loadUserSession(request, response);
1338 jmachado 248
            1.5.0/docs/api/java/lang/String.html">String id = request.getParameter("id");
219 jmachado 249
            long userToLoad;
1338 jmachado 250
 
251
            if (id != null)
252
                userToLoad = 1.5.0/docs/api/java/lang/Long.html">Long.valueOf(id);
253
            else if (pF.getUserView().getId() > 0)
219 jmachado 254
                userToLoad = pF.getUserView().getId();
255
            else
256
                userToLoad = userSession.getUser().getId();
257
            UserView uV = loadUserWithGrades(userToLoad, request, response);
258
            pF.setUserView(uV);
259
            return mapping.findForward("grades");
260
        }
261
        catch (FilterChainFailedException e)
262
        {
263
            return mapping.findForward("error401");
264
        }
265
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
266
        {
267
            logger.error(e, e);
268
            throw e;
269
        }
270
    }
113 fvelez 271
 
219 jmachado 272
 
215 jmachado 273
    public ActionForward homeCode(ActionMapping mapping,
338 jmachado 274
                                  ActionForm form,
275
                                  HttpServletRequest request,
276
                                  HttpServletResponse response)
215 jmachado 277
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
278
    {
279
        try
280
        {
281
            ProfileForm pF = (ProfileForm) form;
282
            UserSessionImpl userSession = (UserSessionImpl) UserSessionProxy.loadUserSession(request, response);
283
            int userToLoad = pF.getUserView().getCode();
284
            UserView uV = loadUserWithRecordsCode(userToLoad, request, response);
285
            pF.setUserView(uV);
286
            return mapping.findForward("home");
287
        }
288
        catch (FilterChainFailedException e)
289
        {
290
            return mapping.findForward("error401");
291
        }
292
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
293
        {
294
            logger.error(e, e);
295
            throw e;
296
        }
297
    }
298
 
299
    public ActionForward curriculum(ActionMapping mapping,
300
                                    ActionForm form,
301
                                    HttpServletRequest request,
302
                                    HttpServletResponse response)
303
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
304
    {
305
        try
306
        {
307
            ProfileForm pF = (ProfileForm) form;
308
            UserSessionImpl userSession = (UserSessionImpl) UserSessionProxy.loadUserSession(request, response);
309
            long userToLoad = userSession.getUser().getId();
310
            UserView uV = loadUserWithRecords(userToLoad, request, response);
311
            pF.setUserView(uV);
312
            return mapping.findForward("curriculum");
313
        }
314
        catch (FilterChainFailedException e)
315
        {
316
            return mapping.findForward("error401");
317
        }
318
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
319
        {
320
            logger.error(e, e);
321
            throw e;
322
        }
323
    }
324
 
175 jmachado 325
    private UserView loadUser(long id, HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, InvalidFilterException, ServiceManagerException, InvalidFilterExpressionException, IncompatibleFilterException, FilterRetrieveException, NoCookiesException
326
    {
327
        IServiceManager sm = ServiceManager.getInstance();
328
        1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
329
        5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id};
330
        UserView uV = (UserView) sm.execute(RequestUtils.getRequester(request, response), "LoadUserById", args, names);
331
        return uV;
332
    }
333
 
215 jmachado 334
    private UserView loadUserWithRecords(long id, HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, InvalidFilterException, ServiceManagerException, InvalidFilterExpressionException, IncompatibleFilterException, FilterRetrieveException, NoCookiesException
335
    {
336
        IServiceManager sm = ServiceManager.getInstance();
337
        1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
338
        5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id};
339
        UserView uV = (UserView) sm.execute(RequestUtils.getRequester(request, response), "LoadUserWithRecordsById", args, names);
340
        return uV;
341
    }
338 jmachado 342
 
219 jmachado 343
    private UserView loadUserWithGrades(long id, HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, InvalidFilterException, ServiceManagerException, InvalidFilterExpressionException, IncompatibleFilterException, FilterRetrieveException, NoCookiesException
344
    {
345
        IServiceManager sm = ServiceManager.getInstance();
346
        1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
347
        5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{id};
348
        UserView uV = (UserView) sm.execute(RequestUtils.getRequester(request, response), "LoadUserWithGradesById", args, names);
349
        return uV;
350
    }
338 jmachado 351
 
1283 jmachado 352
    public UserView  loadUserWithRecordsCode(int code, HttpServletRequest request, HttpServletResponse response) throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, InvalidFilterException, ServiceManagerException, InvalidFilterExpressionException, IncompatibleFilterException, FilterRetrieveException, NoCookiesException
215 jmachado 353
    {
354
        IServiceManager sm = ServiceManager.getInstance();
355
        1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
356
        5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{code};
357
        UserView uV = (UserView) sm.execute(RequestUtils.getRequester(request, response), "LoadUserWithRecordsByCode", args, names);
358
        return uV;
359
    }
360
 
113 fvelez 361
    public ActionForward search(ActionMapping mapping,
168 fvelez 362
                                ActionForm form,
113 fvelez 363
                                HttpServletRequest request,
364
                                HttpServletResponse response)
168 fvelez 365
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
366
    {
113 fvelez 367
        try
368
        {
168 fvelez 369
            ProfileForm fromRequest = (ProfileForm) form;
373 jmachado 370
 
113 fvelez 371
            IServiceManager sm = ServiceManager.getInstance();
372
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
338 jmachado 373
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{fromRequest.getTextToSearch(), fromRequest.getTypeToSearch()};
168 fvelez 374
            List<UserView> uVs = (List<UserView>) sm.execute(RequestUtils.getRequester(request, response), "SearchUser", args, names);
373 jmachado 375
            fromRequest.setUsersFind(uVs);
376
            request.setAttribute("ProfileForm", fromRequest);
168 fvelez 377
            if (uVs.size() != 0)
378
                addMessage(request, "profile.search.user.find", "" + uVs.size());
148 fvelez 379
            else
168 fvelez 380
                addMessage(request, "profile.search.user.not.find");
113 fvelez 381
            return mapping.findForward("search");
382
        }
168 fvelez 383
        catch (FilterChainFailedException e)
113 fvelez 384
        {
385
            return mapping.findForward("error401");
386
        }
387
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
388
        {
168 fvelez 389
            logger.error(e, e);
113 fvelez 390
            throw e;
391
        }
392
    }
186 fvelez 393
 
215 jmachado 394
    public ActionForward delete(ActionMapping mapping,
338 jmachado 395
                                ActionForm form,
186 fvelez 396
                                HttpServletRequest request,
397
                                HttpServletResponse response)
398
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
399
    {
400
        try
401
        {
402
 
403
            IServiceManager sm = ServiceManager.getInstance();
404
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
405
            5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{new 1.5.0/docs/api/java/lang/Long.html">Long(request.getParameter("id"))};
338 jmachado 406
            1.5.0/docs/api/java/lang/Boolean.html">Boolean status = (1.5.0/docs/api/java/lang/Boolean.html">Boolean) sm.execute(RequestUtils.getRequester(request, response), "DeleteUser", args, names);
407
            if (status)
186 fvelez 408
            {
338 jmachado 409
                addMessage(request, "user.deleted.sucess");
186 fvelez 410
                return mapping.findForward("success");
411
            }
412
            else
413
            {
338 jmachado 414
                addMessage(request, "user.deleted.fail");
186 fvelez 415
                return mapping.findForward("success");
416
            }
417
        }
338 jmachado 418
        catch (FilterChainFailedException e)
186 fvelez 419
        {
420
            return mapping.findForward("error401");
421
        }
422
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
423
        {
338 jmachado 424
            logger.error(e, e);
186 fvelez 425
            throw e;
426
        }
427
    }
428
 
215 jmachado 429
    public ActionForward createRecord(ActionMapping mapping,
338 jmachado 430
                                      ActionForm form,
431
                                      HttpServletRequest request,
432
                                      HttpServletResponse response)
215 jmachado 433
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
434
    {
435
        try
436
        {
437
            ProfileForm profileForm = (ProfileForm) form;
438
            IServiceManager sm = ServiceManager.getInstance();
439
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"object"};
440
 
441
            5+0%2Fdocs%2Fapi+Object">Object[] args;
338 jmachado 442
            if (profileForm.getUploadFile() != null)
443
                args = new 5+0%2Fdocs%2Fapi+Object">Object[]{profileForm.getRecordView(), profileForm.getUploadFile().getInputStream(), profileForm.getUploadFile().getFileName(), profileForm.getUploadFile().getContentType(), profileForm.getUploadFile().getFileSize()};
215 jmachado 444
            else
338 jmachado 445
                args = new 5+0%2Fdocs%2Fapi+Object">Object[]{profileForm.getRecordView(), null, null, null, 0};
215 jmachado 446
 
359 jmachado 447
            boolean newRecord = false;
448
            if(profileForm.getRecordView().getId() <= 0)
449
                newRecord = true;
215 jmachado 450
            UserView userView;
338 jmachado 451
            if (profileForm.getRecordView().getId() > 0)
452
                userView = (UserView) sm.execute(RequestUtils.getRequester(request, response), "EditUserProfileRecord", args, names);
453
            else
454
                userView = (UserView) sm.execute(RequestUtils.getRequester(request, response), "CreateUserProfileRecord", args, names);
215 jmachado 455
 
359 jmachado 456
            if(newRecord)
457
                addMessage(request, "profile.record.add.sucess", profileForm.getRecordView().getTitle());
458
            else
459
                addMessage(request, "profile.record.updated.sucess", profileForm.getRecordView().getTitle());
215 jmachado 460
            profileForm.setUserView(userView);
461
            return mapping.findForward("home");
462
        }
338 jmachado 463
        catch (FilterChainFailedException e)
215 jmachado 464
        {
465
            return mapping.findForward("error401");
466
        }
467
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
468
        {
338 jmachado 469
            logger.error(e, e);
215 jmachado 470
            throw e;
471
        }
472
    }
473
 
474
    public ActionForward deleteRecord(ActionMapping mapping,
338 jmachado 475
                                      ActionForm form,
476
                                      HttpServletRequest request,
477
                                      HttpServletResponse response)
215 jmachado 478
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
479
    {
480
        try
481
        {
482
            ProfileForm profileForm = (ProfileForm) form;
483
            IServiceManager sm = ServiceManager.getInstance();
484
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
485
            5+0%2Fdocs%2Fapi+Object">Object[] args;
338 jmachado 486
            args = new 5+0%2Fdocs%2Fapi+Object">Object[]{profileForm.getRecordView().getId()};
215 jmachado 487
 
338 jmachado 488
            UserView userView = (UserView) sm.execute(RequestUtils.getRequester(request, response), "DeleteUserProfileRecord", args, names);
489
            addMessage(request, "profile.record.deleted.sucess");
215 jmachado 490
            profileForm.setUserView(userView);
491
            return mapping.findForward("home");
492
        }
338 jmachado 493
        catch (FilterChainFailedException e)
215 jmachado 494
        {
495
            return mapping.findForward("error401");
496
        }
497
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
498
        {
338 jmachado 499
            logger.error(e, e);
215 jmachado 500
            throw e;
501
        }
502
    }
503
 
504
    public ActionForward loadEditRecord(ActionMapping mapping,
338 jmachado 505
                                        ActionForm form,
506
                                        HttpServletRequest request,
507
                                        HttpServletResponse response)
215 jmachado 508
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
509
    {
510
        try
511
        {
512
            ProfileForm profileForm = (ProfileForm) form;
513
            IServiceManager sm = ServiceManager.getInstance();
514
            1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
515
            5+0%2Fdocs%2Fapi+Object">Object[] args;
338 jmachado 516
            args = new 5+0%2Fdocs%2Fapi+Object">Object[]{profileForm.getRecordView().getId()};
215 jmachado 517
 
338 jmachado 518
            RecordView recordView = (RecordView) sm.execute(RequestUtils.getRequester(request, response), "LoadEditUserProfileRecord", args, names);
215 jmachado 519
            UserView uV = recordView.getOwnerUserView();
359 jmachado 520
//            addMessage(request, "profile.record.deleted.sucess");
215 jmachado 521
            profileForm.setUserView(uV);
522
            profileForm.setRecordView(recordView);
523
            return mapping.findForward("curriculum");
524
        }
338 jmachado 525
        catch (FilterChainFailedException e)
215 jmachado 526
        {
527
            return mapping.findForward("error401");
528
        }
529
        catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
530
        {
338 jmachado 531
            logger.error(e, e);
215 jmachado 532
            throw e;
533
        }
534
    }
535
 
1054 jmachado 536
    public ActionForward addRole(ActionMapping mapping,
537
                                 ActionForm form ,
538
                                 HttpServletRequest request,
539
                                 HttpServletResponse response)
540
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
541
    {
542
        ProfileForm profileForm = (ProfileForm) form;
543
        UserView uV = loadUser(profileForm.getUserView().getId(), request, response);
544
        profileForm.getUserView().setPasswordLocal(uV.isPasswordLocal());
545
        profileForm.setUserView(uV);
546
        UserSessionImpl userSession = (UserSessionImpl) UserSessionProxy.loadUserSession(request, response);
547
        return super.addRole(mapping,form,request,response);
548
    }
549
 
550
    public ActionForward removeRole(ActionMapping mapping,
551
                                 ActionForm form ,
552
                                 HttpServletRequest request,
553
                                 HttpServletResponse response)
554
            throws 1.5.0/docs/api/java/lang/Throwable.html">Throwable, ServletException
555
    {
556
        ProfileForm profileForm = (ProfileForm) form;
557
        UserView uV = loadUser(profileForm.getUserView().getId(), request, response);
558
        profileForm.setUserView(uV);
559
        profileForm.getUserView().setPasswordLocal(uV.isPasswordLocal());
560
        UserSessionImpl userSession = (UserSessionImpl) UserSessionProxy.loadUserSession(request, response);
561
        return super.removeRole(mapping,form,request,response);
562
    }
563
 
109 fvelez 564
}