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.MetadataForm; |
---|
6 | import com.medias.xml.metadata.Metadata; |
---|
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 | * @author combaz |
---|
20 | * Created on 15 févr. 2005 |
---|
21 | */ |
---|
22 | public class LoadMetadataAction |
---|
23 | extends Action |
---|
24 | { |
---|
25 | public ActionForward execute( ActionMapping mapping, ActionForm form, |
---|
26 | HttpServletRequest request, |
---|
27 | HttpServletResponse response ) |
---|
28 | throws ServletException |
---|
29 | { |
---|
30 | String target = "failure"; |
---|
31 | String path = request.getParameter( "metadataUri" ); |
---|
32 | ActionErrors errors = new ActionErrors(); |
---|
33 | |
---|
34 | if( form != null ) |
---|
35 | { |
---|
36 | MetadataForm mform = (MetadataForm) form; |
---|
37 | if( ( path != null ) && ( path.length() != 0 ) ) |
---|
38 | { |
---|
39 | try |
---|
40 | { |
---|
41 | // On charge la métadonnée... |
---|
42 | Metadata meta = new Metadata( path ); |
---|
43 | mform.setMetadata( meta ); |
---|
44 | |
---|
45 | // On vérifie les droits de l'utilisateur sur la métadonnée |
---|
46 | Personne user = (Personne) request.getSession().getAttribute( "SES_USER" ); |
---|
47 | String rights = "read"; |
---|
48 | if( ( user.getRoles().equals( UserRole.COORDINATOR.name() ) ) || ( user.hasSet( meta.getPres().getNom() ) ) ) |
---|
49 | rights = "write"; |
---|
50 | request.getSession().setAttribute( "SES_RIGHTS", rights ); |
---|
51 | |
---|
52 | target = "success"; |
---|
53 | } |
---|
54 | catch( Exception e ) |
---|
55 | { |
---|
56 | System.out.println( "exception_LoadMetadataAction" ); |
---|
57 | errors.add( ActionErrors.GLOBAL_MESSAGE, new ActionError( "errors.upload.metadata.notfound" ) ); |
---|
58 | |
---|
59 | e.printStackTrace(); |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | if( !errors.isEmpty() ) |
---|
65 | { |
---|
66 | saveErrors( request, errors ); |
---|
67 | } |
---|
68 | |
---|
69 | return mapping.findForward( target ); |
---|
70 | } |
---|
71 | } |
---|