use of uk.ac.bbsrc.tgac.miso.core.data.Experiment in project miso-lims by miso-lims.
the class EnaSubmissionPreparation method toBytes.
public byte[] toBytes() {
try (ByteArrayOutputStream outputBytes = new ByteArrayOutputStream()) {
ZipOutputStream output = new ZipOutputStream(outputBytes);
submission.setSubmissionDate(new Date());
Document submissionDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element s = submissionDocument.createElementNS(null, "SUBMISSION");
s.setAttribute("alias", submission.getAlias());
s.setAttribute("submission_date", DF_TIMESTAMP.format(submission.getSubmissionDate()));
s.setAttribute("submission_comment", submission.getDescription());
s.setAttribute("center_name", centreName);
Element title = submissionDocument.createElementNS(null, "TITLE");
title.setTextContent(submission.getTitle());
s.appendChild(title);
Element contacts = submissionDocument.createElementNS(null, "CONTACTS");
Stream.concat(Stream.of(user), submission.getExperiments().stream().map(experiment -> experiment.getCreator()).filter(Objects::nonNull)).map(User::getFullName).distinct().map(contactName -> {
Element contact = submissionDocument.createElementNS(null, "CONTACT");
contact.setAttribute("name", contactName);
return contact;
}).forEach(contacts::appendChild);
s.appendChild(contacts);
Element actions = submissionDocument.createElementNS(null, "ACTIONS");
for (ChildSubmissionFile subFile : FILES) {
subFile.generateDocument(output);
if (!subFile.isEmpty()) {
if (submissionAction == SubmissionActionType.ADD || submissionAction == SubmissionActionType.VALIDATE) {
Element action = submissionDocument.createElementNS(null, "ACTION");
Element validate = submissionDocument.createElementNS(null, submissionAction.name());
validate.setAttribute("schema", subFile.name());
validate.setAttribute("source", subFile.fileName());
action.appendChild(validate);
actions.appendChild(action);
}
}
}
s.appendChild(actions);
if (submissionDocument.getElementsByTagName("SUBMISSION_SET").item(0) != null) {
submissionDocument.getElementsByTagName("SUBMISSION_SET").item(0).appendChild(s);
} else {
Element submissionSet = submissionDocument.createElementNS(null, "SUBMISSION_SET");
submissionDocument.appendChild(submissionSet);
submissionSet.appendChild(s);
}
ZipEntry mainFile = new ZipEntry("SUBMISSON.xml");
output.putNextEntry(mainFile);
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StreamResult result = new StreamResult(output);
DOMSource source = new DOMSource(submissionDocument);
transformer.transform(source, result);
output.closeEntry();
output.close();
return outputBytes.toByteArray();
} catch (ParserConfigurationException | TransformerException | IOException e) {
throw new RuntimeException("Cannot generate data.");
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.Experiment in project miso-lims by miso-lims.
the class PoolRestController method assignPool.
@PostMapping(value = "/{poolId}/assign", produces = "application/json")
@ResponseStatus(code = HttpStatus.NO_CONTENT)
public void assignPool(@PathVariable Long poolId, @RequestBody AssignPoolDto request) throws IOException {
Pool pool = poolId == 0 ? null : poolService.get(poolId);
// Determine if this pool transition is allowed for this experiment. If removing a pool, it strictly isn't. If the new pool contains the
// same library as the experiment, it's fine.
Predicate<Experiment> isTransitionValid = pool == null ? experiment -> false : experiment -> pool.getPoolContents().stream().map(pd -> pd.getAliquot().getLibraryId()).anyMatch(id -> id == experiment.getLibrary().getId());
//
request.getPartitionIds().stream().map(//
WhineyFunction.rethrow(containerService::getPartition)).peek(WhineyConsumer.rethrow(partition -> {
for (RunPosition runPos : partition.getSequencerPartitionContainer().getRunPositions()) {
Run run = runPos.getRun();
// Check that we aren't going to hose any existing experiments through this reassignment
boolean relatedExperimentsOkay = //
experimentService.listAllByRunId(run.getId()).stream().flatMap(//
experiment -> experiment.getRunPartitions().stream()).filter(//
rp -> rp.getRun().getId() == run.getId() && rp.getPartition().getId() == partition.getId()).map(//
RunPartition::getExperiment).allMatch(isTransitionValid);
if (!relatedExperimentsOkay) {
throw new RestException(String.format("%s %d is used in an experiment.", partition.getSequencerPartitionContainer().getModel().getPlatformType().getPartitionName(), partition.getPartitionNumber()), Status.BAD_REQUEST);
}
}
if (pool != null && partition.getSequencerPartitionContainer().getModel().getPlatformType() != pool.getPlatformType()) {
throw new RestException(String.format("%s %d in %s is not compatible with pool %s.", partition.getSequencerPartitionContainer().getModel().getPlatformType().getPartitionName(), partition.getPartitionNumber(), partition.getSequencerPartitionContainer().getIdentificationBarcode(), pool.getName()), Status.BAD_REQUEST);
}
partition.setPool(pool);
if (request.getConcentration() != null) {
partition.setLoadingConcentration(new BigDecimal(request.getConcentration()));
partition.setLoadingConcentrationUnits(request.getUnits());
} else {
partition.setLoadingConcentration(null);
partition.setLoadingConcentrationUnits(null);
}
})).forEach(WhineyConsumer.rethrow(containerService::update));
if (pool != null) {
poolService.update(pool);
}
}
use of uk.ac.bbsrc.tgac.miso.core.data.Experiment in project miso-lims by miso-lims.
the class ExperimentRestController method addKit.
@PostMapping(value = "/{experimentId}/addkit", produces = "application/json")
@ResponseBody
public KitConsumableDto addKit(@PathVariable Long experimentId, @RequestBody KitConsumableDto dto) throws IOException {
Experiment experiment = experimentService.get(experimentId);
if (experiment == null) {
throw new RestException("No such experiment.", Status.NOT_FOUND);
}
Kit kit = kitService.getKitByLotNumber(dto.getLotNumber());
if (kit == null) {
kit = Dtos.to(dto);
kitService.saveKit(kit);
} else {
if (kit.getKitDescriptor().getId() != (dto.getDescriptor().getId())) {
throw new RestException("Kit exists, but kit type does not match.", Status.BAD_REQUEST);
}
}
long savedKitId = kit.getId();
if (experiment.getKits().stream().noneMatch(k -> k.getId() == savedKitId)) {
experiment.addKit(kit);
}
experimentService.update(experiment);
return Dtos.asDto(kit);
}
use of uk.ac.bbsrc.tgac.miso.core.data.Experiment in project miso-lims by miso-lims.
the class HibernateExperimentDao method listAll.
@Override
public List<Experiment> listAll() {
Criteria criteria = currentSession().createCriteria(Experiment.class);
@SuppressWarnings("unchecked") List<Experiment> results = criteria.list();
return results;
}
use of uk.ac.bbsrc.tgac.miso.core.data.Experiment in project miso-lims by miso-lims.
the class HibernateExperimentDao method listByLibrary.
@Override
public Collection<Experiment> listByLibrary(long id) throws IOException {
Criteria criteria = currentSession().createCriteria(Experiment.class);
criteria.createAlias("library", "library");
criteria.add(Restrictions.eq("library.id", id));
@SuppressWarnings("unchecked") List<Experiment> results = criteria.list();
return results;
}
Aggregations