Changeset 3802


Ignore:
Timestamp:
Oct 3, 2007, 1:58:56 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

References #721: File validation is now in place. More robust code for users with not enough
permissions.

Location:
branches/filedb
Files:
1 added
19 edited

Legend:

Unmodified
Added
Removed
  • branches/filedb/src/clients/web/net/sf/basedb/clients/web/Base.java

    r3801 r3802  
    11101110  }
    11111111 
     1112  /**
     1113    Update files that are associated with a {@link FileStoreEnabled}
     1114    item. The <code>request</code> parameter is checked for parameters
     1115    with a name like <code>datafile.id</code> where <code>id</code> is
     1116    the numeric id of a {@link DataFileType}. The parameter value is the
     1117    path of the file to associated with the data file type, or null
     1118    to remove an existing association.
     1119   
     1120    @param dc A DbControl to access the database
     1121    @param item The item the files should be associated with
     1122    @param request The request object containing the selected files
     1123    @param validate If {@link FileSet#validate(DbControl, boolean)}
     1124      should be called or not
     1125    @param extractMetadata If meta data should be extracted or not
     1126      (requires that validate is true)
     1127    @since 2.5
     1128  */
    11121129  @SuppressWarnings("unchecked")
    1113   public static void updateFiles(DbControl dc, FileStoreEnabled item, HttpServletRequest request)
    1114     throws ItemModifiedException, BaseException
     1130  public static void updateFiles(DbControl dc, FileStoreEnabled item,
     1131    HttpServletRequest request, boolean validate, boolean extractMetadata,
     1132    ItemContext cc, int maxRecent)
    11151133  {
    11161134    Enumeration<String> names = (Enumeration<String>)request.getParameterNames();
     
    11221140      {
    11231141        int dataFileTypeId = Values.getInt(param.substring(9));
    1124         String filePath = request.getParameter(param);
     1142        DataFileType dft = DataFileType.getById(dc, dataFileTypeId);
     1143        String filePath = Values.getStringOrNull(request.getParameter(param));
    11251144        if (fileSet == null) fileSet = item.getFileSet();
    1126         DataFileType dft = DataFileType.getById(dc, dataFileTypeId);
    1127         File file = File.getByPath(dc, new Path(filePath, Path.Type.FILE), false);
    1128         fileSet.setMember(file, dft);
    1129       }
    1130     }
    1131    
     1145        if (filePath == null)
     1146        {
     1147          fileSet.removeMember(dft);
     1148        }
     1149        else
     1150        {
     1151          File file = File.getByPath(dc, new Path(filePath, Path.Type.FILE), false);
     1152          fileSet.setMember(file, dft);
     1153          if (cc != null)
     1154          {
     1155            cc.setRecent(file, dft.getExternalId(), maxRecent);
     1156          }
     1157        }
     1158      }
     1159    }
     1160    if (validate)
     1161    {
     1162      fileSet.validate(dc, extractMetadata);
     1163    }
    11321164  }
    11331165 
  • branches/filedb/src/core/net/sf/basedb/core/Affymetrix.java

    r3801 r3802  
    2626
    2727import net.sf.basedb.core.data.ReporterData;
     28import net.sf.basedb.core.filehandler.CdfFileHandler;
    2829import affymetrix.fusion.cdf.FusionCDFData;
    2930import affymetrix.fusion.cel.FusionCELData;
     
    356357    @throws InvalidDataException If the file is not a CDF file
    357358    @since 2.4
     359    @deprecated Use {@link CdfFileHandler#loadCdfFile(File)} instead
    358360  */
    359361  public static FusionCDFData loadCdfFile(File cdfFile)
    360362    throws ItemNotFoundException, InvalidDataException
    361363  {
    362     if (cdfFile == null) throw new InvalidUseOfNullException("cdfFile");
    363     if (cdfFile.getLocation() != Location.PRIMARY)
    364     {
    365       throw new ItemNotFoundException("File data is not online for file '" +
    366         cdfFile.getName() + "'; location=" + cdfFile.getLocation());
    367     }
    368     FusionCDFData cdf = new FusionCDFData();
    369     cdf.setFileName(cdfFile.getName());
    370     cdf.setInputStream(cdfFile.getDownloadStream(0));
    371     if (!cdf.readHeader())
    372     {
    373       throw new InvalidDataException("Could not read CDF file '" +
    374           cdfFile.getPath()+"': " + cdf.getError());
    375     }
    376     return cdf;
     364    return new CdfFileHandler().loadCdfFile(cdfFile);
    377365  }
    378366 
  • branches/filedb/src/core/net/sf/basedb/core/ArrayDesign.java

    r3801 r3802  
    633633  }
    634634 
     635  public void setNumFileFeatures(int numFeatures)
     636  {
     637    checkPermission(Permission.WRITE);
     638    getData().setNumFileFeatures(numFeatures);
     639    getData().setHasFeatures(numFeatures > 0 || getNumDbFeatures() > 0);
     640  }
     641 
    635642}
  • branches/filedb/src/core/net/sf/basedb/core/DataFileType.java

    r3801 r3802  
    380380 
    381381  /**
     382    Create a new instance of the {@link DataFileValidator} class specified
     383    by {@link #getValidatorClass()}.
     384    @return A validator instance or null if no class has been specified
     385    @throws BaseException If an instance of the class can't be created
     386  */
     387  public DataFileValidator getValidator()
     388  {
     389    String validatorClass = getData().getValidatorClass();
     390    if (validatorClass == null) return null;
     391    DataFileValidator validator = null;
     392    try
     393    {
     394      validator = (DataFileValidator)ClassUtil.checkAndLoadClass(
     395          null, validatorClass, true, DataFileValidator.class).newInstance();
     396    }
     397    catch (Throwable t)
     398    {
     399      throw new BaseException(t);
     400    }
     401    return validator;
     402  }
     403 
     404  /**
    382405    Get the class name of the Java class that is used to extract metadata from files of
    383406    this type. The class must implement the {@link DataFileMetadataReader} interface.
     
    418441 
    419442  /**
     443    Create a new instance of the {@link DataFileMetadataReader} class specified
     444    by {@link #getMetadataReaderClass()}.
     445    @return A metadata reader instance or null if no class has been specified
     446    @throws BaseException If an instance of the class can't be created
     447  */
     448  public DataFileMetadataReader getMetadataReader()
     449  {
     450    String readerClass = getData().getMetadataReaderClass();
     451    if (readerClass == null) return null;
     452    DataFileMetadataReader reader = null;
     453    try
     454    {
     455      reader = (DataFileMetadataReader)ClassUtil.checkAndLoadClass(
     456          null, readerClass, true, DataFileMetadataReader.class).newInstance();
     457    }
     458    catch (Throwable t)
     459    {
     460      throw new BaseException(t);
     461    }
     462    return reader;
     463  }
     464
     465 
     466  /**
    420467    Get a query that returns all platforms/variants that are using this
    421468    file type.
  • branches/filedb/src/core/net/sf/basedb/core/FileSet.java

    r3793 r3802  
    2424package net.sf.basedb.core;
    2525
     26import java.util.ArrayList;
     27import java.util.HashMap;
    2628import java.util.HashSet;
     29import java.util.LinkedList;
     30import java.util.List;
    2731import java.util.Map;
    2832import java.util.Set;
     
    3640import net.sf.basedb.core.data.FileSetMemberData;
    3741import net.sf.basedb.core.data.DataFileTypeData;
     42import net.sf.basedb.core.filehandler.DataFileHandler;
     43import net.sf.basedb.core.filehandler.DataFileMetadataReader;
     44import net.sf.basedb.core.filehandler.DataFileValidator;
    3845
    3946/**
     
    104111
    105112  /**
    106     The item this annotation set belongs to.
     113    The item this file set belongs to.
    107114  */
    108115  private FileStoreEnabled item;
     
    187194      granted |= Permission.grant(Permission.USE);
    188195    }
    189     else
     196    else if (item != null && item.hasPermission(Permission.READ))
    190197    {
    191198      granted |= Permission.grant(Permission.READ);       
     
    331338        FileSetMember m = dc.getItem(FileSetMember.class, member);
    332339        dc.deleteItem(m);
    333       }
    334     }
     340        DataFileMetadataReader metadataReader = type.getMetadataReader();
     341        if (metadataReader != null)
     342        {
     343          metadataReader.setItem(getItem());
     344          metadataReader.setFile(m);
     345          metadataReader.resetMetadata(dc);
     346        }
     347      }
     348    }
     349  }
     350 
     351  /**
     352    Remove all members in a file set.
     353    @throws PermissionDeniedException If the logged in user
     354      doesn't have write permission for this file set
     355  */
     356  public void removeAllMembers()
     357  {
     358    checkPermission(Permission.WRITE);
     359    getData().getMembers().clear();
    335360  }
    336361 
     
    435460  }
    436461 
     462  /**
     463    Validate the files in this file set. This method will
     464    load the validator and metadata reader for the {@link DataFileType}
     465    for each member in the file set. If more than one file type
     466    uses the same validator or metadata reader, they will all
     467    share the same instance. This method will not throw any errors
     468    that have been caused by the validation process. Errors are returned
     469    in the list and is reported to by setting the {@link FileSetMember#isValid()}
     470    and {@link FileSetMember#getErrorMessage()} properties for each invalid file.
     471    @param dc The DbControl to use in the validation process
     472    @param extractMetadata TRUE to also extract metadata, FALSE otherwise
     473    @return A list of validation errors, if everything is successful the
     474      list is empty
     475  */
     476  public List<Throwable> validate(DbControl dc, boolean extractMetadata)
     477  {
     478    checkPermission(Permission.WRITE);
     479    // Map: Classname --> DataFileHandler instance
     480    Map<String, DataFileHandlerWrapper> handlers =
     481      new HashMap<String, DataFileHandlerWrapper>();
     482 
     483    // All validation errors
     484    List<Throwable> errors = new LinkedList<Throwable>();
     485   
     486    // First pass, create validator/metadata reader instances
     487    for (FileSetMemberData memberData : getData().getMembers().values())
     488    {
     489      FileSetMember member = dc.getItem(FileSetMember.class, memberData);
     490      DataFileType dft = member.getDataFileType();
     491      String validatorClass = dft.getValidatorClass();
     492      String metadataReaderClass = dft.getMetadataReaderClass();
     493      DataFileHandlerWrapper validator = null;
     494      DataFileHandlerWrapper metadataReader = null;
     495     
     496      // Only one instance of each type is created
     497      if (validatorClass != null)
     498      {
     499        validator = handlers.get(validatorClass);
     500        if (validator == null)
     501        {
     502          validator = new DataFileHandlerWrapper(dft.getValidator(), getItem());
     503          handlers.put(validatorClass, validator);
     504        }
     505        validator.setFile(member);
     506      }
     507      if (extractMetadata && metadataReaderClass != null)
     508      {
     509        metadataReader = handlers.get(metadataReaderClass);
     510        if (metadataReader == null)
     511        {
     512          metadataReader = new DataFileHandlerWrapper(dft.getMetadataReader(), getItem());
     513          handlers.put(metadataReaderClass, metadataReader);
     514        }
     515        if (metadataReader != validator) metadataReader.setFile(member);
     516      }
     517    }
     518   
     519    // Second pass - validate and extract metadata
     520    for (DataFileHandlerWrapper handler : handlers.values())
     521    {
     522      boolean ignore = false;
     523      boolean isValid = true;
     524      String errorMessage = null;
     525      if (handler.isValidator)
     526      {
     527        try
     528        {
     529          handler.validate(dc);
     530        }
     531        catch (Throwable t)
     532        {
     533          ignore = t instanceof PermissionDeniedException;
     534          errors.add(t);
     535          isValid = false;
     536          errorMessage = t.getMessage();
     537          if (!ignore) handler.resetMetadata(dc);
     538        }
     539      }
     540      if (extractMetadata && handler.isMetadataReader && isValid)
     541      {
     542        try
     543        {
     544          handler.extractMetadata(dc);
     545        }
     546        catch (Throwable t)
     547        {
     548          ignore = t instanceof PermissionDeniedException;
     549          errors.add(t);
     550          isValid = false;
     551          errorMessage = t.getMessage();
     552          if (!ignore) handler.resetMetadata(dc);
     553        }
     554      }
     555      if (!ignore) handler.setValid(isValid, errorMessage);
     556    }
     557    return errors;
     558  }
    437559 
    438560 
     
    445567    }
    446568  }
     569  private static class DataFileHandlerWrapper
     570  {
     571    private final DataFileHandler handler;
     572    private final boolean isValidator;
     573    private final boolean isMetadataReader;
     574    private final FileStoreEnabled item;
     575    private final List<FileSetMember> files;
     576   
     577    DataFileHandlerWrapper(DataFileHandler handler, FileStoreEnabled item)
     578    {
     579      this.handler = handler;
     580      this.item = item;
     581      this.isValidator = handler instanceof DataFileValidator;
     582      this.isMetadataReader = handler instanceof DataFileMetadataReader;
     583      this.handler.setItem(item);
     584      this.files = new ArrayList<FileSetMember>();
     585    }
     586   
     587    void setFile(FileSetMember member)
     588    {
     589      handler.setFile(member);
     590      this.files.add(member);
     591    }
     592   
     593    void validate(DbControl dc)
     594    {
     595      if (isValidator) ((DataFileValidator)handler).validate(dc);
     596    }
     597   
     598    void extractMetadata(DbControl dc)
     599    {
     600      if (isMetadataReader) ((DataFileMetadataReader)handler).extractMetadata(dc);
     601    }
     602   
     603    void resetMetadata(DbControl dc)
     604    {
     605      if (isMetadataReader) ((DataFileMetadataReader)handler).resetMetadata(dc);
     606    }
     607   
     608    void setValid(Boolean isValid, String errorMessage)
     609    {
     610      for (FileSetMember member : files)
     611      {
     612        member.getData().setValid(isValid);
     613        member.getData().setErrorMessage(errorMessage);
     614      }
     615    }
     616   
     617  }
     618 
    447619}
  • branches/filedb/src/core/net/sf/basedb/core/FileSetMember.java

    r3800 r3802  
    130130  -------------------------------------------
    131131  */
     132  /**
     133    READ permission is granted to all users. CREATE, WRITE and DELETE permissions are
     134    granted if the logged in user has WRITE permission on the associated file set.
     135  */
     136  void initPermissions(int granted, int denied)
     137    throws BaseException
     138  {
     139    FileSet fileSet = getFileSet();
     140    if (fileSet.hasPermission(Permission.WRITE))
     141    {
     142      granted |= Permission.grant(Permission.CREATE, Permission.READ, Permission.WRITE, Permission.DELETE);       
     143    }
     144    else if (fileSet.hasPermission(Permission.USE))
     145    {
     146      granted |= Permission.grant(Permission.USE);
     147    }
     148    else if (fileSet.hasPermission(Permission.READ))
     149    {
     150      granted |= Permission.grant(Permission.READ);       
     151    }
     152    super.initPermissions(granted, denied);
     153  }
     154  PluginPermission getPluginPermissions()
     155  {
     156    return PluginPermission.NO_PLUGIN;
     157  }
    132158  // -------------------------------------------
    133159 
     
    168194    return getData().isValid();
    169195  }
     196 
     197  /**
     198    Get the error message if the validation failed.
     199    @return The error message or null if the file is valid or if it
     200      hasn't been validated
     201  */
     202  public String getErrorMessage()
     203  {
     204    return getData().getErrorMessage();
     205  }
    170206
    171207  private static class QueryRuntimeFilterImpl
  • branches/filedb/src/core/net/sf/basedb/core/ItemContext.java

    r3796 r3802  
    614614 
    615615  /**
     616    Add an item to the "recently used items" list. Each type of item
     617    has their own list and sublists which may contain at
     618    most <code>maxInList</code> items.
     619    <p>
     620    Note! The lists are stored as string of colon-separated ID:s in
     621    the setting given by the item type and sublist name. For example the
     622    recently used protocols are found in the setting:
     623    <code>getSetting("PROTOCOL.subList.recent")</code>. Client code is advised to
     624    not change these settings.
     625
     626    @param item The item to add
     627    @param subList The sublist
     628    @param maxInList The maximum number of items in the list
     629    @since 2.5
     630  */
     631  public void setRecent(BasicItem item, String subList, int maxInList)
     632  {
     633    setRecent(item.getType().name() + "." + subList, Integer.toString(item.getId()), maxInList);
     634  }
     635 
     636  /**
    616637    Add a value to the list of recently used values for the specified key.
    617638    Each key has it's own list of values which may contain at most
     
    649670 
    650671  /**
     672    Get the number of recently used items in a list with a sublist.
     673    @param itemType The type of items
     674    @param subList The name of the sublist
     675    @since 2.5
     676  */
     677  public int getNumRecent(Item itemType, String subList)
     678  {
     679    return getRecent(itemType.name() + "." + subList).size();
     680  }
     681 
     682  /**
    651683    Get the number of recently used value in the list.
    652684    @param key The key to the list
     
    670702  public List<? extends BasicItem> getRecent(DbControl dc, Item itemType)
    671703  {
    672     List<String> recentIds = getRecent(itemType.name());
     704    return loadRecent(dc, itemType, itemType.name());
     705  }
     706 
     707  /**
     708    Get all recently used items of the specified type in a given sublist.
     709    The list only contains items that the logged in user has read permission
     710    to and that hasn't been deleted. Thus, the {@link #getNumRecent(Item)}
     711    may return a larger number than what is actually returned in this
     712    list.
     713   
     714    @param dc The DbControl used to access the database
     715    @param itemType The type of items
     716    @param subList The name of the sublist
     717    @return A list with the items
     718    @since 2.5
     719  */
     720  public List<? extends BasicItem> getRecent(DbControl dc, Item itemType, String subList)
     721  {
     722    return loadRecent(dc, itemType, itemType.name() + "." + subList);
     723  }
     724 
     725  private List<? extends BasicItem> loadRecent(DbControl dc, Item itemType, String key)
     726  {
     727    List<String> recentIds = getRecent(key);
    673728    List<BasicItem> recent = new ArrayList<BasicItem>(recentIds.size());
    674729    for (String id : recentIds)
     
    687742  }
    688743 
     744 
    689745  public BasicItem getRecent(DbControl dc, Item itemType, int index)
    690746  {
    691     List<String> recentIds = getRecent(itemType.name());
     747    return loadRecent(dc, itemType, itemType.name(), index);
     748  }
     749 
     750  public BasicItem getRecent(DbControl dc, Item itemType, String subList, int index)
     751  {
     752    return loadRecent(dc, itemType, itemType.name() + "." + subList, index);
     753  }
     754 
     755  private BasicItem loadRecent(DbControl dc, Item itemType, String key, int index)
     756  {
     757    List<String> recentIds = getRecent(key);
    692758    BasicItem item = null;
    693759    if (index >= 0 && index < recentIds.size())
     
    707773    return item;
    708774  }
     775
    709776 
    710777  /**
     
    742809  {
    743810    setRecent(itemType.name(), null);
     811  }
     812 
     813  /**
     814    Clear the recently used items sublist from items of the specified type.
     815    @param itemType The type of items
     816    @param subList The name of the sublist
     817  */
     818  public void clearRecent(Item itemType, String subList)
     819  {
     820    setRecent(itemType.name() + "." + subList, null);
    744821  }
    745822 
  • branches/filedb/src/core/net/sf/basedb/core/data/FileSetMemberData.java

    r3793 r3802  
    100100  }
    101101
     102  private String errorMessage;
     103  /**
     104    The error message if the file validation failed.
     105    @hibernate.property column="`error_message`" type="text"
     106  */
     107  public String getErrorMessage()
     108  {
     109    return errorMessage;
     110  }
     111  public void setErrorMessage(String errorMessage)
     112  {
     113    this.errorMessage = errorMessage;
     114  }
    102115
    103116}
  • branches/filedb/src/core/net/sf/basedb/core/filehandler/AbstractDataFileHandler.java

    r3793 r3802  
    2424package net.sf.basedb.core.filehandler;
    2525
     26import java.util.HashMap;
     27import java.util.Map;
     28
     29import net.sf.basedb.core.DataFileType;
     30import net.sf.basedb.core.FileSetMember;
     31import net.sf.basedb.core.FileStoreEnabled;
     32
    2633/**
    2734  This abstract class should, if possible, be used as a
     
    4148  implements DataFileHandler
    4249{
     50  private FileStoreEnabled item;
     51  private Map<String, FileSetMember> members;
     52 
     53  protected AbstractDataFileHandler()
     54  {}
     55 
     56  /*
     57    From the DataFileHandler interface
     58    ----------------------------------------
     59  */
     60  public void setItem(FileStoreEnabled item)
     61  {
     62    this.item = item;
     63  }
     64  public void setFile(FileSetMember member)
     65  {
     66    if (members == null)
     67    {
     68      members = new HashMap<String, FileSetMember>();
     69    }
     70    members.put(member.getDataFileType().getExternalId(), member);
     71  }
     72  // -------------------------------------------
    4373
     74  /**
     75    Get the itemt that was set by {@link #setItem(FileStoreEnabled)}
     76  */
     77  protected FileStoreEnabled getItem()
     78  {
     79    return item;
     80  }
     81 
     82  /**
     83    Get the file set member of a specific {@link DataFileType}.
     84    @param dataFileType The external ID of the data file type.
     85    @return The file set member or null if no member of
     86      that type is found
     87   */
     88  protected FileSetMember getMember(String dataFileType)
     89  {
     90    return members == null ? null : members.get(dataFileType);
     91  }
     92 
    4493}
  • branches/filedb/src/core/net/sf/basedb/core/filehandler/CdfFileHandler.java

    r3793 r3802  
    2424package net.sf.basedb.core.filehandler;
    2525
     26import affymetrix.fusion.cdf.FusionCDFData;
     27import net.sf.basedb.core.ArrayDesign;
     28import net.sf.basedb.core.DataFileType;
     29import net.sf.basedb.core.DbControl;
     30import net.sf.basedb.core.File;
     31import net.sf.basedb.core.FileSetMember;
     32import net.sf.basedb.core.InvalidDataException;
     33import net.sf.basedb.core.Platform;
     34
    2635/**
    2736  File handler that can validate and extract metadata from
     
    3342*/
    3443public class CdfFileHandler
     44  extends AffymetrixFileHandler
    3545  implements DataFileValidator, DataFileMetadataReader
    3646{
    3747
     48  private FusionCDFData cdfData;
     49 
     50  public CdfFileHandler()
     51  {}
     52 
     53  /*
     54    From the DataFileValidator interface
     55    ----------------------------------------
     56  */
     57  /**
     58    Check that the array design is using the Affymetrix platform
     59    ({@link Platform#AFFYMETRIX}) and that the file selected
     60    as the CDF file really is a CDF file.
     61  */
     62  public void validate(DbControl dc)
     63  {
     64    ArrayDesign design = (ArrayDesign)getItem();
     65    // Check platform
     66    if (!isAffymetrix(design))
     67    {
     68      throw new InvalidDataException("Array design '" + design +
     69        "' is not using the Affymetrix platform");
     70    }
     71   
     72    // Get the member for CDF file type
     73    FileSetMember cdfMember = getMember(DataFileType.AFFYMETRIX_CDF);
     74    if (cdfMember != null)
     75    {
     76      // Verify CDF file
     77      File cdfFile = cdfMember.getFile();
     78      cdfData = loadCdfFile(cdfFile);
     79    }
     80  }
     81 
     82  /**
     83    Reads the number of probesets in the CDF file and stores it
     84    in {@link ArrayDesign#getNumFileFeatures()}.
     85  */
     86  public void extractMetadata(DbControl dc)
     87  {
     88    if (cdfData == null)
     89    {
     90      FileSetMember cdfMember = getMember(DataFileType.AFFYMETRIX_CDF);
     91      if (cdfMember != null) cdfData = loadCdfFile(cdfMember.getFile());
     92    }
     93    if (cdfData != null)
     94    {
     95      ArrayDesign design = (ArrayDesign)getItem();
     96      design.setNumFileFeatures(cdfData.getHeader().getNumProbeSets());
     97    }
     98  }
     99 
     100  /**
     101    Reset {@link ArrayDesign#getNumFileFeatures()} to 0.
     102  */
     103  public void resetMetadata(DbControl dc)
     104  {
     105    ArrayDesign design = (ArrayDesign)getItem();
     106    design.setNumFileFeatures(0);
     107  }
     108  // -------------------------------------------
     109
    38110}
  • branches/filedb/src/core/net/sf/basedb/core/filehandler/CelFileHandler.java

    r3793 r3802  
    2424package net.sf.basedb.core.filehandler;
    2525
     26import net.sf.basedb.core.DbControl;
     27
    2628/**
    2729  File handler that can validate and extract metadata from
     
    3335*/
    3436public class CelFileHandler
     37  extends AffymetrixFileHandler
    3538  implements DataFileValidator, DataFileMetadataReader
    3639{
    3740
     41  public CelFileHandler()
     42  {}
     43 
     44  public void validate(DbControl dc)
     45  {
     46   
     47  }
     48 
     49  public void extractMetadata(DbControl dc)
     50  {
     51   
     52  }
     53 
     54  public void resetMetadata(DbControl dc)
     55  {
     56   
     57  }
     58
    3859}
  • branches/filedb/src/core/net/sf/basedb/core/filehandler/DataFileHandler.java

    r3793 r3802  
    2525
    2626import net.sf.basedb.core.DataFileType;
     27import net.sf.basedb.core.FileSetMember;
     28import net.sf.basedb.core.FileStoreEnabled;
    2729
    2830/**
     
    3941*/
    4042public interface DataFileHandler
    41 
    4243{
    4344
     45  /**
     46    Sets the item that we are currently working with.
     47    @param item The item
     48  */
     49  public void setItem(FileStoreEnabled item);
     50 
     51  /**
     52    Set the file that is part of the file set with a {@link DataFileType}
     53    that is using this file handler. If the file set contains more
     54    than one file with the same data handler this method is called
     55    one time for each member.
     56    @param member The member of the file set
     57  */
     58  public void setFile(FileSetMember member);
     59
    4460}
  • branches/filedb/src/core/net/sf/basedb/core/filehandler/DataFileMetadataReader.java

    r3793 r3802  
    2525
    2626import net.sf.basedb.core.DataFileType;
     27import net.sf.basedb.core.DbControl;
    2728
    2829/**
     
    4041{
    4142
     43  /**
     44    Extract metadata from the file(s) and write the metadata
     45    to the item passed to the {@link DataFileHandler#setItem(net.sf.basedb.core.FileStoreEnabled)}
     46    method.
     47   
     48    @param dc A DbControl object that can be used for database
     49      access
     50  */
     51  public void extractMetadata(DbControl dc);
     52
     53  /**
     54    Reset all metadata that this class normally can set. This method is called
     55    if the validation of a file failed. Any previous metadata that may signal
     56    that a valid file is present should be reset.
     57   
     58    @param dc A DbControl object that can be used for database
     59      access
     60  */
     61  public void resetMetadata(DbControl dc);
    4262}
  • branches/filedb/src/core/net/sf/basedb/core/filehandler/DataFileValidator.java

    r3793 r3802  
    2525
    2626import net.sf.basedb.core.DataFileType;
     27import net.sf.basedb.core.DbControl;
     28import net.sf.basedb.core.InvalidDataException;
     29import net.sf.basedb.core.PermissionDeniedException;
    2730
    2831/**
     
    3942  extends DataFileHandler
    4043{
    41 
     44 
     45  /**
     46    Validate the file(s) that has been added to this validator
     47    with the {@link DataFileHandler#setFile(net.sf.basedb.core.FileSetMember)}
     48    method. This method is recommended to throw an {@link InvalidDataException}
     49    or a subclass if the file is not a valid file. {@link PermissionDeniedException}:s
     50    are ignored by the core and will not change the validation status.
     51   
     52    @param dc A DbControl object that can be used for database
     53      access
     54    @throws InvalidDataException If the validator detects an invalid
     55      file
     56  */
     57  public void validate(DbControl dc)
     58    throws InvalidDataException;
    4259}
  • branches/filedb/www/common/datafiles/list_files.jsp

    r3801 r3802  
    9090    for (FileSetMember member : query.list(dc))
    9191    {
    92       members.put(member.getDataFileType(), member);
     92      DataFileType dft = null;
     93      try
     94      {
     95        dft = member.getDataFileType();
     96      }
     97      catch (Throwable t)
     98      {
     99        dft = DataFileType.getNew(dc, "", itemType);
     100      }
     101      members.put(dft, member);
    93102    }
    94103  }
     
    109118    for (PlatformFileType pft : query.list(dc))
    110119    {
    111       DataFileType dft = pft.getDataFileType();
    112       platformFileTypes.put(dft, pft);
    113       if (!members.containsKey(dft))
    114       {
    115         members.put(dft, null);
    116       }
     120      DataFileType dft = null;
     121      try
     122      {
     123        dft = pft.getDataFileType();
     124        platformFileTypes.put(dft, pft);
     125        if (!members.containsKey(dft))
     126        {
     127          members.put(dft, null);
     128        }
     129      }
     130      catch (Throwable t)
     131      {}
    117132    }
    118133  }
     
    158173        />
    159174        <tbl:columndef
    160           id="valid"
    161           title="Valid"
     175          id="validation"
     176          title="Validation"
    162177        />
    163178        <tbl:data>
     
    168183          for (Map.Entry<DataFileType, FileSetMember> entry : members.entrySet())
    169184          {
    170             DataFileType dft = entry.getKey();
    171185            FileSetMember member = entry.getValue();
     186            Boolean validFile = null;
     187            String validationMessage = "";
    172188            boolean readFile = true;
    173189            File file = null;
    174             Boolean validFile = null;
     190            boolean readDataFileType = true;
     191            DataFileType dft = null;
     192            if (member != null)
     193            {
     194              try
     195              {
     196                file = member.getFile();
     197              }
     198              catch (PermissionDeniedException ex)
     199              {
     200                readFile = false;
     201              }
     202              try
     203              {
     204                dft = member.getDataFileType();
     205              }
     206              catch (PermissionDeniedException ex)
     207              {
     208                readDataFileType = false;
     209              }
     210            }
    175211            PlatformFileType pft = platformFileTypes.get(dft);
    176212            boolean isRequired = pft == null ? false : pft.isRequired();
    177             if (member != null)
     213            String icon = null;
     214            if (member == null)
     215            {
     216              if (isRequired)
     217              {
     218                icon = "warning.gif";
     219                validationMessage = "Missing a required file";
     220              }
     221            }
     222            else
    178223            {
    179224              validFile = member.isValid();
    180               try
    181               {
    182                 file = member.getFile();
    183               }
    184               catch (PermissionDeniedException ex)
    185               {
    186                 readFile = false;
     225              if (Boolean.TRUE.equals(validFile))
     226              {
     227                validationMessage = "Ok";
     228                icon = "ok.gif";
     229              }
     230              else if (Boolean.FALSE.equals(validFile))
     231              {
     232                validationMessage = HTML.encodeTags(member.getErrorMessage());
     233                icon = "error.gif";
     234              }
     235              else
     236              {
     237                validationMessage = "<i>- not validated -</i>";
    187238              }
    188239            }
    189240            %>
    190241            <tbl:row>
    191               <tbl:cell column="type"><%=Base.getLinkedName(ID, dft, false, true)%></tbl:cell>
     242              <tbl:cell column="type"><%=Base.getLinkedName(ID, dft, !readDataFileType, true)%></tbl:cell>
    192243              <tbl:cell column="file"><%=Base.getLinkedFile(ID, file, !readFile, true, true, "../../")%></tbl:cell>
    193244              <tbl:cell column="required"><%=isRequired ? "yes" : "no" %></tbl:cell>
    194               <tbl:cell column="valid"><%=validFile == null ? "<i>- not validated -</i>" : Boolean.TRUE.equals(validFile) ? "yes" : "no" %></tbl:cell>
     245              <tbl:cell column="validation">
     246                <base:icon image="<%=icon%>" visible="<%=icon != null %>" />
     247                <%=validationMessage %>
     248              </tbl:cell>
    195249            </tbl:row>
    196250            <%
  • branches/filedb/www/common/datafiles/select_files.jsp

    r3801 r3802  
    2929  import="net.sf.basedb.core.DbControl"
    3030  import="net.sf.basedb.core.Item"
     31  import="net.sf.basedb.core.ItemContext"
    3132  import="net.sf.basedb.core.Type"
    3233  import="net.sf.basedb.core.BasicItem"
     
    7172final int platformId = Values.getInt(request.getParameter("platform_id"), -1);
    7273final int variantId = Values.getInt(request.getParameter("variant_id"), -1);
     74final ItemContext cc = sc.getCurrentContext(itemType);
    7375
    7476final DbControl dc = sc.newDbControl();
     
    8890  PlatformVariant variant = null;
    8991  Platform platform = null;
    90  
    91   if (variantId > 0)
    92   {
    93     variant = PlatformVariant.getById(dc, variantId);
    94     platform = variant.getPlatform();
    95   }
    96   else if (platformId > 0)
    97   {
    98     platform = Platform.getById(dc, platformId);
    99   }
    100   else if (item != null)
    101   {
    102     variant = item.getVariant();
    103     platform = item.getPlatform();
     92  boolean deniedPlatform = false;
     93  try
     94  {
     95    if (variantId > 0)
     96    {
     97      variant = PlatformVariant.getById(dc, variantId);
     98      platform = variant.getPlatform();
     99    }
     100    else if (platformId > 0)
     101    {
     102      platform = Platform.getById(dc, platformId);
     103    }
     104    else if (item != null)
     105    {
     106      variant = item.getVariant();
     107      platform = item.getPlatform();
     108    }
     109  }
     110  catch (PermissionDeniedException ex)
     111  {
     112    deniedPlatform = true; 
    104113  }
    105114 
     
    109118  List<DataFileType> fileTypes = fileTypeQuery.list(dc);
    110119 
    111  
    112120  String title = "Select data files for " +
    113121    HTML.encodeTags((item instanceof Nameable ? ((Nameable)item).getName() :
     
    118126  final StringBuilder sb = new StringBuilder();
    119127  List<File> recentFiles = null;
     128 
    120129  %>
    121130<%@page import="net.sf.basedb.core.PlatformFileType"%>
     
    139148    var frm = document.forms['datafiles'];
    140149    frm[lastFileInputName].value = path;
     150    fileOnChange(lastFileInputName);
     151  }
     152  function fileOnChange(inputName)
     153  {
     154    var frm = document.forms['datafiles'];
     155    if (frm[inputName].value != '')
     156    {
     157      frm['datafiles.validate'].checked = true;
     158      frm['datafiles.metadata'].checked = true;
     159    }
     160  }
     161  function recentOnChange(inputName)
     162  {
     163    var frm = document.forms['datafiles'];
     164    var recentInput = frm['recent.'+inputName];
     165    if (recentInput.selectedIndex > 0)
     166    {
     167      var path = recentInput[recentInput.selectedIndex].text;
     168      if (frm[inputName].value != path)
     169      {
     170        frm[inputName].value = path;
     171        fileOnChange(inputName);
     172      }
     173      recentInput.selectedIndex = 0;
     174    }
    141175  }
    142176  </script>
     
    148182    <table class="form" cellspacing="2" border="0" cellpadding="0" width="100%">
    149183    <%
     184    if (deniedPlatform)
     185    {
     186      %>
     187      <div class="error">Denied</div>
     188      <%
     189    }
     190    %>
     191    <%
    150192    for (DataFileType dft : fileTypes)
    151193    {
    152194      PlatformFileType pft = platform == null ?
    153       null : platform.getFileType(dft, variant);
     195        null : platform.getFileType(dft, variant);
    154196      boolean isRequired = pft == null ? false : pft.isRequired();
    155197      FileSetMember member = fileSet == null || !fileSet.hasMember(dft) ?
    156198        null : fileSet.getMember(dft);
    157       File file = member == null ? null : member.getFile();
    158       String path = file == null ? "" : file.getPath().toString();
     199      File file = null;
     200      boolean deniedFile = false;
     201      if (member != null)
     202      {
     203        try
     204        {
     205          file = member.getFile();
     206        }
     207        catch (PermissionDeniedException ex)
     208        {
     209          deniedFile = true;
     210        }
     211      }
     212     
     213      String path = "";
     214      if (file != null)
     215      {
     216        path = file.getPath().toString();
     217      }
     218      else if (deniedFile || deniedPlatform)
     219      {
     220        path = "- denied -";
     221      }
    159222      String inputName= "datafile."+dft.getId();
     223      recentFiles = (List<File>)cc.getRecent(dc, Item.FILE, dft.getExternalId());
    160224      %>
    161225      <tr>
     
    164228          <table border="0" cellspacing="0" cellpadding="0">
    165229          <tr>
    166             <td><input <%=isRequired ? requiredClazz : clazz%> type="text"
     230            <td>     
     231              <input <%=isRequired ? requiredClazz : clazz%> type="text"
    167232              name="<%=inputName%>" value="<%=HTML.encodeTags(path)%>"
    168               size="50" title="<%=HTML.encodeTags(dft.getDescription())%>">&nbsp;</td>
     233              size="50" title="<%=HTML.encodeTags(dft.getDescription())%>"
     234              <%=deniedFile || deniedPlatform ? "disabled" : "" %>
     235              onchange="fileOnChange('<%=inputName%>')">&nbsp;
     236            </td>
    169237            <td><base:button
    170238                title="Browse&hellip;"
    171239                onclick="<%="browseOnClick('"+inputName+"')"%>"
     240                disabled="<%=deniedFile || deniedPlatform %>"
    172241                />
    173242            </td>
     
    176245        </td>
    177246      </tr>
     247      <tr>
     248        <td align="right"></td>
     249        <td>
     250        <%
     251        if (recentFiles != null && recentFiles.size() > 0)
     252        {
     253          %>
     254          <select name="recent.<%=inputName%>" onchange="recentOnChange('<%=inputName%>')">
     255          <option value="">- recently used -
     256          <%
     257          for (File recent : recentFiles)
     258          {
     259            %>
     260            <option value="<%=recent.getId()%>"><%=HTML.encodeTags(recent.getPath().toString())%>
     261            <%
     262          }
     263          %>
     264          </select>
     265          <%
     266        }
     267        %>
     268        </td>
     269      </tr>
    178270      <%
    179271    }
    180272    %>
     273    <tr>
     274      <td class="prompt">Validate</td>
     275      <td><input type="checkbox" value="1" name="datafiles.validate"></td>
     276    </tr>
     277    <tr>
     278      <td class="prompt">Extract metadata</td>
     279      <td><input type="checkbox" value="1" name="datafiles.metadata"></td>
     280    </tr>
    181281    </table>
    182282
  • branches/filedb/www/include/scripts/platforms.js

    r3801 r3802  
    4545  this.addDataFilesToForm = function(theFrame, frm)
    4646  {
    47    
    48     for (var i = 0; i < theFrame.document.forms['datafiles'].length; i++)
     47    var dataFilesFrm = theFrame.document.forms['datafiles'];
     48    for (var i = 0; i < dataFilesFrm.length; i++)
    4949    {
    50       var input = theFrame.document.forms['datafiles'][i];
    51       Forms.createHidden(frm, input.name, input.value);
     50      var input = dataFilesFrm[i];
     51      if (!input.disabled)
     52      {
     53        Forms.createHidden(frm, input.name, input.value);
     54      }
    5255    }
    5356  }
  • branches/filedb/www/lims/arraydesigns/edit_design.jsp

    r3801 r3802  
    6767  ArrayDesign design = null;
    6868 
     69  boolean deniedPlatform = false;
    6970  Platform currentPlatform = null;
    7071  PlatformVariant currentVariant = null;
     
    8182    title = "Edit array design -- " + HTML.encodeTags(design.getName());
    8283   
    83     currentPlatform = design.getPlatform();
    84     currentVariant = design.getVariant();
     84    try
     85    {
     86      currentPlatform = design.getPlatform();
     87      currentVariant = design.getVariant();
     88    }
     89    catch (PermissionDeniedException ex)
     90    {
     91      deniedPlatform = true;
     92    }
    8593    design.checkPermission(Permission.WRITE);
    8694  }
     
    178186    {
    179187      var frm = document.forms['design'];
     188      if (frm.platform.length == 0) return 0;
    180189      var pv = frm.platform[frm.platform.selectedIndex].value.split(':');
    181190      return pv[0];
     
    185194    {
    186195      var frm = document.forms['design'];
     196      if (frm.platform.length == 0) return 0;
    187197      var pv = frm.platform[frm.platform.selectedIndex].value.split(':');
    188198      return pv.length > 1 ? pv[1] : null;
     
    268278        <td class="prompt">Platform</td>
    269279        <td>
    270           <select name="platform" onchange="platformOnChange()">
     280          <select name="platform" onchange="platformOnChange()" <%=deniedPlatform ? "disabled" : "" %>>
     281          <%
     282          if (deniedPlatform)
     283          {
     284            %>
     285            <option value="-1">- denied -
     286            <%
     287          }
     288          %>
    271289          </select>
    272290        </td>
  • branches/filedb/www/lims/arraydesigns/index.jsp

    r3801 r3802  
    176176
    177177    // Data files tab
    178     Base.updateFiles(dc, design, request);
     178    boolean validate = Values.getBoolean(request.getParameter("datafiles.validate"));
     179    boolean metadata = Values.getBoolean(request.getParameter("datafiles.metadata"));
     180    Base.updateFiles(dc, design, request, validate, metadata, cc, maxRecent);
    179181   
    180182    // Annotations tab
Note: See TracChangeset for help on using the changeset viewer.