Exemple #1
0
 public String createNewWorksheetTemplate(
     String worksheetDefinition, String modelName, String query) throws SourceBeanException {
   SourceBean templateSB = new SourceBean(TAG_WORKSHEET);
   templateSB.setAttribute(ATTRIBUTE_VERSION, CURRENT_VERSION);
   SourceBean worksheetDefinitionSB = new SourceBean(TAG_WORKSHEET_DEFINITION);
   worksheetDefinitionSB.setCharacters(worksheetDefinition);
   templateSB.setAttribute(worksheetDefinitionSB);
   if (modelName != null && !modelName.equals("")) {
     // case when starting from a model
     SourceBean templateQBE = new SourceBean(TAG_QBE);
     SourceBean templateDatamart = new SourceBean(DATAMART);
     templateDatamart.setAttribute("name", modelName);
     templateQBE.setAttribute(templateDatamart);
     SourceBean templateQuery = new SourceBean(QUERY);
     templateQuery.setCharacters(query);
     templateQBE.setAttribute(templateQuery);
     templateSB.setAttribute(templateQBE);
   } else if (query != null && !query.trim().equals("")) {
     // case when starting from a dataset
     SourceBean qbeSB = new SourceBean(TAG_QBE);
     SourceBean queryDefinitionSB = new SourceBean(QUERY);
     queryDefinitionSB.setCharacters(query);
     qbeSB.setAttribute(queryDefinitionSB);
     templateSB.setAttribute(qbeSB);
   }
   String template = templateSB.toXML(false);
   return template;
 }
  private String parametersJsonToXML(String parsJson) {
    String xml = null;
    SourceBean sb = null;

    try {
      JSONObject json = new JSONObject(parsJson);
      sb = new SourceBean("PARAMETERSLIST");
      SourceBean sb1 = new SourceBean("ROWS");
      for (Iterator iterator = json.keys(); iterator.hasNext(); ) {
        String key = (String) iterator.next();
        String t = json.getString(key);
        SourceBean b = new SourceBean("ROW");
        b.setAttribute("NAME", key);
        b.setAttribute("TYPE", t);
        sb1.setAttribute(b);
      }

      sb.setAttribute(sb1);
      xml = sb.toXML(false);
    } catch (Exception e) {
      logger.error("error in parsing " + parsJson, e);
    }
    Assert.assertNotNull(xml, "There was an error in parsing " + parsJson);

    return xml;
  }
Exemple #3
0
  public String composeWorksheetTemplate(
      String workSheetDef, String workSheetQuery, String smartFilterValues, String originalQbeTempl)
      throws SourceBeanException {
    SourceBean templateSB = new SourceBean(TAG_WORKSHEET);
    templateSB.setAttribute(ATTRIBUTE_VERSION, CURRENT_VERSION);
    SourceBean confSB = SourceBean.fromXMLString(originalQbeTempl);
    // from version 0 to version 1 worksheet change compensation: on version 0 the
    // worksheet definition was inside QBE tag; on version 1 the QBE tag is inside
    // WORKSHEET tag
    if (confSB.getName().equalsIgnoreCase(TAG_QBE)
        || confSB.getName().equalsIgnoreCase(TAG_QBE_COMPOSITE)
        || confSB.getName().equalsIgnoreCase(TAG_SMART_FILTER)) {

      if (confSB.containsAttribute(TAG_WORKSHEET_DEFINITION)) {
        confSB.delAttribute(TAG_WORKSHEET_DEFINITION);
      }
      templateSB.setAttribute(confSB);
      SourceBean wk_def_sb = new SourceBean(TAG_WORKSHEET_DEFINITION);
      wk_def_sb.setCharacters(workSheetDef);
      templateSB.setAttribute(wk_def_sb);

      if (workSheetQuery != null && !workSheetQuery.equals("")) {
        SourceBean query_sb = new SourceBean(QUERY);
        query_sb.setCharacters(workSheetQuery);
        confSB.updAttribute(query_sb);
      }

      if (smartFilterValues != null && !smartFilterValues.equals("")) {
        SourceBean smartFilterValuesSB = new SourceBean(FORM_VALUES);
        smartFilterValuesSB.setCharacters(smartFilterValues);
        confSB.updAttribute(smartFilterValuesSB);
      }

    } else {

      SourceBean qbeSB = null;

      if (confSB.containsAttribute(TAG_QBE)) {
        qbeSB = (SourceBean) confSB.getAttribute(TAG_QBE);
      } else if (confSB.containsAttribute(TAG_QBE_COMPOSITE)) {
        qbeSB = (SourceBean) confSB.getAttribute(TAG_QBE_COMPOSITE);
      } else if (confSB.containsAttribute(TAG_SMART_FILTER)) {
        qbeSB = (SourceBean) confSB.getAttribute(TAG_SMART_FILTER);
      }

      if (qbeSB != null) {
        templateSB.setAttribute(qbeSB);
        if (workSheetQuery != null && !workSheetQuery.equals("")) {
          SourceBean query_sb = new SourceBean(QUERY);
          query_sb.setCharacters(workSheetQuery);
          qbeSB.updAttribute(query_sb);
        }

        if (smartFilterValues != null && !smartFilterValues.equals("")) {
          SourceBean smartFilterValuesSB = new SourceBean(FORM_VALUES);
          smartFilterValuesSB.setCharacters(smartFilterValues);
          qbeSB.updAttribute(smartFilterValuesSB);
        }
      }

      SourceBean wk_def_sb = new SourceBean(TAG_WORKSHEET_DEFINITION);
      wk_def_sb.setCharacters(workSheetDef);
      templateSB.setAttribute(wk_def_sb);
    }

    String template = templateSB.toXML(false);
    return template;
  }