/** getXml. */ @Get public void getXml() { authenticate(); WorkflowService ss = BeanFactory.getWorkflowServiceBean(); Hibernate3DtoCopier copier = new Hibernate3DtoCopier(); JaxbObject<Workflow> jaxbTool = new JaxbObject<Workflow>(); Workflow workflow = (Workflow) testIfNull(ss.findBySWAccession(Integer.parseInt(getId()))); Workflow dto = copier.hibernate2dto(Workflow.class, workflow); if (fields.contains("params")) { SortedSet<WorkflowParam> wps = workflow.getWorkflowParams(); if (wps != null) { SortedSet<WorkflowParam> copiedParams = new TreeSet<WorkflowParam>(); for (WorkflowParam param : workflow.getWorkflowParams()) { copiedParams.add(copier.hibernate2dto(WorkflowParam.class, param)); } dto.setWorkflowParams(copiedParams); } else { Log.info("Could not be found: workflow params"); } } if (fields.contains("attributes")) { Set<WorkflowAttribute> was = workflow.getWorkflowAttributes(); if (was != null && !was.isEmpty()) { Set<WorkflowAttribute> newwas = new TreeSet<WorkflowAttribute>(); for (WorkflowAttribute wa : was) { newwas.add(copier.hibernate2dto(WorkflowAttribute.class, wa)); } dto.setWorkflowAttributes(newwas); } } Document line = XmlTools.marshalToDocument(jaxbTool, dto); getResponse().setEntity(XmlTools.getRepresentation(line)); }
/** 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)); }
/** getXml. */ @Get public void getXml() { authenticate(); JaxbObject<Lane> jaxbTool = new JaxbObject<>(); Hibernate3DtoCopier copier = new Hibernate3DtoCopier(); SampleService ss = BeanFactory.getSampleServiceBean(); Sample sample = testIfNull(ss.findBySWAccession(getId())); CollectionPropertyName<Sample>[] createCollectionPropertyNames = CollectionPropertyName.createCollectionPropertyNames( Sample.class, new String[] {"sampleAttributes"}); Sample dto = copier.hibernate2dto( Sample.class, sample, new Class<?>[] {}, createCollectionPropertyNames); if (fields.contains("lanes")) { SortedSet<Lane> lanes = sample.getLanes(); if (lanes != null) { SortedSet<Lane> copiedLanes = new TreeSet<>(); for (Lane lane : lanes) { copiedLanes.add(copier.hibernate2dto(Lane.class, lane)); } dto.setLanes(copiedLanes); } else { Log.info("Could not be found: lanes"); } } if (fields.contains("ius")) { SortedSet<IUS> ius = sample.getIUS(); if (ius != null) { SortedSet<IUS> copiedIUS = new TreeSet<>(); for (IUS i : ius) { copiedIUS.add(copier.hibernate2dto(IUS.class, i)); } dto.setIUS(copiedIUS); } { Log.info("Could not be found : ius"); } } Document line = XmlTools.marshalToDocument(jaxbTool, dto); getResponse().setEntity(XmlTools.getRepresentation(line)); }
/** 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)); }
/** * {@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; }
/** {@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; }
/** {@inheritDoc} */ @Override public Representation put(Representation entity) { authenticate(); Representation representation = null; Workflow newWorkflow = null; JaxbObject<Workflow> jo = new JaxbObject<Workflow>(); try { String text = entity.getText(); newWorkflow = (Workflow) XmlTools.unMarshal(jo, new Workflow(), text); } catch (SAXException ex) { ex.printStackTrace(); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, ex.getMessage()); } catch (IOException e) { e.printStackTrace(); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage()); } try { WorkflowService fs = BeanFactory.getWorkflowServiceBean(); Workflow workflow = (Workflow) testIfNull(fs.findByID(newWorkflow.getWorkflowId())); workflow.givesPermission(registration); // simple types String name = newWorkflow.getName(); String desc = newWorkflow.getDescription(); String baseIniFile = newWorkflow.getBaseIniFile(); String command = newWorkflow.getCommand(); String cwd = newWorkflow.getCwd(); String host = newWorkflow.getHost(); String inputAlgorithm = newWorkflow.getInputAlgorithm(); String permanentBundleLocation = newWorkflow.getPermanentBundleLocation(); String seqwareVersion = newWorkflow.getSeqwareVersion(); String template = newWorkflow.getTemplate(); String username = newWorkflow.getUsername(); String version = newWorkflow.getVersion(); // foreign keys Registration owner = newWorkflow.getOwner(); workflow.setName(name); workflow.setDescription(desc); workflow.setBaseIniFile(baseIniFile); workflow.setCommand(command); workflow.setCwd(cwd); workflow.setHost(host); workflow.setInputAlgorithm(inputAlgorithm); workflow.setPermanentBundleLocation(permanentBundleLocation); workflow.setSeqwareVersion(seqwareVersion); workflow.setTemplate(template); workflow.setUsername(username); workflow.setVersion(version); workflow.setUpdateTimestamp(new Date()); workflow.setWorkflowClass(newWorkflow.getWorkflowClass()); workflow.setWorkflowType(newWorkflow.getWorkflowType()); workflow.setWorkflowEngine(newWorkflow.getWorkflowEngine()); if (owner != null) { RegistrationService rs = BeanFactory.getRegistrationServiceBean(); Registration newReg = rs.findByEmailAddress(owner.getEmailAddress()); if (newReg != null) { workflow.setOwner(newReg); } else { Log.info("Could not be found: " + owner); } } else if (workflow.getOwner() == null) { workflow.setOwner(registration); } if (newWorkflow.getWorkflowAttributes() != null) { workflow.getWorkflowAttributes().clear(); for (WorkflowAttribute wfa : newWorkflow.getWorkflowAttributes()) { wfa.setWorkflow(workflow); workflow.getWorkflowAttributes().add(wfa); } } fs.update(registration, workflow); Hibernate3DtoCopier copier = new Hibernate3DtoCopier(); Workflow detachedWorkflow = copier.hibernate2dto(Workflow.class, workflow); Document line = XmlTools.marshalToDocument(jo, detachedWorkflow); representation = XmlTools.getRepresentation(line); getResponse().setEntity(representation); getResponse() .setLocationRef( getRequest().getRootRef() + "/workflows/" + detachedWorkflow.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; }
/** * {@inheritDoc} * * @return */ @Override @Put public Representation put(Representation entity) { authenticate(); Representation representation = null; try { JaxbObject<Sample> jo = new JaxbObject<>(); String text = entity.getText(); Sample o = null; try { o = (Sample) XmlTools.unMarshal(jo, new Sample(), text); } catch (SAXException ex) { throw new ResourceException(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY, ex); } SampleService service = BeanFactory.getSampleServiceBean(); Sample sample = testIfNull(service.findByID(o.getSampleId())); sample.givesPermission(registration); String anonymizedName = o.getAnonymizedName(); String individualName = o.getIndividualName(); Integer swAccession = o.getSwAccession(); String name = o.getName(); String title = o.getTitle(); String alias = o.getAlias(); String description = o.getDescription(); String type = o.getType(); String tags = o.getTags(); String adapters = o.getAdapters(); String regions = o.getRegions(); Integer expectedNumRuns = o.getExpectedNumRuns(); Integer expectedNumSpots = o.getExpectedNumSpots(); Integer expectedNumReads = o.getExpectedNumReads(); Boolean skip = o.getSkip(); Boolean isSelected = o.getIsSelected(); Boolean isHasFile = o.getIsHasFile(); Integer countFile = o.getCountFile(); if (null != anonymizedName) sample.setAnonymizedName(anonymizedName); if (null != individualName) sample.setIndividualName(individualName); if (null != swAccession) sample.setSwAccession(swAccession); if (null != name) sample.setName(name); if (null != title) sample.setTitle(title); if (null != alias) sample.setAlias(alias); if (null != description) sample.setDescription(description); if (null != type) sample.setType(type); if (null != tags) sample.setTags(tags); if (null != adapters) sample.setAdapters(adapters); if (null != regions) sample.setRegions(regions); if (null != expectedNumRuns) sample.setExpectedNumRuns(expectedNumRuns); if (null != expectedNumSpots) sample.setExpectedNumSpots(expectedNumSpots); if (null != expectedNumReads) sample.setExpectedNumReads(expectedNumReads); if (null != skip) sample.setSkip(skip); if (null != isSelected) sample.setIsSelected(isSelected); if (null != isHasFile) sample.setIsHasFile(isHasFile); if (null != countFile) sample.setCountFile(countFile); if (null != o.getSampleAttributes()) { // SEQWARE-1577 - AttributeAnnotator cascades deletes when annotating SampleIDResource.mergeAttributes( sample.getSampleAttributes(), o.getSampleAttributes(), sample); } if (null != o.getParents()) { SampleService ss = BeanFactory.getSampleServiceBean(); Set<Sample> parents = new HashSet<>(sample.getParents()); for (Sample s : o.getParents()) { parents.add(ss.findByID(s.getSampleId())); } sample.setParents(parents); } if (null != o.getChildren()) { SampleService ss = BeanFactory.getSampleServiceBean(); Set<Sample> children = new HashSet<>(sample.getChildren()); for (Sample s : o.getChildren()) { children.add(ss.findByID(s.getSampleId())); } sample.setChildren(children); } service.update(sample); // persist object Hibernate3DtoCopier copier = new Hibernate3DtoCopier(); Sample detachedSample = copier.hibernate2dto(Sample.class, sample); Document line = XmlTools.marshalToDocument(jo, detachedSample); getResponse().setEntity(XmlTools.getRepresentation(line)); getResponse() .setLocationRef( getRequest().getRootRef() + "/samples/" + detachedSample.getSwAccession()); getResponse().setStatus(Status.SUCCESS_CREATED); } catch (SecurityException e) { getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN, e); } catch (Exception e) { e.printStackTrace(); getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, e); } return representation; }