Changeset 3720
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/plugins/core/net/sf/basedb/plugins/PluginConfigurationImporter.java
r3679 r3720 69 69 import java.util.Arrays; 70 70 import java.util.Date; 71 import java.util.HashMap; 71 72 import java.util.HashSet; 72 73 import java.util.List; 74 import java.util.Map; 73 75 import java.util.Set; 74 76 … … 90 92 implements InteractivePlugin, AutoDetectingImporter 91 93 { 94 private static final String COMMAND_SELECT_CONFIGURATIONS = "select_configurations"; 95 92 96 private static final About about = new AboutImpl 93 97 ( … … 123 127 ); 124 128 129 private static final PluginParameter<Boolean> importAllParameter = 130 new PluginParameter<Boolean>( 131 "importAll", 132 "Import all configurations", 133 "Select if all or only a selection of the configurations in the XML-file should be " + 134 "imported. If FALSE, the configurations " + 135 "is selected in the next window.", 136 new BooleanParameterType(true, true)); 137 125 138 private RequestInformation configureJob; 139 private RequestInformation configureSelection; 126 140 127 141 // Variables to store the job parameters in. 128 142 private File xmlFile; 129 143 private boolean setPermissions; 144 private boolean importAll; 130 145 131 146 /* … … 157 172 Integer.toString(Location.PRIMARY.getValue()), Type.INT) 158 173 ); 159 } 174 } 175 else if (command.equals(COMMAND_SELECT_CONFIGURATIONS)) 176 { 177 requestinformation = getConfiguredSelectionParameters(); 178 } 160 179 return requestinformation; 161 180 } 162 181 182 @SuppressWarnings("unchecked") 163 183 public void configure(GuiContext context, Request request, Response response) 164 184 { … … 178 198 storeValue(job, request, xmlFileParameter); 179 199 storeValue(job, request, setPermissionsParameter); 180 response.setDone("The job configuration is complete"); 181 } 200 storeValue(job, request, importAllParameter); 201 if (!(Boolean)request.getParameterValue("importAll")) 202 { 203 response.setContinue(COMMAND_SELECT_CONFIGURATIONS); 204 } 205 else 206 { 207 response.setDone("The job configuration is complete"); 208 } 209 } 210 else if (command.equals(COMMAND_SELECT_CONFIGURATIONS)) 211 { 212 List<PluginParameter<?>> selectionParameters = getConfiguredSelectionParameters().getParameters(); 213 List<Throwable> errors = validateRequestParameters ( 214 selectionParameters, 215 request 216 ); 217 218 if (errors != null) 219 { 220 response.setError(errors.size() + "invalid parameters were found in the request", errors); 221 } 222 for (PluginParameter p : selectionParameters) 223 { 224 if (request.getParameterValue(p.getName()) != null) 225 { 226 storeValue(job, request, (PluginParameter<Boolean>)p); 227 } 228 } 229 230 response.setDone("The job configuration is complete"); 231 } 182 232 } 183 233 … … 216 266 xmlFile = (File)job.getValue("xmlfile"); 217 267 setPermissions = Boolean.TRUE.equals(job.getValue("setPermissions")); 268 importAll = job.getValue("importAll") == null ? true : Boolean.TRUE.equals(job.getValue("importAll")); 269 218 270 is = xmlFile.getDownloadStream(0); 219 271 boolean importable = isImportable(is); … … 312 364 Element rootElement = doc.getRootElement(); 313 365 366 int parameternumber = 0; 314 367 List configurations = rootElement.getChildren(); 315 368 for (Object obj : configurations) … … 320 373 String pluginClassName = configuration.getAttributeValue("pluginClassName"); 321 374 322 PluginDefinition pluginDefinition = PluginDefinition.getByClassName(dc, pluginClassName); 323 PluginConfiguration pluginConfig = PluginConfiguration.getNew(dc, pluginDefinition); 324 if (setPermissions) 325 { 326 pluginConfig.setItemKey(pluginDefinition.getItemKey()); 327 pluginConfig.setProjectKey(pluginDefinition.getProjectKey()); 328 } 329 pluginConfig.setName(name); 330 pluginConfig.setDescription(description); 331 dc.saveItem(pluginConfig); 332 333 List parameters = configuration.getChildren("parameter"); 334 setPluginConf(parameters, pluginConfig); 375 boolean importConfiguration = !importAll && 376 job.getValue("configuration"+parameternumber) != null ? Boolean.TRUE.equals(job.getValue("configuration"+parameternumber)) : false; 377 if (importConfiguration || importAll) 378 { 379 PluginDefinition pluginDefinition = PluginDefinition.getByClassName(dc, pluginClassName); 380 PluginConfiguration pluginConfig = PluginConfiguration.getNew(dc, pluginDefinition); 381 if (setPermissions) 382 { 383 pluginConfig.setItemKey(pluginDefinition.getItemKey()); 384 pluginConfig.setProjectKey(pluginDefinition.getProjectKey()); 385 } 386 pluginConfig.setName(name); 387 pluginConfig.setDescription(description); 388 dc.saveItem(pluginConfig); 389 390 List parameters = configuration.getChildren("parameter"); 391 setPluginConf(parameters, pluginConfig); 392 } 393 parameternumber++; 335 394 } 336 395 dc.commit(); … … 361 420 parameters.add(xmlFileParameter); 362 421 parameters.add(setPermissionsParameter); 422 parameters.add(importAllParameter); 363 423 364 424 configureJob = new RequestInformation … … 371 431 } 372 432 return configureJob; 433 } 434 435 private RequestInformation getConfiguredSelectionParameters() 436 { 437 if (configureSelection == null) 438 { 439 Map<String, List<PluginParameter<?>>> configLists = new HashMap<String, List<PluginParameter<?>>>(); 440 441 DbControl dc = null; 442 443 try 444 { 445 dc = sc.newDbControl(); 446 //Get the root element of the XML file 447 String filePath = null; 448 File file = (File)job.getValue("xmlfile"); 449 { 450 file = File.getById(dc, file.getId()); 451 filePath = file.getPath().toString(); 452 } 453 URL dtdURL = PluginConfigurationImporter.class.getResource("/net/sf/basedb/core/dtd/"+dtdFileName); 454 InputStream is = file.getDownloadStream(0); 455 Document doc = XMLUtil.getValidatedXML(is, dtdURL, filePath); 456 is.close(); 457 Element rootElement = doc.getRootElement(); 458 459 List<PluginParameter<?>> typeList = null; 460 List configurations = rootElement.getChildren(); 461 int parameternumber = 0; 462 for (Object obj : configurations) 463 { 464 Element configElement = (Element)obj; 465 String configName = configElement.getChildText("configname"); 466 String description = configElement.getChildText("description"); 467 String pluginName = configElement.getAttributeValue("pluginClassName"); 468 469 if (configLists.get(pluginName) == null) 470 { 471 typeList = new ArrayList<PluginParameter<?>>(); 472 typeList.add(new PluginParameter<Boolean> 473 ( 474 pluginName, 475 pluginName.substring(pluginName.lastIndexOf('.') + 1), 476 "Configurations for plugin: " +pluginName, 477 null 478 )); 479 } 480 else 481 { 482 typeList = configLists.get(pluginName); 483 } 484 485 PluginParameter<Boolean> configurationParameter = 486 new PluginParameter<Boolean>( 487 "configuration"+parameternumber, 488 configName, 489 "Select if configuration should be imported or not. " + 490 "TRUE will include this configuration in the import.\n\n" + description, 491 new BooleanParameterType(null, false) 492 ); 493 typeList.add(configurationParameter); 494 configLists.put(pluginName, typeList); 495 parameternumber++; 496 } 497 List<PluginParameter<?>>parameters = new ArrayList<PluginParameter<?>>(); 498 for (List<PluginParameter<?>> list : configLists.values()) 499 { 500 parameters.addAll(list); 501 } 502 configureSelection = new RequestInformation 503 ( 504 COMMAND_SELECT_CONFIGURATIONS, 505 "Select configurations", 506 "Select which plugin-configurations to import", 507 parameters 508 ); 509 } 510 catch (Throwable ex) 511 { 512 throw new BaseException(ex); 513 } 514 finally 515 { 516 if (dc != null) 517 { 518 dc.close(); 519 } 520 } 521 522 } 523 return configureSelection; 373 524 } 374 525
Note: See TracChangeset
for help on using the changeset viewer.