KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > webui > actions > config > EditApplicationAction


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.jmanage.webui.actions.config;
17
18 import org.jmanage.webui.actions.BaseAction;
19 import org.jmanage.webui.util.WebContext;
20 import org.jmanage.webui.util.Forwards;
21 import org.jmanage.webui.forms.ApplicationForm;
22 import org.jmanage.core.config.ApplicationConfig;
23 import org.jmanage.core.config.ApplicationConfigManager;
24 import org.jmanage.core.util.UserActivityLogger;
25 import org.jmanage.core.services.AccessController;
26 import org.jmanage.core.alert.AlertEngine;
27 import org.apache.struts.action.ActionForward;
28 import org.apache.struts.action.ActionMapping;
29 import org.apache.struts.action.ActionForm;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.HashMap JavaDoc;
35
36 /**
37  *
38  * date: Jun 25, 2004
39  * @author Rakesh Kalra, Shashank Bellary
40  */

41 public class EditApplicationAction extends BaseAction {
42
43     public ActionForward execute(WebContext context,
44                                  ActionMapping mapping,
45                                  ActionForm actionForm,
46                                  HttpServletRequest JavaDoc request,
47                                  HttpServletResponse JavaDoc response)
48             throws Exception JavaDoc {
49
50         AccessController.checkAccess(context.getServiceContext(),
51                 ACL_EDIT_APPLICATIONS);
52         ApplicationForm appForm = (ApplicationForm)actionForm;
53         ApplicationConfig config =
54                 ApplicationConfigManager.getApplicationConfig(
55                         appForm.getApplicationId());
56         assert config != null;
57
58         config.setName(appForm.getName());
59         config.setHost(appForm.getHost());
60         if(appForm.getPort() != null)
61             config.setPort(new Integer JavaDoc(appForm.getPort()));
62             config.setURL(appForm.getURL());
63             config.setUsername(appForm.getUsername());
64
65         final String JavaDoc password = appForm.getPassword();
66         if(!ApplicationForm.FORM_PASSWORD.equals(password)){
67             config.setPassword(password);
68         }
69
70         Map JavaDoc paramValues = config.getParamValues();
71         if(appForm.getJndiFactory() != null){
72             paramValues.put(ApplicationConfig.JNDI_FACTORY, appForm.getJndiFactory());
73         }else{
74             paramValues.remove(ApplicationConfig.JNDI_FACTORY);
75         }
76
77         if(appForm.getJndiURL() != null){
78             paramValues.put(ApplicationConfig.JNDI_URL, appForm.getJndiURL());
79         }else{
80             paramValues.remove(ApplicationConfig.JNDI_URL);
81         }
82
83         ApplicationConfigManager.updateApplication(config);
84
85         /* update the AlertEngine */
86         AlertEngine.getInstance().updateApplication(config);
87
88         UserActivityLogger.getInstance().logActivity(
89                 context.getUser().getUsername(),
90                 "Updated application "+"\""+config.getName()+"\"");
91         return mapping.findForward(Forwards.SUCCESS);
92     }
93 }
94
Popular Tags