1 | package com.medias.megapoli.struts.actions; |
---|
2 | |
---|
3 | import com.ether.user.UserRole; |
---|
4 | import com.medias.annuaire.Personne; |
---|
5 | import com.medias.megapoli.struts.forms.PrepareTreeForm; |
---|
6 | import com.medias.xml.hierarchie.Hierarchie; |
---|
7 | import org.apache.struts.action.Action; |
---|
8 | import org.apache.struts.action.ActionError; |
---|
9 | import org.apache.struts.action.ActionErrors; |
---|
10 | import org.apache.struts.action.ActionForm; |
---|
11 | import org.apache.struts.action.ActionForward; |
---|
12 | import org.apache.struts.action.ActionMapping; |
---|
13 | |
---|
14 | import javax.servlet.ServletException; |
---|
15 | import javax.servlet.http.HttpServletRequest; |
---|
16 | import javax.servlet.http.HttpServletResponse; |
---|
17 | |
---|
18 | |
---|
19 | /** |
---|
20 | * @author combaz |
---|
21 | * <p/> |
---|
22 | * Created on 24 févr. 2005 |
---|
23 | */ |
---|
24 | public class PrepareTreeAction |
---|
25 | extends Action |
---|
26 | { |
---|
27 | public ActionForward execute( ActionMapping mapping, |
---|
28 | ActionForm form, |
---|
29 | HttpServletRequest request, |
---|
30 | HttpServletResponse response ) |
---|
31 | throws ServletException |
---|
32 | { |
---|
33 | |
---|
34 | String target = "failure"; |
---|
35 | ActionErrors errors = new ActionErrors(); |
---|
36 | String path = (String) request.getSession().getServletContext().getAttribute( "DataDescPathName" ); |
---|
37 | Hierarchie arborescence; |
---|
38 | // Hierarchie tree = (Hierarchie)request.getSession ().getServletContext ().getAttribute ("APP_UPLOADTREE"); |
---|
39 | |
---|
40 | if( form != null ) |
---|
41 | { |
---|
42 | PrepareTreeForm pTreeForm = (PrepareTreeForm) form; |
---|
43 | try |
---|
44 | { |
---|
45 | // On charge la métadonnée... |
---|
46 | if( path != null ) |
---|
47 | { |
---|
48 | arborescence = new Hierarchie( path ); |
---|
49 | pTreeForm.setHierarchie( arborescence ); |
---|
50 | // On vérifie les droits de l'utilisateur sur la métadonnée |
---|
51 | Personne user = (Personne) request.getSession().getAttribute( "SES_USER" ); |
---|
52 | if( user == null ) |
---|
53 | { |
---|
54 | target = "login"; |
---|
55 | } |
---|
56 | else |
---|
57 | { |
---|
58 | String rights = "read"; |
---|
59 | if( ( user.getRoles().equals( UserRole.COORDINATOR.name() ) ) ) |
---|
60 | rights = "write"; |
---|
61 | request.getSession().setAttribute( "SES_RIGHTS", rights ); |
---|
62 | // tree.createTreeView (); |
---|
63 | target = "success"; |
---|
64 | } |
---|
65 | } |
---|
66 | else |
---|
67 | { |
---|
68 | throw new Exception( "Chemin vers le fichier de description de hierarchie xml introuvable" ); |
---|
69 | } |
---|
70 | } |
---|
71 | catch( Exception e ) |
---|
72 | { |
---|
73 | System.out.println( "exception_PrepareTreeAction" ); |
---|
74 | errors.add( ActionErrors.GLOBAL_MESSAGE, new ActionError( "errors.upload.prepareTree.failed" ) ); |
---|
75 | e.printStackTrace(); |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | if( !errors.isEmpty() ) |
---|
80 | { |
---|
81 | saveErrors( request, errors ); |
---|
82 | } |
---|
83 | |
---|
84 | return mapping.findForward( target ); |
---|
85 | } |
---|
86 | |
---|
87 | } |
---|