@RequestMapping(value = "/save", method = RequestMethod.POST) @ResponseBody public JsonResponse save( @RequestParam("ids") String[] ids, @RequestParam("counts") int[] counts, @RequestParam("fields") String[] fields, @RequestParam("values") String[] values) { Map<String, Map<String, ScenarioParameter>> params = new HashMap<String, Map<String, ScenarioParameter>>(); Map<String, ConfigurableObject> oldParams = this.engineService.getScenarioParameters(); int countsum = 0; String error = null; for (int i = 0; i < ids.length; i++) { Map<String, ScenarioParameter> p = new HashMap<String, ScenarioParameter>(); for (int j = countsum; j < countsum + counts[i]; j++) { Object value; ConfigurableObject obj = oldParams.get(ids[i]); ScenarioParameter param = obj.getParameter(fields[j]); try { value = this.parseValue(param.getValue(), values[j]); } catch (IllegalArgumentException e) { error = "Incorrect value for '" + ids[i] + "' field '" + fields[j] + "' (" + e.getMessage() + ")"; break; } p.put(fields[j], new ScenarioParameter(fields[j], value)); } if (error != null) break; params.put(ids[i], p); countsum += counts[i]; } if (error == null) { this.engineService.setScenarioParameters(params); return new JsonResponse(true); } else { JsonResponse response = new JsonResponse(false); response.setError(error); return response; } }
@RequestMapping(value = "/list") public @ResponseBody JsonResponse parameters() { JsonResponse response = new JsonResponse(true); response.put("parameters", this.engineService.getScenarioParameters().values()); return response; }