KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > services > EditServiceManagedBean


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13 package org.ejbca.ui.web.admin.services;
14
15 import java.io.IOException JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.Collection JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20
21 import javax.faces.application.Application;
22 import javax.faces.context.FacesContext;
23 import javax.faces.el.ValueBinding;
24 import javax.faces.event.ValueChangeEvent;
25 import javax.faces.model.SelectItem;
26
27 import org.apache.log4j.Logger;
28 import org.ejbca.core.model.services.ServiceConfiguration;
29 import org.ejbca.ui.web.admin.BaseManagedBean;
30 import org.ejbca.ui.web.admin.configuration.EjbcaJSFHelper;
31 import org.ejbca.ui.web.admin.services.servicetypes.ActionType;
32 import org.ejbca.ui.web.admin.services.servicetypes.CertificateExpirationNotifierWorkerType;
33 import org.ejbca.ui.web.admin.services.servicetypes.CustomActionType;
34 import org.ejbca.ui.web.admin.services.servicetypes.CustomIntervalType;
35 import org.ejbca.ui.web.admin.services.servicetypes.CustomWorkerType;
36 import org.ejbca.ui.web.admin.services.servicetypes.IntervalType;
37 import org.ejbca.ui.web.admin.services.servicetypes.MailActionType;
38 import org.ejbca.ui.web.admin.services.servicetypes.PeriodicalIntervalType;
39 import org.ejbca.ui.web.admin.services.servicetypes.WorkerType;
40
41 /**
42  * Class used to manage the GUI editing of a Service Configuration
43  *
44  * @author Philip Vendil 2006 sep 30
45  *
46  * @version $Id: EditServiceManagedBean.java,v 1.4.2.1 2007/03/12 09:57:51 anatom Exp $
47  */

48 public class EditServiceManagedBean extends BaseManagedBean {
49     private static final Logger log = Logger.getLogger(EditServiceManagedBean.class);
50     
51     private ServiceConfigurationView serviceConfigurationView;
52     
53     private String JavaDoc serviceName = "";
54     
55
56     
57     public EditServiceManagedBean(){
58         try {
59             setServiceConfiguration(new ServiceConfiguration());
60         } catch (IOException JavaDoc e) {
61             log.error(e);
62         }
63     }
64     
65     public static EditServiceManagedBean getBean(){
66         FacesContext context = FacesContext.getCurrentInstance();
67         Application app = context.getApplication();
68         ValueBinding binding = app.createValueBinding("#{editService}");
69         Object JavaDoc value = binding.getValue(context);
70         return (EditServiceManagedBean) value;
71     }
72     
73     /**
74      * @return the serviceName
75      */

76     public String JavaDoc getServiceName() {
77         return serviceName;
78     }
79
80     /**
81      * @param serviceName the serviceName to set
82      */

83     public void setServiceName(String JavaDoc serviceName) {
84         this.serviceName = serviceName;
85     }
86
87     /**
88      * @return the serviceConfigurationView
89      */

90     public ServiceConfigurationView getServiceConfigurationView() {
91         return serviceConfigurationView;
92     }
93     
94     public void setServiceConfiguration(ServiceConfiguration serviceConfiguration) throws IOException JavaDoc{
95         this.serviceConfigurationView = new ServiceConfigurationView(serviceConfiguration);
96         
97     }
98
99     public String JavaDoc save(){
100         String JavaDoc retval = "listservices";
101         ArrayList JavaDoc errorMessages = new ArrayList JavaDoc();
102         try {
103             serviceConfigurationView.getServiceConfiguration(errorMessages);
104             if(errorMessages.size() == 0){
105               EjbcaJSFHelper.getBean().getServiceSession().changeService(getAdmin(), serviceName, serviceConfigurationView.getServiceConfiguration(errorMessages));
106               EjbcaJSFHelper.getBean().getServiceSession().activateServiceTimer(getAdmin(), serviceName);
107             }else{
108                 Iterator JavaDoc iter = errorMessages.iterator();
109                 while(iter.hasNext()){
110                     addErrorMessage((String JavaDoc) iter.next());
111                 }
112                 
113                 retval = null;
114             }
115         } catch (IOException JavaDoc e) {
116             addErrorMessage((String JavaDoc) EjbcaJSFHelper.getBean().getText().get("ERROREDITINGSERVICE") + " " + e.getMessage());
117         }
118         
119         return retval;
120     }
121     
122     public String JavaDoc cancel(){
123         return "listservices";
124     }
125     
126     public String JavaDoc update(){
127         return "editservice";
128     }
129     
130     
131     /**
132      * Help method used to edit data in the custom worker type.
133      */

134     public CustomWorkerType getCustomWorkerType(){
135         return (CustomWorkerType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(CustomWorkerType.NAME);
136     }
137     
138     /**
139      * Help method used to edit data in the custom action type.
140      */

141     public CustomActionType getCustomActionType(){
142         return (CustomActionType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(CustomActionType.NAME);
143     }
144     
145     /**
146      * Help method used to edit data in the custom interval type.
147      */

148     public CustomIntervalType getCustomIntervalType(){
149         return (CustomIntervalType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(CustomIntervalType.NAME);
150     }
151     
152     /**
153      * Help method used to edit data in the mail action type.
154      */

155     public MailActionType getMailActionType(){
156         return (MailActionType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(MailActionType.NAME);
157     }
158     
159     /**
160      * Help method used to edit data in the certificate expriation worker type.
161      */

162     public CertificateExpirationNotifierWorkerType getCertificateExpriationType(){
163         return (CertificateExpirationNotifierWorkerType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(CertificateExpirationNotifierWorkerType.NAME);
164     }
165     
166     /**
167      * Help method used to edit data in the custom interval type.
168      */

169     public PeriodicalIntervalType getPeriodicalIntervalType(){
170         return (PeriodicalIntervalType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(PeriodicalIntervalType.NAME);
171     }
172
173     public void changeWorker(ValueChangeEvent e){
174         
175         String JavaDoc newName = (String JavaDoc) e.getNewValue();
176         WorkerType newWorkerType = (WorkerType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(newName);
177         serviceConfigurationView.setWorkerType(newWorkerType);
178         serviceConfigurationView.setSelectedWorker(newName);
179         
180         
181     }
182     
183     public void changeInterval(ValueChangeEvent e){
184         String JavaDoc newName = (String JavaDoc) e.getNewValue();
185         
186         WorkerType workerType = (WorkerType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(serviceConfigurationView.getSelectedWorker());
187         if(workerType.getCompatibleIntervalTypeNames().contains(newName)){
188             IntervalType newIntervalType = (IntervalType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(newName);
189             serviceConfigurationView.setIntervalType(newIntervalType);
190             serviceConfigurationView.setSelectedInterval(newName);
191         }
192     }
193     
194     public void changeAction(ValueChangeEvent e){
195         
196         String JavaDoc newName = (String JavaDoc) e.getNewValue();
197         
198         WorkerType workerType = (WorkerType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(serviceConfigurationView.getSelectedWorker());
199         if(workerType.getCompatibleActionTypeNames().contains(newName)){
200           ActionType newActionType = (ActionType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(newName);
201           serviceConfigurationView.setActionType(newActionType);
202           serviceConfigurationView.setSelectedAction(newName);
203         }
204     }
205     
206     public List JavaDoc getAvailableCAs(){
207         List JavaDoc availableCANames = new ArrayList JavaDoc();
208         Collection JavaDoc cAIds = EjbcaJSFHelper.getBean().getCAAdminSession().getAvailableCAs(getAdmin());
209         Iterator JavaDoc iter = cAIds.iterator();
210         while(iter.hasNext()){
211             int next = ((Integer JavaDoc) iter.next()).intValue();
212             availableCANames.add(new SelectItem(new Integer JavaDoc(EjbcaJSFHelper.getBean().getCAAdminSession().getCAInfo(getAdmin(), next).getCAId()).toString(),EjbcaJSFHelper.getBean().getCAAdminSession().getCAInfo(getAdmin(), next).getName()));
213         }
214         
215         return availableCANames;
216         
217     }
218
219 }
220
221
Popular Tags