package uk.ac.ebi.atlas.experimentimport.expressiondataserializer;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.UnsafeInput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import uk.ac.ebi.atlas.commons.serializers.ImmutableSetKryoSerializer;
import uk.ac.ebi.atlas.commons.serializers.OntologyTermKryoSerializer;
import uk.ac.ebi.atlas.model.Experiment;
import uk.ac.ebi.atlas.profiles.BaselineExpressionsKryoReader;
import uk.ac.ebi.atlas.trader.ExperimentTrader;
import uk.ac.ebi.atlas.trader.cache.BaselineExperimentsCache;

import javax.inject.Inject;
import javax.inject.Named;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

/**
 * Created by Alfonso Muñoz-Pomer Fuentes <amunoz@ebi.ac.uk> on 02/04/15.
 */
@Named
@Scope("singleton")
public class ExpressionSerializerService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ExpressionSerializerService.class);

    private ExperimentTrader experimentTrader;
    private ExpressionSerializerFactory expressionSerializerFactory;
    private BaselineExperimentsCache baselineExperimentsCache;


    @Inject
    public ExpressionSerializerService(ExperimentTrader experimentTrader, ExpressionSerializerFactory expressionSerializerFactory,
                                       BaselineExperimentsCache baselineExperimentsCache) {
        this.experimentTrader = experimentTrader;
        this.expressionSerializerFactory = expressionSerializerFactory;
        this.baselineExperimentsCache = baselineExperimentsCache;
    }

    public void kryoSerializeExpressionData(String experimentAccession) {
        try {
            Experiment experiment = experimentTrader.getPublicExperiment(experimentAccession);
            expressionSerializerFactory.getKryoSerializer(experiment.getType())
                    .serializeExpressionData(experimentAccession, baselineExperimentsCache.getExperiment(experimentAccession).getExperimentalFactors());
        } catch (ExecutionException e) {
            throw new IllegalStateException("Failed to load experiment from cache: " + experimentAccession, e);
        }
    }

}

@@ -72,973 +72,306 @@
 ort 
-com.esotericsoftware.kryo.Kryo;%0Aimport com.esotericsoftware.kryo.io.UnsafeInput;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.context.annotation.Scope;%0Aimport uk.ac.ebi.atlas.commons.serializers.ImmutableSetKryoSerializer;%0Aimport uk.ac.ebi.atlas.commons.serializers.OntologyTermKryoSerializer;%0Aimport uk.ac.ebi.atlas.model.Experiment;%0Aimport uk.ac.ebi.atlas.profiles.BaselineExpressionsKryoReader;%0Aimport uk.ac.ebi.atlas.trader.ExperimentTrader;%0Aimport uk.ac.ebi.atlas.trader.cache.BaselineExperimentsCache;%0A%0Aimport javax.inject.Inject;%0Aimport javax.inject.Named;%0Aimport java.io.FileInputStream;%0Aimport java.io.IOException;%0Aimport java.util.concurrent.ExecutionException;%0A%0A/**%0A * Created by Alfonso Mu%C3%B1oz-Pomer Fuentes %3Camunoz@ebi.ac.uk%3E on 02/04/15.%0A */%0A@Named%0A@Scope(%22singleton%22)%0Apublic class ExpressionSerializerService %7B%0A%0A    private static final Logger LOGGER = LoggerFactory.getLogger(ExpressionSerializerService.class);
+uk.ac.ebi.atlas.model.Experiment;%0Aimport uk.ac.ebi.atlas.trader.ExperimentTrader;%0Aimport uk.ac.ebi.atlas.trader.cache.BaselineExperimentsCache;%0A%0Aimport javax.inject.Inject;%0Aimport javax.inject.Named;%0Aimport java.util.concurrent.ExecutionException;%0A%0A@Named%0Apublic class ExpressionSerializerService %7B
 %0A%0A  

Clean imports