org.springframework.validation.support.BindingAwareModelMap Java Examples

The following examples show how to use org.springframework.validation.support.BindingAwareModelMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProvidersController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/add")
public String add(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "add", "providers");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    Long id = (Long)newModel.get("id");
    String service = (String)newModel.get("service");
    if (service == null) {
        List<String> serviceList = Tool.sortSimpleName(new ArrayList<String>(providerService.findServices()));
        model.addAttribute("serviceList", serviceList);
    }
    if (id != null) {
        Provider p = providerService.findProvider(id);
        if (p != null) {
            model.addAttribute("provider", p);
            String parameters = p.getParameters();
            if (parameters != null && parameters.length() > 0) {
                Map<String, String> map = StringUtils.parseQueryString(parameters);
                map.put("timestamp", String.valueOf(System.currentTimeMillis()));
                map.remove("pid");
                p.setParameters(StringUtils.toQueryString(map));
            }
        }
    }
    return "governance/screen/providers/add";
}
 
Example #2
Source File: OverridesController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "index", "overrides");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    String application = (String)newModel.get("app");
    String address = (String)newModel.get("address");
    List<Override> overrides;
    if (StringUtils.isNotEmpty(service)) {
        overrides = overrideService.findByService(service);
    } else if (StringUtils.isNotEmpty(application)) {
        overrides = overrideService.findByApplication(application);
    } else if (StringUtils.isNotEmpty(address)) {
        overrides = overrideService.findByAddress(address);
    } else {
        overrides = overrideService.findAll();
    }
    model.addAttribute("overrides", overrides);
    return "governance/screen/overrides/index";
}
 
Example #3
Source File: WeightsController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "index", "weights");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    String address = (String)newModel.get("address");
    service = StringUtils.trimToNull(service);
    address = Tool.getIP(address);
    List<Weight> weights;
    if (service != null && service.length() > 0) {
        weights = OverrideUtils.overridesToWeights(overrideService.findByService(service));
    } else if (address != null && address.length() > 0) {
        weights = OverrideUtils.overridesToWeights(overrideService.findByAddress(address));
    } else {
        weights = OverrideUtils.overridesToWeights(overrideService.findAll());
    }
    model.addAttribute("weights", weights);
    return "governance/screen/weights/index";
}
 
Example #4
Source File: WeightsController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
/**
 * load page for the adding
 *
 */
@RequestMapping("/add")
public String add(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "add", "weights");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    String input = request.getParameter("input");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for (Provider provider : providerList) {
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        model.addAttribute("addressList", addressList);
        model.addAttribute("service", service);
        model.addAttribute("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        model.addAttribute("serviceList", serviceList);
    }
    if (input != null) model.addAttribute("input", input);
    return "governance/screen/weights/add";
}
 
Example #5
Source File: RoutesController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Routing module home page
 *
 */
@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "index", "routes");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String address = (String)newModel.get("address");
    String service = (String)newModel.get("service");
    address = Tool.getIP(address);
    List<Route> routes;
    if (service != null && service.length() > 0
            && address != null && address.length() > 0) {
        routes = routeService.findByServiceAndAddress(service, address);
    } else if (service != null && service.length() > 0) {
        routes = routeService.findByService(service);
    } else if (address != null && address.length() > 0) {
        routes = routeService.findByAddress(address);
    } else {
        routes = routeService.findAll();
    }
    model.addAttribute("routes", routes);
    return "governance/screen/routes/index";
}
 
Example #6
Source File: RoutesController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Load new route page
 *
 */
@RequestMapping("/add")
public String add(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "add", "routes");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    if (service != null && service.length() > 0 && !service.contains("*")) {
        model.addAttribute("service", service);
        model.addAttribute("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
    } else {
        List<String> serviceList = Tool.sortSimpleName(new ArrayList<String>(providerService.findServices()));
        model.addAttribute("serviceList", serviceList);
    }

    //if (input != null) model.addAttribute("input", input);
    return "governance/screen/routes/add";
}
 
Example #7
Source File: LoadbalancesController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "index", "loadbalances");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    service = StringUtils.trimToNull(service);

    List<LoadBalance> loadbalances;
    if (service != null && service.length() > 0) {
        loadbalances = OverrideUtils.overridesToLoadBalances(overrideService.findByService(service));
    } else {
        loadbalances = OverrideUtils.overridesToLoadBalances(overrideService.findAll());
    }
    model.addAttribute("loadbalances", loadbalances);
    return "governance/screen/loadbalances/index";
}
 
Example #8
Source File: LoadbalancesController.java    From open-capacity-platform with Apache License 2.0 6 votes vote down vote up
@RequestMapping("/add")
public String add(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "add", "loadbalances");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");

    if (service != null && service.length() > 0 && !service.contains("*")) {
        List<Provider> providerList = providerService.findByService(service);
        List<String> addressList = new ArrayList<String>();
        for (Provider provider : providerList) {
            addressList.add(provider.getUrl().split("://")[1].split("/")[0]);
        }
        model.addAttribute("addressList", addressList);
        model.addAttribute("service", service);
        model.addAttribute("methods", CollectionUtils.sort(providerService.findMethodsByService(service)));
    } else {
        List<String> serviceList = Tool.sortSimpleName(providerService.findServices());
        model.addAttribute("serviceList", serviceList);
    }
    //if (input != null) model.addAttribute("input", input);
    return "governance/screen/loadbalances/add";
}
 
Example #9
Source File: OwnersController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/add")
public String add(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "add", "owners");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    if (service == null || service.length() == 0) {
        List<String> serviceList = Tool.sortSimpleName(new ArrayList<String>(providerService.findServices()));
        model.addAttribute("serviceList", serviceList);
    }
    return "governance/screen/owners/add";
}
 
Example #10
Source File: AnnotationMethodHandlerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
protected ModelAndView invokeHandlerMethod(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws Exception {

	ServletHandlerMethodResolver methodResolver = getMethodResolver(handler);
	Method handlerMethod = methodResolver.resolveHandlerMethod(request);
	ServletHandlerMethodInvoker methodInvoker = new ServletHandlerMethodInvoker(methodResolver);
	ServletWebRequest webRequest = new ServletWebRequest(request, response);
	ExtendedModelMap implicitModel = new BindingAwareModelMap();

	Object result = methodInvoker.invokeHandlerMethod(handlerMethod, handler, webRequest, implicitModel);
	ModelAndView mav =
			methodInvoker.getModelAndView(handlerMethod, handler.getClass(), result, implicitModel, webRequest);
	methodInvoker.updateModelAttributes(handler, (mav != null ? mav.getModel() : null), implicitModel, webRequest);
	return mav;
}
 
Example #11
Source File: AnnotationMethodHandlerAdapter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected ModelAndView invokeHandlerMethod(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws Exception {

	ServletHandlerMethodResolver methodResolver = getMethodResolver(handler);
	Method handlerMethod = methodResolver.resolveHandlerMethod(request);
	ServletHandlerMethodInvoker methodInvoker = new ServletHandlerMethodInvoker(methodResolver);
	ServletWebRequest webRequest = new ServletWebRequest(request, response);
	ExtendedModelMap implicitModel = new BindingAwareModelMap();

	Object result = methodInvoker.invokeHandlerMethod(handlerMethod, handler, webRequest, implicitModel);
	ModelAndView mav =
			methodInvoker.getModelAndView(handlerMethod, handler.getClass(), result, implicitModel, webRequest);
	methodInvoker.updateModelAttributes(handler, (mav != null ? mav.getModel() : null), implicitModel, webRequest);
	return mav;
}
 
Example #12
Source File: CommentSimulator.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@EventListener
public void simulateUsersClicking(ApplicationReadyEvent event) {
	Flux
		.interval(Duration.ofMillis(500))
		.flatMap(tick ->
			Mono.defer(() ->
				homeController.index(new BindingAwareModelMap())))
		.subscribe();
}
 
Example #13
Source File: CommentSimulator.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@EventListener
public void simulateUsersClicking(ApplicationReadyEvent event) {
	Flux
		.interval(Duration.ofMillis(500))
		.flatMap(tick ->
			Mono.defer(() ->
				homeController.index(new BindingAwareModelMap())))
		.subscribe();
}
 
Example #14
Source File: CacheKeyUtil.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 获取方法参数组成的key
 *
 * @param params
 *         参数数组
 */
public static String getMethodParamsKey(Object... params) {
    if (null == params || params.length == 0) {
        return "";
    }
    StringBuilder key = new StringBuilder("(");
    for (Object obj : params) {
        if (obj.getClass().equals(BindingAwareModelMap.class)) {
            continue;
        }
        key.append(JSON.toJSONString(obj).replaceAll("\"", "'"));
    }
    key.append(")");
    return key.toString();
}
 
Example #15
Source File: LoadbalancesController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/create")
public String create(LoadBalance loadBalance, HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "create", "loadbalances");
    boolean success = true;
    if (!super.currentUser.hasServicePrivilege(loadBalance.getService())) {
        model.addAttribute("message", getMessage("HaveNoServicePrivilege", loadBalance.getService()));
        success = false;
    } else {
        loadBalance.setUsername((String) ((BindingAwareModelMap)model).get("operator"));
        overrideService.saveOverride(OverrideUtils.loadBalanceToOverride(loadBalance));
    }
    model.addAttribute("success", success);
    model.addAttribute("redirect", "../loadbalances");
    return "governance/screen/redirect";
}
 
Example #16
Source File: OverridesController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("/add")
public String add(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model,"add", "overrides");
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String application = (String)newModel.get("app");
    String service = (String)newModel.get("service");
    List<String> serviceList = new ArrayList<String>();
    List<String> applicationList = new ArrayList<String>();
    if (StringUtils.isNotEmpty(application)) {
        serviceList.addAll(providerService.findServicesByApplication(application));
        serviceList.addAll(consumerService.findServicesByApplication(application));
        model.addAttribute("serviceList", serviceList);
    } else if (StringUtils.isNotEmpty(service)) {
        applicationList.addAll(providerService.findApplicationsByServiceName(service));
        applicationList.addAll(consumerService.findApplicationsByServiceName(service));
        model.addAttribute("applicationList", applicationList);
    } else {
        serviceList.addAll(providerService.findServices());
        serviceList.addAll(consumerService.findServices());
        providerService.findServicesByApplication(application);
        consumerService.findServicesByApplication(application);
    }
    model.addAttribute("serviceList", serviceList);

    if (StringUtils.isNotEmpty(service) && !service.contains("*")) {
        model.addAttribute("methods", CollectionUtils.sort(new ArrayList<String>(providerService.findMethodsByService(service))));
    }
    return "governance/screen/overrides/add";
}
 
Example #17
Source File: ProvidersController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value =  "/create", method = RequestMethod.POST)  //post
public String create(@ModelAttribute Provider provider, HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model,"create" ,"providers");
    boolean success = true;
    String service = provider.getService();
    if (service == null) {
        service = (String)((BindingAwareModelMap)model).get("service");
        provider.setService(service);
    }
    if (!super.currentUser.hasServicePrivilege(service)) {
        model.addAttribute("message", getMessage("HaveNoServicePrivilege", service));
        success = false;
        model.addAttribute("success", success);
        model.addAttribute("redirect", "../providers");
        return "governance/screen/redirect";
    }
    if (provider.getParameters() == null) {
        String url = provider.getUrl();
        if (url != null) {
            int i = url.indexOf('?');
            if (i > 0) {
                provider.setUrl(url.substring(0, i));
                provider.setParameters(url.substring(i + 1));
            }
        }
    }
    provider.setDynamic(false); // Provider add through web page must be static
    providerService.create(provider);
    model.addAttribute("success", success);
    model.addAttribute("redirect", "../providers");
    return "governance/screen/redirect";
}
 
Example #18
Source File: OwnersController.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
    prepare(request, response, model, "index", "owners");
    List<Owner> owners;
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    if (service != null && service.length() > 0) {
        owners = ownerService.findByService(service);
    } else {
        owners = ownerService.findAll();
    }
    model.addAttribute("owners", owners);
    return "governance/screen/owners/index";
}
 
Example #19
Source File: ConsumersController.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response,
                  Model model) {
    prepare(request, response, model, "index", "consumers");
    List<Consumer> consumers;
    List<Override> overrides;
    List<Provider> providers = null;
    List<Route> routes = null;
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    String address = (String)newModel.get("address");
    String application = (String)newModel.get("app");
    // service
    if (service != null && service.length() > 0) {
        consumers = consumerService.findByService(service);
        overrides = overrideService.findByService(service);
        providers = providerService.findByService(service);
        routes = routeService.findByService(service);
    }
    // address
    else if (address != null && address.length() > 0) {
        consumers = consumerService.findByAddress(address);
        overrides = overrideService.findByAddress(Tool.getIP(address));
    }
    // application
    else if (application != null && application.length() > 0) {
        consumers = consumerService.findByApplication(application);
        overrides = overrideService.findByApplication(application);
    }
    // all
    else {
        consumers = consumerService.findAll();
        overrides = overrideService.findAll();
    }
    if (consumers != null && consumers.size() > 0) {
        for (Consumer consumer : consumers) {
            if (service == null || service.length() == 0) {
                providers = providerService.findByService(consumer.getService());
                routes = routeService.findByService(consumer.getService());
            }
            List<Route> routed = new ArrayList<Route>();
            consumer.setProviders(RouteUtils
                .route(consumer.getService(), consumer.getAddress(), consumer.getParameters(), providers, overrides, routes, null, routed));
            consumer.setRoutes(routed);
            OverrideUtils.setConsumerOverrides(consumer, overrides);
        }
    }
    model.addAttribute("consumers", consumers);
    return "governance/screen/consumers/index";
}
 
Example #20
Source File: CommentSimulator.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 4 votes vote down vote up
@Scheduled(fixedRate = 500)
public void simulateUsersClicking() {
	homeController.index(
		new BindingAwareModelMap(),
		null);
}
 
Example #21
Source File: CommentSimulator.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 4 votes vote down vote up
@Scheduled(fixedRate = 500)
public void simulateUsersClicking() {
	homeController.index(
		new BindingAwareModelMap());
}
 
Example #22
Source File: CommentSimulator.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 4 votes vote down vote up
@Scheduled(fixedRate = 500)
public void simulateUsersClicking() {
	homeController.index(
		new BindingAwareModelMap());
}
 
Example #23
Source File: CommentSimulator.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 4 votes vote down vote up
@Scheduled(fixedRate = 500)
public void simulateUsersClicking() {
	homeController.index(
		new BindingAwareModelMap());
}
 
Example #24
Source File: CommentSimulator.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 4 votes vote down vote up
@Scheduled(fixedRate = 500)
public void simulateUsersClicking() {
	homeController.index(
		new BindingAwareModelMap(),
		null);
}
 
Example #25
Source File: ProvidersController.java    From open-capacity-platform with Apache License 2.0 4 votes vote down vote up
@RequestMapping("")
public String index(HttpServletRequest request, HttpServletResponse response, Model model) {


    prepare(request, response, model, "index", "providers");

    String value = "";
    String separators = "....";

    List<Provider> providers = null;
    BindingAwareModelMap newModel = (BindingAwareModelMap)model;
    String service = (String)newModel.get("service");
    String address = (String)newModel.get("address");
    String application = (String)newModel.get("app");

    // service
    if (service != null && service.length() > 0) {
        providers = providerService.findByService(service);

        value = service + separators + request.getRequestURI();
    }
    // address
    else if (address != null && address.length() > 0) {
        providers = providerService.findByAddress(address);

        value = address + separators + request.getRequestURI();
    }
    // application
    else if (application != null && application.length() > 0) {
        providers = providerService.findByApplication(application);

        value = application + separators + request.getRequestURI();
    }
    // all
    else {
        providers = providerService.findAll();
    }

    model.addAttribute("providers", providers);
    model.addAttribute("serviceAppMap", getServiceAppMap(providers));

    // record search history to cookies
    try {
        setSearchHistroy(value, request, response);
    } catch (Exception e) {
        //
    }
    return "governance/screen/providers/index";
}
 
Example #26
Source File: CustomerDetailsControllerTest.java    From sales-order-system with The Unlicense 4 votes vote down vote up
@Test
public void testGetCustomerDetailsPage() {
    Mockito.when(customerService.findCustomerByCustomerId(Matchers.anyInt()))
        .thenReturn(new Customer());
    assertEquals("customers/customerDetails", customerDetailsController.getCustomerDetailsPage("1", new BindingAwareModelMap()));
}