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

import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.springframework.beans.factory.annotation.Value;
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;

/**
 * Configure the provision of metadata for the Ontology service.
 *
 * @author Tony Wardell
 * Date: 07/03/2017
 * Time: 10:55
 * Created with IntelliJ IDEA.
 */
@Configuration
@ConfigurationProperties(prefix = "metadata.ontology")
public class MetaDataConfig {
    private static final Path DEFAULT_ONTOLOGY_PATH = Paths.get("ONTOLOGY_IRI.dat.gz");
    @Value("${metadata.ontology.source}")
    private Resource source;

    @Bean
    MetaDataProvider metaDataProvider() throws IOException {
        Path osPath = source != null ? Paths.get(source.getURI()) : DEFAULT_ONTOLOGY_PATH;
        return new MetaDataProvider(osPath);
    }
}

@@ -50,141 +50,488 @@
 ort 
-java.io.IOException;%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0Aimport org.springframework.beans.factory.annotation.Value
+uk.ac.ebi.quickgo.common.loader.GZIPFiles;%0Aimport uk.ac.ebi.quickgo.rest.metadata.MetaData;%0Aimport uk.ac.ebi.quickgo.rest.metadata.MetaDataConfigProperties;%0Aimport uk.ac.ebi.quickgo.rest.metadata.MetaDataProvider;%0Aimport uk.ac.ebi.quickgo.rest.metadata.MetaDataStringOnly;%0A%0Aimport java.io.IOException;%0Aimport java.nio.file.Path;%0Aimport java.nio.file.Paths;%0Aimport java.util.function.Function;%0Aimport java.util.stream.Stream;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory
 ;%0Aim
@@ -1029,16 +1029,104 @@
 onfig %7B%0A
+    private static final Logger LOGGER = LoggerFactory.getLogger(MetaDataConfig.class);%0A
     priv
@@ -1151,32 +1151,32 @@
 ath DEFAULT_
-ONTOLOGY
+METADATA
 _PATH = Path
@@ -1213,237 +1213,1324 @@
     
-@Value(%22$%7Bmetadata.ontology.source%7D%22)%0A    private Resource source;%0A%0A    @Bean%0A    MetaDataProvider metaDataProvider() throws IOException %7B%0A        Path osPath = source != null ? Paths.get(source.getURI()) : DEFAULT_ONTOLOGY_PATH;
+private static final String SERVICE = %22GO%22;%0A    private static final Function%3CPath, MetaData%3E MAPPER = (Path p) -%3E %7B%0A        try (Stream%3CString%3E stream = GZIPFiles.lines(p)) %7B%0A            MetaDataStringOnly metaDataStringOnly = new MetaDataStringOnly();%0A            stream.forEach(s -%3E %7B%0A                String%5B%5D a = s.split(%22%5Ct%22);%0A                metaDataStringOnly.add(MetaData.VERSION, a%5B2%5D);%0A                metaDataStringOnly.add(MetaData.TIMESTAMP, a%5B1%5D);%0A            %7D);%0A            MetaData metaData = new MetaData();%0A            metaData.add(SERVICE, metaDataStringOnly);%0A            return metaData;%0A        %7D%0A    %7D;%0A%0A    @Bean%0A    @ConfigurationProperties(prefix = %22ontology.metadata%22)%0A    public MetaDataConfigProperties metaDataConfigProperties() %7B%0A        return new MetaDataConfigProperties();%0A    %7D%0A%0A    @Bean%0A    MetaDataProvider metaDataProvider(MetaDataConfigProperties metaDataConfigProperties) throws IOException %7B%0A        Path metaDataPath = DEFAULT_METADATA_PATH;%0A        final Resource source = metaDataConfigProperties.getSource();%0A        if (source != null) %7B%0A            try %7B%0A                metaDataPath = Paths.get(source.getURI());%0A            %7D catch (IOException e) %7B%0A                LOGGER.error(%22Failed to get the URI of the metadata source %22 + source, e);%0A            %7D%0A        %7D
 %0A   
@@ -2566,10 +2566,24 @@
 der(
-os
+MAPPER, metaData
 Path

Replace Ontology specific with generic MetaDataProvider.