package uk.ac.ebi.quickgo.annotation.download.http;

import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import org.springframework.http.MediaType;

/**
 * Hold the definitions of MediaTypes used in downloads, and their components.
 * @author Tony Wardell
 * Date: 27/04/2017
 * Time: 10:38
 * Created with IntelliJ IDEA.
 */
public class MediaTypeFactory {
    private static final String TEXT_TYPE = "text";
    private static final String APPLICATION_TYPE = "application";
    private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");

    public static final String TSV_SUB_TYPE = "tsv";
    public static final String GAF_SUB_TYPE = "gaf";
    public static final String GPAD_SUB_TYPE = "gpad";
    public static final String EXCEL_SUB_TYPE = "vnd.ms-excel";
    public static final String JSON_SUB_TYPE = "json";

    public static final String TSV_MEDIA_TYPE_STRING = TEXT_TYPE + "/" + TSV_SUB_TYPE;
    public static final String GAF_MEDIA_TYPE_STRING = TEXT_TYPE + "/" + GAF_SUB_TYPE;
    public static final String GPAD_MEDIA_TYPE_STRING = TEXT_TYPE + "/" + GPAD_SUB_TYPE;
    public static final String EXCEL_MEDIA_TYPE_STRING = APPLICATION_TYPE + "/" + EXCEL_SUB_TYPE;
    public static final String JSON_MEDIA_TYPE_STRING = APPLICATION_TYPE + "/" + JSON_SUB_TYPE;

    public static final MediaType TSV_MEDIA_TYPE = new MediaType(TEXT_TYPE, TSV_SUB_TYPE, DEFAULT_CHARSET);
    public static final MediaType GAF_MEDIA_TYPE = new MediaType(TEXT_TYPE, GAF_SUB_TYPE, DEFAULT_CHARSET);
    public static final MediaType GPAD_MEDIA_TYPE = new MediaType(TEXT_TYPE, GPAD_SUB_TYPE, DEFAULT_CHARSET);

    public static final MediaType EXCEL_MEDIA_TYPE = new MediaType(APPLICATION_TYPE, EXCEL_SUB_TYPE);
    public static final MediaType JSON_MEDIA_TYPE = new MediaType(APPLICATION_TYPE, JSON_SUB_TYPE);

    public static Map<MediaType, String> MEDIA_TYPE_TO_FILE_EXTENSIONS = new HashMap<>();

    static {
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(TSV_MEDIA_TYPE, TSV_SUB_TYPE);
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(GAF_MEDIA_TYPE, GAF_SUB_TYPE);
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(GPAD_MEDIA_TYPE, GPAD_SUB_TYPE);
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(EXCEL_MEDIA_TYPE, "xls");
        MEDIA_TYPE_TO_FILE_EXTENSIONS.put(JSON_MEDIA_TYPE, JSON_SUB_TYPE);
    }

}

@@ -1842,37 +1842,38 @@
 UB_TYPE);%0A%0A    p
-ublic
+rivate
  static Map%3CMedi
@@ -2321,10 +2321,139 @@
 %0A    %7D%0A%0A
+    public static String fileExtension(MediaType mediaType)%7B%0A        return MEDIA_TYPE_TO_FILE_EXTENSIONS.get(mediaType);%0A    %7D%0A%0A
 %7D%0A

Add fileExtension method to generate file extension based on media type.