use of uk.ac.bbsrc.tgac.miso.core.data.impl.OrderLibraryAliquot in project miso-lims by miso-lims.
the class DefaultPoolOrderService method loadChildEntities.
@Override
protected void loadChildEntities(PoolOrder object) throws IOException {
loadChildEntity(object.getParameters(), object::setParameters, sequencingParametersService);
loadChildEntity(object.getPurpose(), object::setPurpose, runPurposeService);
loadChildEntity(object.getContainerModel(), object::setContainerModel, containerModelService);
for (OrderLibraryAliquot orderAliquot : object.getOrderLibraryAliquots()) {
orderAliquot.setAliquot(libraryAliquotService.get(orderAliquot.getAliquot().getId()));
}
loadChildEntity(object.getPool(), object::setPool, poolService);
loadChildEntity(object.getSequencingOrder(), object::setSequencingOrder, sequencingOrderService);
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.OrderLibraryAliquot in project miso-lims by miso-lims.
the class DefaultPoolService method getMismatchesWithOrders.
private List<ValidationError> getMismatchesWithOrders(Pool pool, List<PoolOrder> poolOrders) throws IOException {
Set<Long> poolAliquotIds = new HashSet<>();
List<ValidationError> errors = new LinkedList<>();
for (PoolElement pe : pool.getPoolContents()) {
poolAliquotIds.add(pe.getAliquot().getId());
for (ParentAliquot parent = pe.getAliquot().getParentAliquot(); parent != null; parent = parent.getParentAliquot()) {
poolAliquotIds.add(parent.getId());
}
}
for (PoolOrder order : poolOrders) {
for (OrderLibraryAliquot orderAliquot : order.getOrderLibraryAliquots()) {
if (!poolAliquotIds.contains(orderAliquot.getAliquot().getId())) {
String errorMessage = String.format("Pool must contain library aliquot '%s', as specified by pool order '%s'", orderAliquot.getAliquot().getAlias(), order.getAlias());
errors.add(new ValidationError("poolElements", errorMessage));
}
}
}
return errors;
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.OrderLibraryAliquot in project miso-lims by miso-lims.
the class EditPoolOrderController method create.
@GetMapping("/new")
public ModelAndView create(@RequestParam(name = "aliquotIds", required = false) String aliquotIds, ModelMap model) throws IOException {
model.put("title", "New Pool Order");
model.put(PageMode.PROPERTY, PageMode.CREATE.getLabel());
PoolOrder order = new PoolOrder();
if (aliquotIds != null) {
for (Long aliquotId : LimsUtils.parseIds(aliquotIds)) {
LibraryAliquot ali = libraryAliquotService.get(aliquotId);
if (ali == null) {
throw new ClientErrorException("Library aliquot " + aliquotId + " not found");
}
OrderLibraryAliquot orderLib = new OrderLibraryAliquot();
orderLib.setAliquot(ali);
order.getOrderLibraryAliquots().add(orderLib);
}
}
return orderPage(order, model);
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.OrderLibraryAliquot in project miso-lims by miso-lims.
the class DefaultPoolOrderService method applyChanges.
@Override
protected void applyChanges(PoolOrder to, PoolOrder from) throws IOException {
to.setPartitions(from.getPartitions());
to.setContainerModel(from.getContainerModel());
to.setParameters(from.getParameters());
to.setAlias(from.getAlias());
to.setPurpose(from.getPurpose());
to.setDescription(from.getDescription());
to.setDraft(from.isDraft());
// remove from TO if library isn't in FROM
// add to TO if library isn't in TO
// update proportion in TO if different in FROM
Set<Long> fromIds = new HashSet<>();
for (OrderLibraryAliquot fromOrderAli : from.getOrderLibraryAliquots()) {
fromIds.add(fromOrderAli.getAliquot().getId());
}
Set<OrderLibraryAliquot> removed = new HashSet<>();
List<String> aliquotChangeMessages = new ArrayList<>();
for (OrderLibraryAliquot toOrderAli : to.getOrderLibraryAliquots()) {
if (!fromIds.contains(toOrderAli.getAliquot().getId())) {
aliquotChangeMessages.add("Removed library aliquot: " + toOrderAli.getAliquot().getAlias());
removed.add(toOrderAli);
}
}
to.getOrderLibraryAliquots().removeAll(removed);
for (OrderLibraryAliquot fromOrderAli : from.getOrderLibraryAliquots()) {
OrderLibraryAliquot toOrderAli = to.getOrderLibraryAliquots().stream().filter(lib -> lib.getAliquot().getId() == fromOrderAli.getAliquot().getId()).findFirst().orElse(null);
if (toOrderAli == null) {
aliquotChangeMessages.add("Added library aliquot: " + fromOrderAli.getAliquot().getAlias());
to.getOrderLibraryAliquots().add(fromOrderAli);
} else {
if (toOrderAli.getProportion() != fromOrderAli.getProportion()) {
aliquotChangeMessages.add(fromOrderAli.getAliquot().getAlias() + " proportion changed: " + toOrderAli.getProportion() + " to " + fromOrderAli.getProportion());
toOrderAli.setProportion(fromOrderAli.getProportion());
}
}
}
if (!aliquotChangeMessages.isEmpty()) {
changeLogService.create(to.createChangeLog(String.join("\n", aliquotChangeMessages), "library aliquots", authorizationManager.getCurrentUser()));
}
to.setPool(from.getPool());
to.setSequencingOrder(from.getSequencingOrder());
}
use of uk.ac.bbsrc.tgac.miso.core.data.impl.OrderLibraryAliquot in project miso-lims by miso-lims.
the class DefaultPoolOrderService method collectValidationErrors.
@Override
protected void collectValidationErrors(PoolOrder object, PoolOrder beforeChange, List<ValidationError> errors) throws IOException {
if (object.getPool() != null || object.getSequencingOrder() != null) {
// order should be fulfilled
if (object.isDraft()) {
errors.add(new ValidationError("draft", "Fulfilled order cannot be a draft"));
}
if (object.getPool() == null) {
errors.add(new ValidationError("poolId", "Pool must be provided if a sequencing order is linked"));
} else {
for (OrderLibraryAliquot orderAli : object.getOrderLibraryAliquots()) {
if (object.getPool().getPoolContents().stream().map(PoolElement::getAliquot).noneMatch(poolElement -> {
if (poolElement.getId() == orderAli.getAliquot().getId()) {
return true;
}
for (ParentAliquot parent = poolElement.getParentAliquot(); parent != null; parent = parent.getParentAliquot()) {
if (parent.getId() == orderAli.getAliquot().getId()) {
return true;
}
}
return false;
})) {
errors.add(new ValidationError("Pool does not contain all of the required aliquots"));
break;
}
}
if (object.getSequencingOrder() != null) {
SequencingOrder seqOrder = object.getSequencingOrder();
if (seqOrder.getPurpose().getId() != object.getPurpose().getId() || seqOrder.getSequencingParameter().getId() != object.getParameters().getId() || !seqOrder.getPartitions().equals(object.getPartitions()) || seqOrder.getPool().getId() != object.getPool().getId() || (object.getContainerModel() != null && (seqOrder.getContainerModel() == null || seqOrder.getContainerModel().getId() != object.getContainerModel().getId()))) {
errors.add(new ValidationError("Sequencing order does not match the pool order"));
}
}
}
preventFulfilledChange("partitions", PoolOrder::getPartitions, object, beforeChange, errors);
preventFulfilledChange("parametersId", PoolOrder::getParameters, object, beforeChange, errors);
preventFulfilledChange("containerModelId", PoolOrder::getContainerModel, object, beforeChange, errors);
preventFulfilledChange("description", PoolOrder::getDescription, object, beforeChange, errors);
preventFulfilledChange("alias", PoolOrder::getAlias, object, beforeChange, errors);
preventFulfilledChange("purposeId", PoolOrder::getPurpose, object, beforeChange, errors);
if (!allMatch(object.getOrderLibraryAliquots(), beforeChange.getOrderLibraryAliquots())) {
errors.add(new ValidationError("Aliquots cannot be changed after the order is fulfilled"));
}
}
// if any sequencing requirements are specified, all are required
if (object.getContainerModel() != null || object.getParameters() != null || object.getPartitions() != null) {
// exception: container model not required for legacy orders (from before container model was added to orders)
if ((beforeChange == null || beforeChange.getContainerModel() != null) && object.getContainerModel() == null) {
errors.add(ValidationUtils.makeNoNullError("containerModelId"));
}
if (object.getParameters() == null) {
errors.add(ValidationUtils.makeNoNullError("parametersId"));
}
if (object.getPartitions() == null) {
errors.add(ValidationUtils.makeNoNullError("partitions"));
}
}
// Container model and seq params must be linked to same instrument model
if (object.getContainerModel() != null && object.getParameters().getInstrumentModel().getContainerModels().stream().noneMatch(model -> model.getId() == object.getContainerModel().getId())) {
errors.add(new ValidationError("containerModelId", "Not compatible with the selected sequencing parameters"));
}
PlatformType orderPlatform = object.getParameters() == null ? null : object.getParameters().getInstrumentModel().getPlatformType();
for (OrderLibraryAliquot orderAli : object.getOrderLibraryAliquots()) {
PlatformType libPlatform = orderAli.getAliquot().getLibrary().getPlatformType();
if (orderPlatform == null) {
orderPlatform = libPlatform;
} else if (!libPlatform.equals(orderPlatform)) {
errors.add(new ValidationError("Platform for all aliquots and sequencing parameters (if specified) must match"));
break;
}
}
if (!object.isDraft() && object.getOrderLibraryAliquots().isEmpty()) {
errors.add(new ValidationError("Non-draft order must include at least one library aliquot"));
}
if (strictPools) {
validateNoNewDuplicateIndices(object, beforeChange, errors);
}
}
Aggregations