1 13 package org.ejbca.ui.web.admin.services; 14 15 16 17 import java.io.IOException ; 18 import java.io.Serializable ; 19 import java.util.ArrayList ; 20 import java.util.Collection ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import javax.faces.model.SelectItem; 25 26 import org.apache.log4j.Logger; 27 import org.ejbca.core.model.services.ServiceConfiguration; 28 import org.ejbca.ui.web.admin.configuration.EjbcaJSFHelper; 29 import org.ejbca.ui.web.admin.services.servicetypes.ActionType; 30 import org.ejbca.ui.web.admin.services.servicetypes.CustomActionType; 31 import org.ejbca.ui.web.admin.services.servicetypes.CustomIntervalType; 32 import org.ejbca.ui.web.admin.services.servicetypes.CustomWorkerType; 33 import org.ejbca.ui.web.admin.services.servicetypes.IntervalType; 34 import org.ejbca.ui.web.admin.services.servicetypes.ServiceType; 35 import org.ejbca.ui.web.admin.services.servicetypes.WorkerType; 36 37 45 public class ServiceConfigurationView implements Serializable { 46 private static final Logger log = Logger.getLogger(ServiceConfigurationView.class); 47 48 private WorkerType workerType; 49 private ActionType actionType; 50 private IntervalType intervalType; 51 52 private String selectedWorker; 53 private String selectedInterval; 54 private String selectedAction; 55 56 private ServiceTypeManager typeManager; 57 58 private boolean active = false; 59 private String description = ""; 60 61 private ServiceConfiguration serviceConfiguration; 62 63 public ServiceConfigurationView(ServiceConfiguration serviceConfiguration) throws IOException { 64 65 typeManager = new ServiceTypeManager(); 66 67 this.serviceConfiguration = serviceConfiguration; 68 WorkerType workerType = (WorkerType) typeManager.getServiceTypeByClassPath(serviceConfiguration.getWorkerClassPath()); 69 if(workerType == null){ 70 workerType = (WorkerType) typeManager.getServiceTypeByName(CustomWorkerType.NAME); 71 ((CustomWorkerType) workerType).setClassPath(serviceConfiguration.getWorkerClassPath()); 72 } 73 setWorkerType(workerType); 74 selectedWorker = workerType.getName(); 75 76 IntervalType intervalType = (IntervalType) typeManager.getServiceTypeByClassPath(serviceConfiguration.getIntervalClassPath()); 77 if(intervalType == null){ 78 intervalType = (IntervalType) typeManager.getServiceTypeByName(CustomIntervalType.NAME); 79 ((CustomIntervalType) intervalType).setClassPath(serviceConfiguration.getIntervalClassPath()); 80 } 81 setIntervalType(intervalType); 82 selectedInterval = intervalType.getName(); 83 84 ActionType actionType = (ActionType) typeManager.getServiceTypeByClassPath(serviceConfiguration.getActionClassPath()); 85 if(actionType == null){ 86 actionType = (ActionType) typeManager.getServiceTypeByName(CustomActionType.NAME); 87 ((CustomActionType) actionType).setClassPath(serviceConfiguration.getActionClassPath()); 88 } 89 setActionType(actionType); 90 selectedAction = actionType.getName(); 91 92 setDescription(serviceConfiguration.getDescription()); 93 setActive(serviceConfiguration.isActive()); 94 95 96 } 97 98 102 public ServiceConfiguration getServiceConfiguration(ArrayList errorMessages) throws IOException { 103 ServiceConfiguration retval = new ServiceConfiguration(); 104 retval.setActive(isActive()); 105 retval.setDescription(getDescription()); 106 retval.setActionClassPath(getActionType().getClassPath()); 107 retval.setActionProperties(getActionType().getProperties(errorMessages)); 108 retval.setIntervalClassPath(getIntervalType().getClassPath()); 109 retval.setIntervalProperties(getIntervalType().getProperties(errorMessages)); 110 retval.setWorkerClassPath(getWorkerType().getClassPath()); 111 retval.setWorkerProperties(getWorkerType().getProperties(errorMessages)); 112 return retval; 113 } 114 115 118 public ActionType getActionType() { 119 return actionType; 120 } 121 122 125 public void setActionType(ActionType actionType) { 126 try { 127 actionType.setProperties(serviceConfiguration.getActionProperties()); 128 } catch (IOException e) { 129 log.error(e); 130 } 131 this.actionType = actionType; 132 } 133 134 137 public boolean isActive() { 138 return active; 139 } 140 141 144 public void setActive(boolean active) { 145 this.active = active; 146 } 147 148 151 public String getDescription() { 152 return description; 153 } 154 155 158 public void setDescription(String description) { 159 this.description = description; 160 } 161 162 165 public IntervalType getIntervalType() { 166 return intervalType; 167 } 168 169 172 public void setIntervalType(IntervalType intervalType) { 173 try { 174 intervalType.setProperties(serviceConfiguration.getIntervalProperties()); 175 } catch (IOException e) { 176 log.error(e); 177 } 178 this.intervalType = intervalType; 179 } 180 181 184 public WorkerType getWorkerType() { 185 return workerType; 186 } 187 188 191 public void setWorkerType(WorkerType workerType) { 192 try{ 193 workerType.setProperties(serviceConfiguration.getWorkerProperties()); 194 this.workerType = workerType; 195 196 197 if(selectedInterval != null && !workerType.getCompatibleIntervalTypeNames().contains(selectedInterval)){ 198 setSelectedInterval((String ) workerType.getCompatibleIntervalTypeNames().iterator().next()); 199 setIntervalType((IntervalType) typeManager.getServiceTypeByName(getSelectedInterval())); 200 } 201 202 203 if(selectedAction != null && !workerType.getCompatibleActionTypeNames().contains(selectedAction)){ 204 setSelectedAction((String ) workerType.getCompatibleActionTypeNames().iterator().next()); 205 setActionType((ActionType) typeManager.getServiceTypeByName(getSelectedAction())); 206 } 207 208 }catch(IOException e){ 209 log.error(e); 210 } 211 } 212 213 214 215 218 public String getSelectedAction() { 219 return selectedAction; 220 } 221 222 225 public void setSelectedAction(String selectedAction) { 226 this.selectedAction = selectedAction; 227 } 228 229 232 public String getSelectedInterval() { 233 return selectedInterval; 234 } 235 236 239 public void setSelectedInterval(String selectedInterval) { 240 this.selectedInterval = selectedInterval; 241 } 242 243 246 public String getSelectedWorker() { 247 return selectedWorker; 248 } 249 250 253 public void setSelectedWorker(String selectedWorker) { 254 this.selectedWorker = selectedWorker; 255 } 256 257 public List getAvailableWorkers(){ 258 ArrayList retval = new ArrayList (); 259 Collection available = typeManager.getAvailableWorkerTypes(); 260 Iterator iter = available.iterator(); 261 while(iter.hasNext()){ 262 ServiceType next = (ServiceType) iter.next(); 263 String label = next.getName(); 264 if(next.isTranslatable()){ 265 label = (String ) EjbcaJSFHelper.getBean().getText().get(next.getName()); 266 } 267 retval.add(new SelectItem(next.getName(),label)); 268 } 269 270 return retval; 271 } 272 273 public List getAvailableIntervals(){ 274 ArrayList retval = new ArrayList (); 275 WorkerType currentWorkerType = (WorkerType) typeManager.getServiceTypeByName(selectedWorker); 276 Iterator iter = currentWorkerType.getCompatibleIntervalTypeNames().iterator(); 277 while(iter.hasNext()){ 278 String name = (String ) iter.next(); 279 ServiceType next = typeManager.getServiceTypeByName(name); 280 String label = name; 281 if(next.isTranslatable()){ 282 label = (String ) EjbcaJSFHelper.getBean().getText().get(name); 283 } 284 285 retval.add(new SelectItem(name,label)); 286 } 287 288 289 return retval; 290 } 291 292 public List getAvailableActions(){ 293 ArrayList retval = new ArrayList (); 294 WorkerType currentWorkerType = (WorkerType) typeManager.getServiceTypeByName(selectedWorker); 295 Iterator iter = currentWorkerType.getCompatibleActionTypeNames().iterator(); 296 while(iter.hasNext()){ 297 String name = (String ) iter.next(); 298 ServiceType next = typeManager.getServiceTypeByName(name); 299 String label = name; 300 if(next.isTranslatable()){ 301 label = (String ) EjbcaJSFHelper.getBean().getText().get(name); 302 } 303 retval.add(new SelectItem(name,label)); 304 } 305 return retval; 306 } 307 308 309 public ServiceTypeManager getServiceTypeManager(){ 310 return typeManager; 311 } 312 313 314 315 316 317 } 318 | Popular Tags |