public static <T, R> Function<T, R> rethrow(WhineyFunction<? super T, R> function) { return arg -> { try { return function.apply(arg); } catch (IOException e) { throw new RuntimeException(e); } }; }
public static <M extends Identifiable, D, X extends RuntimeException> List<D> bulkSearch(Collection<String> names, PaginatedDataSource<M> service, Function<M, D> dto, Function<String, X> makeException) { return names.stream()// .filter(name -> !LimsUtils.isStringBlankOrNull(name))// .flatMap(WhineyFunction.flatRethrow(name -> { Collection<M> matches = service.list(0, 0, true, "id", exactQuery(name)); if (matches.isEmpty()) { throw makeException.apply(String.format("Cannot find \"%s\".", name)); } return matches; }))// .collect(Collectors.groupingBy(Identifiable::getId))// .values()// .stream()// .map(list -> list.get(0))// .map(dto).collect(Collectors.toList()); }
private void updatePartitionContents(final GetLaneContents getLaneContents, SequencerPartitionContainer newContainer) { newContainer.getPartitions().stream().filter(partition -> partition.getPool() == null) .forEach(partition -> getLaneContents.getLaneContents(partition.getPartitionNumber()).filter(s -> !LimsUtils.isStringBlankOrNull(s)) .map(WhineyFunction.rethrow(poolService::getByBarcode)).ifPresent(partition::setPool)); }
public static <T, R> Function<T, Stream<R>> flatRethrow(WhineyFunction<? super T, Collection<R>> function) { return input -> { try { return function.apply(input).stream(); } catch (IOException e) { throw new RuntimeException(e); } }; }
private void loadMembers(Workset newWorkflow) { newWorkflow.setSamples(loadMembers("Sample", newWorkflow.getSamples(), WhineyFunction.rethrow(id -> sampleService.get(id)))); newWorkflow.setLibraries(loadMembers("Library", newWorkflow.getLibraries(), WhineyFunction.rethrow(id -> libraryService.get(id)))); newWorkflow.setDilutions(loadMembers("Dilution", newWorkflow.getDilutions(), WhineyFunction.rethrow(id -> dilutionService.get(id)))); }
public static <T extends Barcodable> void validateBarcodeUniqueness(T barcodable, T beforeChange, WhineyFunction<String, T> lookupByBarcode, Collection<ValidationError> errors, String typeLabel) throws IOException { if (barcodable.getIdentificationBarcode() != null && (beforeChange == null || !barcodable.getIdentificationBarcode().equals(beforeChange.getIdentificationBarcode())) && lookupByBarcode.apply(barcodable.getIdentificationBarcode()) != null) { errors.add(new ValidationError("identificationBarcode", String.format("There is already a %s with this barcode", typeLabel))); } }
private void applyMemberChanges(Workset changed, Workset managed) { applyMemberChanges(changed.getSamples(), managed.getSamples(), WhineyFunction.rethrow(ids -> sampleService.listByIdList(ids))); applyMemberChanges(changed.getLibraries(), managed.getLibraries(), WhineyFunction.rethrow(ids -> libraryService.listByIdList(ids))); applyMemberChanges(changed.getDilutions(), managed.getDilutions(), WhineyFunction.rethrow(ids -> dilutionService.listByIdList(ids))); }
@Override public long save(Submission submission) throws IOException { if (submission.getId() == Submission.UNSAVED_ID) { submission.setExperiments(submission.getExperiments().stream().map(Experiment::getId) .map(WhineyFunction.rethrow(experimentService::get)) .collect(Collectors.toSet())); return submissionStore.save(submission); } else { Submission managed = submissionStore.get(submission.getId()); managed.setAccession(submission.getAccession()); managed.setAlias(submission.getAlias()); managed.setCompleted(submission.isCompleted()); managed.setDescription(submission.getDescription()); managed.setSubmissionDate(submission.getSubmissionDate()); managed.setTitle(submission.getTitle()); managed.setVerified(submission.isVerified()); return submissionStore.save(submission); } }
experiment.setRunPartitions(Collections.emptyList()); } else { experiment.setRunPartitions(experiment.getRunPartitions().stream().map(WhineyFunction.rethrow(from -> { RunPartition to = new RunPartition(); to.setExperiment(experiment);