Changeset 4527


Ignore:
Timestamp:
Sep 16, 2008, 12:58:42 PM (13 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1112: Create new items with project default properties from active project

Location:
trunk/src
Files:
12 edited

Legend:

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

    r4517 r4527  
    126126    if (from == null) throw new InvalidUseOfNullException("from");
    127127    if (name == null) throw new InvalidUseOfNullException("name");
     128    AnyToAny ata = dc.getItem(AnyToAny.class,
     129      getDataByName(dc.getHibernateSession(), from.getId(), from.getType(), name));
     130    if (ata == null) throw new ItemNotFoundException("AnyToAny[name="+name+"]");
     131    return ata;
     132  }
     133 
     134  /**
     135    Get an any-to-any link.
     136    @param session An open Hibernate session
     137    @param fromId The id of the source item
     138    @param fromType The type of the source item
     139    @param name The name of the link
     140    @return The linked item, or null if no link is found
     141    @since 2.9
     142  */
     143  static AnyToAnyData getDataByName(org.hibernate.Session session, int fromId, Item fromType, String name)
     144  {
    128145    name = name.trim();
    129     org.hibernate.Query query = HibernateUtil.getPredefinedQuery(dc.getHibernateSession(),
     146    org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session,
    130147      "GET_ANYTOANY_FOR_NAME");
    131148    /*
     
    134151      WHERE ata.fromId = :fromId AND ata.fromType = :fromType AND ata.name = :name
    135152    */
    136     query.setInteger("fromId", from.getId());
    137     query.setInteger("fromType", from.getType().getValue());
     153    query.setInteger("fromId", fromId);
     154    query.setInteger("fromType", fromType.getValue());
    138155    query.setString("name", name);
    139     AnyToAny ata = dc.getItem(AnyToAny.class, HibernateUtil.loadData(AnyToAnyData.class, query));
    140     if (ata == null) throw new ItemNotFoundException("AnyToAny[name="+name+"]");
    141     return ata;   
     156    AnyToAnyData ata = HibernateUtil.loadData(AnyToAnyData.class, query);
     157    return ata;
    142158  }
    143159 
  • trunk/src/core/net/sf/basedb/core/ArrayBatch.java

    r4517 r4527  
    2424
    2525import net.sf.basedb.core.data.ArrayBatchData;
     26import net.sf.basedb.core.data.HardwareData;
     27import net.sf.basedb.core.data.ProtocolData;
    2628import net.sf.basedb.core.query.Hql;
    2729import net.sf.basedb.core.query.Restrictions;
     
    175177    return using;
    176178  }
     179  /**
     180    Set print robot and protocol from project default settings.
     181    @since 2.9
     182  */
     183  @Override
     184  void setProjectDefaults(Project activeProject)
     185    throws BaseException
     186  {
     187    super.setProjectDefaults(activeProject);
     188    if (!robotHasBeenSet)
     189    {
     190      HardwareData robot =
     191        (HardwareData)activeProject.getDefaultData(getDbControl(),
     192        Project.Default.PRINTROBOT_HARDWARE);
     193      if (robot != null) getData().setPrintRobot(robot);
     194      robotHasBeenSet = true;
     195    }
     196    if (!protocolHasBeenSet)
     197    {
     198      ProtocolData protocol =
     199        (ProtocolData)activeProject.getDefaultData(getDbControl(),
     200        Project.Default.PRINTING_PROTOCOL);
     201      if (protocol != null) getData().setProtocol(protocol);
     202      protocolHasBeenSet = true;
     203    }
     204  }
    177205  // -------------------------------------------
    178206
     
    221249  }
    222250
     251  private boolean protocolHasBeenSet = false;
    223252  /**
    224253    Set the {@link Protocol} used for printing the arrays.
     
    235264    checkPermission(Permission.WRITE);
    236265    if (protocol != null) protocol.checkPermission(Permission.USE);
     266    protocolHasBeenSet = true;
    237267    getData().setProtocol(protocol == null ? null : protocol.getData());
    238268  }
     
    252282    return getDbControl().getItem(Hardware.class, getData().getPrintRobot());
    253283  }
     284  private boolean robotHasBeenSet = false;
    254285  /**
    255286    Set the {@link Hardware print robot} used for this array batch.
     
    266297    checkPermission(Permission.WRITE);
    267298    if (printRobot != null) printRobot.checkPermission(Permission.USE);
     299    robotHasBeenSet = true;
    268300    getData().setPrintRobot(printRobot == null ? null : printRobot.getData());
    269301  }
  • trunk/src/core/net/sf/basedb/core/BasicItem.java

    r4517 r4527  
    438438
    439439  /**
     440    This method is called before inserting new items into the database
     441    to allow items to propagate default values from the active project.
     442    This method is only called when a project is active.
     443    <p>
     444    Implementation note! Subclasses should only set default values
     445    for properties that hasn't been set explicitly by client code,
     446    also accounting for setAbc(null) calls.
     447   
     448    @param activeProject The currently active project
     449    @throws BaseException
     450    @since 2.9
     451  */
     452  void setProjectDefaults(Project activeProject)
     453    throws BaseException
     454  {}
     455 
     456  /**
    440457    This method is called on all items directly after Hibernate has inserted
    441458    it into the database. This method can be used in place of the
  • trunk/src/core/net/sf/basedb/core/BioMaterialEvent.java

    r4517 r4527  
    2727
    2828import net.sf.basedb.core.data.BioMaterialEventData;
     29import net.sf.basedb.core.data.HardwareData;
    2930import net.sf.basedb.core.data.MeasuredBioMaterialData;
     31import net.sf.basedb.core.data.ProtocolData;
    3032import net.sf.basedb.core.data.UserData;
    3133import net.sf.basedb.core.data.UsedQuantity;
     
    250252    super.initPermissions(granted, denied);
    251253  }
     254  /**
     255    Set protocol and hardware from project default settings.
     256    @since 2.9
     257  */
     258  @Override
     259  void setProjectDefaults(Project activeProject)
     260    throws BaseException
     261  {
     262    super.setProjectDefaults(activeProject);
     263    if (getEventType() == Type.OTHER) return;
     264   
     265    Project.Default defaultProtocolType = null;
     266    Project.Default defaultHardwareType = null;
     267
     268    if (getEventType() == Type.HYBRIDIZATION)
     269    {
     270      defaultProtocolType = Project.Default.HYBRIDIZATION_PROTOCOL;
     271      defaultHardwareType = Project.Default.HYBRIDIZATION_HARDWARE;
     272    }
     273    else
     274    {
     275      MeasuredBioMaterial parent = getBioMaterial();
     276      Item parentType = parent.getType();
     277      if (parent.isPooled())
     278      {
     279        defaultProtocolType = Project.Default.POOLING_PROTOCOL;
     280      }
     281      else if (parentType == Item.SAMPLE)
     282      {
     283        defaultProtocolType = Project.Default.SAMPLING_PROTOCOL;
     284      }
     285      else if (parentType == Item.EXTRACT)
     286      {
     287        defaultProtocolType = Project.Default.EXTRACTING_PROTOCOL;
     288      }
     289      else if (parentType == Item.LABELEDEXTRACT)
     290      {
     291        defaultProtocolType = Project.Default.LABELING_PROTOCOL;
     292      }
     293    }
     294   
     295    if (!protocolHasBeenSet && defaultProtocolType != null)
     296    {
     297      ProtocolData protocol =
     298        (ProtocolData)activeProject.getDefaultData(getDbControl(),
     299        defaultProtocolType);
     300      if (protocol != null) getData().setProtocol(protocol);
     301      protocolHasBeenSet = true;
     302    }
     303    if (!hardwareHasBeenSet && defaultHardwareType != null)
     304    {
     305      HardwareData hardware =
     306        (HardwareData)activeProject.getDefaultData(getDbControl(),
     307        defaultHardwareType);
     308      if (hardware != null) getData().setHardware(hardware);
     309      hardwareHasBeenSet = true;
     310    }
     311  }
    252312  // -------------------------------------------
    253313  /*
     
    365425  }
    366426
     427  private boolean protocolHasBeenSet = false;
    367428  /**
    368429    Set the {@link Protocol} that describes the procedure used in this event.
     
    376437    checkPermission(Permission.WRITE);
    377438    if (protocol != null) protocol.checkPermission(Permission.USE);
     439    protocolHasBeenSet = true;
    378440    getData().setProtocol(protocol == null ? null : protocol.getData());
    379441  }
     
    392454  }
    393455 
     456  private boolean hardwareHasBeenSet = false;
    394457  /**
    395458    Get the {@link Hardware} that was used in this event.
     
    403466    checkPermission(Permission.WRITE);
    404467    if (hardware != null) hardware.checkPermission(Permission.USE);
     468    hardwareHasBeenSet = true;
    405469    getData().setHardware(hardware == null ? null : hardware.getData());
    406470  }
  • trunk/src/core/net/sf/basedb/core/DbControl.java

    r4517 r4527  
    328328    sc.updateLastAccess();
    329329
     330    Project activeProject = sc.getActiveProjectId() == 0 ?
     331      null : Project.getById(this, sc.getActiveProjectId());
     332   
    330333    Map<BasicItem, Transactional.Action> tempQueue = null;
    331334    Map<BasicItem, Transactional.Action> afterCommitQueue = new HashMap<BasicItem, Transactional.Action>();
     
    377380          if (action == Transactional.Action.CREATE)
    378381          {
     382            if (activeProject != null) item.setProjectDefaults(activeProject);
    379383            HibernateUtil.saveData(hSession, data);
    380384            item.onAfterInsert();
  • trunk/src/core/net/sf/basedb/core/Project.java

    r4517 r4527  
    2424package net.sf.basedb.core;
    2525
     26import net.sf.basedb.core.data.AnyToAnyData;
    2627import net.sf.basedb.core.data.BasicData;
    2728import net.sf.basedb.core.data.ProjectData;
     
    3637import java.util.ArrayList;
    3738import java.util.EnumSet;
     39import java.util.HashMap;
    3840import java.util.HashSet;
    3941import java.util.List;
     42import java.util.Map;
    4043import java.util.Set;
    4144import java.util.Collections;
     
    145148
    146149 
     150  private Map<Default, BasicData> defaults;
     151 
    147152  Project(ProjectData projectData)
    148153  {
     
    533538  {
    534539    String lnkName = defaultType.getName();
     540    BasicData defaultData = null;
    535541    if (defaultItem == null)
    536542    {
     
    540546    {
    541547      AnyToAny defaultLink = AnyToAny.getNewOrExisting(dc, this, lnkName, defaultItem, false);
    542       if (defaultLink.getId() == 0)     
    543       {
    544         dc.saveItem(defaultLink);
    545       }
    546     }     
     548      if (defaultLink.getId() == 0) dc.saveItem(defaultLink);
     549      defaultData = defaultItem.getData();
     550    }
     551    if (defaults == null) defaults = new HashMap<Default, BasicData>();
     552    defaults.put(defaultType, defaultData);
    547553  }
    548554 
     
    558564  public BasicItem getDefaultItem(DbControl dc, Default defaultType)
    559565  {
    560     if (defaultType == null) throw new InvalidUseOfNullException("defaultType");   
    561     BasicItem defaultItem = null;   
    562     AnyToAny ata;   
    563     try
    564     {
    565       ata = AnyToAny.getByName(dc, this, defaultType.getName());
    566       defaultItem = ata.getTo();
    567     }
    568     catch (ItemNotFoundException ex)
    569     {
    570       defaultItem = null;
    571     }   
    572     return defaultItem;
    573   }
     566    if (defaultType == null) throw new InvalidUseOfNullException("defaultType");
     567    BasicData defaultData = getDefaultData(dc, defaultType);
     568    return dc.getItem(BasicItem.class, defaultData);
     569  }
     570 
     571  /**
     572      Gets the project's default item as a data object.
     573      If no item of the specified type is found this will return Null
     574      @since 2.9
     575  */
     576  BasicData getDefaultData(DbControl dc, Default defaultType)
     577  {
     578    BasicData defaultData = null;   
     579    if (defaults != null && defaults.containsKey(defaultType))
     580    {
     581      defaultData = defaults.get(defaultType);
     582    }
     583    else
     584    {
     585      org.hibernate.Session session = dc.getHibernateSession();
     586      AnyToAnyData any = AnyToAny.getDataByName(session, getId(), getType(), defaultType.getName());
     587      if (any != null)
     588      {
     589        defaultData = HibernateUtil.loadData(session,
     590          defaultType.getItemType().getDataClass(), any.getToId());
     591      }
     592      if (defaults == null) defaults = new HashMap<Default, BasicData>();
     593      defaults.put(defaultType, defaultData);
     594    }
     595    return defaultData;
     596  }
    574597 
    575598  /**
  • trunk/src/core/net/sf/basedb/core/RawBioAssay.java

    r4517 r4527  
    2828import net.sf.basedb.core.data.PlatformData;
    2929import net.sf.basedb.core.data.PlatformVariantData;
     30import net.sf.basedb.core.data.ProtocolData;
    3031import net.sf.basedb.core.data.RawBioAssayData;
    3132import net.sf.basedb.core.data.RawData;
    3233import net.sf.basedb.core.data.ReporterData;
     34import net.sf.basedb.core.data.SoftwareData;
    3335import net.sf.basedb.core.data.SpotImagesData;
    3436
     
    426428    }
    427429  }
     430  /**
     431    Set software, protocol and array design from project default settings.
     432    @since 2.9
     433  */
     434  @Override
     435  void setProjectDefaults(Project activeProject)
     436    throws BaseException
     437  {
     438    super.setProjectDefaults(activeProject);
     439    if (!softwareHasBeenSet)
     440    {
     441      SoftwareData software =
     442        (SoftwareData)activeProject.getDefaultData(getDbControl(),
     443        Project.Default.SOFTWARE);
     444      if (software != null) getData().setSoftware(software);
     445      softwareHasBeenSet = true;
     446    }
     447    if (!arrayDesignHasBeenSet)
     448    {
     449      ArrayDesignData design =
     450        (ArrayDesignData)activeProject.getDefaultData(getDbControl(),
     451        Project.Default.ARRAYDESIGN);
     452      if (design != null) getData().setArrayDesign(design);
     453      arrayDesignHasBeenSet = true;
     454    }
     455    if (!protocolHasBeenSet)
     456    {
     457      ProtocolData protocol =
     458        (ProtocolData)activeProject.getDefaultData(getDbControl(),
     459        Project.Default.FEATURE_EXTRACTION_PROTOCOL);
     460      if (protocol != null) getData().setProtocol(protocol);
     461      protocolHasBeenSet = true;
     462    }
     463  }
    428464 
    429465  /**
     
    688724  }
    689725 
     726  private boolean softwareHasBeenSet = false;
    690727  /**
    691728    Set the {@link Software} used while analysing the scanned images.
     
    701738    checkPermission(Permission.WRITE);
    702739    if (software != null) software.checkPermission(Permission.USE);
     740    softwareHasBeenSet = true;
    703741    getData().setSoftware(software == null ? null : software.getData());
    704742  }
     
    718756  }
    719757 
     758  private boolean protocolHasBeenSet = false;
    720759  /**
    721760    Set the {@link Protocol} used while analysing the scanned images.
     
    731770    checkPermission(Permission.WRITE);
    732771    if (protocol != null) protocol.checkPermission(Permission.USE);
     772    protocolHasBeenSet = true;
    733773    getData().setProtocol(protocol == null ? null : protocol.getData());
    734774  }
     
    750790  }
    751791 
     792  private boolean arrayDesignHasBeenSet = false;
    752793  /**
    753794    Set the {@link ArrayDesign} this raw data uses. The array design can't be
     
    771812      throw new PermissionDeniedException("Not allowed to change the array design after raw data has been added");
    772813    }
     814    arrayDesignHasBeenSet = true;
    773815    getData().setArrayDesign(arrayDesign == null ? null : arrayDesign.getData());
    774816  }
  • trunk/src/core/net/sf/basedb/core/Scan.java

    r4517 r4527  
    2525import net.sf.basedb.core.data.ArrayBatchData;
    2626import net.sf.basedb.core.data.ArraySlideData;
     27import net.sf.basedb.core.data.HardwareData;
    2728import net.sf.basedb.core.data.HybridizationData;
     29import net.sf.basedb.core.data.ProtocolData;
    2830import net.sf.basedb.core.data.ScanData;
    2931import net.sf.basedb.core.query.Restrictions;
     
    173175    return using;
    174176  }
     177  /**
     178    Set scanner and protocol from project default settings.
     179    @since 2.9
     180  */
     181  @Override
     182  void setProjectDefaults(Project activeProject)
     183    throws BaseException
     184  {
     185    super.setProjectDefaults(activeProject);
     186    if (!scannerHasBeenSet)
     187    {
     188      HardwareData scanner =
     189        (HardwareData)activeProject.getDefaultData(getDbControl(),
     190        Project.Default.SCANNER_HARDWARE);
     191      if (scanner != null) getData().setScanner(scanner);
     192      scannerHasBeenSet = true;
     193    }
     194    if (!protocolHasBeenSet)
     195    {
     196      ProtocolData protocol =
     197        (ProtocolData)activeProject.getDefaultData(getDbControl(),
     198        Project.Default.SCANNING_PROTOCOL);
     199      if (protocol != null) getData().setProtocol(protocol);
     200      protocolHasBeenSet = true;
     201    }
     202  }
    175203  // -------------------------------------------
    176204
     
    222250  }
    223251 
     252  private boolean scannerHasBeenSet = false;
    224253  /**
    225254    Set the {@link Hardware} (scanner) used to create this scan.
     
    235264    checkPermission(Permission.WRITE);
    236265    if (scanner != null) scanner.checkPermission(Permission.USE);
     266    scannerHasBeenSet = true;
    237267    getData().setScanner(scanner == null ? null : scanner.getData());
    238268  }
     
    252282  }
    253283 
     284  private boolean protocolHasBeenSet = false;
    254285  /**
    255286    Set the {@link Protocol} used to create this scan.
     
    265296    checkPermission(Permission.WRITE);
    266297    if (protocol != null) protocol.checkPermission(Permission.USE);
     298    protocolHasBeenSet = true;
    267299    getData().setProtocol(protocol == null ? null : protocol.getData());
    268300  }
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java

    r4513 r4527  
    6464import net.sf.basedb.core.PlatformVariant;
    6565import net.sf.basedb.core.PluginParameter;
     66import net.sf.basedb.core.Project;
    6667import net.sf.basedb.core.Protocol;
     68import net.sf.basedb.core.RawDataType;
    6769import net.sf.basedb.core.RequestInformation;
    6870import net.sf.basedb.core.Sample;
     
    11321134    return findReferencedItem(dc, idMethod, platformQuery, identifier);
    11331135  }
     1136  /**
     1137    Get the default platform of the currently active project.
     1138    @return The active platform, or null if no project is active or
     1139      the project doesn't specify a platform
     1140    @since 2.9
     1141  */
     1142  protected Platform getProjectDefaultPlatform(DbControl dc)
     1143  {
     1144    if (sc.getActiveProjectId() == 0) return null;
     1145    Project activeProject = Project.getById(dc, sc.getActiveProjectId());
     1146    return (Platform)activeProject.getDefaultItem(dc, Project.Default.PLATFORM);
     1147  }
     1148 
     1149  /**
     1150    Get the default platform variant of the currently active project.
     1151    @return The active platform variant, or null if no project is active or
     1152      the project doesn't specify a variant
     1153    @since 2.9
     1154  */
     1155  protected PlatformVariant getProjectDefaultVariant(DbControl dc)
     1156  {
     1157    if (sc.getActiveProjectId() == 0) return null;
     1158    Project activeProject = Project.getById(dc, sc.getActiveProjectId());
     1159    return (PlatformVariant)activeProject.getDefaultItem(dc, Project.Default.PLATFORM_VARIANT);
     1160  }
    11341161 
    11351162  private ItemQuery<PlatformVariant> variantQuery;
     
    11661193    return findReferencedItem(dc, idMethod, variantQuery, identifier);
    11671194  }
     1195 
     1196  /**
     1197    Get the default raw data type of the currently active project.
     1198    @return The active raw data type, or null if no project is active or
     1199      the project doesn't specify raw data type
     1200    @since 2.9
     1201  */
     1202  protected RawDataType getProjectDefaultRawDataType(DbControl dc)
     1203  {
     1204    if (sc.getActiveProjectId() == 0) return null;
     1205    Project activeProject = Project.getById(dc, sc.getActiveProjectId());
     1206    return activeProject.getDefaultRawDataType();
     1207  }
     1208
    11681209 
    11691210  private ItemQuery<DataFileType> fileTypeQuery;
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ArrayDesignImporter.java

    r4513 r4527  
    252252      platform = findPlatform(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, platformMapper.getValue(data));
    253253    }
     254    else
     255    {
     256      platform = getProjectDefaultPlatform(dc);
     257    }
    254258    if (variantMapper != null)
    255259    {
    256260      variant = findVariant(dc, platform, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, variantMapper.getValue(data));
     261    }
     262    else
     263    {
     264      variant = getProjectDefaultVariant(dc);
    257265    }
    258266   
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/RawBioAssayImporter.java

    r4513 r4527  
    315315      platform = findPlatform(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, platformMapper.getValue(data));
    316316    }
     317    else
     318    {
     319      platform = getProjectDefaultPlatform(dc);
     320    }
    317321    if (variantMapper != null)
    318322    {
    319323      variant = findVariant(dc, platform, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, variantMapper.getValue(data));
    320324    }
     325    else
     326    {
     327      variant = getProjectDefaultVariant(dc);
     328    }
    321329    if (rawDataTypeMapper != null)
    322330    {
    323331      rawDataType = RawDataTypes.getRawDataType(rawDataTypeMapper.getValue(data));
     332    }
     333    else
     334    {
     335      rawDataType = getProjectDefaultRawDataType(dc);
    324336    }
    325337   
  • trunk/src/test/TestProject.java

    r4514 r4527  
    7070    test_listgroups(id, 0);
    7171    TestGroup.test_delete(groupId);
    72    
     72 
     73    // Extra test: set default item.
     74    int samplingId = TestProtocol.test_create(
     75        SystemItems.getId(ProtocolType.SAMPLING), "Sampling protocol", false);
     76    int hybStationId = TestHardware.test_create(
     77        SystemItems.getId(HardwareType.HYBRIDIZATION_STATION), "Hyb station", false);
     78    test_defaultItem(id, Project.Default.SAMPLING_PROTOCOL, samplingId);
     79    test_defaultItem(id, Project.Default.HYBRIDIZATION_HARDWARE, hybStationId);
     80
    7381    // Extra test: activate project, create shared item, and list all items
    7482    test_activate_project(id);
    75     int labelId = TestLabel.test_create(true);
    76     int clientId = TestClient.test_create("shared.to.project", true);
     83    int sampleId = TestSample.test_create(0, "Sample (shared)", false);
     84    int hybId = TestHybridization.test_create(0, false, new int[] {});
    7785    test_list_items(id, 2);
    7886    test_noactive_project();
     87   
    7988    if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
    80     TestLabel.test_delete(labelId);
    81     TestClient.test_delete(clientId);
    82    
    83     // Extra test: set default item.   
    84     test_defaultItem(id);
    85    
     89    TestSample.test_delete(sampleId);
     90    TestHybridization.test_delete(hybId);
    8691   
    8792    // Standard test: Delete
    8893    test_delete(id);
    8994    test_delete(id2);
     95    TestProtocol.test_delete(sampleId);
     96    TestHardware.test_delete(hybStationId);
     97   
    9098    write("++Testing projects "+(ok ? "OK" : "Failed")+"\n");
    9199    return ok;
    92100  }
    93101
    94   static void test_defaultItem(int id)
    95   {
    96     if (id == 0) return;
     102  static void test_defaultItem(int project_id, Project.Default defaultType, int item_id)
     103  {
     104    if (project_id == 0 || item_id == 0) return;
    97105    DbControl dc = null;   
    98106    try
    99107    {     
    100       dc = TestUtil.getDbControl();     
    101       int adId = TestArrayDesign.test_create(Platform.GENERIC, false);     
    102       ArrayDesign ad = ArrayDesign.getById(dc, adId);
    103       Project p = Project.getById(dc, id);
    104      
    105       p.setDefaultItem(dc, ad, Project.Default.ARRAYDESIGN);
    106       dc.commit();
    107       write("--Set default item OK");
    108       dc = TestUtil.getDbControl();
    109       ArrayDesign testAD = (ArrayDesign)p.getDefaultItem(dc, Project.Default.ARRAYDESIGN);
    110       if (testAD.getId() != adId) throw new BaseException("Expected " + adId + " but got " + testAD.getId());
    111       write("--Get default item OK");
    112       if (TestUtil.waitBeforeDelete()) TestUtil.waitForEnter();
    113       p.setDefaultItem(dc, null, Project.Default.ARRAYDESIGN);
    114       dc.commit();   
    115       dc = TestUtil.getDbControl();
    116       try
    117       {
    118         testAD = (ArrayDesign)p.getDefaultItem(dc, Project.Default.ARRAYDESIGN);
    119       }
    120       catch(ItemNotFoundException ex)
    121       {
    122         write("--Reset default item OK");
    123       }     
    124       TestArrayDesign.test_delete(adId);     
     108      dc = TestUtil.getDbControl();
     109      Project p = Project.getById(dc, project_id);
     110      BasicItem defaultItem = defaultType.getItemType().getById(dc, item_id);
     111      p.setDefaultItem(dc, defaultItem, defaultType);
     112      dc.commit();
     113      write("--Set default item OK (" + defaultType + "; id=" + item_id + ")");
    125114    }
    126115    catch(Throwable ex)
    127116    {
    128       write("--Set default item FAILED");
     117      write("--Set default item FAILED (" + defaultType + "; id=" + item_id + ")");
    129118      ex.printStackTrace();
    130119      ok = false;
Note: See TracChangeset for help on using the changeset viewer.