Exemple #1
0
  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;
  }
Exemple #2
0
  @Override
  public String getDecoratedMenu() {
    String menuItem = null;
    boolean showRowCount = Boolean.valueOf(getPropertyString("rowCount")).booleanValue();
    if (showRowCount) {
      // get datalist and row count
      DataList dataList = getDataList();
      if (dataList != null) {
        int rowCount = dataList.getTotal();

        // sanitize label
        String label = getPropertyString("label");
        if (label != null) {
          label = StringUtil.stripHtmlRelaxed(label);
        }

        // generate menu link
        menuItem =
            "<a href=\""
                + getUrl()
                + "\" class=\"menu-link default\"><span>"
                + label
                + "</span> <span class='rowCount'>("
                + rowCount
                + ")</span></a>";
      }
    }
    return menuItem;
  }
  @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";
  }
Exemple #4
0
  @Override
  public String getJspPage() {
    try {
      // get data list
      DataList dataList = getDataList();

      if (dataList != null) {
        // overide datalist result to use userview result
        DataListActionResult ac = dataList.getActionResult();
        if (ac != null) {
          if (ac.getMessage() != null && !ac.getMessage().isEmpty()) {
            setAlertMessage(ac.getMessage());
          }
          if (ac.getType() != null
              && DataListActionResult.TYPE_REDIRECT.equals(ac.getType())
              && ac.getUrl() != null
              && !ac.getUrl().isEmpty()) {
            if ("REFERER".equals(ac.getUrl())) {
              HttpServletRequest request = WorkflowUtil.getHttpServletRequest();
              if (request != null && request.getHeader("Referer") != null) {
                setRedirectUrl(request.getHeader("Referer"));
              } else {
                setRedirectUrl("REFERER");
              }
            } else {
              setRedirectUrl(ac.getUrl());
            }
          }
        }

        // set data list
        setProperty("dataList", dataList);
      } else {
        setProperty("error", "Data List \"" + getPropertyString("datalistId") + "\" not exist.");
      }
    } 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>";
      setProperty("error", message);
    }
    return "userview/plugin/datalist.jsp";
  }
  @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;
  }
  @RequestMapping(
      value = "/json/console/app/(*:appId)/(~:appVersion)/builder/binder/columns",
      method = RequestMethod.POST)
  public void getBuilderDataColumnList(
      ModelMap map,
      Writer writer,
      @RequestParam("appId") String appId,
      @RequestParam(required = false) String appVersion,
      @RequestParam String id,
      @RequestParam String binderId,
      HttpServletRequest request)
      throws Exception {
    AppDefinition appDef = appService.getAppDefinition(appId, appVersion);
    JSONObject jsonObject = new JSONObject();

    // get data list
    DataList dataList = new DataList();

    // parse JSON from request if available
    dataList = parseFromJsonParameter(map, dataList, id, request);

    // get binder from request
    DataListBinder binder = createDataListBinderFromRequestInternal(appDef, id, binderId, request);
    if (binder != null) {
      dataList.setBinder(binder);
    }

    DataListColumn[] sourceColumns = (binder != null) ? binder.getColumns() : new DataListColumn[0];

    // sort columns by label
    List<DataListColumn> binderColumnList = Arrays.asList(sourceColumns);
    Collections.sort(
        binderColumnList,
        new Comparator<DataListColumn>() {

          public int compare(DataListColumn o1, DataListColumn o2) {
            return o1.getLabel().toLowerCase().compareTo(o2.getLabel().toLowerCase());
          }
        });

    Collection<String> columnNameList = new HashSet<String>();
    DataListColumn[] targetColumns = dataList.getColumns();
    if (targetColumns != null) {
      for (DataListColumn selectedColumn : targetColumns) {
        columnNameList.add(selectedColumn.getName());
      }
    }
    for (Iterator i = binderColumnList.iterator(); i.hasNext(); ) {
      DataListColumn column = (DataListColumn) i.next();
      if (columnNameList.contains(column.getName())) {
        i.remove();
      }
    }
    sourceColumns = (DataListColumn[]) binderColumnList.toArray(new DataListColumn[0]);
    DataList sourceDataList = new DataList();
    sourceDataList.setColumns(sourceColumns);

    Collection<Object> collection = new ArrayList<Object>();
    for (DataListColumn sourceColumn : sourceColumns) {
      HashMap hm = new HashMap();
      hm.put("name", sourceColumn.getName());
      hm.put("label", sourceColumn.getLabel());
      hm.put("sortable", true);
      hm.put("filterable", true);
      hm.put("type", sourceColumn.getType());
      collection.add(hm);
    }
    jsonObject.accumulate("columns", collection);
    jsonObject.write(writer);
  }