예제 #1
0
  // this method depends on all of the Flow Cell's channel being sent in the doc, if an entire
  // channel was deleted, this will not work!
  //  It depends on hibernate's cacade=all to delete the channel and all sequence lanes in
  // SaveFlowCell
  // now that we no longer use cascade=all, and in order to allow sequence lanes to move backward in
  // the workflow
  // we need to manage their work items individually and not just delete the sequence lanes when
  // they are removed from a channel
  public void parse(Session sess) throws Exception {
    FlowCellChannel channel = new FlowCellChannel();
    Element root = this.doc.getRootElement();

    for (Iterator i = root.getChildren("FlowCellChannel").iterator(); i.hasNext(); ) {
      Boolean isNewChannel = false;
      Map sequenceLaneMap = new HashMap();
      Element node = (Element) i.next();

      String idFlowCellChannelString = node.getAttributeValue("idFlowCellChannel");
      // Is this HISEQ or MISEQ?
      String codeStepNext = "";
      // What is the core?
      Integer idCoreFacility = -1;
      List workItems =
          sess.createQuery(
                  "SELECT wi from WorkItem wi where idFlowCellChannel = " + idFlowCellChannelString)
              .list();
      for (Iterator i1 = workItems.iterator(); i1.hasNext(); ) {
        WorkItem wi = (WorkItem) i1.next();
        codeStepNext = wi.getCodeStepNext();
        idCoreFacility = wi.getIdCoreFacility();
        break;
      }

      if (idFlowCellChannelString.startsWith("FlowCellChannel")
          || idFlowCellChannelString.equals("")) {

        isNewChannel = true;
        channel = new FlowCellChannel();
        channel.setSequenceLanes(new TreeSet(new LaneComparator()));

      } else {
        isNewChannel = false;
        channel =
            (FlowCellChannel)
                sess.get(FlowCellChannel.class, Integer.parseInt(idFlowCellChannelString));
      }

      this.initializeFlowCellChannel(sess, node, channel);

      if (node.getChild("sequenceLanes") != null
          && !node.getChild("sequenceLanes").getChildren("SequenceLane").isEmpty()) {

        for (Iterator i1 = node.getChild("sequenceLanes").getChildren("SequenceLane").iterator();
            i1.hasNext(); ) {
          Boolean isNewLane = false;
          SequenceLane sl = new SequenceLane();

          Element sequenceLaneNode = (Element) i1.next();
          String idSequenceLaneString = sequenceLaneNode.getAttributeValue("idSequenceLane");

          if (idSequenceLaneString.startsWith("SequenceLane") || idSequenceLaneString.equals("")) {

            isNewLane = true;
            sl = new SequenceLane();
          } else {
            isNewLane = false;
            sl =
                (SequenceLane) sess.get(SequenceLane.class, Integer.parseInt(idSequenceLaneString));
          }

          sl.setIdFlowCellChannel(channel.getIdFlowCellChannel());

          if (isNewLane) {
            sess.save(sl);
            idSequenceLaneString = sl.getIdSequenceLane().toString();
          }
          sequenceLaneMap.put(idSequenceLaneString, sl);
        }
      }

      //
      // Remove lanes which have been deleted by the user
      //
      if (channel.getSequenceLanes() != null || !channel.getSequenceLanes().isEmpty()) {

        TreeSet lanesToDelete = new TreeSet(new LaneComparator());
        for (Iterator i2 = channel.getSequenceLanes().iterator(); i2.hasNext(); ) {
          SequenceLane existingLane = (SequenceLane) i2.next();
          if (!sequenceLaneMap.containsKey(existingLane.getIdSequenceLane().toString())) {
            lanesToDelete.add(
                existingLane); // delete lane if it was stored in this channel but was not sent in
                               // the request (meaning the user deleted it from the channel)
          }
        }
        for (Iterator i2 = lanesToDelete.iterator(); i2.hasNext(); ) {
          SequenceLane laneToDelete = (SequenceLane) i2.next();
          channel.getSequenceLanes().remove(laneToDelete);
          laneToDelete.setIdFlowCellChannel(null);
          // create a work item to move the sequence lane back to the assembly stage
          WorkItem wi = new WorkItem();
          wi.setIdRequest(laneToDelete.getIdRequest());
          wi.setSequenceLane(laneToDelete);
          wi.setCreateDate(new Date(System.currentTimeMillis()));
          if (idCoreFacility > 0) {
            wi.setIdCoreFacility(idCoreFacility);
          }
          if (codeStepNext.equals("HSEQFINFC") || codeStepNext.equals("HSEQPIPE")) {
            wi.setCodeStepNext("HSEQASSEM");
          } else if (codeStepNext.equals("MISEQFINFC") || codeStepNext.equals("MISEQPIPE")) {
            wi.setCodeStepNext("MISEQASSEM");
          }
          sess.save(wi);
        }
      }

      //
      // Save newly added lanes to channel
      //
      for (Iterator i2 = sequenceLaneMap.keySet().iterator(); i2.hasNext(); ) {
        String idLaneString = (String) i2.next();
        SequenceLane sl = (SequenceLane) sequenceLaneMap.get(idLaneString);

        boolean exists = false;
        if (!isNewChannel) {
          if (channel.getSequenceLanes() != null || !channel.getSequenceLanes().isEmpty()) {

            for (Iterator i3 = channel.getSequenceLanes().iterator(); i3.hasNext(); ) {
              SequenceLane existingLane = (SequenceLane) i3.next();

              if (existingLane.getIdSequenceLane().equals(sl.getIdSequenceLane())) {

                exists = true;
              }
            }
          }
        }
        // New sequence lane -- add it to the list
        if (!exists) {
          channel.getSequenceLanes().add(sl);
          // delete the work item for the sequence lane
          workItems =
              sess.createQuery(
                      "SELECT wi from WorkItem wi where idSequenceLane = " + sl.getIdSequenceLane())
                  .list();
          for (Iterator i1 = workItems.iterator(); i1.hasNext(); ) {
            WorkItem wi = (WorkItem) i1.next();
            sess.delete(wi);
            break;
          }
        }
      }

      sess.flush();

      if (isNewChannel) {
        sess.save(channel);
        idFlowCellChannelString = channel.getIdFlowCellChannel().toString();
      }
      channelMap.put(idFlowCellChannelString, channel);
    }
  }
예제 #2
0
 public int compare(Object o1, Object o2) {
   SequenceLane u1 = (SequenceLane) o1;
   SequenceLane u2 = (SequenceLane) o2;
   return u1.getIdSequenceLane().compareTo(u2.getIdSequenceLane());
 }