use of com.hartwig.api.model.CreateRun in project platinum by hartwigmedical.
the class ApiRerun method create.
Long create(final String sampleId) {
try {
List<Sample> samples = sampleApi.list(null, null, null, null, SampleType.TUMOR, sampleId);
for (Sample sample : samples) {
Optional<SampleSet> maybeSampleSet = OnlyOne.ofNullable(setApi.list(null, sample.getId(), true), SampleSet.class);
if (maybeSampleSet.isPresent()) {
SampleSet sampleSet = maybeSampleSet.get();
if (runApi.list(null, null, sampleSet.getId(), null, null, null, null, null).stream().anyMatch(r1 -> r1.getStatus().equals(Status.VALIDATED))) {
return OnlyOne.ofNullable(runApi.list(null, Ini.RERUN_INI, sampleSet.getId(), version, version, null, null, null), Run.class).filter(r -> !r.getStatus().equals(Status.INVALIDATED)).map(r -> {
LOGGER.info("Using existing run for sample [{}] id [{}]", sampleId, r.getId());
return r.getId();
}).orElseGet(() -> {
final Long id = runApi.create(new CreateRun().bucket(bucket).cluster("gcp").context("RESEARCH").ini(Ini.RERUN_INI).version(version).status(Status.PENDING).setId(sampleSet.getId())).getId();
LOGGER.info("Created API run for sample [{}] id [{}]", sampleId, id);
return id;
});
}
}
}
} catch (Exception e) {
LOGGER.error("Unable to create run for [{}] reason [{}]", sampleId, e.getMessage());
return null;
}
return null;
}
Aggregations