Changeset 5719


Ignore:
Timestamp:
Sep 6, 2011, 1:56:29 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1604: Support for multiple files of the same type in a FileSet?

Batch importers now have support for adding multiple files of the same type. This must be done by having one line in the import file for each file to add.

Location:
trunk/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/FileSet.java

    r5718 r5719  
    307307    is called. Calling this method is equivalent to first call
    308308    {@link #removeAllOfType(DataFileType)} and then {@link
    309     #addMember(File, DataFileType)}.
     309    #addMember(File, DataFileType)} except that if the given file
     310    already is a member that member entry is kept.
    310311   
    311312    @param file The file to set as a member (or null to remove it)
     
    329330    if (file != null) file.checkPermission(Permission.USE);
    330331
    331     removeAllOfType(type);
    332     return file == null ? null : addMember(file, type);
     332    FileSetMember member = removeAllOfTypeExcept(type, file);
     333    if (member == null && file != null)
     334    {
     335      member = addMember(file, type);
     336    }
     337    return member;
    333338  }
    334339 
     
    408413      of the specified type exists
    409414  */
    410   @Deprecated
    411415  public FileSetMember getMember(DataFileType type)
    412416  {
     
    537541    return removed.size();
    538542  }
     543 
     544  /**
     545    Remove all member files of the given type.
     546 
     547    @param type A <code>DataFileType</code> object
     548    @throws InvalidUseOfNullException If type is null
     549    @throws PermissionDeniedException If the logged in user
     550      doesn't have write permission for this file set
     551    @return The number of removed files
     552    @since 3.0
     553  */
     554  private FileSetMember removeAllOfTypeExcept(DataFileType type, File file)
     555  {
     556    DbControl dc = getDbControl();
     557    int typeId = type.getId();
     558    int fileId = file.getId();
     559    FileSetMember remain = null;
     560    Iterator<FileSetMemberData> it = getData().getMembers().iterator();
     561    // Keep track of removed members so that we can invoke metadata extensions
     562    List<ValidatingFileSetMember> removed = new ArrayList<ValidatingFileSetMember>();
     563    while (it.hasNext())
     564    {
     565      FileSetMemberData member = it.next();
     566      if (member.getDataFileType().getId() == typeId)
     567      {
     568        // Type is matching -- what about the file?
     569        if (member.getFile().getId() == fileId)
     570        {
     571          // Keep
     572          remain = dc.getItem(FileSetMember.class, member);
     573        }
     574        else
     575        {
     576          // Remove
     577          it.remove();
     578          if (member.getId() > 0)
     579          {
     580            FileSetMember m = dc.getItem(FileSetMember.class, member);
     581            dc.deleteItem(m);
     582            removed.add(new ValidatingFileSetMember(m));
     583          }
     584        }
     585      }
     586    }
     587    if (removed.size() > 0)
     588    {
     589      // Create context and invoke the extensions system
     590      ExtensionsInvoker<ValidationAction> invoker = getInvoker(dc);
     591     
     592      // Reset the metadata
     593      invoker.render(new ResetMetadataRenderer(removed));
     594    }
     595    return remain;
     596  }
     597
    539598 
    540599  /**
  • trunk/src/core/net/sf/basedb/core/FileStoreUtil.java

    r5713 r5719  
    219219    FileSet fileSet = item.getFileSet();
    220220    DataFileType type = DataFileType.getByExternalId(dc, dataFileType);
    221     FileSetMember member = null;
    222     if (file == null)
    223     {
    224       // TODO #1604
    225 //      fileSet.removeMember(type);
    226     }
    227     else
    228     {
    229       member = fileSet.setMember(file, type);
    230     }
     221    FileSetMember member = fileSet.setMember(file, type);
    231222    return member;
    232223  }
     
    276267    // Now, add/remove the file to the fileset
    277268    FileSet fileSet = item.getFileSet();
    278     FileSetMember member = null;
    279     if (file == null)
    280     {
    281       // TODO #1604
    282 //      fileSet.removeMember(type);
    283     }
    284     else
    285     {
    286       member = fileSet.setMember(file, type);
    287     }
     269    FileSetMember member = fileSet.setMember(file, type);
    288270    return member;
    289271  }
  • trunk/src/core/net/sf/basedb/core/data/FileSetMemberData.java

    r5713 r5719  
    4343    Get the file set this file belongs to.
    4444    @hibernate.many-to-one outer-join="false" update="false"
    45     @hibernate.column name="`fileset_id`" not-null="true"
     45    @hibernate.column name="`fileset_id`" not-null="true" unique-key="uniquefile"
    4646  */
    4747  public FileSetData getFileSet()
     
    5858    Get the type of this file. A set may only contain one file for each type.
    5959    @hibernate.many-to-one outer-join="false" update="false"
    60     @hibernate.column name="`datafiletype_id`" not-null="true"
     60    @hibernate.column name="`datafiletype_id`" not-null="true" unique-key="uniquefile"
    6161  */
    6262  public DataFileTypeData getDataFileType()
     
    7373    Get the file.
    7474    @hibernate.many-to-one outer-join="false"
    75     @hibernate.column name="`file_id`" not-null="true"
     75    @hibernate.column name="`file_id`" not-null="true" unique-key="uniquefile"
    7676  */
    7777  public FileData getFile()
  • trunk/src/plugins/core/net/sf/basedb/plugins/ManualTransformCreator.java

    r5623 r5719  
    192192        for (DataFileType ft : fileTypes)
    193193        {
    194           File file = (File)job.getValue("file." + ft.getExternalId());
    195           if (file != null)
     194          List<File> files = (List<File>)job.getValues("file." + ft.getExternalId());
     195          if (files != null && files.size() > 0)
    196196          {
    197             fs.setMember(file, ft);
     197            for (File f : files)
     198            {
     199              fs.addMember(f, ft);
     200            }
    198201          }
    199202        }
     
    274277        for (DataFileType ft : fileTypes)
    275278        {
    276           storeValue(job, request, ri.getParameter("file." + ft.getExternalId()));
     279          storeValues(job, request, ri.getParameter("file." + ft.getExternalId()));
    277280        }
    278281      }
     
    460463              ft.getName(),
    461464              ft.getDescription(),
    462               new FileParameterType()
     465              new FileParameterType(null, false, 0)
    463466          ));
    464467        }
     
    524527        "fileTypes",
    525528        "File types",
    526         "Select all registered file types that the external tool generates as" +
     529        "Select all registered file types that the external tool generates as " +
    527530        "output.",
    528531        new ItemParameterType<DataFileType>(DataFileType.class, null, false, 0, fileTypes)
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java

    r5696 r5719  
    2828import java.util.EnumSet;
    2929import java.util.HashMap;
     30import java.util.HashSet;
    3031import java.util.List;
    3132import java.util.Map;
     
    4849import net.sf.basedb.core.Extract;
    4950import net.sf.basedb.core.File;
     51import net.sf.basedb.core.FileSet;
     52import net.sf.basedb.core.FileSetMember;
     53import net.sf.basedb.core.FileStoreEnabled;
    5054import net.sf.basedb.core.Hardware;
    5155import net.sf.basedb.core.ItemParameterType;
     
    19151919  }
    19161920 
     1921  private Set<String> fileCache;
     1922  /**
     1923    Set or add a file to a file set. The first time this method is called for
     1924    a given item and file type combination {@link FileSet#setMember(File, DataFileType)}
     1925    is used to add the file to the file set (which will replace all other files of
     1926    the same file type. If this method is called more times then
     1927    {@link FileSet#addMember(File, DataFileType)} is used so that already added
     1928    files are preserved.
     1929   
     1930    If the file is null the first time, all files of the given file types are removed.
     1931    If the file is null after the first time, this call is ignored.
     1932   
     1933    @param item The item to set/add a file to
     1934    @param fileType The type of the file
     1935    @param file The file, or null
     1936    @return The new member entry, or null if the call didn't result in
     1937      an addition
     1938    @since 3.0
     1939  */
     1940  protected FileSetMember setOrAddFile(FileStoreEnabled item, DataFileType fileType, File file)
     1941  {
     1942    if (fileCache == null) fileCache = new HashSet<String>();
     1943    String cacheId = item.getType().name() + "#" + item.getId() + "#" + fileType.getId();
     1944    FileSetMember added = null;
     1945    if (!fileCache.contains(cacheId))
     1946    {
     1947      // Has been called at least one time before
     1948      if (file != null)
     1949      {
     1950        added = item.getFileSet().addMember(file, fileType);
     1951      }
     1952    }
     1953    else
     1954    {
     1955      added = item.getFileSet().setMember(file, fileType);
     1956      fileCache.add(cacheId);
     1957    }
     1958    return added;
     1959  }
     1960 
    19171961  /**
    19181962    Cache that holds loaded/created items. The cache key is item type + identifier,
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ArrayDesignImporter.java

    r5713 r5719  
    313313          file = File.getByPath(dc, new Path(filePath, Path.Type.FILE), false);
    314314        }
    315         if (file != null)
    316         {
    317           design.getFileSet().setMember(file, fileType);
    318         }
    319         else
    320         {
    321           // TODO #1604
    322           //design.getFileSet().removeMember(fileType);
    323         }
     315        setOrAddFile(design, fileType, file);
    324316      }
    325317    }
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/DerivedBioAssayImporter.java

    r5713 r5719  
    391391          file = File.getByPath(dc, new Path(filePath, Path.Type.FILE), false);
    392392        }
    393         if (file != null)
    394         {
    395           bioAssay.getFileSet().setMember(file, fileType);
    396         }
    397         else
    398         {
    399           // TODO #1604
    400           //bioAssay.getFileSet().removeMember(fileType);
    401         }
     393        setOrAddFile(bioAssay, fileType, file);
    402394      }
    403395    }
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/RawBioAssayImporter.java

    r5713 r5719  
    461461          file = File.getByPath(dc, new Path(filePath, Path.Type.FILE), false);
    462462        }
    463         if (file != null)
    464         {
    465           rba.getFileSet().setMember(file, fileType);
    466         }
    467         else
    468         {
    469           // TODO #1604
    470           //rba.getFileSet().removeMember(fileType);
    471         }
     463        setOrAddFile(rba, fileType, file);
    472464      }
    473465    }
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ScanImporter.java

    r5713 r5719  
    255255      File imageFile = File.getByPath(dc, new Path(filePath, Path.Type.FILE), false);
    256256      DataFileType imageType = DataFileType.getByExternalId(dc, DataFileType.MICROARRAY_IMAGE);
    257       if (imageFile != null)
    258       {
    259         scan.getFileSet().setMember(imageFile, imageType);
    260       }
    261       else
    262       {
    263         // TODO #1604
    264         //scan.getFileSet().removeMember(imageType);
    265       }
     257      setOrAddFile(scan, imageType, imageFile);
    266258    }
    267259  }
  • trunk/src/test/data/test.batchimport.rawbioassays.txt

    r5177 r5719  
    22Raw data 1  The first data set  1 Generic   genepix Scan 1  Feature Feature Generic.1 Generic raw data  test.gpr
    33Raw data 2  The second  1 Generic Variant GenePix Scan 2  Feature Feature Generic.2 Generic raw data  test.gpr
     4Raw data 2                    Generic raw data  test.cel
    45Raw data 3.1  From same hyb 1 Affymetrix      Scan 3  Feature Feature Affy  CEL file  test.cel
    56Raw data 3.2  From same hyb 2 Affymetrix      Scan 3  Feature Feature Affy  CEL file  test.cel
Note: See TracChangeset for help on using the changeset viewer.