extensions/net.sf.basedb.genepattern/trunk/src/net/sf/basedb/genepattern/wrapper/TaskInfo.java

Code
Comments
Other
Rev Date Author Line
1115 10 Jun 09 nicklas 1 package net.sf.basedb.genepattern.wrapper;
1115 10 Jun 09 nicklas 2
1132 18 Jun 09 nicklas 3 import net.sf.basedb.util.filter.Filter;
1132 18 Jun 09 nicklas 4
1115 10 Jun 09 nicklas 5 /**
1115 10 Jun 09 nicklas 6   Wraps information about an installed module/pipeline on a GenePattern server.
1115 10 Jun 09 nicklas 7   Information is exposed as it is needed by other parts of our code. Use
1115 10 Jun 09 nicklas 8   {@link #getGPTaskInfo()} to access the underlying {@link 
1115 10 Jun 09 nicklas 9   org.genepattern.webservice.TaskInfo} instance.
1115 10 Jun 09 nicklas 10   @author Nicklas
1115 10 Jun 09 nicklas 11   @since 1.0
1115 10 Jun 09 nicklas 12 */
1115 10 Jun 09 nicklas 13 public class TaskInfo 
1115 10 Jun 09 nicklas 14 {
1115 10 Jun 09 nicklas 15
1115 10 Jun 09 nicklas 16   private final org.genepattern.webservice.TaskInfo gpInfo;
1115 10 Jun 09 nicklas 17   
1115 10 Jun 09 nicklas 18   /**
1115 10 Jun 09 nicklas 19     Creates a new wrapper instance.
1115 10 Jun 09 nicklas 20     @param gpInfo The underlying task information from the GenePattern server
1115 10 Jun 09 nicklas 21   */
1115 10 Jun 09 nicklas 22   public TaskInfo(org.genepattern.webservice.TaskInfo gpInfo)
1115 10 Jun 09 nicklas 23   {
1115 10 Jun 09 nicklas 24     this.gpInfo = gpInfo;
1115 10 Jun 09 nicklas 25   }
1115 10 Jun 09 nicklas 26   
1115 10 Jun 09 nicklas 27   /**
1115 10 Jun 09 nicklas 28     Get the underlying {@link org.genepattern.webservice.TaskInfo} instance.
1115 10 Jun 09 nicklas 29     Use this method to access functionality that is not exposed by this
1115 10 Jun 09 nicklas 30     class.
1115 10 Jun 09 nicklas 31   */
1115 10 Jun 09 nicklas 32   public org.genepattern.webservice.TaskInfo getGPTaskInfo()
1115 10 Jun 09 nicklas 33   {
1115 10 Jun 09 nicklas 34     return gpInfo;
1115 10 Jun 09 nicklas 35   }
1115 10 Jun 09 nicklas 36   
1115 10 Jun 09 nicklas 37   /**
1115 10 Jun 09 nicklas 38     Get the name of the module.
1115 10 Jun 09 nicklas 39   */
1115 10 Jun 09 nicklas 40   public String getName()
1115 10 Jun 09 nicklas 41   {
1115 10 Jun 09 nicklas 42     return getGPTaskInfo().getName();
1115 10 Jun 09 nicklas 43   }
1115 10 Jun 09 nicklas 44   
1115 10 Jun 09 nicklas 45   /**
1115 10 Jun 09 nicklas 46     Get the LSID of the module.
1115 10 Jun 09 nicklas 47   */
1115 10 Jun 09 nicklas 48   public String getLsid()
1115 10 Jun 09 nicklas 49   {
1115 10 Jun 09 nicklas 50     return getGPTaskInfo().getLsid();
1115 10 Jun 09 nicklas 51   }
1115 10 Jun 09 nicklas 52   
1115 10 Jun 09 nicklas 53   /**
1115 10 Jun 09 nicklas 54     Get a description of the module.
1115 10 Jun 09 nicklas 55   */
1115 10 Jun 09 nicklas 56   public String getDescription()
1115 10 Jun 09 nicklas 57   {
1115 10 Jun 09 nicklas 58     return getGPTaskInfo().getDescription();
1115 10 Jun 09 nicklas 59   }
1115 10 Jun 09 nicklas 60   
1115 10 Jun 09 nicklas 61   /**
1115 10 Jun 09 nicklas 62     Is is a module or pipeline?
1115 10 Jun 09 nicklas 63   */
1115 10 Jun 09 nicklas 64   public boolean isPipeline()
1115 10 Jun 09 nicklas 65   {
1115 10 Jun 09 nicklas 66     return getGPTaskInfo().isPipeline();
1115 10 Jun 09 nicklas 67   }
1115 10 Jun 09 nicklas 68
1115 10 Jun 09 nicklas 69   /**
1115 10 Jun 09 nicklas 70     Get the value of some other attribute as a string.
1115 10 Jun 09 nicklas 71     If the attribute is not a string, it is converted by calling
1115 10 Jun 09 nicklas 72     the 'toString()' method. 
1115 10 Jun 09 nicklas 73     @param key The name of the attribute
1115 10 Jun 09 nicklas 74   */
1115 10 Jun 09 nicklas 75   public String getAttribute(String key)
1115 10 Jun 09 nicklas 76   {
1115 10 Jun 09 nicklas 77     Object value = getGPTaskInfo().getAttributes().get(key);
1115 10 Jun 09 nicklas 78     return value == null ? null : value.toString();
1115 10 Jun 09 nicklas 79   }
1132 18 Jun 09 nicklas 80   
1132 18 Jun 09 nicklas 81   public String getAttribute(String key, String defaultValue)
1132 18 Jun 09 nicklas 82   {
1132 18 Jun 09 nicklas 83     Object value = getGPTaskInfo().getAttributes().get(key);
1132 18 Jun 09 nicklas 84     return value == null ? defaultValue : value.toString();
1132 18 Jun 09 nicklas 85   }
1115 10 Jun 09 nicklas 86
1115 10 Jun 09 nicklas 87   /**
1115 10 Jun 09 nicklas 88     Get the task type of the module. Uses the value from
1115 10 Jun 09 nicklas 89     the 'taskType' attribute.
1115 10 Jun 09 nicklas 90   */
1115 10 Jun 09 nicklas 91   public String getTaskType()
1115 10 Jun 09 nicklas 92   {
1115 10 Jun 09 nicklas 93     return getAttribute("taskType");
1115 10 Jun 09 nicklas 94   }
1115 10 Jun 09 nicklas 95   
1115 10 Jun 09 nicklas 96   /**
1115 10 Jun 09 nicklas 97     Get the author of the module. Uses the value from
1115 10 Jun 09 nicklas 98     the 'author' attribute.
1115 10 Jun 09 nicklas 99   */
1115 10 Jun 09 nicklas 100   public String getAuthor()
1115 10 Jun 09 nicklas 101   {
1115 10 Jun 09 nicklas 102     return getAttribute("author");
1115 10 Jun 09 nicklas 103   }
1115 10 Jun 09 nicklas 104   
1132 18 Jun 09 nicklas 105   public String getOs()
1132 18 Jun 09 nicklas 106   {
1132 18 Jun 09 nicklas 107     return getAttribute("os", "any");
1132 18 Jun 09 nicklas 108   }
1115 10 Jun 09 nicklas 109   
1132 18 Jun 09 nicklas 110   public String getCpuType()
1132 18 Jun 09 nicklas 111   {
1132 18 Jun 09 nicklas 112     return getAttribute("cpuType", "any");
1132 18 Jun 09 nicklas 113   }
1115 10 Jun 09 nicklas 114   
1132 18 Jun 09 nicklas 115   public String getCommandLine()
1132 18 Jun 09 nicklas 116   {
1132 18 Jun 09 nicklas 117     return getAttribute("commandLine");
1132 18 Jun 09 nicklas 118   }
1132 18 Jun 09 nicklas 119   
1132 18 Jun 09 nicklas 120   public ParameterInfo[] getParameters(Filter<? super ParameterInfo> filter)
1132 18 Jun 09 nicklas 121   {
1132 18 Jun 09 nicklas 122     org.genepattern.webservice.ParameterInfo[] gpParams = gpInfo.getParameterInfoArray();
1132 18 Jun 09 nicklas 123     ParameterInfo[] parameters = new ParameterInfo[gpParams.length];
1132 18 Jun 09 nicklas 124     int index = 0;
1132 18 Jun 09 nicklas 125     for (int i = 0; i < gpParams.length; ++i)
1132 18 Jun 09 nicklas 126     {
1132 18 Jun 09 nicklas 127       ParameterInfo pi = new ParameterInfo(gpParams[i]);
1132 18 Jun 09 nicklas 128       if (filter == null || filter.evaluate(pi))
1132 18 Jun 09 nicklas 129       {
1132 18 Jun 09 nicklas 130         parameters[index] = pi;
1132 18 Jun 09 nicklas 131         index++;
1132 18 Jun 09 nicklas 132       }
1132 18 Jun 09 nicklas 133     }
1132 18 Jun 09 nicklas 134     return parameters;
1132 18 Jun 09 nicklas 135   }
1132 18 Jun 09 nicklas 136   
1115 10 Jun 09 nicklas 137 }