Esempio n. 1
0
  /** getXml. */
  @Get
  public void getXml() {
    ExperimentService ss = BeanFactory.getExperimentServiceBean();
    Experiment experiment =
        (Experiment) testIfNull(ss.findBySWAccession(Integer.parseInt(getId())));
    Hibernate3DtoCopier copier = new Hibernate3DtoCopier();
    JaxbObject<Experiment> jaxbTool = new JaxbObject<Experiment>();

    Experiment dto = copier.hibernate2dto(Experiment.class, experiment);
    if (fields.contains("attributes")) {
      Set<ExperimentAttribute> eas = experiment.getExperimentAttributes();
      if (eas != null && !eas.isEmpty()) {
        Set<ExperimentAttribute> newEas = new TreeSet<ExperimentAttribute>();
        for (ExperimentAttribute ea : eas) {
          newEas.add(copier.hibernate2dto(ExperimentAttribute.class, ea));
        }
        dto.setExperimentAttributes(newEas);
      }
    }
    Document line = XmlTools.marshalToDocument(jaxbTool, dto);

    getResponse().setEntity(XmlTools.getRepresentation(line));
  }
Esempio n. 2
0
  /** {@inheritDoc} */
  @Override
  @Put
  public Representation put(Representation entity) {
    authenticate();
    Representation representation = null;
    Experiment newObj = null;
    JaxbObject<Experiment> jo = new JaxbObject<Experiment>();
    try {
      String text = entity.getText();
      newObj = (Experiment) XmlTools.unMarshal(jo, new Experiment(), text);
    } catch (SAXException ex) {
      ex.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, ex);
    } catch (IOException e) {
      e.printStackTrace();
      throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, e);
    }
    try {
      ExperimentService service = BeanFactory.getExperimentServiceBean();
      Experiment exp = (Experiment) testIfNull(service.findByID(newObj.getExperimentId()));
      exp.givesPermission(registration);

      // simple types
      String title = newObj.getTitle();
      String name = newObj.getName();
      String desc = newObj.getDescription();
      String alias = newObj.getAlias();
      String accession = newObj.getAccession();
      String status = newObj.getStatus();
      String centerName = newObj.getCenterName();
      String sequencerSpace = newObj.getSequenceSpace();
      String baseCaller = newObj.getBaseCaller();
      String qualityScorer = newObj.getQualityScorer();
      Integer qualityNumberLevels = newObj.getQualityNumberOfLevels();
      Integer qualityMultiplier = newObj.getQualityMultiplier();
      Long expectedNumberSpots = newObj.getExpectedNumberSpots();
      Long expectedNumberReads = newObj.getExpectedNumberReads();

      // foreign keys
      Study study = newObj.getStudy();
      Registration owner = newObj.getOwner();

      // sets
      Set<ExperimentAttribute> expAttributes = newObj.getExperimentAttributes();

      if (title != null) {
        exp.setTitle(title);
      }
      if (name != null) {
        exp.setName(name);
      }
      if (desc != null) {
        exp.setDescription(desc);
      }
      if (alias != null) {
        exp.setAlias(alias);
      }
      if (accession != null) {
        exp.setAccession(accession);
      }
      if (status != null) {
        exp.setStatus(status);
      }
      if (centerName != null) {
        exp.setCenterName(centerName);
      }
      if (sequencerSpace != null) {
        exp.setSequenceSpace(sequencerSpace);
      }
      if (baseCaller != null) {
        exp.setBaseCaller(baseCaller);
      }
      if (qualityScorer != null) {
        exp.setQualityScorer(qualityScorer);
      }
      if (qualityNumberLevels != null) {
        exp.setQualityNumberOfLevels(qualityNumberLevels);
      }
      if (qualityMultiplier != null) {
        exp.setQualityMultiplier(qualityMultiplier);
      }
      if (expectedNumberSpots != null) {
        exp.setExpectedNumberSpots(expectedNumberSpots);
      }
      if (expectedNumberReads != null) {
        exp.setExpectedNumberReads(expectedNumberReads);
      }

      if (study != null) {
        StudyService ss = BeanFactory.getStudyServiceBean();
        Study newStudy = ss.findByID(study.getStudyId());
        if (newStudy != null && newStudy.givesPermission(registration)) {
          exp.setStudy(newStudy);
        } else if (newStudy == null) {
          Log.info("Could not be found " + study);
        }
      }

      if (owner != null) {
        RegistrationService rs = BeanFactory.getRegistrationServiceBean();
        Registration newReg = rs.findByEmailAddress(owner.getEmailAddress());
        if (newReg != null) {
          exp.setOwner(newReg);
        } else {
          Log.info("Could not be found " + owner);
        }
      } else if (exp.getOwner() == null) {
        exp.setOwner(registration);
      }

      if (null != expAttributes) {
        exp.getExperimentAttributes().clear();
        for (ExperimentAttribute ea : expAttributes) {
          ea.setExperiment(exp);
          exp.getExperimentAttributes().add(ea);
        }
      }

      service.update(registration, exp);

      Hibernate3DtoCopier copier = new Hibernate3DtoCopier();
      Experiment detachedLane = copier.hibernate2dto(Experiment.class, exp);

      Document line = XmlTools.marshalToDocument(jo, detachedLane);
      representation = XmlTools.getRepresentation(line);
      getResponse().setEntity(representation);
      getResponse()
          .setLocationRef(
              getRequest().getRootRef() + "/experiments/" + 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;
  }