package uk.ac.ebi.quickgo.annotation.metadata;

import uk.ac.ebi.quickgo.rest.metadata.MetaData;
import uk.ac.ebi.quickgo.rest.metadata.MetaDataConfigProperties;
import uk.ac.ebi.quickgo.rest.metadata.MetaDataProvider;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;

import static java.util.stream.Collectors.toList;

/**
 * Configure the provision of metadata for the Annotation service.
 *
 * @author Tony Wardell
 * Date: 07/03/2017
 * Time: 10:55
 * Created with IntelliJ IDEA.
 */
@Configuration
public class MetaDataConfig {
    private static final Logger LOGGER = LoggerFactory.getLogger(MetaDataConfig.class);
    private static final String SERVICE = "Annotation";
    private static final Path DEFAULT_METADATA_PATH = Paths.get("goa_uniprot.gpa-version");
    private static final Function<Path, List<MetaData>> PATH_TO_METADATA_MAPPER = (Path p) -> {
        try {
            Stream<String> stream = Files.lines(p);
            return stream.map(s -> new MetaData(null, s.substring(s.indexOf("2"))))
                         .collect(toList());
        } catch (IOException e) {
            throw new java.io.UncheckedIOException(e);
        }
    };

    private static final int NUMBER_OF_METADATA_LINES = 1;

    @Bean
    @ConfigurationProperties(prefix = "annotation.metadata")
    public MetaDataConfigProperties metaDataConfigProperties() {
        return new MetaDataConfigProperties();
    }

    @Bean
    MetaDataProvider metaDataProvider(MetaDataConfigProperties metaDataConfigProperties) {
        Path metaDataPath = DEFAULT_METADATA_PATH;
        final Resource source = metaDataConfigProperties.getSource();
        if (source != null) {
            try {
                metaDataPath = Paths.get(source.getURI());
            } catch (IOException e) {
                LOGGER.error("Failed to get the URI of the metadata source " + source, e);
            }
        }
        return new MetaDataProvider(SERVICE, PATH_TO_METADATA_MAPPER, metaDataPath, NUMBER_OF_METADATA_LINES);
    }
}

@@ -84,138 +84,9 @@
 ata.
-MetaData;%0Aimport uk.ac.ebi.quickgo.rest.metadata.MetaDataConfigProperties;%0Aimport uk.ac.ebi.quickgo.rest.metadata.MetaDataProvider
+*
 ;%0A%0Ai
@@ -1122,13 +1122,8 @@
 th, 
-List%3C
 Meta
@@ -1131,27 +1131,9 @@
 ata%3E
-%3E PATH_TO_METADATA_
+ 
 MAPP
@@ -1163,30 +1163,17 @@
     try 
-%7B%0A            
+(
 Stream%3CS
@@ -1202,17 +1202,18 @@
 lines(p)
-;
+)%7B
 %0A       
@@ -1221,79 +1221,171 @@
     
-return stream.map(s -%3E new MetaData(null, s.substring(s.indexOf(%222%22)
+MetaDataStringOnly metaDataStringOnly = new MetaDataStringOnly();%0A            stream.forEach(s -%3E metaDataStringOnly.add(MetaData.TIMESTAMP, extractTimestamp(s
 )))
+;
 %0A   
@@ -1397,39 +1397,127 @@
     
-             .collect(toList())
+MetaData metaData  = new MetaData();%0A            metaData.add(SERVICE, metaDataStringOnly);%0A            return metaData
 ;%0A  
@@ -1644,47 +1644,93 @@
 tic 
-final int NUMBER_OF_METADATA_LINES = 1;
+String extractTimestamp(String s) %7B%0A        return s.substring(s.indexOf('2'));%0A    %7D
 %0A%0A  
@@ -2439,80 +2439,28 @@
 der(
-SERVICE, PATH_TO_METADATA_MAPPER, metaDataPath, NUMBER_OF_METADATA_LINES
+MAPPER, metaDataPath
 );%0A 

Replace MetaData with hardcoded properties to Map based solution.