1 13 package org.ejbca.ui.web.admin.services; 14 15 import java.io.IOException ; 16 import java.util.ArrayList ; 17 import java.util.Collection ; 18 import java.util.Iterator ; 19 import java.util.List ; 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 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 serviceName = ""; 54 55 56 57 public EditServiceManagedBean(){ 58 try { 59 setServiceConfiguration(new ServiceConfiguration()); 60 } catch (IOException 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 value = binding.getValue(context); 70 return (EditServiceManagedBean) value; 71 } 72 73 76 public String getServiceName() { 77 return serviceName; 78 } 79 80 83 public void setServiceName(String serviceName) { 84 this.serviceName = serviceName; 85 } 86 87 90 public ServiceConfigurationView getServiceConfigurationView() { 91 return serviceConfigurationView; 92 } 93 94 public void setServiceConfiguration(ServiceConfiguration serviceConfiguration) throws IOException { 95 this.serviceConfigurationView = new ServiceConfigurationView(serviceConfiguration); 96 97 } 98 99 public String save(){ 100 String retval = "listservices"; 101 ArrayList errorMessages = new ArrayList (); 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 iter = errorMessages.iterator(); 109 while(iter.hasNext()){ 110 addErrorMessage((String ) iter.next()); 111 } 112 113 retval = null; 114 } 115 } catch (IOException e) { 116 addErrorMessage((String ) EjbcaJSFHelper.getBean().getText().get("ERROREDITINGSERVICE") + " " + e.getMessage()); 117 } 118 119 return retval; 120 } 121 122 public String cancel(){ 123 return "listservices"; 124 } 125 126 public String update(){ 127 return "editservice"; 128 } 129 130 131 134 public CustomWorkerType getCustomWorkerType(){ 135 return (CustomWorkerType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(CustomWorkerType.NAME); 136 } 137 138 141 public CustomActionType getCustomActionType(){ 142 return (CustomActionType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(CustomActionType.NAME); 143 } 144 145 148 public CustomIntervalType getCustomIntervalType(){ 149 return (CustomIntervalType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(CustomIntervalType.NAME); 150 } 151 152 155 public MailActionType getMailActionType(){ 156 return (MailActionType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(MailActionType.NAME); 157 } 158 159 162 public CertificateExpirationNotifierWorkerType getCertificateExpriationType(){ 163 return (CertificateExpirationNotifierWorkerType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(CertificateExpirationNotifierWorkerType.NAME); 164 } 165 166 169 public PeriodicalIntervalType getPeriodicalIntervalType(){ 170 return (PeriodicalIntervalType) serviceConfigurationView.getServiceTypeManager().getServiceTypeByName(PeriodicalIntervalType.NAME); 171 } 172 173 public void changeWorker(ValueChangeEvent e){ 174 175 String newName = (String ) 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 newName = (String ) 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 newName = (String ) 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 getAvailableCAs(){ 207 List availableCANames = new ArrayList (); 208 Collection cAIds = EjbcaJSFHelper.getBean().getCAAdminSession().getAvailableCAs(getAdmin()); 209 Iterator iter = cAIds.iterator(); 210 while(iter.hasNext()){ 211 int next = ((Integer ) iter.next()).intValue(); 212 availableCANames.add(new SelectItem(new Integer (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 |