package uk.ac.ebi.atlas.resource;


import com.google.common.base.Optional;
import org.springframework.beans.factory.annotation.Value;
import uk.ac.ebi.atlas.model.resource.ContrastImage;
import uk.ac.ebi.atlas.model.resource.ExternalImage;
import uk.ac.ebi.atlas.model.resource.ResourceType;

import javax.inject.Named;

@Named
public class ContrastImageFactory{

    @Value("#{configuration['experiment.gsea-plot.path.template']}")
    String gseaPathTemplate;

    @Value("#{configuration['experiment.rnaseq.ma-plot.path.template']}")
    String rnaSeqPathTemplate;

    @Value("#{configuration['experiment.microarray.ma-plot.path.template']}")
    String microarrayPathTemplate;


    ExternalImage getContrastImage(ResourceType resourceType, String experimentAccession, Optional<String>
            arrayDesign,
                                   String contrastId ){
        String pathTemplate = "";
        switch (resourceType) {
            case PLOT_GSEA_INTERPRO:
                pathTemplate = gseaPathTemplate.replace("{2}", "interpro");
                break;
            case PLOT_GSEA_GO:
                pathTemplate = gseaPathTemplate.replace("{2}", "go");
                break;
            case PLOT_GSEA_REACTOME:
                pathTemplate = gseaPathTemplate.replace("{2}", "reactome");
                break;
            case PLOT_MA:
                pathTemplate = arrayDesign.isPresent()? microarrayPathTemplate : rnaSeqPathTemplate;
                break;
        }

        String uriTemplate = (arrayDesign.isPresent()
                ? "external-resources/{0}/{1}/{2}/"
                :"external-resources/{0}/{1}/")+resourceType.fileName();


        return arrayDesign.isPresent() && resourceType.equals(ResourceType.PLOT_MA)
        ?   new ContrastImage(resourceType,pathTemplate,uriTemplate,
                experimentAccession,arrayDesign.get(), contrastId)
                :new ContrastImage(resourceType,pathTemplate,uriTemplate,
                experimentAccession, contrastId);
    }

    ExternalImage getContrastImage(ResourceType resourceType, String experimentAccession,
                                   String contrastId ){
        return getContrastImage(resourceType, experimentAccession, Optional.<String>absent(), contrastId);
    }
}

@@ -1501,196 +1501,11 @@
     
-String uriTemplate = (arrayDesign.isPresent()%0A                ? %22external-resources/%7B0%7D/%7B1%7D/%7B2%7D/%22%0A                :%22external-resources/%7B0%7D/%7B1%7D/%22)+resourceType.fileName();%0A%0A%0A        return 
+if(
 arra
@@ -1568,16 +1568,18 @@
 PLOT_MA)
+)%7B
 %0A       
@@ -1583,12 +1583,19 @@
     
-?
+ 
    
+return 
 new 
@@ -1630,37 +1630,87 @@
 athTemplate,
-uriTemplate,%0A
+%22external-resources/%7B0%7D/%7B1%7D/%7B2%7D/%22+resourceType.fileName(),%0A    
             
@@ -1763,16 +1763,17 @@
 trastId)
+;
 %0A       
@@ -1777,17 +1777,36 @@
     
-        :
+%7D else %7B%0A            return 
 new 
@@ -1849,21 +1849,67 @@
 ate,
-uriTemplate,%0A
+%22external-resources/%7B0%7D/%7B1%7D/%22+resourceType.fileName(),%0A    
     
@@ -1950,24 +1950,34 @@
 ontrastId);%0A
+        %7D%0A
     %7D%0A%0A    E

Fix bug that my awesome AtlasResourceHubEIT has caught