Changeset 5721


Ignore:
Timestamp:
Sep 6, 2011, 3:39:13 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

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

Added 'too many files' validation rule to the Item overview that links with the 'Allow multiple files' setting.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/util/overview/OverviewUtil.java

    r5689 r5721  
    120120            Validator.DATAFILE_INVALID, Validator.DATAFILE_NOTVALIDATED,
    121121            Validator.MISSING_DATAFILE, Validator.DATAFILE_NOTPLATFORM,
     122            Validator.DATAFILE_TOOMANYFILES,
    122123            Validator.DATAFILE_INVALID_ITEM, Validator.DENIED_DATAFILETYPE,
    123124            Validator.DENIED_FILE
  • trunk/src/core/net/sf/basedb/util/overview/Validator.java

    r5651 r5721  
    748748
    749749  /**
    750     Validator rule that checks if all files required by the platform
    751     are present or not. Default severity level is WARNING.
     750    Validator rule that checks if a file is registered with
     751    a platform/item subtype or not. Default severity level is WARNING.
    752752  */
    753753  public static final Validator DATAFILE_NOTPLATFORM = new Validator(
    754       "datafile.notplatform", "File is not used by platform",
    755       "Checks that all data files are used by the current platform.",
    756       "File is not used by platform", Severity.WARNING
     754      "datafile.notplatform", "File is not used by platform/subtype",
     755      "Checks that all data files are used by the current platform/subtype.",
     756      "File is not used by platform/subtype", Severity.WARNING
     757    );
     758 
     759  /**
     760    Validator rule that checks if there are more than one file
     761    of a file type that doesn't allow multiple files. Default
     762    severity level is WARNING.
     763    @since 3.0
     764  */
     765  public static final Validator DATAFILE_TOOMANYFILES = new Validator(
     766      "datafile.toomanyfiles", "Too many files",
     767      "Checks if an item has too many files of a type that doesn't " +
     768      "allow more than one file.",
     769      "Too many files", Severity.WARNING
    757770    );
    758771 
  • trunk/src/core/net/sf/basedb/util/overview/validator/DataFileValidator.java

    r5713 r5721  
    2222package net.sf.basedb.util.overview.validator;
    2323
     24import java.util.List;
     25
    2426import net.sf.basedb.core.BasicItem;
    2527import net.sf.basedb.core.DataFileType;
    2628import net.sf.basedb.core.DbControl;
    2729import net.sf.basedb.core.File;
     30import net.sf.basedb.core.FileSet;
    2831import net.sf.basedb.core.FileSetMember;
    2932import net.sf.basedb.core.FileStoreEnabled;
    3033import net.sf.basedb.core.ItemQuery;
    31 import net.sf.basedb.core.ItemResultIterator;
     34import net.sf.basedb.core.ItemSubtype;
     35import net.sf.basedb.core.ItemSubtypeFileType;
    3236import net.sf.basedb.core.PermissionDeniedException;
    3337import net.sf.basedb.core.Platform;
    3438import net.sf.basedb.core.PlatformFileType;
    3539import net.sf.basedb.core.PlatformVariant;
    36 import net.sf.basedb.core.Type;
     40import net.sf.basedb.core.Subtypable;
     41import net.sf.basedb.core.UsableDataFileType;
    3742import net.sf.basedb.core.query.Expressions;
    3843import net.sf.basedb.core.query.Hql;
    39 import net.sf.basedb.core.query.Restriction;
    4044import net.sf.basedb.core.query.Restrictions;
    4145import net.sf.basedb.util.overview.Fix;
     
    5862  <li>File type doesn't match parent item type: {@link Validator#DATAFILE_INVALID_ITEM}
    5963  <li>File type is not part of used platform: {@link Validator#DATAFILE_NOTPLATFORM}
     64  <li>Too many files of a single-file file type: {@link Validator#DATAFILE_TOOMANYFILES}
    6065  <li>Missing a required file: {@link Validator#MISSING_DATAFILE}
    6166  </ul>
     
    141146      }
    142147
    143       // Check that the file type is part of the used platform/variant
     148      // Check that the file type is part of the used platform/variant/subtype
    144149      try
    145150      {
     
    161166            pvName = platform.getName();
    162167          }
    163           // TODO #1604
    164           /*
    165           if (platform.getFileType(fileType, variant) == null)
     168          if (platform.getFileType(fileType, variant, false) == null)
    166169          {
    167170            context.createFailure(Validator.DATAFILE_NOTPLATFORM, node,
     
    172175              );
    173176          }
    174           */
     177        }
     178        else if (parentItem instanceof Subtypable)
     179        {
     180          ItemSubtype subtype = ((Subtypable)parentItem).getItemSubtype();
     181          if (subtype != null)
     182          {
     183            if (subtype.getAssociatedDataFileType(fileType, false) == null)
     184            {
     185              context.createFailure(Validator.DATAFILE_NOTPLATFORM, node,
     186                  fileType.getName() + " can't be used with '" + subtype.getName() + "' subtype",
     187                  new Fix("Remove '" + fileType.getName() + "' from " + parentItem.getType().toString().toLowerCase(),
     188                    (BasicItem)parentItem, fileType),
     189                  new Fix("Add '" + fileType.getName() +"' to '" + subtype.getName() + "' subtype", subtype, fileType)
     190                );
     191            }
     192          }
    175193        }
    176194      }
     
    197215   
    198216    // Check that we have linked a file for all file types that
    199     // are required by the platform
     217    // are required by the platform and that the multiplicity setting
     218    // is ok
    200219    try
    201220    {
    202221      Platform platform = parentItem.getPlatform();
    203222      PlatformVariant variant = parentItem.getVariant();
    204       BasicItem pvItem = variant != null ? variant : platform;
    205       if (platform == null) return;
    206      
    207       // Create a query that returns all required platform file types
    208       ItemQuery<PlatformFileType> query = platform.getFileTypes(variant, variant == null);
    209       query.join(Hql.innerJoin("dataFileType", "dft"));
    210       query.restrict(
    211         Restrictions.eq(
    212           Hql.property("required"),
    213           Expressions.parameter("isRequired", true, Type.BOOLEAN)
    214         )
    215       );
    216       query.restrict(
    217         Restrictions.eq(
    218           Hql.property("dft", "itemType"),
    219           Expressions.integer(parentNode.getItemType().getValue())
    220         )
    221       );
    222       if (parentItem.hasFileSet())
    223       {
    224         // Add a restriction that filters out the files that we already have
    225         Restriction myFileSet = Restrictions.eq(Hql.property("mbr", "fileSet.id"),
    226             Hql.entity(parentItem.getFileSet()));
    227         query.join(Hql.leftJoin("dft", "fileSetMembers", "mbr", myFileSet, false));
    228         query.restrict(Restrictions.eq(Hql.alias("mbr"), null));
    229       }
    230       ItemResultIterator<PlatformFileType> it = query.iterate(dc);
    231       while (it.hasNext())
    232       {
    233         PlatformFileType pft = it.next();
    234         DataFileType dft = pft.getDataFileType();
    235         context.createFailure(Validator.MISSING_DATAFILE, parentNode,
    236             "Missing '" + dft.getName() + "'",
    237             new Fix("Add '" + dft.getName() + "' to " + parentItem.getType().toString().toLowerCase(),
    238                 (BasicItem)parentItem, dft),
    239             new Fix("Remove 'Required' flag from '" + dft.getName() + "'", pvItem, dft)
    240           );
     223      BasicItem pvItem = null;
     224      ItemSubtype subtype = parentItem instanceof Subtypable ?
     225          ((Subtypable)parentItem).getItemSubtype() : null;
     226      // List for holding all file types defined by the platform or subtype
     227      List<? extends UsableDataFileType> fileTypes = null;
     228      if (platform != null)
     229      {
     230        pvItem = variant != null ? variant : platform;
     231        // Create a query that returns all required platform file types
     232        ItemQuery<PlatformFileType> query = platform.getFileTypes(variant, variant == null);
     233        query.join(Hql.innerJoin("dataFileType", "dft"));
     234        query.restrict(
     235          Restrictions.eq(
     236            Hql.property("dft", "itemType"),
     237            Expressions.integer(parentNode.getItemType().getValue())
     238          )
     239        );
     240        fileTypes = query.list(dc);
     241      }
     242      if (subtype != null)
     243      {
     244        pvItem = subtype;
     245        // Create a query that returns all required subtype file types
     246        ItemQuery<ItemSubtypeFileType> query = subtype.getDataFileTypes();
     247        query.join(Hql.innerJoin("dataFileType", "dft"));
     248        query.restrict(
     249          Restrictions.eq(
     250            Hql.property("dft", "itemType"),
     251            Expressions.integer(parentNode.getItemType().getValue())
     252          )
     253        );
     254        fileTypes = query.list(dc);
     255      }
     256      FileSet fs = parentItem.hasFileSet() ? parentItem.getFileSet() : null;
     257      for (UsableDataFileType fileType : fileTypes)
     258      {
     259        DataFileType dft = fileType.getDataFileType();
     260        int numMembers = fs == null ? 0 : fs.getNumMembers(dft);
     261        if (fileType.isRequired() && numMembers == 0)
     262        {
     263          context.createFailure(Validator.MISSING_DATAFILE, parentNode,
     264              "Missing '" + dft.getName() + "'",
     265              new Fix("Add '" + dft.getName() + "' to " + parentItem.getType().toString().toLowerCase(),
     266                  (BasicItem)parentItem, dft),
     267              new Fix("Remove 'Required' flag from '" + dft.getName() + "'", pvItem, dft)
     268            );
     269        }
     270        if (!fileType.getAllowMultiple() && numMembers > 1)
     271        {
     272          context.createFailure(Validator.DATAFILE_TOOMANYFILES, parentNode,
     273              "Too many files: '" + dft.getName() + "'",
     274              new Fix("Remove '" + dft.getName() + "' from " + parentItem.getType().toString().toLowerCase(),
     275                  (BasicItem)parentItem, dft),
     276              new Fix("Check 'Allow multiple files' on '" + dft.getName() + "'", pvItem, dft)
     277            );
     278        }
    241279      }
    242280    }
  • trunk/www/views/derivedbioassays/edit_bioassay.jsp

    r5714 r5721  
    6060final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
    6161final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
     62final String tabId = Values.getString(request.getParameter("tab"), null);
    6263final int itemId = cc.getId();
    6364final String ID = sc.getId();
     
    672673    <form action="index.jsp?ID=<%=ID%>" method="post" name="bioAssay" onsubmit="return false;">
    673674    <input type="hidden" name="cmd" value="UpdateItem">
    674 
    675675    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
    676676    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>"
    677       position="bottom"  remember="<%=bioAssay != null%>" switch="switchTab"
     677      position="bottom" active="<%=tabId%>" remember="<%=tabId == null && bioAssay != null%>" switch="switchTab"
    678678      extensions="<%=invoker%>">
    679679    <t:tab id="info" title="Bioassay" validate="validateBioAssay()" helpid="derivedbioassay.edit">
  • trunk/www/views/derivedbioassays/index.jsp

    r5687 r5721  
    154154    // Display the edit page for a single item (should be opened in a popup)
    155155    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
    156     redirect = editPage;
     156    forward = editPage;
    157157  }
    158158  else if ("NewItem".equals(cmd))
Note: See TracChangeset for help on using the changeset viewer.