Changeset 1161


Ignore:
Timestamp:
Sep 16, 2009, 8:57:22 AM (13 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #241: Add MeV Analysis file as a file type for bioassay sets

The installation now adds a "MeV analysis" configuration for the manual transform plug-in.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.mev/trunk/src/server/net/sf/basedb/mev/install/Install.java

    r1160 r1161  
    2727import net.sf.basedb.core.DbControl;
    2828import net.sf.basedb.core.FileType;
     29import net.sf.basedb.core.Group;
     30import net.sf.basedb.core.GroupPermissions;
     31import net.sf.basedb.core.Include;
    2932import net.sf.basedb.core.Item;
    3033import net.sf.basedb.core.ItemAlreadyExistsException;
     34import net.sf.basedb.core.ItemKey;
    3135import net.sf.basedb.core.ItemNotFoundException;
     36import net.sf.basedb.core.ItemQuery;
    3237import net.sf.basedb.core.Job;
    3338import net.sf.basedb.core.Permission;
     39import net.sf.basedb.core.PluginConfiguration;
     40import net.sf.basedb.core.PluginConfigurationRequest;
    3441import net.sf.basedb.core.PluginDefinition;
    3542import net.sf.basedb.core.PluginParameter;
     43import net.sf.basedb.core.PluginResponse;
    3644import net.sf.basedb.core.ProgressReporter;
    3745import net.sf.basedb.core.RequestInformation;
     
    4250import net.sf.basedb.core.plugin.GuiContext;
    4351import net.sf.basedb.core.plugin.InteractivePlugin;
    44 import net.sf.basedb.core.plugin.Permissions;
    4552import net.sf.basedb.core.plugin.Plugin;
    4653import net.sf.basedb.core.plugin.Request;
    4754import net.sf.basedb.core.plugin.Response;
     55import net.sf.basedb.core.plugin.Response.Status;
     56import net.sf.basedb.core.query.Expressions;
     57import net.sf.basedb.core.query.Hql;
     58import net.sf.basedb.core.query.Restrictions;
    4859import net.sf.basedb.mev.Mev;
     60import net.sf.basedb.plugins.ManualTransformCreator;
    4961
    5062import java.util.ArrayList;
    5163import java.util.Arrays;
    52 import java.util.Collection;
    5364import java.util.Collections;
    5465import java.util.EnumSet;
    55 import java.util.HashSet;
     66import java.util.HashMap;
    5667import java.util.List;
     68import java.util.Map;
    5769import java.util.Set;
    5870
    5971/**
    60 
    6172  Installation program for the MeV extension package. The installation
    6273  will perform the following steps:
     
    6980      <li>MeV CGH file
    7081    </ul>
     82  <li>Create a 'MeV analysis' configuration for the manual transform plug-in
    7183  </ul>
    7284  @since 1.5
     
    94106  private RequestInformation configureJob = null;
    95107 
    96   private static final Set<Permissions> permissions = new HashSet<Permissions>();
    97 
    98108  public Install()
    99109  {}
     
    108118  }
    109119  @Override
    110   public Collection<Permissions> getPermissions()
    111   {
    112     if (permissions.size() == 0)
    113     {
    114       permissions.add(new Permissions(Item.DATAFILETYPE, null, EnumSet.of(Permission.WRITE, Permission.CREATE)));
    115       permissions.add(new Permissions(Item.FILETYPE, EnumSet.of(Permission.READ), null));
    116     }
    117     return permissions;
    118   }
    119   @Override
    120120  public boolean supportsConfigurations()
    121121  {
     
    139139      try
    140140      {
    141         instalMevPackage(dc);
     141        installMevPackage(dc);
    142142        dc.commit();
    143143      }
     
    230230    Creates items that are required when working with the MeV package in BASE.
    231231  */
    232   public void instalMevPackage(DbControl dc)
     232  public void installMevPackage(DbControl dc)
    233233  {   
    234234    FileType spotDataType = FileType.getById(dc, SystemItems.getId(net.sf.basedb.core.FileType.SPOT_DATA));
    235235
    236236    //Data file types
    237     createDataFileType(dc, Mev.ANALYSIS_FILE, "MeV analysis file",
     237    DataFileType mevAnalysisFile = createDataFileType(dc, Mev.ANALYSIS_FILE, "MeV analysis file",
    238238      "A MeV analysis file",
    239239      Item.BIOASSAYSET, "anl", spotDataType, null, null, null);
     
    244244      "A MeV Tab-Delimited Multiple Sample file",
    245245      Item.BIOASSAYSET, null, spotDataType, null, null, null);
    246   }
    247 
     246    ItemKey everyoneUse = getEveryoneUseKey(dc);
     247    Map<String, Object> params = new HashMap<String, Object>();
     248    params.put("fileTypes", mevAnalysisFile);
     249    params.put("allowMoreFiles", true);
     250    createPluginConfiguration(dc, ManualTransformCreator.class.getName(),
     251        "MeV analysis",
     252        "This manual transform represents work done " +
     253        "in MeV. The resulting analysis file has been uploaded and attached " +
     254        "to the bioassayset.", everyoneUse, params);
     255  }
     256
     257  private PluginConfiguration createPluginConfiguration(DbControl dc,
     258    String pluginClass, String name, String description, ItemKey key,
     259    Map<String, Object> parameters)
     260  {
     261    ItemQuery<PluginConfiguration> query = PluginConfiguration.getQuery();
     262    query.include(Include.ALL);
     263    query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(name)));
     264    query.restrict(Restrictions.eq(Hql.property("pluginDefinition.className"),
     265        Expressions.string(pluginClass)));
     266    List<PluginConfiguration> list = query.list(dc);
     267    PluginConfiguration config = null;
     268    if (list.size() > 0)
     269    {
     270      config = list.get(0);
     271    }
     272    else
     273    {
     274      PluginDefinition plugin = PluginDefinition.getByClassName(dc, pluginClass);
     275      config = plugin.newPluginConfiguration();
     276      config.setName(name);
     277      config.setDescription(description);
     278      config.setItemKey(key);
     279      dc.saveItem(config);
     280     
     281      PluginConfigurationRequest request = config.configure();
     282      while (request != null)
     283      {
     284        RequestInformation ri = request.getRequestInformation();
     285        for (PluginParameter<?> parameter : ri.getParameters())
     286        {
     287          String parameterName = parameter.getName();
     288          Object value = parameters.get(parameterName);
     289          request.setParameterValue(parameterName, value);
     290        }
     291        PluginResponse response = request.invoke();
     292        Status status = response.getStatus();
     293        if (status == Status.CONTINUE)
     294        {
     295          request = response.getNextRequest();
     296        }
     297        else if (status == Status.ERROR)
     298        {
     299          throw new BaseException(response.getMessage());
     300        }
     301        else
     302        {
     303          request = null;
     304          response.saveParameters(dc);
     305        }
     306      }
     307    }
     308    return config;
     309  }
     310 
    248311  private RequestInformation getConfigureJobParameters()
    249312  {
     
    301364    return dft;
    302365  }
     366 
     367  private ItemKey getEveryoneUseKey(DbControl dc)
     368  {
     369    ItemKey everyoneUse = null;
     370    try
     371    {
     372      Group everyone = Group.getById(dc, SystemItems.getId(Group.EVERYONE));
     373      GroupPermissions gp = new GroupPermissions();
     374      gp.addPermissions(everyone, EnumSet.of(Permission.USE));
     375      everyoneUse = ItemKey.getNewOrExisting(dc, null, gp);
     376    }
     377    catch (Exception ex)
     378    {}
     379    return everyoneUse;
     380  }
    303381}
Note: See TracChangeset for help on using the changeset viewer.