package ca.intelliware.ihtsdo.mlds.config;

import java.util.Collection;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

import ca.intelliware.ihtsdo.mlds.domain.Affiliate;
import ca.intelliware.ihtsdo.mlds.domain.json.InternalPrivacyFilter;
import ca.intelliware.ihtsdo.mlds.domain.json.MLDSJacksonModule;
import ca.intelliware.ihtsdo.mlds.repository.MemberRepository;
import ca.intelliware.ihtsdo.mlds.security.ihtsdo.CurrentSecurityContext;
import ca.intelliware.ihtsdo.mlds.web.rest.dto.MemberDTO;

@Configuration
@ConditionalOnClass(ObjectMapper.class)
public class JacksonConfigurer {

	@Autowired
	private ListableBeanFactory beanFactory;

	@Bean
	public Module mldsModule(final MemberRepository memberRepository, CurrentSecurityContext securityContext) {
		SimpleModule mldsModule = new MLDSJacksonModule(memberRepository, securityContext);
		
		return mldsModule;
	}
	
	@PostConstruct
	public void init() {
		Collection<ObjectMapper> mappers = BeanFactoryUtils
				.beansOfTypeIncludingAncestors(this.beanFactory, ObjectMapper.class)
				.values();
		for (ObjectMapper mapper : mappers) {
			mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
			
			registerFilters(mapper);
		}
	}

	public void registerFilters(ObjectMapper mapper) {
		SimpleFilterProvider filterProvider = new SimpleFilterProvider();
		filterProvider.addFilter("affiliatePrivacyFilter", new InternalPrivacyFilter(Affiliate.PRIVATE_FIELDS) );
		filterProvider.addFilter("memberDtoPrivacyFilter", new InternalPrivacyFilter(MemberDTO.PRIVATE_FIELDS) );
		
		mapper.setFilters(filterProvider);
	}

}

@@ -107,16 +107,73 @@
 truct;%0A%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import o
@@ -1294,16 +1294,102 @@
 igurer %7B
+%0A%09%0A    private final Logger logger = LoggerFactory.getLogger(JacksonConfigurer.class);
 %0A%0A%09@Auto
@@ -1706,16 +1706,64 @@
 nit() %7B%0A
+%09%09logger.debug(%22Initialising Jackson Mappers%22);%0A
 %09%09Collec
@@ -1936,16 +1936,113 @@
 pers) %7B%0A
+%09%09%09logger.debug(%22Configuring Jackson mapper: %7B%7D%22, mapper.getTypeFactory().getClass().getName());%0A
 %09%09%09mappe
@@ -2113,12 +2113,8 @@
 e);%0A
-%09%09%09%0A
 %09%09%09r
@@ -2145,16 +2145,16 @@
 %09%09%7D%0A%09%7D%0A%0A
-
 %09public 
@@ -2193,24 +2193,79 @@
 r mapper) %7B%0A
+%09%09logger.debug(%22Registering jackson privacy filters%22);%0A
 %09%09SimpleFilt

Add debug to help work out why privacy filters are not being found on dev. Fine locally