Changeset 6520


Ignore:
Timestamp:
Aug 18, 2014, 1:29:37 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

Merge changes between 3.3-beta-2 and 3.3.0 to trunk.

Location:
trunk
Files:
41 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/ExtensionsControl.java

    r6444 r6520  
    139139  private static ServletContext servletContext;
    140140   
    141   // The result of the last automatic update
    142   private static ProcessResults lastScanResults;
    143    
    144141  /**
    145142    Initialise the extension system. This method is called once from the
     
    166163    // Add default web-client extension points and extensions
    167164    manager.addURI(URI.create(ExtensionsControl.class.getResource("/web-extensions.xml").toString()));
    168 
    169     // Install extensions
    170     lastScanResults = new ProcessResults();
    171165   
    172166    // Initial scan
     
    189183    registry = null;
    190184    servletContext = null;
    191     lastScanResults = null;
    192185    initialised = false;
    193186    log.info("Extensions controller closed successfully");
     
    203196
    204197    // Collect the results from this scan
    205     ProcessResults results = new ProcessResults(lastScanResults);
     198    ProcessResults results = new ProcessResults(manager.getLastProcessResults());
    206199   
    207200    // File statistics
     
    253246      if (!initialScan)
    254247      {
    255         ResetErrorFlagProcessor resetError = new ResetErrorFlagProcessor();
     248        ResetErrorFlagProcessor resetError = new ResetErrorFlagProcessor(results);
    256249        manager.processFiles(resetError, new InstallFilter(request, true)); // Ignore error flag
    257250      }
     
    318311    results.setSummary(summary.toString());
    319312
    320     lastScanResults = results;
     313    manager.setLastProcessResults(results);
    321314    return results;
    322315  }
     
    544537  public ProcessResults getLastScanResults()
    545538  {
    546     return lastScanResults;
     539    return manager.getLastProcessResults();
    547540  }
    548541 
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/service/Services.java

    r6444 r6520  
    8484    or updated/enabled an existing on.
    8585    @param ext The extension, or null to start all enabled extension
     86    @since 3.3 (was protected before that)
    8687  */
    87   static synchronized void start(Extension ext)
     88  public static synchronized void start(Extension ext)
    8889  {
    8990    if (!initialised) return;
     
    9899    or is updating/disabling an existing on.
    99100    @param ext The extension, or null to stop all enabled extension
     101    @since 3.3 (was protected before that)
    100102  */
    101   static synchronized void stop(Extension ext)
     103  public static synchronized void stop(Extension ext)
    102104  {
    103105    if (!initialised) return;
     
    106108    invoker.render(new StopServiceRenderer());
    107109    log.info("Stopping services in extension done: " + ext);
     110  }
     111 
     112  /**
     113    Restart services as a result of an administrator has uninstalled an extension
     114    or is updating/disabling an existing on.
     115    @param ext The extension, or null to stop all enabled extension
     116    @since 3.3
     117  */
     118  public static synchronized void restart(Extension ext)
     119  {
     120    if (!initialised) return;
     121    log.info("Restarting services in extension: " + ext);
     122    ExtensionsInvoker<ServiceControllerAction> invoker = getInvoker(ext);
     123    invoker.render(new RestartServiceRenderer());
     124    log.info("Restarting services in extension done: " + ext);
    108125  }
    109126
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Body.java

    r6192 r6520  
    217217          sb.append(" data-project-id=\"").append(sc.getActiveProjectId()).append("\"");
    218218        }
     219        sb.append(" data-remember-dialog-positions=\"").append(Values.getString(sc.getUserClientSetting("dialogs.remember-positions"), "1")).append("\"");
    219220        if (message == null)
    220221        {
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Head.java

    r6402 r6520  
    183183      allScripts.add("menu.js");
    184184    }
     185    if (pageType == Page.PAGE_TYPE_POPUP) allScripts.add("popup.js");
    185186    if (getScripts() != null)
    186187    {
  • trunk/src/core/net/sf/basedb/core/Application.java

    r6468 r6520  
    554554        // Finalize registration
    555555        xtManager.processFiles(new MarkAsProcessedProcessor(), new WasProcessedFilter(results));
    556            
     556        xtManager.setLastProcessResults(results);
     557       
    557558        // Adding a task that cleans the session control cache at regular intervals
    558559        long milliSeconds = 60000L * sessionCacheTimeout;  // minutes --> milliseconds
  • trunk/src/core/net/sf/basedb/core/Directory.java

    r6127 r6520  
    2929import net.sf.basedb.core.query.Restrictions;
    3030
     31import java.util.HashMap;
    3132import java.util.LinkedList;
     33import java.util.Map;
    3234import java.util.Set;
    3335
     
    106108  }
    107109
     110  private static ThreadLocal<Map<String, Directory>> DIRECTORY_CACHE = new ThreadLocal<Map<String,Directory>>()
     111  {
     112    @Override
     113    protected Map<String, Directory> initialValue()
     114    {
     115      return new HashMap<String, Directory>();
     116    }
     117  };
     118 
    108119  /**
    109120    Create a new or existing <code>Directory</code> from a path. Every
     
    137148    Directory currentDir = null;
    138149    boolean creating = false;
     150    String currentPath = "";
     151    Map<String, Directory> directoryCache = null;
     152   
    139153    org.hibernate.Query query = HibernateUtil.getPredefinedQuery(
    140154        dc.getHibernateSession(), "GET_SUBDIRECTORY_WITH_NAME");
     
    148162    {
    149163      String subDirName = path.getDirectory(i);
     164      currentPath +="/" + subDirName;
    150165      if (!creating)
    151166      {
     
    168183      if (creating)
    169184      {
    170         // This must be permission checked
    171         Directory newSubDir = currentDir.newSubDirectory();
    172         newSubDir.setName(subDirName);
    173         dc.saveItem(newSubDir);
    174         currentDir = newSubDir;
     185        directoryCache = DIRECTORY_CACHE.get();
     186        if (directoryCache.size() == 0)
     187        {
     188          // Clean up when transaction is about to complete
     189          dc.addTransactionalAction(
     190            new TransactionalAction()
     191            {
     192              @Override
     193              public void onRollback()
     194              {
     195                DIRECTORY_CACHE.remove();
     196              }
     197             
     198              @Override
     199              public void onBeforeCommit()
     200              {}
     201             
     202              @Override
     203              public void onAfterCommit()
     204              {
     205                DIRECTORY_CACHE.remove();
     206              }
     207            }
     208          );
     209        }
     210        // Check cache if we have already created the subdir
     211        if (directoryCache.containsKey(currentPath))
     212        {
     213          currentDir = directoryCache.get(currentPath);
     214        }
     215        else
     216        {
     217          // This must be permission checked
     218          Directory newSubDir = currentDir.newSubDirectory();
     219          newSubDir.setName(subDirName);
     220          dc.saveItem(newSubDir);
     221          currentDir = newSubDir;
     222          directoryCache.put(currentPath, currentDir);
     223        }
    175224      }
    176225    }
  • trunk/src/core/net/sf/basedb/core/File.java

    r6497 r6520  
    10271027    if (loadMetadata)
    10281028    {
    1029       ConnectionParameters server = getServerInfo();
    1030       ConnectionManager manager = ConnectionManagerUtil.createConnectionManager(this, server);
    1031       try
    1032       {
    1033         setMetadataFromURI(manager.getMetadata());
    1034       }
    1035       catch (IOException ex)
    1036       {
    1037         throw new BaseException("Could not load metadata for URL:" + url, ex);
    1038       }
     1029      updateURLMetadata();
    10391030    }
    10401031    // Use auto-detection by file extension if no MIME type has been set
     
    10451036  }
    10461037
     1038  /**
     1039    If this is an external file, try to update the metadata.
     1040    @since 3.3
     1041  */
     1042  public void updateURLMetadata()
     1043  {
     1044    if (getLocation() != Location.EXTERNAL) return;
     1045   
     1046    checkPermission(Permission.WRITE);
     1047   
     1048    FileData data = getData();
     1049    data.setSize(-1);
     1050    data.setCompressedSize(-1);
     1051    data.setLastUpdate(new Date());
     1052   
     1053    ConnectionParameters server = getServerInfo();
     1054    ConnectionManager manager = ConnectionManagerUtil.createConnectionManager(this, server);
     1055    try
     1056    {
     1057      setMetadataFromURI(manager.getMetadata());
     1058    }
     1059    catch (IOException ex)
     1060    {
     1061      throw new BaseException("Could not load metadata for URL:" + data.getUrl(), ex);
     1062    }
     1063  }
     1064 
    10471065  /**
    10481066    Get the file server on which the external file is located. The file server
  • trunk/src/core/net/sf/basedb/core/Update.java

    r6497 r6520  
    834834        if (info.startsWith("Annotation created: "))
    835835        {
    836           // Annotation created: <name> --> CREATE + Annotation[<name>]
     836          // Annotation created: <name> --> ADD + Annotation[<name>]
    837837          fixQuery.setString("ci", "Annotation[" + info.substring("Annotation created: ".length()) + "]");
    838           fixQuery.setInteger("ct", ChangeType.CREATE.getValue());
     838          fixQuery.setInteger("ct", ChangeType.ADD.getValue());
    839839        }
    840840        else if (info.startsWith("Annotation updated: "))
     
    846846        else if (info.startsWith("Annotation deleted: "))
    847847        {
    848           // Annotation deleted: <name> --> DELETE + Annotation[<name>]
     848          // Annotation deleted: <name> --> REMOVE + Annotation[<name>]
    849849          fixQuery.setString("ci", "Annotation[" + info.substring("Annotation deleted: ".length()) + "]");
    850           fixQuery.setInteger("ct", ChangeType.DELETE.getValue());
     850          fixQuery.setInteger("ct", ChangeType.REMOVE.getValue());
    851851        }
    852852        else if (info.startsWith("File created: "))
    853853        {
    854           // File created: <name> --> CREATE + File[<name>]
     854          // File created: <name> --> ADD + File[<name>]
    855855          fixQuery.setString("ci", "File[" + info.substring("File created: ".length()) + "]");
    856           fixQuery.setInteger("ct", ChangeType.CREATE.getValue());
     856          fixQuery.setInteger("ct", ChangeType.ADD.getValue());
    857857        }
    858858        else if (info.startsWith("File updated: "))
     
    864864        else if (info.startsWith("File deleted: "))
    865865        {
    866           // File deleted: <name> --> DELETE + File[<name>]
     866          // File deleted: <name> --> REMOVE + File[<name>]
    867867          fixQuery.setString("ci", "File[" + info.substring("File deleted: ".length()) + "]");
    868           fixQuery.setInteger("ct", ChangeType.DELETE.getValue());
     868          fixQuery.setInteger("ct", ChangeType.REMOVE.getValue());
    869869        }
    870870        else if (info.startsWith("Updated: "))
  • trunk/src/core/net/sf/basedb/core/log/ChangeType.java

    r5054 r6520  
    3434  CREATE(1, "created"),
    3535  UPDATE(2, "updated"),
    36   DELETE(3, "deleted");
     36  DELETE(3, "deleted"),
     37  ADD(4, "added"),
     38  REMOVE(5, "removed");
    3739 
    3840  private final int value;
  • trunk/src/core/net/sf/basedb/core/log/db/AnnotationLogger.java

    r6358 r6520  
    3434import net.sf.basedb.core.data.ChangeHistoryDetailData;
    3535import net.sf.basedb.core.data.LoggableData;
     36import net.sf.basedb.core.log.ChangeType;
    3637import net.sf.basedb.core.log.EntityDetails;
    3738import net.sf.basedb.core.log.EntityLogger;
     
    124125    if (parentId == null) return;
    125126   
     127    ChangeType changeType = details.getChangeType();
     128    if (changeType == ChangeType.CREATE)
     129    {
     130      changeType = ChangeType.ADD;
     131    }
     132    else if (changeType == ChangeType.DELETE)
     133    {
     134      changeType = ChangeType.REMOVE;
     135    }
     136   
    126137    ChangeHistoryDetailData change = new ChangeHistoryDetailData();
    127     change.setChangeType(details.getChangeType().getValue());
     138    change.setChangeType(changeType.getValue());
    128139    change.setItemId(parentId);
    129140    change.setItemType(parentType);
  • trunk/src/core/net/sf/basedb/core/log/db/AnyToAnyLogger.java

    r6359 r6520  
    7979    String propertyPrefix = "Link["+link.getName()+"]";
    8080    ChangeType changeType = details.getChangeType();
    81    
     81    if (changeType == ChangeType.CREATE)
     82    {
     83      changeType = ChangeType.ADD;
     84    }
     85    else if (changeType == ChangeType.DELETE)
     86    {
     87      changeType = ChangeType.REMOVE;
     88    }
     89
    8290    boolean delegateLogging = false;
    8391    if (!factory.isLoggingDetailedProperties())
     
    107115          int toId = link.getToId();
    108116         
    109           if (changeType == ChangeType.CREATE)
     117          if (changeType == ChangeType.ADD)
    110118          {
    111119            change.setNewValue(createLoggableString(logControl, toType, toId));
    112120          }
    113           else if (changeType == ChangeType.DELETE)
     121          else if (changeType == ChangeType.REMOVE)
    114122          {
    115123            change.setOldValue(createLoggableString(logControl, toType, toId));
     
    136144    if (delegateLogging)
    137145    {
    138       List<ChangeHistoryDetailData> changes = details.toChangeDetails(parentType, parentId, propertyPrefix, details.getChangeType(), factory.isLoggingDetailedProperties(), factory.isLoggingOldPropertyValues());
     146      List<ChangeHistoryDetailData> changes = details.toChangeDetails(parentType, parentId, propertyPrefix, changeType, factory.isLoggingDetailedProperties(), factory.isLoggingOldPropertyValues());
    139147      dbLogManager.logChangeDetails(changes, details);
    140148    }
  • trunk/src/core/net/sf/basedb/core/log/db/FileSetMemberLogger.java

    r6359 r6520  
    126126    else
    127127    {
     128      if (changeType == ChangeType.CREATE)
     129      {
     130        changeType = ChangeType.ADD;
     131      }
     132      else if (changeType == ChangeType.DELETE)
     133      {
     134        changeType = ChangeType.REMOVE;
     135      }
     136
    128137      // Create a single entry with the file name
    129138      ChangeHistoryDetailData change = new ChangeHistoryDetailData();
     
    135144      {
    136145        String fileName = member.getFile().getName();
    137         if (changeType == ChangeType.CREATE)
     146        if (changeType == ChangeType.ADD)
    138147        {
    139148          change.setNewValue(fileName);
  • trunk/src/core/net/sf/basedb/util/extensions/manager/ExtensionsManager.java

    r6444 r6520  
    7070  private final Map<ObjectKey<?>, ExtensionsFile> installedObjects;
    7171 
     72  private ProcessResults lastResults;
     73 
    7274  private int numNew;
    7375  private int numModified;
     
    108110  {
    109111    return settings;
     112  }
     113 
     114  /**
     115    Save the last process results so that they can be used
     116    later on.
     117    @param results
     118    @since 3.3
     119  */
     120  public void setLastProcessResults(ProcessResults results)
     121  {
     122    this.lastResults = results;
     123  }
     124 
     125  /**
     126    Get the results of the last processing.
     127    @since 3.3
     128  */
     129  public ProcessResults getLastProcessResults()
     130  {
     131    return lastResults;
    110132  }
    111133 
  • trunk/src/core/net/sf/basedb/util/extensions/manager/ProcessResults.java

    r6372 r6520  
    182182    if (m == null)
    183183    {
    184       m = new FileResults(xtFile);
     184      m = new FileResults(xtFile, oldFileResults.get(xtFile));
    185185      fileResults.put(xtFile, m);
    186186      oldFileResults.put(xtFile, m);
     
    217217    if (m == null)
    218218    {
    219       m = new FileResults(xtFile);
     219      m = new FileResults(xtFile, oldFileResults.get(xtFile));
    220220      fileResults.put(xtFile, m);
    221221      oldFileResults.put(xtFile, m);
     
    244244    String status = null;
    245245
    246     FileResults(ExtensionsFile xtFile)
     246    FileResults(ExtensionsFile xtFile, FileResults old)
    247247    {
    248248      this.xtFile = xtFile;
    249249      this.time = System.currentTimeMillis();
    250250      this.messages = new LinkedList<String>();
     251      if (old != null)
     252      {
     253        hasError = old.hasError;
     254        status = old.status;
     255        messages.addAll(old.messages);
     256      }
    251257    }
    252258   
  • trunk/src/core/net/sf/basedb/util/extensions/manager/filter/InstalledFilter.java

    r6444 r6520  
    8585      return false;
    8686    }
     87    if (!xtFile.isValid() || xtFile.hasError())
     88    {
     89      // Do not install files with errors
     90      return false;
     91    }
    8792    return true;
    8893  }
  • trunk/src/core/net/sf/basedb/util/extensions/manager/processor/ResetErrorFlagProcessor.java

    r6372 r6520  
    2525import net.sf.basedb.util.extensions.manager.ExtensionsManager;
    2626import net.sf.basedb.util.extensions.manager.ExtensionsFile.WriteableExtensionsFile;
     27import net.sf.basedb.util.extensions.manager.ProcessResults;
    2728
    2829/**
     
    3940{
    4041
     42  private final ProcessResults results;
    4143  private int numFiles;
    4244 
    43   public ResetErrorFlagProcessor()
    44   {}
     45  public ResetErrorFlagProcessor(ProcessResults results)
     46  {
     47    this.results = results;
     48  }
    4549 
    4650  /*
     
    5963    numFiles++;
    6064    wFile.setError(false);
     65    results.forgetOldResults(wFile.getExtensionsFile());
    6166  }
    6267
  • trunk/src/core/net/sf/basedb/util/overview/loader/PlatformLoader.java

    r4740 r6520  
    8989      denied = true;
    9090    }
    91     Node platformNode = createItemNode(nf, platform, platform, denied, parentNode, ChildNodeDirection.NONE);
    92     if (platformNode != null && variant != null)
     91    Node platformNode = createItemNode(nf, platform, variant != null ? variant : platform, denied, parentNode, ChildNodeDirection.NONE);
     92    if (platformNode != null && variant != null && platformNode.getChild("variant") == null)
    9393    {
    9494      NodeNameGenerator<PlatformVariant> nameGenerator =
     
    9696      NodeFactory<PlatformVariant> variantNodeFactory =
    9797        new NodeFactory<PlatformVariant>(dc, context, null, nameGenerator);
    98       variantNodeFactory.createNode(variant, variant, platformNode, ChildNodeDirection.NONE);
     98      variantNodeFactory.createNode(variant, null, platformNode, ChildNodeDirection.NONE);
    9999    }
    100100    return platformNode;
  • trunk/src/core/net/sf/basedb/util/uri/ConnectionManagerUtil.java

    r6497 r6520  
    176176    // Create ClientContext for extension lookup
    177177    URI uri = file.getURI();
    178     DbControl dc = null;
    179     if (!file.isDetached()) dc = file.getDbControl();
     178    DbControl dc = file.getDbControl();
    180179    ClientContext context = new ClientContext(dc, file);
    181180    context.setAttribute("server", parameters);
  • trunk/src/plugins/core/core-plugins.xml

    r6372 r6520  
    532532  </plugin-definition>
    533533
     534  <plugin-definition id="FileImporter">
     535    <about>
     536      <name>File importer</name>
     537      <description>
     538        Imports and updates files in a batch. The importer
     539        can create new OFFLINE or EXTERNAL files, and update
     540        all types of files.
     541      </description>
     542    </about>
     543    <plugin-class>net.sf.basedb.plugins.batchimport.FileImporter</plugin-class>
     544    <settings>
     545      <property name="everyone-use">1</property>
     546    </settings>
     547  </plugin-definition>
     548
    534549  <plugin-definition id="BioSourceImporter">
    535550    <about>
  • trunk/src/plugins/core/net/sf/basedb/plugins/AbstractFlatFileImporter.java

    r6127 r6520  
    2626import net.sf.basedb.core.BooleanParameterType;
    2727import net.sf.basedb.core.Config;
     28import net.sf.basedb.core.DbControl;
    2829import net.sf.basedb.core.InvalidUseOfNullException;
    2930import net.sf.basedb.core.NumberOutOfRangeException;
     
    4142import net.sf.basedb.core.StringUtil;
    4243import net.sf.basedb.core.UnsupportedFileFormatException;
    43 
    4444import net.sf.basedb.core.plugin.AbstractPlugin;
    4545import net.sf.basedb.core.plugin.AutoDetectingImporter;
     
    5252import net.sf.basedb.core.signal.SignalTarget;
    5353import net.sf.basedb.core.signal.ThreadSignalHandler;
    54 
    5554import net.sf.basedb.plugins.util.Parameters;
    5655import net.sf.basedb.util.FileUtil;
     
    422421      int numTotal = 0;
    423422      String finalMessage = null;
     423      DbControl dc = null;
    424424      try
    425425      {
     
    429429        Iterator<File> files = getFileIterator();
    430430        totalFileSize = getTotalFileSize();
     431        dc = sc.newDbControl();
    431432       
    432433        while (files.hasNext())
     
    436437          try
    437438          {
    438             currentFile = files.next();
     439            currentFile = File.getById(dc, files.next().getId());
    439440            log("Parsing file: " + currentFile.getName());
    440441            in = currentFile.getDownloadStream(0);
     
    507508      finally
    508509      {
     510        if (dc != null) dc.close();
    509511        if (finalMessage != null) log(finalMessage);
    510512        closeLogFile();
  • trunk/src/plugins/core/net/sf/basedb/plugins/PackedFileExporter.java

    r6127 r6520  
    3535import net.sf.basedb.core.ItemParameterType;
    3636import net.sf.basedb.core.ItemQuery;
    37 import net.sf.basedb.core.Location;
    3837import net.sf.basedb.core.Nameable;
    3938import net.sf.basedb.core.ParameterType;
     
    5756import net.sf.basedb.core.signal.SignalTarget;
    5857import net.sf.basedb.core.signal.ThreadSignalHandler;
     58import net.sf.basedb.util.FileUtil;
    5959import net.sf.basedb.util.Values;
    6060import net.sf.basedb.util.zip.FilePacker;
     
    386386      long size = 0;
    387387      InputStream in = null;
    388       if (item.getType() == Item.FILE)
    389       {
    390         File f = (File)item;
    391         entryPath = f.getPath().toString();
    392         lastModified = f.getLastUpdate();
    393         in = f.getDownloadStream(0);
    394         size = f.getSize();
    395         if (removeItems && f.hasPermission(Permission.DELETE)) f.setRemoved(true);
    396       }
    397       else
    398       {
    399         Directory d = (Directory)item;
    400         entryPath = d.getPath().toString();
    401         if (removeItems && d.hasPermission(Permission.DELETE)) d.setRemoved(true);
    402       }
    403      
    404       // Remove rootPath from entryPath
    405       entryPath = entryPath.substring(rootPath.length());
    406      
    407       // Update progress
    408       if (progress != null)
    409       {
    410         int percent = (int)(completedBytes * progressFactor);
    411         progress.display(percent, "Compressing '" + entryPath + "'; " +
    412           currentFile + " of " + numFiles + " file(s) (" +
    413           Values.formatBytes(completedBytes) + " of " + Values.formatBytes(totalBytes) + ")");
    414       }
    415 
    416       // Send to FilePacker
    417       packer.pack(entryPath, in, size, lastModified == null ? 0 : lastModified.getTime());
    418       if (in != null) in.close();
    419       completedBytes += size;
     388      try
     389      {
     390        if (item.getType() == Item.FILE)
     391        {
     392          File f = (File)item;
     393          entryPath = f.getPath().toString();
     394          lastModified = f.getLastUpdate();
     395          in = f.getDownloadStream(0);
     396          size = f.getSize();
     397          if (removeItems && f.hasPermission(Permission.DELETE)) f.setRemoved(true);
     398        }
     399        else
     400        {
     401          Directory d = (Directory)item;
     402          entryPath = d.getPath().toString();
     403          if (removeItems && d.hasPermission(Permission.DELETE)) d.setRemoved(true);
     404        }
     405       
     406        // Remove rootPath from entryPath
     407        entryPath = entryPath.substring(rootPath.length());
     408       
     409        // Update progress
     410        if (progress != null)
     411        {
     412          int percent = (int)(completedBytes * progressFactor);
     413          progress.display(percent, "Compressing '" + entryPath + "'; " +
     414            currentFile + " of " + numFiles + " file(s) (" +
     415            Values.formatBytes(completedBytes) + " of " + Values.formatBytes(totalBytes) + ")");
     416        }
     417 
     418        // Send to FilePacker
     419        packer.pack(entryPath, in, size, lastModified == null ? 0 : lastModified.getTime());
     420        completedBytes += size;
     421      }
     422      finally
     423      {
     424        FileUtil.close(in);
     425      }
    420426    }
    421427   
     
    578584        {
    579585          File f = File.getById(dc, fileId);
    580           if (f.getLocation() == Location.PRIMARY)
     586          if (f.getLocation().isDownloadable())
    581587          {
    582588            loadedFiles.add(f);
     
    623629    {
    624630      ThreadSignalHandler.checkInterrupted();
    625       if (f.getLocation() == Location.PRIMARY)
     631      if (f.getLocation().isDownloadable())
    626632      {
    627633        loadedFiles.add(f);
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java

    r5934 r6520  
    4949import net.sf.basedb.core.Extract;
    5050import net.sf.basedb.core.File;
     51import net.sf.basedb.core.FileServer;
    5152import net.sf.basedb.core.FileSet;
    5253import net.sf.basedb.core.FileSetMember;
     
    354355        {
    355356          // Check that file can be parsed with given regular expressions
     357          dc = sc.newDbControl();
    356358          FlatFileParser ffp = getInitializedFlatFileParser(wrapper);
    357           File f = (File)request.getParameterValue("file");
     359          File f = File.getById(dc, ((File)request.getParameterValue("file")).getId());
    358360          InputStream in = f.getDownloadStream(0);
    359361          ffp.setInputStream(in, getCharset(request));
     
    443445    {
    444446      response.setError(ex.getMessage(), Arrays.asList(ex));
     447    }
     448    finally
     449    {
     450      if (dc != null) dc.close();
    445451    }
    446452  }
     
    19391945  }
    19401946 
     1947  private ItemQuery<FileServer> fileServerQuery;
     1948  /**
     1949    Find a file server with a given identifier. This is a utility method that
     1950    subclasses can use when creating or updating items.
     1951    <p>
     1952    NOTE! The first time this method is called a query object is initialised
     1953    using the {@link IdMethod#prepareQuery(DbControl, ItemQuery)} method.
     1954    Subsequent calls uses the same query. Thus, this method should always be
     1955    called with the same id method object, otherwise the result is undefined.
     1956   
     1957    @param dc The DbControl to use for database access
     1958    @param identifier The identifier protocol
     1959    @return A file server, or null if no item could be found
     1960    @since 3.3
     1961  */
     1962  protected FileServer findFileServer(DbControl dc, IdMethod idMethod, String identifier)
     1963  {
     1964    if (identifier == null) return null;
     1965    if (fileServerQuery == null)
     1966    {
     1967      fileServerQuery = initReferenceQuery(dc, idMethod, FileServer.getQuery(), false);
     1968    }
     1969    return findReferencedItem(dc, idMethod, fileServerQuery, identifier, 0, false);
     1970  }
     1971
    19411972  private Set<String> fileCache;
    19421973  /**
     
    22152246        "property. You need to specify a column mapping for " +
    22162247        "the selected method.",
    2217         new StringParameterType(null, "name", forJob, 1, 0, 0, idMethods)
     2248        new StringParameterType(null, idMethods.getKey(0), forJob, 1, 0, 0, idMethods)
    22182249      );
    22192250      parameters.add(idMethodParameter);
  • trunk/src/test/TestDirectory.java

    r5340 r6520  
    6565    test_list(id1);
    6666   
     67    int[] pid = test_create_multiple("/foo", "/foo/bar1", "/foo/bar2", "/foo/bar1/sub1", "/foo/bar2/sub1", "/foo/bar2/sub2");
     68   
    6769    if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
     70    if (pid != null && pid.length > 0) test_delete(pid[0], true);
    6871    test_delete(id_sub2, false);
    6972
     
    8790      Directory root = Directory.getById(dc, SystemItems.getId(Directory.ROOT));
    8891      Directory d = Directory.getNew(dc, root);
     92      d.setName(directoryName);
    8993      if (testAll)
    9094      {
    91         d.setName(directoryName);
    9295        d.setDescription("Added at "+new Date());
    9396        d.setAutoCompress(true);
     
    147150  }
    148151 
     152  static int[] test_create_multiple(String... path)
     153  {
     154    if (!TestUtil.hasPermission(Permission.CREATE, Item.DIRECTORY)) return null;
     155    Directory d[] = new Directory[path.length];
     156    int id[] = new int[path.length];
     157    DbControl dc = null;
     158    try
     159    {
     160      dc = TestUtil.getDbControl();
     161      for (int i = 0; i < path.length; i++)
     162      {
     163        Path p = new Path(path[i], Path.Type.DIRECTORY);
     164        d[i] = Directory.getNew(dc, p);
     165      }
     166      dc.commit();
     167     
     168      // Copy id values
     169      dc = TestUtil.getDbControl();
     170      for (int i = 0; i < path.length; i++)
     171      {
     172        id[i] = d[i].getId();
     173        dc.reattachItem(d[i], false);
     174        write_item(i, d[i]);
     175      }
     176     
     177      write("--Create multiple by path OK");
     178    }
     179    catch (Throwable ex)
     180    {
     181      write("--Create multiple by path FAILED");
     182      ex.printStackTrace();
     183      ok = false;
     184    }
     185    finally
     186    {
     187      if (dc != null) dc.close();
     188    }
     189    return id;
     190  }
     191
     192 
    149193  static void test_load(int id)
    150194  {
     
    246290    }
    247291  }
     292 
     293  static boolean test_list(String path, int expectedResults)
     294  {
     295    DbControl dc = null;
     296    try
     297    {
     298      dc = TestUtil.getDbControl();
     299      Path p = new Path(path, Path.Type.DIRECTORY);
     300      Directory d = Directory.getByPath(dc, p);
     301      ItemResultList<Directory> subdirs = d.getSubDirectories().list(dc);
     302     
     303      for (int i = 0; i<subdirs.size(); i++)
     304      {
     305        write_item(i, subdirs.get(i));
     306      }
     307      if (expectedResults >=0 && expectedResults != subdirs.size())
     308      {
     309        throw new BaseException("Expected " + expectedResults + " results, " +
     310            "not " + subdirs.size());
     311      }
     312      write("--List subdirectories OK ("+subdirs.size()+")");   
     313    }
     314    catch (Throwable ex)
     315    {
     316      write("--List subdirectories FAILED");
     317      ex.printStackTrace();
     318      ok = false;
     319      return false;
     320    }
     321    finally
     322    {
     323      if (dc != null) dc.close();
     324    }
     325    return true;
     326  }
     327
    248328 
    249329  static void test_delete(int id, boolean deleteAll)
  • trunk/src/test/TestFile.java

    r5864 r6520  
    242242  }
    243243 
     244  static boolean test_list(String path, int expectedResults)
     245  {
     246    DbControl dc = null;
     247    try
     248    {
     249      dc = TestUtil.getDbControl();
     250      Path p = new Path(path, Path.Type.DIRECTORY);
     251      Directory d = Directory.getByPath(dc, p);
     252      ItemResultList<File> files = d.getFiles().list(dc);
     253     
     254      for (int i = 0; i<files.size(); i++)
     255      {
     256        write_item(i, files.get(i));
     257      }
     258      if (expectedResults >=0 && expectedResults != files.size())
     259      {
     260        throw new BaseException("Expected " + expectedResults + " results, " +
     261            "not " + files.size());
     262      }
     263      write("--List files OK ("+files.size()+")");   
     264    }
     265    catch (Throwable ex)
     266    {
     267      write("--List files FAILED");
     268      ex.printStackTrace();
     269      ok = false;
     270      return false;
     271    }
     272    finally
     273    {
     274      if (dc != null) dc.close();
     275    }
     276    return true;
     277  }
     278
     279 
    244280  static void test_delete(int id)
    245281  {
  • trunk/src/test/TestItemImporter.java

    r6063 r6520  
    2626import net.sf.basedb.core.DbControl;
    2727import net.sf.basedb.core.DerivedBioAssay;
     28import net.sf.basedb.core.Directory;
    2829import net.sf.basedb.core.Extract;
    2930import net.sf.basedb.core.File;
     
    3334import net.sf.basedb.core.Job;
    3435import net.sf.basedb.core.ParameterType;
     36import net.sf.basedb.core.Path;
    3537import net.sf.basedb.core.Platform;
    3638import net.sf.basedb.core.PluginConfigurationRequest;
     
    8587    int childScanId = TestItemSubtype.test_create(Item.DERIVEDBIOASSAY, "ChildScan", SystemItems.getId(DerivedBioAssay.SCAN));
    8688    int allSamplesSubtypeId = TestItemSubtype.test_create(Item.SAMPLE, "All samples");
    87    
     89    int base2DemoServer = TestFileServer.test_create("base2.thep.lu.se", "BASE demo site", null, null,
     90        "data/base2.thep.lu.se.crt", null, null);
     91
    8892    TestProject.test_defaultItem(projectId, Item.PROTOCOL, defaultSamplingProtocolId);
    8993    TestProject.test_defaultItem(projectId, Item.PROTOCOL, hybProtocolId);
    9094    TestProject.test_defaultItem(projectId, Item.HARDWARE, hybStationId);
     95   
     96    // Import files
     97    int rootDirectoryId = TestDirectory.test_create(true, "file-import");
     98    int filesFileId = TestFile.test_create("data/test.batchimport.files.txt", false, false);
     99    int fileImporterId  = TestPluginDefinition.test_get("net.sf.basedb.plugins.batchimport.FileImporter");
     100    int fileJobId = test_create_item_import_job(Item.FILE, fileImporterId, filesFileId, 0);
     101    ok = ok & TestJob.test_execute(fileJobId, false);
     102    ok = ok & TestDirectory.test_list("/file-import", 2); // 'raw' and 'ext'
     103    ok = ok & TestFile.test_list("/file-import", 1);  // 'reporters.txt'
     104    ok = ok & TestFile.test_list("/file-import/raw", 2);  // 'file1.txt' and 'file2.txt'
     105    ok = ok & TestFile.test_list("/file-import/ext", 2);  // 'robots.txt' and '2.17.md5'
    91106   
    92107    // Import bioplates
     
    239254    TestFile.test_delete(bioPlateFileId);
    240255   
     256    // Delete files
     257    TestDirectory.test_delete(rootDirectoryId, true);
     258    TestJob.test_delete(fileJobId);
     259    TestFile.test_delete(filesFileId);
     260   
    241261    // References items
    242262    TestProtocol.test_delete(printProtocolId);
     
    257277    TestItemSubtype.test_delete(childScanId);
    258278    TestItemSubtype.test_delete(allSamplesSubtypeId);
     279    TestFileServer.test_delete(base2DemoServer);
    259280    TestProject.test_delete(projectId);
    260281
     
    281302      File file = File.getById(dc, fileId);
    282303      request.setParameterValue("file", file);
    283       setParserParameters(request);
     304      setParserParameters(dc, request, itemType);
    284305      setColumnMappingParameters(request, itemType, file);
    285306      if (subtypeId != 0)
     
    292313      if (response.getStatus() != Response.Status.CONTINUE)
    293314      {
    294         throw new BaseException(response.getMessage(), response.getErrorList().get(0));
     315        Throwable t = response.getErrorList() != null ? response.getErrorList().get(0) : null;
     316        throw new BaseException(response.getMessage(), t);
    295317      }
    296318
     
    347369  }
    348370 
    349   private static void setParserParameters(PluginConfigurationRequest request)
     371  private static void setParserParameters(DbControl dc, PluginConfigurationRequest request, Item itemType)
    350372  {
    351373    request.setParameterValue("dataSplitterRegexp", "\\t");
     
    353375    request.setParameterValue("ignoreRegexp", "#.*");
    354376   
    355     request.setParameterValue("idMethod", "name");
     377    if (itemType == Item.FILE)
     378    {
     379      request.setParameterValue("dataHeaderRegexp", "Path.*");
     380      request.setParameterValue("idMethod", "path");
     381      request.setParameterValue("root", Directory.getByPath(dc, new Path("/file-import", Path.Type.DIRECTORY)));
     382    }
     383    else
     384    {
     385      request.setParameterValue("idMethod", "name");
     386    }
    356387    request.setParameterValue("mode", "create+update");
    357388    request.setParameterValue("charset", "UTF-8");
     
    363394    request.setParameterValue("descriptionColumnMapping", "\\Description\\");
    364395    request.setParameterValue("complexExpressions", "allow");
     396    if (itemType == Item.FILE)
     397    {
     398      request.setParameterValue("pathColumnMapping", "\\Path\\");
     399      request.setParameterValue("urlColumnMapping", "\\URL\\");
     400      request.setParameterValue("fileServerColumnMapping", "\\File server\\");
     401      request.setParameterValue("mimeTypeColumnMapping", "\\Mime type\\");
     402      request.setParameterValue("subtypeColumnMapping", "\\Type\\");
     403    }
    365404    if (itemType == Item.BIOPLATE)
    366405    {
  • trunk/www/admin/services/services.jsp

    r6290 r6520  
    8181          last = ext;
    8282          boolean isRunning = action.isRunning();
    83           Throwable error = ec.getLastExtensionError(ext.getId());
     83          Throwable error = isRunning ? null : ec.getLastExtensionError(ext.getId());
    8484          boolean hasError = error != null;
    8585          %>
  • trunk/www/common/help/view_help.jsp

    r6400 r6520  
    118118  <base:page type="popup" title="Help">
    119119  <base:head styles="help.css" scripts="~help.js" />
    120   <base:body>
     120  <base:body data-read-only="1">
    121121    <h1><%=title%></h1>
    122122   
  • trunk/www/include/scripts/main-2.js

    r6497 r6520  
    5252  app.getLoggedInUserId = function()
    5353  {
    54     return Data.get(document.body, 'user-id');
     54    return Data.int(document.body, 'user-id');
    5555  }
    5656
     
    6060  app.getActiveProjectId = function()
    6161  {
    62     return Data.get(document.body, 'project-id');
     62    return Data.int(document.body, 'project-id');
    6363  }
    6464
     
    6969  app.getScale = function()
    7070  {
    71     return Data.get(document.body, 'gui-scale');
     71    return Data.int(document.body, 'gui-scale');
    7272  }
    7373 
     
    7979  app.getMaxUrlLength = function()
    8080  {
    81     return Data.get(document.body, 'max-url-length', 0);
     81    return Data.int(document.body, 'max-url-length', 0);
     82  }
     83 
     84  /**
     85    Check if popup dialog positions should be remembered or not.
     86   */
     87  app.rememberDialogPositions = function()
     88  {
     89    return Data.int(document.body, 'remember-dialog-positions', 1);
    8290  }
    8391 
     
    883891    try
    884892    {
    885       value = win.pageValues[namespace+'::'+key];
     893      value = win.pageValues[namespace+'::'+key] || null;
    886894    }
    887895    catch (e)
     
    11971205  dialogs.openPopup = function(url, name, width, height)
    11981206  {
    1199    
    1200     // Rescale according to user settings
    1201     var scale = App.getScale();
    1202     width = width * scale;
    1203     height = height * scale;
    1204 
    1205     /*
    1206       We will try to position the popup window in the center of
    1207       the parent window.
    1208     */
    1209     var pos = App.getWindowPosition(window.top);
    1210     var top = Math.ceil(pos.top+(pos.height-height) / 2);
    1211     var left = Math.ceil(pos.left+(pos.width-width) / 2);
    1212     if (top < 0 && pos.top >= 0) top = 0;
    1213     if (left < 0 && pos.left >= 0) left = 0;
     1207    // Get last position of the window
     1208    var position = null;
     1209    if (App.rememberDialogPositions())
     1210    {
     1211      position = JSON.parse(Data.getPageValue("last-position", name));
     1212    }
     1213
     1214    if (!position)
     1215    {
     1216      // If no last position is know, use the specified settings
     1217      position = {};
     1218      // Rescale according to user settings
     1219      var scale = App.getScale();
     1220      position.width = width * scale;
     1221      position.height = height * scale;
     1222     
     1223      //  Try to position the popup window in the center of the parent window.
     1224      var pos = App.getWindowPosition(window.top);
     1225      var top = Math.ceil(pos.top+(pos.height-height) / 2);
     1226      var left = Math.ceil(pos.left+(pos.width-width) / 2);
     1227      position.top = (top < 0 && pos.top >= 0) ? 0 : top;
     1228      position.left = (left < 0 && pos.left >= 0) ? 0 : left;
     1229    }
    12141230
    12151231    var options = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
    1216     options += ",top="+top+",left="+left+",width="+width+",height="+height;
    1217 
    12181232    // Check if another window with the same name already exists
    1219     var oldWin = window.open('', name, options);
     1233    var oldWin = window.open('', name, options+",top="+position.top+",left="+position.left+",width="+position.width+",height="+position.height);
    12201234    try
    12211235    {
    1222       if (oldWin && !oldWin.closed && oldWin.App)
     1236      if (oldWin && !oldWin.closed && oldWin.Popup && !oldWin.Popup.isReadOnly())
    12231237      {
    12241238        var msg = 'This window has already been opened. ';
     
    12291243          return;
    12301244        }
     1245        position = App.getWindowPosition(oldWin);
    12311246        oldWin.close();
    12321247        url += '&warnIfOpen=0';
     
    12361251    {}
    12371252   
     1253    if (App.rememberDialogPositions())
     1254    {
     1255      Data.setPageValue('requested-position', JSON.stringify(position), name);
     1256    }
     1257    options += ",top="+position.top+",left="+position.left+",width="+position.width+",height="+position.height;
    12381258    var newWin;
    12391259    if (App.isTooLongUrl(url))
     
    12471267      newWin = window.open(url, name, options);
    12481268    }
     1269   
    12491270    newWin.focus();
    12501271    return newWin;
     
    27412762  numbers.formatBytes = function(value)
    27422763  {
    2743     if (!value) return '';
     2764    if (typeof value != 'number') return '';
    27442765    if (value > GB)
    27452766    {
  • trunk/www/info/about.jsp

    r6177 r6520  
    6767<base:page type="popup" title="About">
    6868<base:head scripts="tabcontrol-2.js,~info.js" styles="tabcontrol.css" />
    69 <base:body>
     69<base:body data-read-only="1">
    7070  <h1>BASE - BioArray Software Environment</h1>
    7171 
  • trunk/www/info/broadcast.jsp

    r6177 r6520  
    4141<base:page type="popup" title="<%=title%>">
    4242<base:head scripts="~info.js "/>
    43 <base:body>
     43<base:body data-read-only="1">
    4444  <h1><%=HTML.encodeTags(title)%></h1>
    4545 
  • trunk/www/info/forgot_password.jsp

    r6177 r6520  
    4444<base:page type="popup" title="Forgot your password?">
    4545<base:head scripts="~info.js"/>
    46 <base:body>
     46<base:body data-read-only="1">
    4747  <h1>Forgot your password?</h1>
    4848 
  • trunk/www/info/get_account.jsp

    r6177 r6520  
    4444<base:page type="popup" title="Get an account">
    4545<base:head scripts="~info.js" />
    46 <base:body>
     46<base:body data-read-only="1">
    4747  <h1>Get an account</h1>
    4848 
  • trunk/www/lims/arraydesigns/features/view_feature.jsp

    r6307 r6520  
    102102  <base:head scripts="tabcontrol-2.js,~features.js" styles="tabcontrol.css">
    103103  </base:head>
    104   <base:body>
     104  <base:body data-read-only="1">
    105105    <h1><%=title%> <base:help helpid="feature.view.properties" /></h1>
    106106
  • trunk/www/logout.jsp

    r6167 r6520  
    4040<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
    4141<%
    42 final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
     42final SessionControl sc = Base.getExistingSessionControl(pageContext, false);
    4343final String ID = sc.getId();
    44 final String noconfirm = request.getParameter("noconfirm");
    45 if (noconfirm != null)
     44final boolean noconfirm = Values.getBoolean(request.getParameter("noconfirm"), !sc.isLoggedIn());
     45if (noconfirm)
    4646{
    4747  // Redirect to main login page
     
    6868<base:page type="popup" title="<%=title%>">
    6969<base:head scripts="~logout.js" />
    70 <base:body>
     70<base:body data-read-only="1">
    7171  <h1><%=title%></h1>
    7272  <div class="content">
  • trunk/www/my_base/messages/view_message.jsp

    r6307 r6520  
    110110  <base:page type="popup" title="<%=title%>" id="view-page">
    111111  <base:head scripts="~messages.js" />
    112   <base:body>   
     112  <base:body data-read-only="1">   
    113113    <h1><%=title%> <base:help tabcontrol="main" /></h1>
    114114    <div id="page-data" data-item-id="<%=itemId%>"></div>
  • trunk/www/my_base/user/preferences.jsp

    r6187 r6520  
    7575  final String maxColor = Values.getString(sc.getUserClientSetting("ratiocolor.max"), "FFFF00");
    7676 
     77  final boolean rememberDialogPositions = Values.getBoolean(sc.getUserClientSetting("dialogs.remember-positions"), true);
     78 
    7779  ItemContext cc = sc.getCurrentContext(Item.USERCLIENTSETTING);
    7880  List<String> recentColors = cc.getRecent("colors");
     
    295297          </td>
    296298        </tr>
     299        <tr>
     300          <th>Dialogs</th>
     301          <td>
     302            <label><input type="checkbox" name="remember_positions" value="1"
     303              <%=rememberDialogPositions ? "checked" : "" %>
     304              >Remember positions</label>
     305          </td>
     306        </tr>   
    297307        <tr class="dynamic">
    298308          <th></th>
  • trunk/www/my_base/user/submit_user.jsp

    r6428 r6520  
    152152    FormatterSettings.setNumDecimals(sc, numDecimals);
    153153   
     154    sc.setUserClientSetting("dialogs.remember-positions", Values.getBoolean(request.getParameter("remember_positions")) ? "1" : "0");
     155   
    154156    // Plugins tab
    155157    sc.setUserClientSetting("plugins.sendmessage", Values.getString(request.getParameter("sendmessage"), "0"));
  • trunk/www/views/jobs/view_job.jsp

    r6445 r6520  
    192192  <base:head scripts="tabcontrol-2.js,table.js,~jobs.js"
    193193    styles="tabcontrol.css,progressbar.css,table.css" />
    194   <base:body>
     194  <base:body data-read-only="1">
    195195    <h1><%=title%> <base:help tabcontrol="main" /></h1>
    196196    <div id="page-data"
     
    582582              %>
    583583              <tbl:row>
    584                 <tbl:cell column="changeType"><%=change.getChangeType()%> <%=change.getItemType()%></tbl:cell>
     584                <tbl:cell column="changeType"><%=change.getChangeType()%></tbl:cell>
    585585                <tbl:cell column="item"><%=ChangeHistoryUtil.getItem(dc, change, false, false)%></tbl:cell>
    586586                <tbl:cell column="info"><%=HTML.encodeTags(change.getChangeInfo())%></tbl:cell>
  • trunk/www/views/rawbioassays/rawdata/view_rawdata.jsp

    r6311 r6520  
    9393  <base:page title="<%=title%>" type="popup" id="view-page">
    9494  <base:head scripts="tabcontrol-2.js,~rawdata.js" styles="tabcontrol.css" />
    95   <base:body>
     95  <base:body data-read-only="1">
    9696    <h1><%=title%></h1>
    9797 
  • trunk/www/views/sessions/view_session.jsp

    r6311 r6520  
    9191  <base:page type="popup" title="<%=title%>" id="view-page">
    9292  <base:head scripts="~sessions.js" />
    93   <base:body>
     93  <base:body data-read-only="1">
    9494   
    9595    <h1><%=title%> <base:help helpid="session.view" /></h1>
Note: See TracChangeset for help on using the changeset viewer.