protected DataList getDataList() throws BeansException { if (cacheDataList == null) { // get datalist ApplicationContext ac = AppUtil.getApplicationContext(); AppService appService = (AppService) ac.getBean("appService"); DataListService dataListService = (DataListService) ac.getBean("dataListService"); DatalistDefinitionDao datalistDefinitionDao = (DatalistDefinitionDao) ac.getBean("datalistDefinitionDao"); String id = getPropertyString("datalistId"); AppDefinition appDef = appService.getAppDefinition( getRequestParameterString("appId"), getRequestParameterString("appVersion")); DatalistDefinition datalistDefinition = datalistDefinitionDao.loadById(id, appDef); if (datalistDefinition != null) { cacheDataList = dataListService.fromJson(datalistDefinition.getJson()); if (getPropertyString(Userview.USERVIEW_KEY_NAME) != null && getPropertyString(Userview.USERVIEW_KEY_NAME).trim().length() > 0) { cacheDataList.addBinderProperty( Userview.USERVIEW_KEY_NAME, getPropertyString(Userview.USERVIEW_KEY_NAME)); } if (getKey() != null && getKey().trim().length() > 0) { cacheDataList.addBinderProperty(Userview.USERVIEW_KEY_VALUE, getKey()); } cacheDataList.setActionPosition(getPropertyString("buttonPosition")); cacheDataList.setSelectionType(getPropertyString("selectionType")); cacheDataList.setCheckboxPosition(getPropertyString("checkboxPosition")); } } return cacheDataList; }
@RequestMapping("/console/app/(*:appId)/(~:version)/datalist/builder/(*:id)") public String builder( ModelMap map, @RequestParam("appId") String appId, @RequestParam(value = "version", required = false) String version, @RequestParam("id") String id, @RequestParam(required = false) String json) throws Exception { AppDefinition appDef = appService.getAppDefinition(appId, version); map.addAttribute("appId", appId); map.addAttribute("appVersion", appDef.getVersion()); map.addAttribute("appDefinition", appDef); DatalistDefinition datalist = datalistDefinitionDao.loadById(id, appDef); String listJson = null; if (json != null && !json.trim().isEmpty()) { // read custom JSON from request listJson = json; } else { // get JSON from form definition listJson = datalist.getJson(); } map.addAttribute("id", id); map.addAttribute("datalist", datalist); map.addAttribute("json", PropertyUtil.propertiesJsonLoadProcessing(listJson)); return "dbuilder/builder"; }
@RequestMapping("/app/(*:appId)/(~:appVersion)/datalist/embed") public String embedDatalist( ModelMap model, @RequestParam("appId") String appId, @RequestParam(value = "version", required = false) String version, HttpServletRequest request, @RequestParam("_submitButtonLabel") String buttonLabel, @RequestParam("_callback") String callback, @RequestParam("_setting") String callbackSetting, @RequestParam(required = false) String id, @RequestParam(value = "_listId", required = false) String listId, @RequestParam(value = "_type", required = false) String selectionType) throws JSONException { AppDefinition appDef = appService.getAppDefinition(appId, version); DatalistDefinition datalistDefinition = datalistDefinitionDao.loadById(listId, appDef); String json = datalistDefinition.getJson(); DataList dataList = dataListService.fromJson(json); dataList.setSelectionType(selectionType); model.addAttribute("id", id); model.addAttribute("json", json); model.addAttribute("buttonLabel", buttonLabel); model.addAttribute("dataList", dataList); model.addAttribute("setting", callbackSetting); model.addAttribute("callback", callback); return "dbuilder/embedDatalist"; }
protected DataListBinder createDataListBinderFromRequestInternal( AppDefinition appDef, String datalistId, String binderId, HttpServletRequest request) { DataListBinder binder = null; if (binderId != null && binderId.trim().length() > 0) { // create binder binder = dataListService.getBinder(binderId); if (request != null) { // get request params Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String paramName = (String) e.nextElement(); if (paramName.startsWith(PREFIX_BINDER_PROPERTY)) { String[] paramValue = (String[]) request.getParameterValues(paramName); String propName = paramName.substring(PREFIX_BINDER_PROPERTY.length()); String value = CsvUtil.getDeliminatedString(paramValue); if (value.contains(SecurityUtil.ENVELOPE) || value.contains(PropertyUtil.PASSWORD_PROTECTED_VALUE)) { DatalistDefinition datalist = datalistDefinitionDao.loadById(datalistId, appDef); if (datalist != null) { value = PropertyUtil.propertiesJsonStoreProcessing(datalist.getJson(), value); } } binder.setProperty(propName, AppUtil.processHashVariable(value, null, null, null)); } } } } return binder; }
@RequestMapping( value = { "/console/app/(*:appId)/(~:appVersion)/datalist/builderPreview/(*:id)", "/client/app/(*:appId)/(*:appVersion)/datalist/(*:id)" }) public String preview( ModelMap map, HttpServletRequest request, @RequestParam("appId") String appId, @RequestParam(value = "appVersion", required = false) String appVersion, @RequestParam("id") String id, @RequestParam(required = false) String json) throws Exception { String view = "dbuilder/view"; // get current app to set into thread AppDefinition appDef = appService.getAppDefinition(appId, appVersion); try { // get data list DataList dataList = new DataList(); if (json != null && !json.trim().isEmpty()) { String tempJson = json; if (tempJson.contains(SecurityUtil.ENVELOPE) || tempJson.contains(PropertyUtil.PASSWORD_PROTECTED_VALUE)) { DatalistDefinition datalistDef = datalistDefinitionDao.loadById(id, appDef); if (datalistDef != null) { tempJson = PropertyUtil.propertiesJsonStoreProcessing(datalistDef.getJson(), tempJson); } } dataList = dataListService.fromJson(AppUtil.processHashVariable(tempJson, null, null, null)); map.addAttribute("json", json); } else { dataList = parseFromJsonParameter(map, dataList, id, request); } map.addAttribute("dataList", dataList); } catch (Exception ex) { StringWriter out = new StringWriter(); ex.printStackTrace(new PrintWriter(out)); String message = ex.toString(); message += "\r\n<pre class=\"stacktrace\">" + out.getBuffer() + "</pre>"; map.addAttribute("error", message); } // set map into model to be used in the JSP template map.addAttribute("properties", new HashMap(map)); return view; }
@RequestMapping( value = "/console/app/(*:appId)/(~:version)/datalist/builderSave/(*:id)", method = RequestMethod.POST) public void save( Writer writer, @RequestParam("appId") String appId, @RequestParam(value = "version", required = false) String version, @RequestParam("id") String id, @RequestParam("json") String json) throws Exception { AppDefinition appDef = appService.getAppDefinition(appId, version); DatalistDefinition datalist = datalistDefinitionDao.loadById(id, appDef); DataList dlist = dataListService.fromJson(json); datalist.setName(dlist.getName()); datalist.setDescription(dlist.getName()); datalist.setJson(PropertyUtil.propertiesJsonStoreProcessing(datalist.getJson(), json)); boolean success = datalistDefinitionDao.update(datalist); JSONObject jsonObject = new JSONObject(); jsonObject.accumulate("success", success); jsonObject.write(writer); }
protected DataList parseFromJsonParameter( ModelMap map, DataList dataList, String id, HttpServletRequest request) { // get parameters String jsonParam = new ParamEncoder(id).encodeParameterName("json"); String json = request.getParameter(jsonParam); // use preview json if available if (json != null && json.trim().length() > 0) { try { String tempJson = json; if (tempJson.contains(SecurityUtil.ENVELOPE) || tempJson.contains(PropertyUtil.PASSWORD_PROTECTED_VALUE)) { AppDefinition appDef = AppUtil.getCurrentAppDefinition(); DatalistDefinition datalist = datalistDefinitionDao.loadById(id, appDef); if (datalist != null) { tempJson = PropertyUtil.propertiesJsonStoreProcessing(datalist.getJson(), tempJson); } } dataList = dataListService.fromJson(AppUtil.processHashVariable(tempJson, null, null, null)); dataList.setId(id); } catch (Exception ex) { map.addAttribute("dataListError", ex.toString()); } } /* else { json = dataListService.toJson(dataList); }*/ String jsonEncoded = null; try { if (json != null) { jsonEncoded = URLEncoder.encode(json, "UTF-8"); } } catch (Exception ex) { LogUtil.error(this.getClass().getName(), ex, "parseFromJsonParameter Error!"); } // set for view map.addAttribute("json", json); map.addAttribute("jsonEncoded", jsonEncoded); map.addAttribute("jsonParam", jsonParam); return dataList; }