View Javadoc

1   /*Copyright (C) 2004-... Stephane Gauchet for Hyphonem
2   
3    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
4   
5    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6   
7    You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8    
9    Written by Stephane Gauchet
10   mail me at : sgauchet@free.fr
11   */
12  package fr.hyphonem.conges.actions;
13  
14  import java.io.IOException;
15  import java.util.Vector;
16  
17  import javax.servlet.http.HttpServletRequest;
18  import javax.servlet.http.HttpServletResponse;
19  import javax.servlet.http.HttpSession;
20  
21  import org.apache.struts.action.Action;
22  import org.apache.struts.action.ActionError;
23  import org.apache.struts.action.ActionErrors;
24  import org.apache.struts.action.ActionForm;
25  import org.apache.struts.action.ActionForward;
26  import org.apache.struts.action.ActionMapping;
27  
28  import fr.hyphonem.conges.AccessData;
29  import fr.hyphonem.conges.AccessDataMng;
30  import fr.hyphonem.conges.data.ParamsData;
31  import fr.hyphonem.conges.data.UserData;
32  import fr.hyphonem.conges.forms.ValidParamForm;
33  
34  /**
35   * @author Stephane Gauchet pour Hyphonem
36   */
37  public class ValidParamsAction extends Action {
38  	public ActionForward execute(ActionMapping mapping, ActionForm form,
39  			HttpServletRequest request, HttpServletResponse response)
40  			throws Exception {
41  		HttpSession session = request.getSession();
42  		if (session.getAttribute("user") == null) {
43  			return mapping.findForward("invalidsession");
44  		}
45  
46  		UserData userd = (UserData) session.getAttribute("user");
47  		// admin only
48  		if (userd.isModif() || userd.isEmployee()) {
49  			return mapping.findForward("invalidaction");
50  		}
51  		ActionErrors errors = new ActionErrors();
52  		ValidParamForm vpd = (ValidParamForm) form;
53  		String server = vpd.getMailserver();
54  		String pays = vpd.getPays();
55  		session.getServletContext().setAttribute("server", server);
56  		session.getServletContext().setAttribute("country", pays);
57  
58  		ParamsData pd0 = new ParamsData();
59  		pd0.setDateDebut(vpd.getDatedeb0());
60  		pd0.setDateFin(vpd.getDatefin0());
61  		pd0.setNbJours(vpd.getNbjours0());
62  		pd0.setReason(vpd.getRaison0());
63  		pd0.setType(vpd.getType0());
64  
65  		ParamsData pd1 = new ParamsData();
66  		pd1.setDateDebut(vpd.getDatedeb1());
67  		pd1.setDateFin(vpd.getDatefin1());
68  		pd1.setNbJours(vpd.getNbjours1());
69  		pd1.setReason(vpd.getRaison1());
70  		pd1.setType(vpd.getType1());
71  
72  		ParamsData pd2 = new ParamsData();
73  		pd2.setDateDebut(vpd.getDatedeb2());
74  		pd2.setDateFin(vpd.getDatefin2());
75  		pd2.setNbJours(vpd.getNbjours2());
76  		pd2.setReason(vpd.getRaison2());
77  		pd2.setType(vpd.getType2());
78  
79  		ParamsData pd3 = new ParamsData();
80  		pd3.setDateDebut(vpd.getDatedeb3());
81  		pd3.setDateFin(vpd.getDatefin3());
82  		pd3.setNbJours(vpd.getNbjours3());
83  		pd3.setReason(vpd.getRaison3());
84  		pd3.setType(vpd.getType3());
85  
86  		ParamsData pd4 = new ParamsData();
87  		pd4.setDateDebut(vpd.getDatedeb4());
88  		pd4.setDateFin(vpd.getDatefin4());
89  		pd4.setNbJours(vpd.getNbjours4());
90  		pd4.setReason(vpd.getRaison4());
91  		pd4.setType(vpd.getType4());
92  
93  		ParamsData pd5 = new ParamsData();
94  		pd5.setDateDebut(vpd.getDatedeb5());
95  		pd5.setDateFin(vpd.getDatefin5());
96  		pd5.setNbJours(vpd.getNbjours5());
97  		pd5.setReason(vpd.getRaison5());
98  		pd5.setType(vpd.getType5());
99  
100 		ParamsData pd6 = new ParamsData();
101 		pd6.setDateDebut(vpd.getDatedeb6());
102 		pd6.setDateFin(vpd.getDatefin6());
103 		pd6.setNbJours(vpd.getNbjours6());
104 		pd6.setReason(vpd.getRaison6());
105 		pd6.setType(vpd.getType6());
106 
107 		ParamsData pd7 = new ParamsData();
108 		pd7.setDateDebut(vpd.getDatedeb7());
109 		pd7.setDateFin(vpd.getDatefin7());
110 		pd7.setNbJours(vpd.getNbjours7());
111 		pd7.setReason(vpd.getRaison7());
112 		pd7.setType(vpd.getType7());
113 
114 		Vector params = new Vector();
115 		params.add(pd0);
116 		params.add(pd1);
117 		params.add(pd2);
118 		params.add(pd3);
119 		params.add(pd4);
120 		params.add(pd5);
121 		params.add(pd6);
122 		params.add(pd7);
123 		session.getServletContext().setAttribute("params", params);
124 
125 		String dataDirPath = (String) session.getAttribute("dataDirPath");
126 		AccessData ad = new AccessDataMng().getInstance(dataDirPath);
127 		try {
128 			ad.writeParamPays(pays);
129 			ad.writeParamMail(server);
130 			ad.writeParams(params);
131 		} catch (IOException e) {
132 			errors.add("error.concurrent.access", new ActionError(
133 					"error.concurrent.access"));
134 		}
135 
136 		if (!errors.isEmpty()) {
137 			saveErrors(request, errors);
138 			return mapping.getInputForward();
139 		}
140 		return mapping.findForward("success");
141 	}
142 
143 }