/** getXml. */
  @Get
  public void getXml() {
    JaxbObject<Lane> jaxbTool = new JaxbObject<>();
    Hibernate3DtoCopier copier = new Hibernate3DtoCopier();

    Lane dto;
    authenticate();

    LaneService ss = BeanFactory.getLaneServiceBean();
    Lane lane = testIfNull(ss.findBySWAccession(getId()));
    CollectionPropertyName<Lane>[] createCollectionPropertyNames =
        CollectionPropertyName.createCollectionPropertyNames(
            Lane.class, new String[] {"laneAttributes"});
    dto =
        copier.hibernate2dto(
            Lane.class,
            lane,
            new Class<?>[] {LibraryStrategy.class, LibrarySource.class, LibrarySelection.class},
            createCollectionPropertyNames);

    if (fields.contains("sequencerRun")) {
      SequencerRun sr = lane.getSequencerRun();
      if (sr != null) {
        SequencerRun copySR = copier.hibernate2dto(SequencerRun.class, sr);
        dto.setSequencerRun(copySR);
      } else {
        Log.info("Could not be found sequencer run");
      }
    }

    Document line = XmlTools.marshalToDocument(jaxbTool, dto);
    getResponse().setEntity(XmlTools.getRepresentation(line));
  }
  /**
   * {@inheritDoc}
   *
   * @return
   */
  @Override
  @Put
  public Representation put(Representation entity) {
    authenticate();
    Representation representation = null;
    Lane newLane = null;
    JaxbObject<Lane> jo = new JaxbObject<>();
    try {

      String text = entity.getText();
      newLane = (Lane) XmlTools.unMarshal(jo, new Lane(), text);
    } catch (SAXException | IOException ex) {
      ex.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, ex);
    }
    try {
      LaneService fs = BeanFactory.getLaneServiceBean();
      Lane lane = testIfNull(fs.findByID(newLane.getLaneId()));
      lane.givesPermission(registration);
      // simple types
      String name = newLane.getName();
      String desc = newLane.getDescription();
      Integer laneIndex = newLane.getLaneIndex();
      String cycleDescriptor = newLane.getCycleDescriptor();
      Boolean skip = newLane.getSkip();
      String tags = newLane.getTags();
      String regions = newLane.getRegions();
      // foreign keys
      Sample sample = newLane.getSample();
      Registration owner = newLane.getOwner();

      Set<LaneAttribute> newAttributes = newLane.getLaneAttributes();

      if (name != null) {
        lane.setName(name);
      }
      if (desc != null) {
        lane.setDescription(desc);
      }
      if (laneIndex != null) {
        lane.setLaneIndex(laneIndex);
      }
      if (cycleDescriptor != null) {
        lane.setCycleDescriptor(cycleDescriptor);
      }
      if (skip != null) {
        lane.setSkip(skip);
      }
      if (tags != null) {
        lane.setTags(tags);
      }
      if (regions != null) {
        lane.setRegions(regions);
      }

      if (sample != null) {
        SampleService ss = BeanFactory.getSampleServiceBean();
        Sample newSample = ss.findByID(sample.getSampleId());
        if (newSample != null && newSample.givesPermission(registration)) {
          lane.setSample(newSample);
        } else if (newSample == null) {
          Log.info("Could not be found " + sample);
        }
      }

      if (owner != null) {
        RegistrationService rs = BeanFactory.getRegistrationServiceBean();
        Registration newReg = rs.findByEmailAddress(owner.getEmailAddress());
        if (newReg != null) {
          lane.setOwner(newReg);
        } else {
          Log.info("Could not be found " + owner);
        }
      } else if (lane.getOwner() == null) {
        lane.setOwner(registration);
      }
      if (newAttributes != null) {
        // SEQWARE-1577 - AttributeAnnotator cascades deletes when annotating
        LaneIDResource.mergeAttributes(lane.getLaneAttributes(), newAttributes, lane);
      }

      fs.update(registration, lane);

      Hibernate3DtoCopier copier = new Hibernate3DtoCopier();

      Lane detachedLane =
          copier.hibernate2dto(
              Lane.class,
              lane,
              new Class<?>[] {LibraryStrategy.class, LibrarySource.class, LibrarySelection.class},
              new CollectionPropertyName<?>[] {});

      Document line = XmlTools.marshalToDocument(jo, detachedLane);
      representation = XmlTools.getRepresentation(line);
      getResponse().setEntity(representation);
      getResponse()
          .setLocationRef(getRequest().getRootRef() + "/lanes/" + detachedLane.getSwAccession());
      getResponse().setStatus(Status.SUCCESS_CREATED);
    } catch (SecurityException e) {
      getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN, e.getMessage());
    } catch (Exception e) {
      e.printStackTrace();
      getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }

    return representation;
  }