package com.joeldholmes;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

import io.katharsis.resource.registry.ResourceRegistry;

@SpringBootApplication
@EnableAutoConfiguration
@EnableMongoRepositories("com.joeldholmes.repository")
@EnableCircuitBreaker
@RestController
public class LiturgyApiApplication {

	public static void main(String[] args) {

		SpringApplication.run(LiturgyApiApplication.class, args);

	}

	  @Autowired
		private ResourceRegistry resourceRegistry;
		 
			
		@RequestMapping("/resourcesInfo")
	    public Map<?, ?> getResources() {
	        Map<String, String> result = new HashMap<>();
	        // Add all resources (i.e. Project and Task)
	        for (Class<?> clazz : resourceRegistry.getResources().keySet()) {
	           result.put(resourceRegistry.getResourceType(clazz), resourceRegistry.getResourceUrl(clazz));
	        }
	        return result;
		}
}

@@ -1303,18 +1303,16 @@
 ;%0A%0A%09%7D%0A%0A%09
-  
 @Autowir
@@ -1314,17 +1314,16 @@
 towired%0A
-%09
 %09private
@@ -1362,17 +1362,10 @@
 ry;%0A
-%09%09 %0A%09%09%09%0A%09
+%0A%0A
 %09@Re
@@ -1396,20 +1396,16 @@
 Info%22)%0A%09
-    
 public M
@@ -1431,24 +1431,17 @@
 es() %7B%0A%09
-        
+%09
 Map%3CStri
@@ -1479,24 +1479,17 @@
 p%3C%3E();%0A%09
-        
+%09
 // Add a
@@ -1526,24 +1526,17 @@
  Task)%0A%09
-        
+%09
 for (Cla
@@ -1598,19 +1598,10 @@
  %7B%0A%09
-           
+%09%09
 resu
@@ -1694,43 +1694,782 @@
 );%0A%09
-        %7D%0A%09        return result;%0A%09
+%09%7D%0A%09%09return result;%0A%09%7D%0A%0A%09@Bean%0A%09public FilterRegistrationBean corsFilter() %7B%0A%09%09UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();%0A%09%09CorsConfiguration config = new CorsConfiguration();%0A%09%09config.setAllowCredentials(true);%0A%09%09config.addAllowedOrigin(%22*%22);%0A%09%09config.addAllowedHeader(%22*%22);%0A%09%09config.addAllowedMethod(%22OPTIONS%22);%0A%09%09config.addAllowedMethod(%22HEAD%22);%0A%09%09config.addAllowedMethod(%22GET%22);%0A%09%09config.addAllowedMethod(%22PUT%22);%0A%09%09config.addAllowedMethod(%22POST%22);%0A%09%09config.addAllowedMethod(%22DELETE%22);%0A%09%09config.addAllowedMethod(%22PATCH%22);%0A%09%09source.registerCorsConfiguration(%22/**%22, config);%0A%09%09// return new CorsFilter(source);%0A%09%09final FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));%0A%09%09bean.setOrder(0);%0A%09%09return bean;%0A
 %09%7D%0A%7D

clean up cors