Search in sources :

Example 1 with Ini

use of com.hartwig.api.model.Ini 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;
}
Also used : Run(com.hartwig.api.model.Run) Logger(org.slf4j.Logger) Status(com.hartwig.api.model.Status) LoggerFactory(org.slf4j.LoggerFactory) RunApi(com.hartwig.api.RunApi) OnlyOne(com.hartwig.api.helpers.OnlyOne) SampleSet(com.hartwig.api.model.SampleSet) SampleType(com.hartwig.api.model.SampleType) List(java.util.List) ApiException(com.hartwig.ApiException) SetApi(com.hartwig.api.SetApi) CreateRun(com.hartwig.api.model.CreateRun) Optional(java.util.Optional) SampleApi(com.hartwig.api.SampleApi) Sample(com.hartwig.api.model.Sample) Ini(com.hartwig.api.model.Ini) SampleSet(com.hartwig.api.model.SampleSet) CreateRun(com.hartwig.api.model.CreateRun) Sample(com.hartwig.api.model.Sample) Run(com.hartwig.api.model.Run) CreateRun(com.hartwig.api.model.CreateRun) ApiException(com.hartwig.ApiException)

Aggregations

ApiException (com.hartwig.ApiException)1 RunApi (com.hartwig.api.RunApi)1 SampleApi (com.hartwig.api.SampleApi)1 SetApi (com.hartwig.api.SetApi)1 OnlyOne (com.hartwig.api.helpers.OnlyOne)1 CreateRun (com.hartwig.api.model.CreateRun)1 Ini (com.hartwig.api.model.Ini)1 Run (com.hartwig.api.model.Run)1 Sample (com.hartwig.api.model.Sample)1 SampleSet (com.hartwig.api.model.SampleSet)1 SampleType (com.hartwig.api.model.SampleType)1 Status (com.hartwig.api.model.Status)1 List (java.util.List)1 Optional (java.util.Optional)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1