package uk.ac.ebi.quickgo.ontology;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import uk.ac.ebi.quickgo.ontology.controller.validation.OBOControllerValidationHelper;
import uk.ac.ebi.quickgo.ontology.controller.validation.OBOControllerValidationHelperImpl;

import static uk.ac.ebi.quickgo.common.validator.OntologyIdPredicate.isValidECOTermId;
import static uk.ac.ebi.quickgo.common.validator.OntologyIdPredicate.isValidGOTermId;

/**
 * Configure the beans related to the operation of the restful service - id validation helpers and configuration
 * object for page sizes.
 *
 * @author Tony Wardell
 * Date: 17/01/2017
 * Time: 13:32
 * Created with IntelliJ IDEA.
 *
 */
@Configuration
public class OntologyRestConfig {

    private static final int MINUTES = 0;

    @Bean
    public OntologyPagingConfig ontologyPagingConfig(
            @Value("${ontology.default_page_size:25}") int defaultPageSize) {
        return () -> defaultPageSize;
    }

    @Bean
    public OBOControllerValidationHelper goValidationHelper(@Value("${ontology.max_page_size:600}") int maxPageSize) {
        return new OBOControllerValidationHelperImpl(maxPageSize, isValidGOTermId());
    }

    @Bean
    public OBOControllerValidationHelper ecoValidationHelper(@Value("${ontology.max_page_size:600}") int maxPageSize) {
        return new OBOControllerValidationHelperImpl(maxPageSize, isValidECOTermId());
    }

    public interface OntologyPagingConfig {
        int defaultPageSize();
    }
}

@@ -89,16 +89,98 @@
 .Value;%0A
+import org.springframework.boot.context.properties.EnableConfigurationProperties;%0A
 import o
@@ -461,16 +461,132 @@
 perImpl;
+%0Aimport uk.ac.ebi.quickgo.rest.cache.CacheStrategy;%0A%0Aimport java.time.LocalTime;%0Aimport java.util.function.Function;
 %0A%0Aimport
@@ -1015,84 +1015,103 @@
 ion%0A
-public class OntologyRestConfig %7B%0A%0A    private static final int MINUTES = 0;
+@EnableConfigurationProperties(OntologyRestProperties.class)%0Apublic class OntologyRestConfig %7B%0A
 %0A%0A  
@@ -1737,24 +1737,296 @@
 ());%0A    %7D%0A%0A
+    @Bean%0A    Function%3CLocalTime, Long%3E remainingCacheTime(OntologyRestProperties restProperties) %7B%0A        CacheStrategy cacheStrategy = new CacheStrategy();%0A        return cacheStrategy.maxAgeCountDown(restProperties.getStartTime(), restProperties.getEndTime());%0A    %7D%0A%0A
     public i
@@ -2094,10 +2094,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Add remaining cache time function.