Changeset 3593


Ignore:
Timestamp:
Jul 24, 2007, 9:55:04 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #692: Jobs that are part of an experiment should use permissions from that experiment

Location:
trunk
Files:
11 edited

Legend:

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

    r3526 r3593  
    982982 
    983983  /**
     984    Reload the item from the database. If the item isn't attached to this
     985    DbControl it is automatically reattaced first.
     986   
     987    @param item The item to reload
     988    @since 2.4
     989  */
     990  public void refreshItem(BasicItem item)
     991  {
     992    if (isClosed()) throw new ConnectionClosedException();
     993    sc.updateLastAccess();
     994    if (!isAttached(item)) reattachItem(item);
     995    HibernateUtil.refresh(hSession, item.getData());
     996  }
     997 
     998  /**
    984999    Check if an item is attached to this <code>DbControl</code>.
    9851000    An item is attached if it is found in either the item cache (existing items
  • trunk/src/core/net/sf/basedb/core/HibernateUtil.java

    r3526 r3593  
    10871087  }
    10881088
     1089  /**
     1090    Reload the data from the database for a given entity.
     1091    @param session The Hibernate session which is connected to the
     1092      database
     1093    @param data The entity to reload
     1094    @since 2.4
     1095  */
     1096  static void refresh(Session session, BasicData data)
     1097  {
     1098    assert session != null : "session == null";
     1099    try
     1100    {
     1101      session.refresh(data);
     1102    }
     1103    catch(HibernateException ex)
     1104    {
     1105      throw new BaseException(ex);
     1106    }   
     1107  }
     1108 
    10891109  /**
    10901110    Checks if an item with the specified ID exists in the database.
  • trunk/src/core/net/sf/basedb/core/Install.java

    r3592 r3593  
    101101    method.
    102102  */
    103   public static final int NEW_SCHEMA_VERSION = Integer.valueOf(37).intValue();
     103  public static final int NEW_SCHEMA_VERSION = Integer.valueOf(38).intValue();
    104104 
    105105  public static synchronized void createTables(boolean update, final ProgressReporter progress)
  • trunk/src/core/net/sf/basedb/core/Job.java

    r3523 r3593  
    2525
    2626import net.sf.basedb.core.Transactional.Action;
     27import net.sf.basedb.core.data.ExperimentData;
    2728import net.sf.basedb.core.data.JobData;
    2829import net.sf.basedb.core.data.MessageData;
     
    283284    }
    284285  }
     286  /**
     287    Grant read permission if the logged in user has read permission to the
     288    experiment the job belongs to.
     289  */
     290  @Override
     291  void initPermissions(int granted, int denied)
     292  {
     293    ExperimentData parent = getData().getExperiment();
     294    if (parent != null)
     295    {
     296      int parentPermission = 0;
     297      if (parent.getId() != 0)
     298      {
     299        parentPermission = getSessionControl().getAllPermissions(parent);
     300      }
     301      else
     302      {
     303        BasicItem<?> basicParent = getDbControl().getItem(BasicItem.class, parent);
     304        parentPermission = Permission.grant(basicParent.getPermissions());
     305      }
     306      if (Permission.hasPermission(parentPermission, Permission.READ))
     307      {
     308        granted |= Permission.grant(Permission.READ);
     309      }
     310    }
     311    super.initPermissions(granted, denied);
     312  }
    285313  // -------------------------------------------
    286314
     
    351379      getData().setPluginConfiguration(pluginConfiguration.getData());
    352380      getData().setParameterVersion(pluginConfiguration.getParameterVersion());
     381    }
     382  }
     383 
     384  /**
     385    Get the experiment this job is a part of.
     386    @return The <code>Experiment</code> item, or null if this job
     387      isn't part of an experiment
     388    @since 2.4
     389  */
     390  public Experiment getExperiment()
     391  {
     392    return getDbControl().getItem(Experiment.class, getData().getExperiment());     
     393  }
     394  /**
     395    Set the experiment this job is part of. Once an experiment has been set, it
     396    can't be changed.
     397    @since 2.4
     398  */
     399  void setExperiment(Experiment experiment)
     400  {
     401    ExperimentData current = getData().getExperiment();
     402    ExperimentData next = experiment == null ? null : experiment.getData();
     403    if (current == null)
     404    {
     405      getData().setExperiment(next);
     406    }
     407    else if (!current.equals(next))
     408    {
     409      throw new PermissionDeniedException("A job can only be part of one experiment: " + this);
    353410    }
    354411  }
  • trunk/src/core/net/sf/basedb/core/Transformation.java

    r2998 r3593  
    151151  }
    152152
     153  // Keep reference to job so we can call Job.setExperiment at end of transaction
     154  private Job job;
     155 
    153156  /**
    154157    Creates a new experiment item from the given data.
     
    215218  */
    216219  /**
    217     Delete the product bioassaysets.
     220    Delete the product bioassaysets when deleting this transction.
     221    Set the experiment for the job when creating this transction.
    218222  */
    219223  void onBeforeCommit(Transactional.Action action)
     
    224228    {
    225229      deleteProducts();
     230    }
     231    else if (action == Transactional.Action.CREATE)
     232    {
     233      if (job != null)
     234      {
     235        getDbControl().refreshItem(job);
     236        job.setExperiment(getExperiment());
     237      }
    226238    }
    227239  }
     
    358370  private void setJob(Job job)
    359371  {
     372    this.job = job;
    360373    getData().setJob(job == null ? null : job.getData());
    361374  }
  • trunk/src/core/net/sf/basedb/core/Update.java

    r3557 r3593  
    3131import java.util.Date;
    3232import java.util.HashMap;
     33import java.util.HashSet;
    3334import java.util.List;
    3435import java.util.Map;
     36import java.util.Set;
    3537
    3638import org.hibernate.mapping.Table;
    3739
    3840import net.sf.basedb.core.data.DataCubeData;
     41import net.sf.basedb.core.data.ExperimentData;
    3942import net.sf.basedb.core.data.FileData;
    4043import net.sf.basedb.core.data.FormulaData;
     44import net.sf.basedb.core.data.JobData;
    4145import net.sf.basedb.core.data.MeasuredBioMaterialData;
    4246import net.sf.basedb.core.data.PlateData;
    4347import net.sf.basedb.core.data.PlateMappingData;
    4448import net.sf.basedb.core.data.SchemaVersionData;
     49import net.sf.basedb.core.data.TransformationData;
    4550import net.sf.basedb.core.dbengine.DbEngine;
    4651import net.sf.basedb.core.dbengine.TableInfo;
     
    439444    </td>
    440445  </tr>
     446
     447  <tr>
     448    <td>38</td>
     449    <td>
     450      <ul>
     451      <li>Added {@link net.sf.basedb.core.data.JobData#getExperiment()}.
     452      </ul>
     453      The update sets the experiment for jobs that belong to a single
     454      transformation.
     455    </td>
     456  </tr>
    441457
    442458  </table>
     
    617633      }
    618634     
    619       if (schemaVersion < 36)
    620       {
    621         if (progress != null) progress.display((int)(35*progress_factor), "--Updating schema version: " + schemaVersion + " -> 36...");       
    622         schemaVersion = setSchemaVersionInTransaction(session, 36);
    623       }
    624      
    625      
     635      //  Schemaversion 36-37 only updates the version number
    626636      if (schemaVersion < 37)
    627637      {
     
    630640      }
    631641     
     642      if (schemaVersion < 38)
     643      {
     644        if (progress != null) progress.display((int)(37*progress_factor), "--Updating schema version: " + schemaVersion + " -> 38...");       
     645        schemaVersion = updateToSchemaVersion38(session);
     646      }
     647     
    632648      /*
    633       if (schemaVersion < 38)
    634       {
    635         if (progress != null) progress.display((int)(37*progress_factor), "--Updating schema version: " + schemaVersion + " -> 38...");
    636         schemaVersion = setSchemaVersionInTransaction(session, 38);
     649      if (schemaVersion < 39)
     650      {
     651        if (progress != null) progress.display((int)(38*progress_factor), "--Updating schema version: " + schemaVersion + " -> 39...");
     652        schemaVersion = setSchemaVersionInTransaction(session, 39);
    637653        - or -
    638         schemaVersion = updateToSchemaVersion38(session);
     654        schemaVersion = updateToSchemaVersion39(session);
    639655      }
    640656      ... etc...
     
    13861402    return schemaVersion;   
    13871403  }
     1404 
     1405  /**
     1406    Set the experiment for jobs that belong to a single transformation.
     1407    @return The new schema version (=38)
     1408  */
     1409  private static int updateToSchemaVersion38(org.hibernate.Session session)
     1410  {
     1411    final int schemaVersion = 38;
     1412    org.hibernate.Transaction tx = null;
     1413    try
     1414    {
     1415      tx = HibernateUtil.newTransaction(session);
     1416 
     1417      // Load all transformations
     1418      org.hibernate.Query query = HibernateUtil.createQuery(session,
     1419        "SELECT t FROM TransformationData t");
     1420     
     1421      List<TransformationData> transformations = HibernateUtil.loadList(TransformationData.class, query);
     1422      Map<JobData, Set<ExperimentData>> experiments = new HashMap<JobData, Set<ExperimentData>>();
     1423      for (TransformationData transformation : transformations)
     1424      {
     1425        JobData job = transformation.getJob();
     1426        ExperimentData experiment = transformation.getExperiment();
     1427        if (!experiments.containsKey(job))
     1428        {
     1429          experiments.put(job, new HashSet<ExperimentData>());
     1430        }
     1431        experiments.get(job).add(experiment);
     1432      }
     1433     
     1434      for (Map.Entry<JobData, Set<ExperimentData>> entry : experiments.entrySet())
     1435      {
     1436        JobData job = entry.getKey();
     1437        Set<ExperimentData> jobExperiments = entry.getValue();
     1438        if (jobExperiments.size() == 1)
     1439        {
     1440          job.setExperiment(jobExperiments.iterator().next());
     1441          System.out.println("Setting experiment '" + job.getExperiment().getName() + "' to job " + job.getName());
     1442        }
     1443      }
     1444     
     1445      // Update the shcema version number
     1446      setSchemaVersion(session, schemaVersion);
     1447 
     1448      // Commit the changes
     1449      HibernateUtil.commit(tx);
     1450      log.info("updateToSchemaVersion38: OK");
     1451    }
     1452    catch (BaseException ex)
     1453    {
     1454      if (tx != null) HibernateUtil.rollback(tx);
     1455      log.error("updateToSchemaVersion38: FAILED", ex);
     1456      throw ex;
     1457    }
     1458    return schemaVersion;   
     1459  }
     1460
    13881461 
    13891462  /**
  • trunk/src/core/net/sf/basedb/core/data/ExperimentData.java

    r2962 r3593  
    313313    this.transformations = transformations;
    314314  }
     315 
     316  private Set<JobData> jobs;
     317  /**
     318    This is the inverse end.
     319    @see JobData#getExperiment()
     320    @since 2.4
     321    @hibernate.set lazy="true" inverse="true" cascade="delete"
     322    @hibernate.collection-key column="`experiment_id`"
     323    @hibernate.collection-one-to-many class="net.sf.basedb.core.data.JobData"
     324  */
     325  Set<JobData> getJobs()
     326  {
     327    return jobs;
     328  }
     329  void setJobs(Set<JobData> jobs)
     330  {
     331    this.jobs = jobs;
     332  }
    315333
    316334  private Set<AnnotationTypeData> experimentalFactors;
  • trunk/src/core/net/sf/basedb/core/data/JobData.java

    r3480 r3593  
    128128  }
    129129
     130  private ExperimentData experiment;
     131 
     132  /**
     133    The experiment this job is a part of.
     134    @since 2.4
     135    @hibernate.many-to-one column="`experiment_id`" not-null="false" outer-join="false"
     136  */
     137  public ExperimentData getExperiment()
     138  {
     139    return experiment;
     140  }
     141  public void setExperiment(ExperimentData experiment)
     142  {
     143    this.experiment = experiment;
     144  }
     145 
    130146  private int parameterVersion;
    131147  /**
  • trunk/www/my_base/messages/view_message.jsp

    r2978 r3593  
    157157        <td><%=HTML.encodeTags(job.getName())%></td>
    158158      </tr>
    159       <tr valign=top>
     159      <tr valign="top">
    160160        <td class="prompt">Description</td>
    161161        <td>
     
    163163        </td>
    164164      </tr>
    165       <tr valign=top>
     165      <tr valign="top">
    166166        <td class="prompt">Priority</td>
    167167        <td>
     
    169169        </td>
    170170      </tr>
    171       <tr valign=top>
     171      <tr valign="top">
    172172        <td class="prompt">Status</td>
    173173        <td>
     
    175175        </td>
    176176      </tr>
    177       <tr valign=top>
     177      <tr valign="top">
    178178        <td class="prompt">Percent complete</td>
    179179        <td>
     
    206206        </td>
    207207      </tr>
    208       <tr valign=top>
     208      <tr valign="top">
    209209        <td class="prompt">Created</td>
    210210        <td>
     
    212212        </td>
    213213      </tr>
    214       <tr valign=top>
     214      <tr valign="top">
    215215        <td class="prompt">Started</td>
    216216        <td>
     
    218218        </td>
    219219      </tr>
    220       <tr valign=top>
     220      <tr valign="top">
    221221        <td class="prompt">Ended</td>
    222222        <td>
     
    224224        </td>
    225225      </tr>
    226       <tr valign=top>
     226      <tr valign="top">
    227227        <td class="prompt">Server</td>
    228228        <td>
     
    230230        </td>
    231231      </tr>
    232       <tr valign=top>
     232      <tr valign="top">
     233        <td class="prompt">User</td>
     234        <td>
     235          <base:propertyvalue item="<%=job%>" property="owner.name" />
     236        </td>
     237      </tr>
     238      <tr valign="top">
     239        <td class="prompt">Experiment</td>
     240        <td>
     241          <base:propertyvalue item="<%=job%>" property="experiment.name" />
     242        </td>
     243      </tr>
     244      <tr valign="top">
    233245        <td class="prompt">Plugin</td>
    234246        <td>
     
    236248        </td>
    237249      </tr>
    238       <tr valign=top>
     250      <tr valign="top">
    239251        <td class="prompt">Configuration</td>
    240252        <td>
  • trunk/www/views/jobs/list_jobs.jsp

    r3190 r3593  
    329329        title="Type"
    330330        enumeration="<%=pluginTypes%>"
     331        sortable="true"
     332        filterable="true"
     333        exportable="true"
     334      />
     335      <tbl:columndef
     336        id="experiment"
     337        property="experiment.name"
     338        datatype="string"
     339        title="Experiment"
    331340        sortable="true"
    332341        filterable="true"
     
    579588                  %>
    580589                </tbl:cell>
     590                <tbl:cell column="experiment"
     591                  ><base:propertyvalue
     592                    item="<%=item%>"
     593                    property="experiment"
     594                    enableEditLink="<%=mode.hasEditLink()%>"
     595                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
     596                  /></tbl:cell>
    581597                <tbl:cell column="plugin">
    582598                  <%
  • trunk/www/views/jobs/view_job.jsp

    r3523 r3593  
    155155        <td><%=HTML.niceFormat(job.getDescription())%></td>
    156156      </tr>
    157       <tr valign=top>
     157      <tr valign="top">
    158158        <td class="prompt">Priority</td>
    159159        <td>
     
    161161        </td>
    162162      </tr>
    163       <tr valign=top>
     163      <tr valign="top">
    164164        <td class="prompt">Status</td>
    165165        <td>
     
    198198        </td>
    199199      </tr>
    200       <tr valign=top>
     200      <tr valign="top">
    201201        <td class="prompt">Created</td>
    202202        <td>
     
    204204        </td>
    205205      </tr>
    206       <tr valign=top>
     206      <tr valign="top">
    207207        <td class="prompt">Started</td>
    208208        <td>
     
    210210        </td>
    211211      </tr>
    212       <tr valign=top>
     212      <tr valign="top">
    213213        <td class="prompt">Ended</td>
    214214        <td>
     
    216216        </td>
    217217      </tr>
    218       <tr valign=top>
     218      <tr valign="top">
    219219        <td class="prompt">Server</td>
    220220        <td>
     
    222222        </td>
    223223      </tr>
    224       <tr valign=top>
     224      <tr valign="top">
     225        <td class="prompt">User</td>
     226        <td>
     227          <base:propertyvalue item="<%=job%>" property="owner.name" />
     228        </td>
     229      </tr>
     230      <tr valign="top">
     231        <td class="prompt">Experiment</td>
     232        <td>
     233          <base:propertyvalue item="<%=job%>" property="experiment.name" />
     234        </td>
     235      </tr>
     236      <tr valign="top">
    225237        <td class="prompt">Plugin</td>
    226238        <td>
     
    228240        </td>
    229241      </tr>
    230       <tr valign=top>
     242      <tr valign="top">
    231243        <td class="prompt">Configuration</td>
    232244        <td>
Note: See TracChangeset for help on using the changeset viewer.