Changeset 2944


Ignore:
Timestamp:
Nov 23, 2006, 11:09:29 AM (16 years ago)
Author:
Martin Svensson
Message:

Fixes #441. The maxLength of an imported StringParameterType? is now depending on the imported
parametervalue's length.
No configurations will be imported if something goes wrong during the job.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.1/src/plugins/core/net/sf/basedb/plugins/PluginConfigurationImporter.java

    r2828 r2944  
    8888  extends AbstractPlugin
    8989    implements InteractivePlugin, AutoDetectingImporter
    90 {
    91  
     90{
    9291  private static final About about = new AboutImpl
    9392  (
     
    116115 
    117116  private RequestInformation configureJob;
    118  
    119   // Counting variables for the job
    120   private int numImportedConfigurations;
    121   private int numNotImportedConfigurations;
    122117 
    123118  // Variables to store the job parameters in.
     
    232227        is.close();
    233228       
    234         response.setDone(getSuccessMessage());
     229        response.setDone("The configurations were imported successfully!");
    235230       
    236231      }
     
    300295    throws BaseException
    301296  {           
    302     DbControl dc = null;   
    303     numNotImportedConfigurations = 0;
     297    DbControl dc = null;
     298   
    304299    try
    305300    {
     
    319314        String pluginClassName = configuration.getAttributeValue("pluginClassName");
    320315       
    321         try
    322         {
    323           PluginDefinition pluginDefinition = PluginDefinition.getByClassName(dc, pluginClassName);
    324          
    325           PluginConfiguration pluginConfig = PluginConfiguration.getNew(dc, pluginDefinition);         
    326           dc.saveItem(pluginConfig);
    327           pluginConfig.setName(name);
    328           pluginConfig.setDescription(description);
    329          
    330           List parameters = configuration.getChildren("parameter");
    331           setPluginConf(parameters, pluginConfig);         
    332           numImportedConfigurations++;       
    333         }
    334         catch(Throwable ex)
    335         {
    336           numNotImportedConfigurations++;         
    337         }
     316     
     317        PluginDefinition pluginDefinition = PluginDefinition.getByClassName(dc, pluginClassName);
     318       
     319        PluginConfiguration pluginConfig = PluginConfiguration.getNew(dc, pluginDefinition);         
     320        dc.saveItem(pluginConfig);
     321        pluginConfig.setName(name);
     322        pluginConfig.setDescription(description);
     323       
     324        List parameters = configuration.getChildren("parameter");
     325        setPluginConf(parameters, pluginConfig);         
    338326      }       
    339327      dc.commit();
     
    355343      -----------------------------------------------------
    356344  */ 
    357   /**
    358     Gets the message of how many parameters that were handled/imported of the parameters in the xml-file
    359   */
    360   private String getSuccessMessage()
    361   {
    362     StringBuilder message = new StringBuilder();   
    363     message.append(numImportedConfigurations + " configurations were imported.\n");
    364     if (numNotImportedConfigurations > 0)
    365     {
    366       message.append(numNotImportedConfigurations + " configurations were not imported.\n");
    367     }
    368     return message.toString();
    369   }
    370345 
    371346  private RequestInformation getConfiguredJobParameters()
     
    413388      Returns null if this importer doesn't support the class.
    414389  */
    415   private ParameterType getParameterType(Class parameterClass)
     390  private ParameterType getParameterType(Class parameterClass, List<?> values)
    416391  {
    417392    if (parameterClass.equals(Boolean.class)) return new BooleanParameterType();
     
    421396    else if (parameterClass.equals(Integer.class)) return new IntegerParameterType();   
    422397    else if (parameterClass.equals(Long.class)) return new LongParameterType();
    423     else if (parameterClass.equals(String.class)) return new StringParameterType();
     398    else if (parameterClass.equals(String.class))
     399    {
     400      StringParameterType stp = null;
     401      if (values != null && !values.isEmpty())
     402      {
     403        int maxLength = 0;
     404        for (Object obj : values)
     405        {
     406          if (obj instanceof String)
     407          {
     408            String str = obj.toString();
     409            maxLength = maxLength < str.length() ? str.length() : maxLength;           
     410          }
     411        }
     412        stp = new StringParameterType(maxLength, null, false);
     413      }
     414      else
     415      {
     416        stp = new StringParameterType();
     417      }
     418      return stp;
     419     
     420    }
    424421    else return null;
    425422  }
     
    448445        clazz = Class.forName(cl);
    449446        values = getValueList(parameter, clazz);
    450         plc.setParameterValues(name,label, "", getParameterType(clazz), values);
     447        ParameterType pType = getParameterType(clazz, values);
     448        plc.setParameterValues(name,label, "", pType, values);
    451449      }
    452450    }
Note: See TracChangeset for help on using the changeset viewer.