Changeset 3973


Ignore:
Timestamp:
Nov 16, 2007, 8:47:01 AM (14 years ago)
Author:
Nicklas Nordborg
Message:

References #827: Add more web services methods

  • Added services to get experimental factors and annotation values for annotatable items
  • Added methods in TestExperiment? for testing experimental factors
  • Changed methods in TestAnnotation? to allow annotating any item
Location:
trunk/src
Files:
2 added
12 edited

Legend:

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

    r3875 r3973  
    3232import net.sf.basedb.core.query.Expressions;
    3333import net.sf.basedb.core.query.Hql;
     34import net.sf.basedb.info.AnnotationTypeInfo;
    3435
    3536import java.util.Set;
     
    264265    return using;
    265266  }
     267 
     268  public AnnotationTypeInfo toInfo(AnnotationTypeInfo info)
     269  {
     270    super.toInfo(info);
     271    info.setDefaultValue(getDefaultValue());
     272    info.setExternalId(getExternalId());
     273    info.setEnumeration(isEnumeration());
     274    if (isEnumeration())
     275    {
     276      info.setEnumValues(net.sf.basedb.util.Values.toStrings(getValues(), null));
     277    }
     278    info.setMultiplicity(getMultiplicity());
     279    info.setProtocolParameter(isProtocolParameter());
     280    info.setRequiredForMiame(isRequiredForMiame());
     281    info.setValueType(getValueType().name());
     282    return info;
     283  }
     284 
    266285  // -------------------------------------------
    267286
  • trunk/src/core/net/sf/basedb/util/Values.java

    r3675 r3973  
    438438 
    439439  /**
     440    Convert a collection of objects to an array of strings. If a formatter
     441    is specified, the {@link Formatter#format(Object)} method is used, otherwise
     442    {@link Object#toString()}.
     443  */
     444  public static final <T> String[] toStrings(Collection<T> values, Formatter<T> formatter)
     445  {
     446    String[] strings = null;
     447    if (values != null)
     448    {
     449      strings = new String[values.size()];
     450      int index = 0;
     451      for (T value : values)
     452      {
     453        if (value == null)
     454        {
     455          strings[index] = null;
     456        }
     457        else
     458        {
     459          strings[index] = formatter == null ? value.toString() : formatter.format(value);
     460        }
     461        ++index;
     462      }
     463    }
     464    return strings;   
     465  }
     466 
     467  /**
    440468    Trims long strings to a maximum of <code>maxLength</code>
    441469    characters.
  • trunk/src/test/TestAnnotation.java

    r3820 r3973  
    6464
    6565    // Annotate the array design and list the annotations
    66     int intAnnotationId = test_annotatate(arrayDesignId, intId, 10);
    67     int longAnnotationId = test_annotatate(arrayDesignId, longId, 1023456789012345l);
    68     int floatAnnotationId = test_annotatate(arrayDesignId, floatId, 11.365789456857f);
    69     int doubleAnnotationId = test_annotatate(arrayDesignId, doubleId, 11.365789456857d);
    70     int dateAnnotationId = test_annotatate(arrayDesignId, dateId, new Date());
    71     int textAnnotationId = test_annotatate(arrayDesignId, textId, "a text annotation");
    72     int stringAnnotationId = test_annotatate(arrayDesignId, stringId, "a string annotation");
    73     int booleanAnnotationId = test_annotatate(arrayDesignId, booleanId, false);
    74     int enumAnnotationId = test_annotatate(arrayDesignId, enumId, 4);
     66    int intAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, intId, 10);
     67    int longAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, longId, 1023456789012345l);
     68    int floatAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, floatId, 11.365789456857f);
     69    int doubleAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, doubleId, 11.365789456857d);
     70    int dateAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, dateId, new Date());
     71    int textAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, textId, "a text annotation");
     72    int stringAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, stringId, "a string annotation");
     73    int booleanAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, booleanId, false);
     74    int enumAnnotationId = test_annotatate(Item.ARRAYDESIGN, arrayDesignId, enumId, 4);
    7575    test_list_annotations(Item.ARRAYDESIGN, arrayDesignId, 9);
    7676
    7777    // Test: inherit annotations
    7878    int rawBioAssayId = TestRawBioAssay.test_create(Platform.GENERIC, "genepix", 0, 0, 0, arrayDesignId, false);
    79     test_inherit_annotation(rawBioAssayId, intAnnotationId);
    80     test_inherit_annotation(rawBioAssayId, stringAnnotationId);
    81     test_inherit_annotationset(rawBioAssayId, arrayDesignId);
     79    test_inherit_annotation(Item.RAWBIOASSAY, rawBioAssayId, intAnnotationId);
     80    test_inherit_annotation(Item.RAWBIOASSAY, rawBioAssayId, stringAnnotationId);
     81    test_inherit_annotationset(Item.RAWBIOASSAY, rawBioAssayId, Item.ARRAYDESIGN, arrayDesignId);
    8282   
    8383    // Test: list inherited annotations and annotation sets
    84     test_list_inherited_annotations(rawBioAssayId, 2);
    85     test_list_allinherited_annotations(rawBioAssayId, 9);
    86     test_list_inherited_annotationsets(rawBioAssayId, 1);
    87     test_list_inheriting_annotationsets(arrayDesignId, 1);
     84    test_list_inherited_annotations(Item.RAWBIOASSAY, rawBioAssayId, 2);
     85    test_list_allinherited_annotations(Item.RAWBIOASSAY, rawBioAssayId, 9);
     86    test_list_inherited_annotationsets(Item.RAWBIOASSAY, rawBioAssayId, 1);
     87    test_list_inheriting_annotationsets(Item.ARRAYDESIGN, arrayDesignId, 1);
    8888    TestRawBioAssay.test_delete(rawBioAssayId);
    8989   
     
    9191
    9292    // Remove the annotations
    93     test_remove_annotation(arrayDesignId, intId);
    94     test_remove_annotation(arrayDesignId, longId);
    95     test_remove_annotation(arrayDesignId, floatId);
    96     test_remove_annotation(arrayDesignId, doubleId);
    97     test_remove_annotation(arrayDesignId, dateId);
    98     test_remove_annotation(arrayDesignId, textId);
    99     test_remove_annotation(arrayDesignId, stringId);
    100     test_remove_annotation(arrayDesignId, booleanId);
    101     test_remove_annotation(arrayDesignId, enumId);
     93    test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, intId);
     94    test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, longId);
     95    test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, floatId);
     96    test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, doubleId);
     97    test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, dateId);
     98    test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, textId);
     99    test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, stringId);
     100    test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, booleanId);
     101    test_remove_annotation(Item.ARRAYDESIGN, arrayDesignId, enumId);
    102102    test_list_annotations(Item.ARRAYDESIGN, arrayDesignId, 0);
    103103
     
    118118  }
    119119 
    120   static int test_annotatate(int arrayDesignId, int annotationTypeId, Object... value)
    121   {
    122     if (arrayDesignId == 0 || annotationTypeId == 0) return 0;
     120  static int test_annotatate(Item itemType, int itemId, int annotationTypeId, Object... value)
     121  {
     122    if (itemId == 0 || annotationTypeId == 0) return 0;
    123123    int id = 0;
    124124    DbControl dc = null;
     
    126126    {
    127127      dc = TestUtil.getDbControl();
    128       ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId);
     128      Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId);
    129129      AnnotationType at = AnnotationType.getById(dc, annotationTypeId);
    130130
    131       AnnotationSet as = ad.getAnnotationSet();
     131      AnnotationSet as = annotatable.getAnnotationSet();
    132132      Annotation a = as.getAnnotation(at);
    133133     
     
    155155  }
    156156
    157   static void test_remove_annotation(int arrayDesignId, int annotationTypeId)
    158   {
    159     if (arrayDesignId == 0 || annotationTypeId == 0) return;
    160     DbControl dc = null;
    161     try
    162     {
    163       dc = TestUtil.getDbControl();
    164       ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId);
     157  static void test_remove_annotation(Item itemType, int itemId, int annotationTypeId)
     158  {
     159    if (itemId == 0 || annotationTypeId == 0) return;
     160    DbControl dc = null;
     161    try
     162    {
     163      dc = TestUtil.getDbControl();
     164      Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId);
    165165      AnnotationType at = AnnotationType.getById(dc, annotationTypeId);
    166       AnnotationSet as = ad.getAnnotationSet();
     166      AnnotationSet as = annotatable.getAnnotationSet();
    167167      as.removeAnnotation(at);
    168168      dc.commit();
     
    213213  }
    214214
    215   static void test_delete(int id)
    216   {
    217     if (id == 0) return;
    218     DbControl dc = null;
    219     try
    220     {
    221       dc = TestUtil.getDbControl();
    222       AnnotationType at = AnnotationType.getById(dc, id);
    223       dc.deleteItem(at);
    224       dc.commit();
    225       write("--Delete annotation type OK");
    226     }
    227     catch (Throwable ex)
    228     {
    229       write("--Delete annotation type FAILED");
    230       ex.printStackTrace();
    231       ok = false;
    232     }
    233     finally
    234     {
    235       if (dc != null) dc.close();
    236     }
    237   }
    238 
    239215  static void write_header()
    240216  {
     
    262238  }
    263239 
    264   static void test_inherit_annotation(int rawBioAssayId, int annotationId)
    265   {
    266     if (rawBioAssayId == 0 || annotationId == 0) return;
    267     DbControl dc = null;
    268     try
    269     {
    270       dc = TestUtil.getDbControl();
    271       RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId);
     240  static void test_inherit_annotation(Item itemType, int itemId, int annotationId)
     241  {
     242    if (itemId == 0 || annotationId == 0) return;
     243    DbControl dc = null;
     244    try
     245    {
     246      dc = TestUtil.getDbControl();
     247      Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId);
    272248      Annotation a = Annotation.getById(dc, annotationId);
    273       AnnotationSet as = rba.getAnnotationSet();
     249      AnnotationSet as = annotatable.getAnnotationSet();
    274250      as.inheritAnnotation(a);
    275251      dc.commit();
     
    288264  }
    289265 
    290   static void test_inherit_annotationset(int rawBioAssayId, int arrayDesignId)
    291   {
    292     if (rawBioAssayId == 0 || arrayDesignId == 0) return;
    293     DbControl dc = null;
    294     try
    295     {
    296       dc = TestUtil.getDbControl();
    297       RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId);
    298       ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId);
    299       AnnotationSet as = rba.getAnnotationSet();
    300       AnnotationSet inherited = ad.getAnnotationSet();
     266  static void test_inherit_annotationset(Item toItemType, int toItemId, Item fromItemType, int fromItemId)
     267  {
     268    if (toItemId == 0 || fromItemId == 0) return;
     269    DbControl dc = null;
     270    try
     271    {
     272      dc = TestUtil.getDbControl();
     273      Annotatable to = (Annotatable)toItemType.getById(dc, toItemId);
     274      Annotatable from = (Annotatable)fromItemType.getById(dc, fromItemId);
     275      AnnotationSet as = to.getAnnotationSet();
     276      AnnotationSet inherited = from.getAnnotationSet();
    301277      as.inheritAnnotationSet(inherited);
    302278      dc.commit();
     
    315291  }
    316292 
    317   static void test_list_inherited_annotations(int rawBioAssayId, int expectedResults)
    318   {
    319     if (rawBioAssayId == 0) return;
    320     DbControl dc = null;
    321     try
    322     {
    323       dc = TestUtil.getDbControl();
    324       RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId);
    325       List<Annotation> l = rba.getAnnotationSet().getInheritedAnnotations().list(dc);
     293  static void test_list_inherited_annotations(Item itemType, int itemId, int expectedResults)
     294  {
     295    if (itemId == 0) return;
     296    DbControl dc = null;
     297    try
     298    {
     299      dc = TestUtil.getDbControl();
     300      Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId);
     301      List<Annotation> l = annotatable.getAnnotationSet().getInheritedAnnotations().list(dc);
    326302      for (int i = 0; i<l.size(); i++)
    327303      {
     
    346322  }
    347323 
    348   static void test_list_allinherited_annotations(int rawBioAssayId, int expectedResults)
    349   {
    350     if (rawBioAssayId == 0) return;
    351     DbControl dc = null;
    352     try
    353     {
    354       dc = TestUtil.getDbControl();
    355       RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId);
    356       ItemQuery<Annotation> query = rba.getAnnotationSet().getAllInheritedAnnotations();
     324  static void test_list_allinherited_annotations(Item itemType, int itemId, int expectedResults)
     325  {
     326    if (itemId == 0) return;
     327    DbControl dc = null;
     328    try
     329    {
     330      dc = TestUtil.getDbControl();
     331      Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId);
     332      ItemQuery<Annotation> query = annotatable.getAnnotationSet().getAllInheritedAnnotations();
    357333      query.join(Hql.innerJoin(null, "annotationType", "at", true));
    358334      query.order(Orders.asc(Hql.property("at", "name")));
     
    380356  }
    381357
    382   static void test_list_inherited_annotationsets(int rawBioAssayId, int expectedResults)
    383   {
    384     if (rawBioAssayId == 0) return;
    385     DbControl dc = null;
    386     try
    387     {
    388       dc = TestUtil.getDbControl();
    389       RawBioAssay rba = RawBioAssay.getById(dc, rawBioAssayId);
    390       List<AnnotationSet> l = rba.getAnnotationSet().getInheritedAnnotationSets().list(dc);
     358  static void test_list_inherited_annotationsets(Item itemType, int itemId, int expectedResults)
     359  {
     360    if (itemId == 0) return;
     361    DbControl dc = null;
     362    try
     363    {
     364      dc = TestUtil.getDbControl();
     365      Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId);
     366      List<AnnotationSet> l = annotatable.getAnnotationSet().getInheritedAnnotationSets().list(dc);
    391367      for (int i = 0; i<l.size(); i++)
    392368      {
     
    411387  }
    412388
    413   static void test_list_inheriting_annotationsets(int arrayDesignId, int expectedResults)
    414   {
    415     if (arrayDesignId == 0) return;
    416     DbControl dc = null;
    417     try
    418     {
    419       dc = TestUtil.getDbControl();
    420       ArrayDesign ad = ArrayDesign.getById(dc, arrayDesignId);
    421       List<AnnotationSet> l = ad.getAnnotationSet().getInheritingAnnotationSets().list(dc);
     389  static void test_list_inheriting_annotationsets(Item itemType, int itemId, int expectedResults)
     390  {
     391    if (itemId == 0) return;
     392    DbControl dc = null;
     393    try
     394    {
     395      dc = TestUtil.getDbControl();
     396      Annotatable annotatable = (Annotatable)itemType.getById(dc, itemId);
     397      List<AnnotationSet> l = annotatable.getAnnotationSet().getInheritingAnnotationSets().list(dc);
    422398      for (int i = 0; i<l.size(); i++)
    423399      {
  • trunk/src/test/TestExperiment.java

    r3820 r3973  
    7373    test_list(-1);
    7474   
     75    // Experimental factors
     76    int factorId1 = TestAnnotationType.test_create("Drug resistance", Type.STRING, null, null, Item.RAWBIOASSAY, 1, new String[] { "high", "medium", "low" }, false);
     77    int factorId2 = TestAnnotationType.test_create("Temperature", Type.FLOAT, null, null, Item.RAWBIOASSAY, 1, null, false);
     78    test_add_experimental_factors(id, factorId1, factorId2);
     79    test_list_experimental_factors(id, 2);
    7580   
    7681    // Import reporters
     
    137142    test_delete(id2);
    138143
     144    TestAnnotationType.test_delete(factorId1);
     145    TestAnnotationType.test_delete(factorId2);
    139146    TestExtraValueType.test_delete(intExtraId);
    140147    TestExtraValueType.test_delete(floatExtraId);
     
    443450    }
    444451  }
     452 
     453  static void test_add_experimental_factors(int id, int... annotationTypes)
     454  {
     455    if (id == 0) return;
     456    DbControl dc = null;
     457    try
     458    {
     459      dc = TestUtil.getDbControl();
     460      Experiment e = Experiment.getById(dc, id);
     461      for (int atId : annotationTypes)
     462      {
     463        AnnotationType at = AnnotationType.getById(dc, atId);
     464        e.addExperimentalFactor(at);
     465      }
     466      dc.commit();
     467      write("--Add experimental factors OK");
     468    }
     469    catch (Throwable ex)
     470    {
     471      write("--Add experimental factors FAILED");
     472      ex.printStackTrace();
     473      ok = false;
     474    }
     475    finally
     476    {
     477      if (dc != null) dc.close();
     478    }
     479  }
     480 
     481  static void test_remove_experimental_factors(int id, int... annotationTypes)
     482  {
     483    if (id == 0) return;
     484    DbControl dc = null;
     485    try
     486    {
     487      dc = TestUtil.getDbControl();
     488      Experiment e = Experiment.getById(dc, id);
     489      for (int atId : annotationTypes)
     490      {
     491        AnnotationType at = AnnotationType.getById(dc, atId);
     492        e.removeExperimentalFactor(at);
     493      }
     494      dc.commit();
     495      write("--Remove experimental factors OK");
     496    }
     497    catch (Throwable ex)
     498    {
     499      write("--Remove experimental factors FAILED");
     500      ex.printStackTrace();
     501      ok = false;
     502    }
     503    finally
     504    {
     505      if (dc != null) dc.close();
     506    }
     507  }
     508 
     509  static void test_list_experimental_factors(int id, int expectedResults)
     510  {
     511    if (id == 0) return;
     512    DbControl dc = null;
     513    try
     514    {
     515      dc = TestUtil.getDbControl();
     516      Experiment e = Experiment.getById(dc, id);
     517
     518      ItemResultList<AnnotationType> l = e.getExperimentalFactors().list(dc);
     519      for (int i = 0; i<l.size(); i++)
     520      {
     521        TestAnnotationType.write_item(i, l.get(i));
     522      }
     523      if (expectedResults >= 0 && expectedResults != l.size())
     524      {
     525        throw new BaseException("Expected "+expectedResults+" results, not "+l.size());
     526      }
     527      write("--List experimental factors OK ("+l.size()+")");
     528    }
     529    catch (Throwable ex)
     530    {
     531      write("--List experimental factors FAILED");
     532      ex.printStackTrace();
     533      ok = false;
     534    }
     535    finally
     536    {
     537      if (dc != null) dc.close();
     538    }
     539  }
    445540 
    446541  static int test_create_root_bioassayset_using_plugin(int experimentId, int formulaId, int... rawBioAssays)
  • trunk/src/test/TestWebservices.java

    r3972 r3973  
    2727import net.sf.basedb.core.DbControl;
    2828import net.sf.basedb.core.Formula;
     29import net.sf.basedb.core.Item;
    2930import net.sf.basedb.core.ItemQuery;
    3031import net.sf.basedb.core.Platform;
     32import net.sf.basedb.core.Type;
    3133import net.sf.basedb.core.query.Expressions;
    3234import net.sf.basedb.core.query.Hql;
    3335import net.sf.basedb.core.query.Restrictions;
     36import net.sf.basedb.info.AnnotationInfo;
     37import net.sf.basedb.info.AnnotationTypeInfo;
    3438import net.sf.basedb.info.ArrayDesignInfo;
    3539import net.sf.basedb.info.BioAssaySetInfo;
     
    5256import java.io.OutputStream;
    5357import java.util.ArrayList;
     58import java.util.Arrays;
    5459
    5560/**
     
    114119    TestExperiment.test_add_rawbioassay(experimentId2, rawBioAssayId4);
    115120   
     121    int factorId1 = TestAnnotationType.test_create("Drug resistance", Type.STRING, null, null, Item.RAWBIOASSAY, 1, new String[] { "high", "medium", "low" }, false);
     122    int factorId2 = TestAnnotationType.test_create("Temperature", Type.FLOAT, null, null, Item.RAWBIOASSAY, 1, null, false);
     123   
     124    TestExperiment.test_add_experimental_factors(experimentId1, factorId1, factorId2);
     125    TestAnnotation.test_annotatate(Item.RAWBIOASSAY, rawBioAssayId1, factorId1, "medium");
     126    TestAnnotation.test_annotatate(Item.RAWBIOASSAY, rawBioAssayId1, factorId2, 12.5f);
     127    TestAnnotation.test_annotatate(Item.RAWBIOASSAY, rawBioAssayId2, factorId1, "high");
     128    TestAnnotation.test_annotatate(Item.RAWBIOASSAY, rawBioAssayId2, factorId2, 20.3f);
     129   
    116130    //Tests
    117131    test_ProjectClient(client, projectId);
     
    120134    test_getArrayDesign(client, rawBioAssayId1, arrayDesignId1);
    121135    test_getArrayDesign(client, rawBioAssayId3, arrayDesignId2);   
    122     test_BioAssaySetClient(client, experimentId1, rootBioAssaySetId1);       
     136    test_BioAssaySetClient(client, experimentId1, rootBioAssaySetId1);
     137    test_getExperimentalFactorValues(client, experimentId1);
    123138    test_Logout(client);
     139   
     140    if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
    124141   
    125142    //Standard test:Delete/cleanup
     
    138155    TestFile.test_delete(cdfId);
    139156    TestFile.test_delete(celId);
     157   
     158    TestAnnotationType.test_delete(factorId1);
     159    TestAnnotationType.test_delete(factorId2);
    140160   
    141161    TestReporter.test_delete();   
     
    402422  }
    403423 
     424 
     425  /**
     426    This tests getting the experimental factors for an experiment and
     427    listing values for each raw bioassay.
     428      @param client A logged in client.
     429      @param experimentId Id of the Experiment to test with.
     430  */
     431  static void test_getExperimentalFactorValues(SessionClient client, int experimentId)
     432  {
     433    if (client == null || experimentId == 0) return;
     434   
     435    ExperimentClient experimentClient = new ExperimentClient(client);
     436    RawBioAssayClient rawClient = new RawBioAssayClient(client);
     437    QueryOptions qOpt = new QueryOptions();
     438
     439    try
     440    {
     441      AnnotationTypeInfo[] factors = experimentClient.getExperimentalFactors(experimentId, qOpt);
     442      RawBioAssayInfo[] rawInfo = experimentClient.getRawBioAssays(experimentId, qOpt);
     443
     444      StringBuilder header = new StringBuilder("\t");
     445      Integer[] annotationTypes = new Integer[factors.length];
     446      for (int i = 0; i < factors.length; ++i)
     447      {
     448        annotationTypes[i] = factors[i].getId();
     449        header.append(factors[i].getName()).append("\t");
     450      }
     451     
     452      write(header.toString());
     453      for (RawBioAssayInfo rba : rawInfo)
     454      {
     455        StringBuilder row = new StringBuilder();
     456        row.append(rba.getName()).append("\t");
     457        AnnotationInfo[] annotations = rawClient.getAnnotationValues(rba.getId(),
     458          annotationTypes, true);
     459       
     460        for (AnnotationInfo info : annotations)
     461        {
     462          row.append(Arrays.asList(info.getValues()).toString()).append("\t");
     463        }
     464        write(row.toString());
     465      }
     466     
     467      write ("--Test of getExperimentalFactorValues OK");
     468    }
     469    catch(Throwable t)
     470    {
     471      write ("--Test of getExperimentalFactorValues FAILED");
     472      t.printStackTrace();
     473      ok = false;
     474    }
     475   
     476  }
     477 
    404478  static void test_ProjectClient(SessionClient client, int projectId)
    405479  {
  • trunk/src/webservices/client/java/net/sf/basedb/ws/client/ExperimentClient.java

    r3952 r3973  
    2424package net.sf.basedb.ws.client;
    2525
     26import net.sf.basedb.info.AnnotationTypeInfo;
    2627import net.sf.basedb.info.BioAssaySetInfo;
    2728import net.sf.basedb.info.ExperimentInfo;
     
    9192    BioAssaySetInfo[] result = invokeBlocking("getBioAssaySets", BioAssaySetInfo[].class, session.getId(), experimentId, new QueryOptions());
    9293    return result;
    93   }
     94  }
     95
     96
     97  /**
     98    Gets info about the experimental factors for an experiment.
     99      @param experimentId Id of experiment to get experimental factors from
     100      @param qOpt Options to put on the query
     101      @return An array with info object about each annotation type that was found
     102      @throws AxisFault If communication with web services fails.
     103  */
     104  public AnnotationTypeInfo[] getExperimentalFactors(int experimentId, QueryOptions qOpt)
     105    throws AxisFault
     106  {
     107    AnnotationTypeInfo[] result = invokeBlocking("getExperimentalFactors", AnnotationTypeInfo[].class, session.getId(), experimentId, qOpt);
     108    return result;
     109  }
     110
    94111}
  • trunk/src/webservices/client/java/net/sf/basedb/ws/client/RawBioAssayClient.java

    r3964 r3973  
    2424package net.sf.basedb.ws.client;
    2525
     26import net.sf.basedb.info.AnnotationInfo;
    2627import net.sf.basedb.info.ArrayDesignInfo;
    2728import net.sf.basedb.info.DataFileTypeInfo;
     
    142143      );
    143144  }
     145 
     146  /**
     147    Get annotation values for one or more annotation types.
     148    @param rawBioAssayId Id of the raw bioassay to load the annotations from
     149    @param annotationTypes Array with the ID:s of the annotation types
     150    @param findInherited TRUE to look among inherited annotations, FALSE to only
     151      look among primary annotations
     152    @return An array with annotation information, each element corresponds to the
     153      annotation type at the same position in the annotationTypes array
     154    @throws AxisFault
     155  */
     156  public AnnotationInfo[] getAnnotationValues(int rawBioAssayId, Integer[] annotationTypes, boolean findInherited)
     157    throws AxisFault
     158  {
     159    return invokeBlocking("getAnnotations", AnnotationInfo[].class,
     160      session.getId(), rawBioAssayId, annotationTypes, findInherited);
     161  }
    144162}
  • trunk/src/webservices/server/net/sf/basedb/ws/server/ArrayDesignService.java

    r3972 r3973  
    3232import net.sf.basedb.core.ItemQuery;
    3333import net.sf.basedb.core.SessionControl;
     34import net.sf.basedb.info.AnnotationInfo;
    3435import net.sf.basedb.info.DataFileTypeInfo;
    3536import net.sf.basedb.info.QueryOptions;
     
    143144    return new DataFileTypeInfo[0];
    144145  }
     146 
     147  /**
     148    Get the annotation values for one or more annotation types.
     149    @param ID Id of the active session.
     150    @param arrayDesignId Id of the array design it concerns
     151    @param annotationTypes Array with the ID of the annotation types
     152    @param findInherited TRUE to look among inherited annotations, FALSE to only look
     153      at primary annotations
     154    @return An array with AnnotationInfo object, each element in the array
     155      corresponds to the annotation type with the same index in the annotationTypes array
     156  */
     157  public AnnotationInfo[] getAnnotations(String ID, int arrayDesignId, Integer[] annotationTypes, boolean findInherited)
     158  {
     159    SessionControl sc = getSessionControl(ID);
     160    DbControl dc = sc.newDbControl();
     161    try
     162    {
     163      ArrayDesign design = ArrayDesign.getById(dc, arrayDesignId);
     164      return util.getAnnotations(dc, design, annotationTypes, findInherited);
     165    }
     166    finally
     167    {
     168      if (dc != null) dc.close();
     169    }
     170  }
     171 
    145172}
  • trunk/src/webservices/server/net/sf/basedb/ws/server/BioAssaySetService.java

    r3939 r3973  
    2828import net.sf.basedb.core.DbControl;
    2929import net.sf.basedb.core.SessionControl;
     30import net.sf.basedb.info.AnnotationInfo;
    3031import net.sf.basedb.plugins.BioAssaySetExporter;
    3132
     
    151152    return elementWithAttachment;
    152153  }
     154 
     155  /**
     156    Get the annotation values for one or more annotation types.
     157    @param ID Id of the active session.
     158    @param bioAssaySetId Id of the bioassay set it concerns
     159    @param annotationTypes Array with the ID of the annotation types
     160    @param findInherited TRUE to look among inherited annotations, FALSE to only look
     161      at primary annotations
     162    @return An array with AnnotationInfo object, each element in the array
     163      corresponds to the annotation type with the same index in the annotationTypes array
     164  */
     165  public AnnotationInfo[] getAnnotations(String ID, int bioAssaySetId, Integer[] annotationTypes, boolean findInherited)
     166  {
     167    SessionControl sc = getSessionControl(ID);
     168    DbControl dc = sc.newDbControl();
     169    try
     170    {
     171      BioAssaySet bas = BioAssaySet.getById(dc, bioAssaySetId);
     172      return util.getAnnotations(dc, bas, annotationTypes, findInherited);
     173    }
     174    finally
     175    {
     176      if (dc != null) dc.close();
     177    }
     178  }
     179 
    153180}
  • trunk/src/webservices/server/net/sf/basedb/ws/server/ExperimentService.java

    r3972 r3973  
    2424package net.sf.basedb.ws.server;
    2525
     26import net.sf.basedb.core.AnnotationType;
    2627import net.sf.basedb.core.BioAssaySet;
    2728import net.sf.basedb.core.DbControl;
     
    3031import net.sf.basedb.core.RawBioAssay;
    3132import net.sf.basedb.core.SessionControl;
     33import net.sf.basedb.info.AnnotationTypeInfo;
    3234import net.sf.basedb.info.BioAssaySetInfo;
    3335import net.sf.basedb.info.ExperimentInfo;
     
    126128    }
    127129  }
     130
     131  /**
     132    Gets an array with information objects for each
     133    experimental factor in an experiment.
     134      @param ID The id to identify an active session.
     135      @param experimentId The id of the experiment to get the rawbioassays from.
     136      @param qOpt QueryOptions to put on the query
     137      @return Array with {@link net.sf.basedb.info.AnnotationTypeInfo}:s
     138  */
     139  public AnnotationTypeInfo[] getExperimentalFactors(String ID, int experimentId, QueryOptions qOpt)
     140  {
     141    SessionControl sc = getSessionControl(ID);
     142    DbControl dc = sc.newDbControl();
     143    try
     144    {
     145      Experiment experiment = Experiment.getById(dc, experimentId);
     146      ItemQuery<AnnotationType> query = experiment.getExperimentalFactors();     
     147      query = util.getConfiguredItemQuery(query, qOpt);
     148      return util.listToInfo(query.list(dc), AnnotationTypeInfo.class);
     149    }
     150    finally
     151    {
     152      if (dc != null) dc.close();
     153    }
     154  }
    128155}
  • trunk/src/webservices/server/net/sf/basedb/ws/server/RawBioAssayService.java

    r3972 r3973  
    3333import net.sf.basedb.core.RawBioAssay;
    3434import net.sf.basedb.core.SessionControl;
     35import net.sf.basedb.info.AnnotationInfo;
    3536import net.sf.basedb.info.ArrayDesignInfo;
    3637import net.sf.basedb.info.DataFileTypeInfo;
     
    168169    return new DataFileTypeInfo[0];
    169170  }
     171 
     172  /**
     173    Get the annotation values for one or more annotation types.
     174    @param ID Id of the active session.
     175    @param rawBioAssayId Id of the rawbioassay it concerns
     176    @param annotationTypes Array with the ID of the annotation types
     177    @param findInherited TRUE to look among inherited annotations, FALSE to only look
     178      at primary annotations
     179    @return An array with AnnotationInfo object, each element in the array
     180      corresponds to the annotation type with the same index in the annotationTypes array
     181  */
     182  public AnnotationInfo[] getAnnotations(String ID, int rawBioAssayId, Integer[] annotationTypes, boolean findInherited)
     183  {
     184    SessionControl sc = getSessionControl(ID);
     185    DbControl dc = sc.newDbControl();
     186    try
     187    {
     188      RawBioAssay rawBioAssay = RawBioAssay.getById(dc, rawBioAssayId);
     189      return util.getAnnotations(dc, rawBioAssay, annotationTypes, findInherited);
     190    }
     191    finally
     192    {
     193      if (dc != null) dc.close();
     194    }
     195  }
     196 
    170197}
  • trunk/src/webservices/server/net/sf/basedb/ws/server/ServicesUtil.java

    r3972 r3973  
    2424package net.sf.basedb.ws.server;
    2525
     26import net.sf.basedb.core.Annotatable;
     27import net.sf.basedb.core.Annotation;
     28import net.sf.basedb.core.AnnotationSet;
     29import net.sf.basedb.core.AnnotationType;
    2630import net.sf.basedb.core.BasicItem;
     31import net.sf.basedb.core.DbControl;
    2732import net.sf.basedb.core.Include;
    2833import net.sf.basedb.core.ItemQuery;
    2934import net.sf.basedb.core.query.Hql;
    30 import net.sf.basedb.info.BasicItemInfo;
     35import net.sf.basedb.info.AnnotationInfo;
    3136import net.sf.basedb.info.QueryOptions;
    3237
     
    3439import java.lang.reflect.Method;
    3540import java.util.EnumSet;
     41import java.util.LinkedList;
    3642import java.util.List;
    3743import java.util.Set;
     
    133139  }
    134140 
     141  /**
     142    Load annotation values from an annotatable item.
     143    @param dc The DbControl to use for database access
     144    @param annotatable The annotatable item to load annotations from
     145    @param annotationTypes Array of annotation type ID
     146    @param findInherited TRUE to find inherited annotations, FALSE to only look
     147      for primary annotations
     148    @return An array of {@link AnnotationInfo} objects, each position corresponds
     149      to the position with the same index in the annotationTypes array. The returned
     150      array is always the same length as the annotationTypes array. If the annotatable
     151      item doesn't have any annotations of a particular type, that element is null
     152  */
     153  public AnnotationInfo[] getAnnotations(DbControl dc, Annotatable annotatable,
     154    Integer[] annotationTypes, boolean findInherited)
     155  {
     156    AnnotationInfo[] result = new AnnotationInfo[annotationTypes.length];
     157    if (annotatable.isAnnotated())
     158    {
     159      AnnotationSet as = annotatable.getAnnotationSet();
     160      int i = 0;
     161      for (Integer atId : annotationTypes)
     162      {
     163        if (atId != null)
     164        {
     165          AnnotationInfo info = new AnnotationInfo();
     166          AnnotationType at = AnnotationType.getById(dc, atId);
     167          List<Annotation> annotations = as.findAnnotations(dc, at, findInherited);
     168          List<Object> values = new LinkedList<Object>();
     169          for (Annotation a : annotations)
     170          {
     171            values.addAll(a.getValues());
     172          }
     173          info.setAnnotationTypeId(atId);
     174          info.setValueType(at.getValueType().name());
     175          info.setValues(net.sf.basedb.util.Values.toStrings(values, null));
     176          result[i] = info;
     177        }
     178        ++i;
     179      }
     180    }
     181    return result;
     182  }
    135183}
Note: See TracChangeset for help on using the changeset viewer.