Changeset 5241
- Timestamp:
- Feb 10, 2010, 3:25:56 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/src/docbook/appendix/incompatible.xml
r5204 r5241 64 64 </para> 65 65 66 <bridgehead> 67 ReporterFlatFileImporter store file parser settings as job parameters 68 </bridgehead> 69 <para> 70 This change was introduced since it should be possible to run the plug-in 71 without a configuration. Existing code that uses this plug-in outside the 72 web client, may fail due to not setting required parameter values as job 73 parameters. 74 </para> 66 75 </sect1> 67 76 -
trunk/src/core/net/sf/basedb/core/plugin/AbstractPlugin.java
r4889 r5241 319 319 320 320 /** 321 Get the value for a job or configuration parameter. This method first 322 checks the job parameters. If there is no value it will check the 323 configuration parameters. 324 @param name The name of the parameter 325 @return The parameter value, or null 326 @since 2.15 327 */ 328 protected Object getJobOrConfigurationValue(String name) 329 { 330 Object value = null; 331 if (job != null) value = job.getValue(name); 332 if (value == null && configuration != null) value = configuration.getValue(name); 333 return value; 334 } 335 336 /** 337 Clone a plug-in parameter and set the default value to the value that is 338 already stored in the job or configuration parameters. 339 @param pp The parameter to clone 340 @return The cloned parameter 341 @since 2.15 342 */ 343 @SuppressWarnings("unchecked") 344 protected <T> PluginParameter<T> cloneParameterWithDefaultValue(PluginParameter<T> pp) 345 { 346 T defaultValue = (T)getJobOrConfigurationValue(pp.getName()); 347 PluginParameter<T> clone = new PluginParameter<T>( 348 pp.getName(), 349 pp.getLabel(), 350 pp.getDescription(), 351 defaultValue, 352 pp.getParameterType()); 353 return clone; 354 } 355 356 /** 321 357 Check if the current thread has been interrupted and throw 322 358 a SignalException if it has. Subclasses that use the {@link ThreadSignalHandler} … … 434 470 logger.flush(); 435 471 } 472 473 436 474 } -
trunk/src/plugins/core/net/sf/basedb/plugins/AbstractFlatFileImporter.java
r5218 r5241 962 962 Create and initialise a flat file parser by setting all regular expressions 963 963 and other options. This implementation gets all parameters from the 964 {@link # configuration} settings. If a subclass doesn't store the parameters965 there it must override this method and initialise the parser. Note that964 {@link #job} or {@link #configuration} settings. If a subclass doesn't store the 965 parameters there it must override this method and initialise the parser. Note that 966 966 this method is called once for each file returned by the 967 967 {@link #getFileIterator()} and that a new parser is needed for each file. … … 973 973 { 974 974 FlatFileParser ffp = new FlatFileParser(); 975 if (configuration != null) 976 { 977 ffp.setSectionRegexp(getPattern(sectionRegexpParameter.getName())); 978 ffp.setHeaderRegexp(getPattern(headerRegexpParameter.getName())); 979 ffp.setDataHeaderRegexp(getPattern(dataHeaderRegexpParameter.getName())); 980 ffp.setDataSplitterRegexp(getPattern(dataSplitterRegexpParameter.getName())); 981 Boolean trimQuotes = (Boolean)configuration.getValue(trimQuotesParameter.getName()); 982 if (trimQuotes != null) ffp.setTrimQuotes(trimQuotes); 983 ffp.setIgnoreRegexp(getPattern(ignoreRegexpParameter.getName())); 984 ffp.setDataFooterRegexp(getPattern(dataFooterRegexpParameter.getName())); 985 ffp.setMinDataColumns(IntegerUtil.getInt((Integer)configuration.getValue(minDataColumnsParameter.getName()))); 986 ffp.setMaxDataColumns(IntegerUtil.getInt((Integer)configuration.getValue(maxDataColumnsParameter.getName()))); 987 } 975 976 ffp.setSectionRegexp(getPattern(sectionRegexpParameter.getName())); 977 ffp.setHeaderRegexp(getPattern(headerRegexpParameter.getName())); 978 ffp.setDataHeaderRegexp(getPattern(dataHeaderRegexpParameter.getName())); 979 ffp.setDataSplitterRegexp(getPattern(dataSplitterRegexpParameter.getName())); 980 Boolean trimQuotes = (Boolean)getJobOrConfigurationValue(trimQuotesParameter.getName()); 981 if (trimQuotes != null) ffp.setTrimQuotes(trimQuotes); 982 ffp.setIgnoreRegexp(getPattern(ignoreRegexpParameter.getName())); 983 ffp.setDataFooterRegexp(getPattern(dataFooterRegexpParameter.getName())); 984 ffp.setMinDataColumns(IntegerUtil.getInt((Integer)getJobOrConfigurationValue(minDataColumnsParameter.getName()))); 985 ffp.setMaxDataColumns(IntegerUtil.getInt((Integer)getJobOrConfigurationValue(maxDataColumnsParameter.getName()))); 988 986 return ffp; 989 987 } … … 1006 1004 protected String getCharset() 1007 1005 { 1008 String charset = null; 1009 if (job != null) 1010 { 1011 charset = (String)job.getValue(Parameters.CHARSET_PARAMETER); 1012 } 1013 if (charset == null && configuration != null) 1014 { 1015 charset = (String)configuration.getValue(Parameters.CHARSET_PARAMETER); 1016 } 1006 String charset = (String)getJobOrConfigurationValue(Parameters.CHARSET_PARAMETER); 1017 1007 if (charset == null && job != null) 1018 1008 { … … 1050 1040 protected String getDecimalSeparator() 1051 1041 { 1052 String ds = null; 1053 if (job != null) ds = (String)job.getValue(Parameters.DECIMAL_SEPARATOR_PARAMETER); 1054 if (ds == null && configuration != null) 1055 { 1056 ds = (String)configuration.getValue(Parameters.DECIMAL_SEPARATOR_PARAMETER); 1057 } 1058 return ds; 1042 return (String)getJobOrConfigurationValue(Parameters.DECIMAL_SEPARATOR_PARAMETER); 1059 1043 } 1060 1044 … … 1138 1122 throws BaseException 1139 1123 { 1140 String regexp = (String) configuration.getValue(name);1124 String regexp = (String)getJobOrConfigurationValue(name); 1141 1125 return regexp != null ? Pattern.compile(regexp) : null; 1142 1126 } -
trunk/src/plugins/core/net/sf/basedb/plugins/ReporterFlatFileImporter.java
r4985 r5241 31 31 import net.sf.basedb.core.ItemInUseException; 32 32 import net.sf.basedb.core.Permission; 33 import net.sf.basedb.core.PermissionDeniedException; 33 34 import net.sf.basedb.core.ReporterList; 34 35 import net.sf.basedb.core.RequestInformation; … … 210 211 public boolean requiresConfiguration() 211 212 { 212 return true;213 return false; 213 214 } 214 215 /** … … 353 354 } 354 355 storeValue(job, request, fileParameter); 356 storeValue(job, request, ri.getParameter("mode")); 357 358 // Parser settings 359 storeValue(job, request, headerRegexpParameter); 360 storeValue(job, request, dataHeaderRegexpParameter); 361 storeValue(job, request, dataSplitterRegexpParameter); 362 storeValue(job, request, trimQuotesParameter); 363 storeValue(job, request, ignoreRegexpParameter); 364 storeValue(job, request, dataFooterRegexpParameter); 365 storeValue(job, request, minDataColumnsParameter); 366 storeValue(job, request, maxDataColumnsParameter); 355 367 storeValue(job, request, ri.getParameter(Parameters.CHARSET_PARAMETER)); 356 368 storeValue(job, request, ri.getParameter(Parameters.DECIMAL_SEPARATOR_PARAMETER)); 357 storeValue(job, request, ri.getParameter("mode")); 369 370 // Column mappings 371 storeValue(job, request, complexMappings); 372 boolean allowComplex = "allow".equals(request.getParameterValue(complexMappings.getName())); 373 for (PluginParameter<String> pp : getAllColumnMappings()) 374 { 375 String mapExpression = (String)request.getParameterValue(pp.getName()); 376 checkColumnMapping(mapExpression, allowComplex, pp.getLabel()); 377 storeValue(job, pp, mapExpression); 378 } 358 379 359 380 // Error handling parameters … … 470 491 // Mapper that always return null 471 492 Mapper nullMapper = new ConstantMapper((String)null); 472 idMapper = getMapper(ffp, (String) configuration.getValue("reporterIdColumnMapping"),493 idMapper = getMapper(ffp, (String)job.getValue("reporterIdColumnMapping"), 473 494 cropStrings ? ReporterData.MAX_EXTERNAL_ID_LENGTH : null, nullMapper); 474 495 if (!deleteMode) 475 496 { 476 nameMapper = getMapper(ffp, (String) configuration.getValue("nameColumnMapping"),497 nameMapper = getMapper(ffp, (String)job.getValue("nameColumnMapping"), 477 498 cropStrings ? ReporterData.MAX_NAME_LENGTH : null, null); 478 symbolMapper = getMapper(ffp, (String) configuration.getValue("symbolColumnMapping"),499 symbolMapper = getMapper(ffp, (String)job.getValue("symbolColumnMapping"), 479 500 cropStrings ? ReporterData.MAX_SYMBOL_LENGTH : null, null); 480 descriptionMapper = getMapper(ffp, (String) configuration.getValue("descriptionColumnMapping"),501 descriptionMapper = getMapper(ffp, (String)job.getValue("descriptionColumnMapping"), 481 502 cropStrings ? ReporterData.MAX_DESCRIPTION_LENGTH : null, null); 482 reporterTypeMapper = getMapper(ffp, (String) configuration.getValue("reporterTypeColumnMapping"),503 reporterTypeMapper = getMapper(ffp, (String)job.getValue("reporterTypeColumnMapping"), 483 504 cropStrings ? ReporterType.MAX_NAME_LENGTH : null, null); 484 scoreMapper = getMapper(ffp, (String) configuration.getValue("scoreColumnMapping"), null, null);505 scoreMapper = getMapper(ffp, (String)job.getValue("scoreColumnMapping"), null, null); 485 506 486 507 reporterTypes = new HashMap<String, ReporterType>(); … … 492 513 { 493 514 String name = "extendedColumnMapping." + ep.getName(); 494 Mapper m = getMapper(ffp, (String) configuration.getValue(name),515 Mapper m = getMapper(ffp, (String)job.getValue(name), 495 516 cropStrings && ep.getLength() > 0 ? ep.getLength() : null, null); 496 517 if (m != null) extendedMappers.put(ep, m); … … 810 831 811 832 parameters.add(modeParameter); 833 834 // Parser regular expressions 835 parameters.add(parserSection); 836 parameters.add(cloneParameterWithDefaultValue(headerRegexpParameter)); 837 parameters.add(cloneParameterWithDefaultValue(dataHeaderRegexpParameter)); 838 parameters.add(cloneParameterWithDefaultValue(dataSplitterRegexpParameter)); 839 parameters.add(cloneParameterWithDefaultValue(trimQuotesParameter)); 840 parameters.add(cloneParameterWithDefaultValue(ignoreRegexpParameter)); 841 parameters.add(cloneParameterWithDefaultValue(dataFooterRegexpParameter)); 842 parameters.add(cloneParameterWithDefaultValue(minDataColumnsParameter)); 843 parameters.add(cloneParameterWithDefaultValue(maxDataColumnsParameter)); 812 844 parameters.add(Parameters.charsetParameter(null, null, 813 845 (String)configuration.getValue(Parameters.CHARSET_PARAMETER))); 814 846 parameters.add(Parameters.decimalSeparatorParameter(null, null, 815 847 (String)configuration.getValue(Parameters.DECIMAL_SEPARATOR_PARAMETER))); 848 849 // Column mappings 850 parameters.add(mappingSection); 851 parameters.add(complexMappings); 852 parameters.addAll(getAllColumnMappings()); 816 853 817 854 parameters.add(errorSection); -
trunk/src/plugins/core/net/sf/basedb/plugins/util/Parameters.java
r4521 r5241 443 443 } 444 444 445 /** 446 Clone a plug-in parameter but give it a different default value. 447 448 @param pp The plug-in parameter to clone 449 @param defaultValue The new default value 450 @return The cloned plug-in parameter 451 @since 2.15 452 */ 453 public static <T> PluginParameter<T> cloneParameter(PluginParameter<T> pp, T defaultValue) 454 { 455 PluginParameter<T> clone = new PluginParameter<T>( 456 pp.getName(), 457 pp.getLabel(), 458 pp.getDescription(), 459 defaultValue, 460 pp.getParameterType()); 461 return clone; 462 } 463 445 464 } -
trunk/src/test/TestReporterFlatFileImporter.java
r4889 r5241 171 171 PluginConfigurationRequest request = j.configure(new GuiContext(Item.REPORTER, GuiContext.Type.LIST)); 172 172 write_request_information(request.getRequestInformation()); 173 for (PluginParameter pp : request.getRequestInformation().getParameters()) 174 { 175 Object value = request.getCurrentParameterValue(pp.getName()); 176 if (value != null) request.setParameterValue(pp.getName(), value); 177 } 173 178 request.setParameterValue("file", File.getById(dc, fileId)); 174 179 request.setParameterValue("mode", mode); 175 180 request.setParameterValue("invalidUseOfNullError", "skip"); 181 176 182 PluginResponse response = request.invoke(); 177 183 if (response.getStatus() == Response.Status.DONE)
Note: See TracChangeset
for help on using the changeset viewer.