package imcode.services.argumentresolver;

import com.imcode.services.GenericService;
import imcode.services.IvisServiceFactory;
import imcode.services.utils.IvisOAuth2Utils;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebArgumentResolver;
import org.springframework.web.context.request.NativeWebRequest;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by ruslan on 06.12.16.
 */
public class IvisServiceArgumentResolver implements WebArgumentResolver {

    @Override
    public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception {
        Class<?> type = methodParameter.getParameterType();
        Object nativeRequest = webRequest.getNativeRequest();
        if (!GenericService.class.isAssignableFrom(type) && !(nativeRequest instanceof HttpServletRequest)) {
            return UNRESOLVED;
        }

        HttpServletRequest request = (HttpServletRequest) nativeRequest;
        IvisServiceFactory ivisServiceFactory = IvisOAuth2Utils.getServiceFactory(request);

        return ivisServiceFactory.getService((Class<? extends GenericService>) type);

    }

}

@@ -264,32 +264,33 @@
 port.Web
-ArgumentResolver
+DataBinderFactory
 ;%0Aimport
@@ -347,16 +347,162 @@
 Request;
+%0Aimport org.springframework.web.method.support.HandlerMethodArgumentResolver;%0Aimport org.springframework.web.method.support.ModelAndViewContainer;
 %0A%0Aimport
@@ -636,19 +636,29 @@
 lements 
-Web
+HandlerMethod
 Argument
@@ -698,37 +698,24 @@
 lic 
-Object resolveArgument(Method
+boolean supports
 Para
@@ -719,18 +719,18 @@
 arameter
- m
+(M
 ethodPar
@@ -739,89 +739,76 @@
 eter
-, NativeWebRequest webRequest) throws Exception %7B%0A        Class%3C?%3E type = methodP
+ parameter) %7B%0A        return GenericService.class.isAssignableFrom(p
 aram
@@ -834,148 +834,146 @@
 pe()
+)
 ;%0A    
+%7D%0A%0A
     
-Object nativeRequest = webRequest.getNativeRequest();%0A        if (!GenericService.class.isAssignableFrom(type) && !(n
+@Override%0A    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, N
 ative
+Web
 Request 
 inst
@@ -972,83 +972,128 @@
 est 
-instanceof HttpServletRequest)) %7B%0A            return UNRESOLVED;%0A        %7D%0A
+webRequest, WebDataBinderFactory binderFactory) throws Exception %7B%0A        Class%3C?%3E type = parameter.getParameterType();
 %0A   
@@ -1147,17 +1147,31 @@
 equest) 
-n
+webRequest.getN
 ativeReq
@@ -1174,16 +1174,18 @@
 eRequest
+()
 ;%0A      
@@ -1357,18 +1357,16 @@
  type);%0A
-%0A
     %7D%0A
-%0A
 %7D%0A

Change interface for IvisServiceArgumentResolver.