Package com.github.dandelion.datatables.core.export

Examples of com.github.dandelion.datatables.core.export.ExportConf$Builder


  @Test
  public void shoud_handle_controller_export_with_GET_existing_params_and_no_extra_param() {
   
    exportFeature = new ExportFeature();
   
    ExportConf exportConf = new ExportConf("csv");
    exportConf.setHasCustomUrl(true);
    exportConf.setUrl("/myExportUrl?existingParam=val");
    exportConf.setLabel("CSV");
    table.getTableConfiguration().getExportConfiguration().put("csv", exportConf);
    extensionProcessor.process(new HashSet<Extension>(Arrays.asList(exportFeature)));
   
    assertThat(AssetRequestContext.get(table.getTableConfiguration().getRequest()).getBundles(true)).isEmpty();
    assertThat(exportFeature.getBeforeAll().toString()).isEqualTo("function ddl_dt_launch_export_fakeId_csv(){\n   window.location=\"/myExportUrl?existingParam=val&\" + decodeURIComponent($.param(oTable_fakeId.oApi._fnAjaxParameters(oTable_fakeId.fnSettings())).replace(/\\+/g,' '));\n}\n");
View Full Code Here


  @Test
  public void shoud_handle_controller_export_with_POST_and_no_extra_param() {
   
    exportFeature = new ExportFeature();
   
    ExportConf exportConf = new ExportConf("csv");
    exportConf.setHasCustomUrl(true);
    exportConf.setUrl("/myExportUrl");
    exportConf.setMethod(HttpMethod.POST);
    exportConf.setLabel("CSV");
    table.getTableConfiguration().getExportConfiguration().put("csv", exportConf);
    extensionProcessor.process(new HashSet<Extension>(Arrays.asList(exportFeature)));
   
    assertThat(AssetRequestContext.get(table.getTableConfiguration().getRequest()).getBundles(true)).contains(DatatableBundles.DDL_DT_EXPORT.getBundleName());
    assertThat(exportFeature.getBeforeAll().toString()).isEqualTo("function ddl_dt_launch_export_fakeId_csv(){\n   $.download('/myExportUrl', decodeURIComponent($.param(oTable_fakeId.oApi._fnAjaxParameters(oTable_fakeId.fnSettings())).replace(/\\+/g,' '),'POST'));\n}\n");
View Full Code Here

  @Test
  public void shoud_handle_controller_export_with_GET_and_extra_param() {
   
    exportFeature = new ExportFeature();
   
    ExportConf exportConf = new ExportConf("csv");
    exportConf.setHasCustomUrl(true);
    exportConf.setUrl("/myExportUrl");
    exportConf.setLabel("CSV");
    table.getTableConfiguration().getExportConfiguration().put("csv", exportConf);
    table.getTableConfiguration().set(TableConfig.AJAX_SERVERPARAM, "param1=val1&param2=val2");
    extensionProcessor.process(new HashSet<Extension>(Arrays.asList(exportFeature)));
   
    assertThat(AssetRequestContext.get(table.getTableConfiguration().getRequest()).getBundles(true)).isEmpty();
View Full Code Here

  @Test
  public void shoud_handle_controller_export_with_GET_existing_params_and_extra_param() {
   
    exportFeature = new ExportFeature();
   
    ExportConf exportConf = new ExportConf("csv");
    exportConf.setHasCustomUrl(true);
    exportConf.setUrl("/myExportUrl?existingParam=val");
    exportConf.setLabel("CSV");
    table.getTableConfiguration().getExportConfiguration().put("csv", exportConf);
    table.getTableConfiguration().set(TableConfig.AJAX_SERVERPARAM, "param1=val1&param2=val2");
    extensionProcessor.process(new HashSet<Extension>(Arrays.asList(exportFeature)));
   
    assertThat(AssetRequestContext.get(table.getTableConfiguration().getRequest()).getBundles(true)).isEmpty();
View Full Code Here

  @Test
  public void shoud_handle_controller_export_with_POST_and_extra_param() {
   
    exportFeature = new ExportFeature();
   
    ExportConf exportConf = new ExportConf("csv");
    exportConf.setHasCustomUrl(true);
    exportConf.setUrl("/myExportUrl");
    exportConf.setMethod(HttpMethod.POST);
    exportConf.setLabel("CSV");
    table.getTableConfiguration().getExportConfiguration().put("csv", exportConf);
    table.getTableConfiguration().set(TableConfig.AJAX_SERVERPARAM, "param1=val1&param2=val2");
    extensionProcessor.process(new HashSet<Extension>(Arrays.asList(exportFeature)));
   
    assertThat(AssetRequestContext.get(table.getTableConfiguration().getRequest()).getBundles(true)).contains(DatatableBundles.DDL_DT_EXPORT.getBundleName());
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  private void processExportAttributes(Arguments arguments, Element element, Map<String, Map<ConfType, Object>> configs, HttpServletRequest request, HttpServletResponse response,
      String tableId) {

    ExportConf conf = null;
    String exportFormat = null;

    if (hasAttribute(element, "type")) {
      exportFormat = element.getAttributeValue(DataTablesDialect.DIALECT_PREFIX + ":type").trim().toLowerCase();
      conf = new ExportConf(exportFormat);
    } else {
      throw new ConfigurationProcessingException(
          "The attribute 'dt:type' is required when defining an export configuration.");
    }

    StringBuilder exportUrl = null;
    // Custom mode (export using controller)
    if (element.hasAttribute(DataTablesDialect.DIALECT_PREFIX + ":url")) {
      exportUrl = new StringBuilder(AttributeUtils.parseStringAttribute(arguments, element,
          DataTablesDialect.DIALECT_PREFIX + ":url").trim());
      UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_TYPE, "c");
      conf.setHasCustomUrl(true);
    }
    // Default mode (export using filter)
    else{
      exportUrl = UrlUtils.getCurrentUri(request);
      UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_TYPE, "f");
      conf.setHasCustomUrl(false);
    }
   
    if (hasAttribute(element, "fileName")) {
      String fileName = getStringValue(element, "fileName");
      conf.setFileName(fileName);
      UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_NAME, fileName);
    }

    if (hasAttribute(element, "mimeType")) {
      String mimeType = getStringValue(element, "mimeType");
      conf.setMimeType(mimeType);
      UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_MIME_TYPE, mimeType);
    }

    if (hasAttribute(element, "label")) {
      conf.setLabel(getStringValue(element, "label"));
    }

    if (hasAttribute(element, "cssStyle")) {
      conf.setCssStyle(new StringBuilder(getStringValue(element, "cssStyle")));
    }

    if (hasAttribute(element, "cssClass")) {
      conf.setCssClass(new StringBuilder(getStringValue(element, "cssClass")));
    }

    if (hasAttribute(element, "includeHeader")) {
      String includeHeader = getStringValue(element, "includeHeader");
      conf.setIncludeHeader(Boolean.parseBoolean(includeHeader));
      UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_HEADER, includeHeader);
    }
   
    if (hasAttribute(element, "method")) {
      String methodStr = element.getAttributeValue(DataTablesDialect.DIALECT_PREFIX + ":method");

      HttpMethod methodEnum = null;
      try {
        methodEnum = HttpMethod.valueOf(methodStr.toUpperCase().trim());
      } catch (IllegalArgumentException e) {
        StringBuilder sb = new StringBuilder();
        sb.append("'");
        sb.append(methodStr);
        sb.append("' is not a valid HTTP method. Possible values are: ");
        sb.append(EnumUtils.printPossibleValuesOf(HttpMethod.class));
        throw new ConfigurationProcessingException(sb.toString());
      }

      conf.setMethod(methodEnum);
    }

    if (hasAttribute(element, "autoSize")) {
      String autosize = getStringValue(element, "autoSize");
      conf.setAutoSize(Boolean.parseBoolean(autosize));
      UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_AUTOSIZE, autosize);
    }

    if (hasAttribute(element, "exportClass")) {
      conf.setExportClass(getStringValue(element, "exportClass"));
    }

    if (hasAttribute(element, "fileExtension")) {
      String fileExtension = getStringValue(element, "fileExtension");
      conf.setFileExtension(fileExtension);
      UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_EXTENSION, fileExtension);
    }

    if (hasAttribute(element, "orientation")) {
      String orientationStr = element.getAttributeValue(DataTablesDialect.DIALECT_PREFIX + ":orientation");

      Orientation orientationEnum = null;
      try {
        orientationEnum = Orientation.valueOf(orientationStr.toUpperCase().trim());
      } catch (IllegalArgumentException e) {
        StringBuilder sb = new StringBuilder();
        sb.append("'");
        sb.append(orientationStr);
        sb.append("' is not a valid orientation. Possible values are: ");
        sb.append(EnumUtils.printPossibleValuesOf(Orientation.class));
        throw new ConfigurationProcessingException(sb.toString());
      }

      conf.setOrientation(orientationEnum);
      UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_ORIENTATION, orientationStr);
    }

    // Finalizes export URL
    UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_ID, tableId);
    UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_FORMAT, exportFormat);
    UrlUtils.addParameter(exportUrl, ExportUtils.DDL_DT_REQUESTPARAM_EXPORT_IN_PROGRESS, "y");
    UrlUtils.addParameter(exportUrl, WebConstants.DANDELION_ASSET_FILTER_STATE, false);
    conf.setUrl(UrlUtils.getProcessedUrl(exportUrl, request, response));
   
    if (conf != null) {

      if (configs.get(tableId).containsKey(ConfType.EXPORT)) {
        ((Map<String, ExportConf>) configs.get(tableId).get(ConfType.EXPORT)).put(exportFormat, conf);
View Full Code Here

TOP

Related Classes of com.github.dandelion.datatables.core.export.ExportConf$Builder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.