Package com.senseidb.util.JSONUtil

Examples of com.senseidb.util.JSONUtil.FastJSONObject


  SenseiQuery createSenseiQuery()
      throws JSONException
  {

    JSONObject obj = new FastJSONObject();

    obj.put("query", "key words are useful")// 'query' in the JSONObj gets translated into 'q' in the GET request

    for (int i = 0; i < 10; i++) {
      obj.put("key" + i, "val" + i);
    }

    SenseiQuery query = new SenseiJSONQuery(obj);

    return query;
View Full Code Here


  @Override
  public JSONObject render(Double reduceResult) {
  
    try {
      return new FastJSONObject().put("sum", reduceResult);
    } catch (JSONException e) {
      throw new RuntimeException(e);
    }
  }
View Full Code Here

    return ret;
  }

  public JSONObject render(ArrayList<GroupedValue> reduceResult) {
    try {
      JSONObject ret = new FastJSONObject();
      for (GroupedValue grouped : reduceResult) {
        ret.put(grouped.key, grouped.value);
      }
      return new FastJSONObject().put("facetCounts", ret);
    } catch (JSONException ex) {
      throw new RuntimeException(ex);
    }
  }
View Full Code Here

        File jsonSchema = new File(confDir, SCHEMA_FILE_JSON);
        if (jsonSchema.exists()) {
            InputStream is = new FileInputStream(jsonSchema);
            String json = IOUtils.toString(is);
            is.close();
            return new FastJSONObject(json);
        } else {
            File xmlSchema = new File(confDir, SCHEMA_FILE_XML);
            if (!xmlSchema.exists()) {
                throw new ConfigurationException("schema not file");
            }
View Full Code Here

    }

    public static JSONObject loadSchema(Resource confDir) throws Exception {
        if (confDir.createRelative(SCHEMA_FILE_JSON).exists()) {
            String json = IOUtils.toString(confDir.createRelative(SCHEMA_FILE_JSON).getInputStream());
            return new FastJSONObject(json);
        } else {
            if (confDir.createRelative(SCHEMA_FILE_XML).exists()) {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                dbf.setIgnoringComments(true);
                DocumentBuilder db = dbf.newDocumentBuilder();
View Full Code Here

    throw new IOException(e.getMessage(),e);
    }

    // Try to create directly.
  try {
    return new FastJSONObject(line);
  } catch (JSONException e) {
    throw new IOException(e.getMessage(),e);
  }
  }
View Full Code Here

  private static Logger logger = Logger.getLogger(SchemaConverter.class);

  static public JSONObject convert(Document schemaDoc)
      throws ConfigurationException, JSONException
  {
    JSONObject jsonObj = new FastJSONObject();
    JSONObject tableObj = new FastJSONObject();
    jsonObj.put("table", tableObj);

    NodeList tables = schemaDoc.getElementsByTagName("table");
    if (tables != null && tables.getLength() > 0)
    {
      Element tableElem = (Element) tables.item(0);
      tableObj.put("uid", tableElem.getAttribute("uid"));
      String deleteField = tableElem.getAttribute("delete-field");
      if (deleteField != null)
        tableObj.put("delete-field", deleteField);

      String skipField = tableElem.getAttribute("skip-field");
      if (skipField != null)
        tableObj.put("skip-field", skipField);

      String srcDataStore = tableElem.getAttribute("src-data-store");
      if (srcDataStore != null)
        tableObj.put("src-data-store", srcDataStore);

      String srcDatafield = tableElem.getAttribute("src-data-field");
      if (srcDatafield == null || srcDatafield.length() == 0)
        srcDatafield = "src_data";
      tableObj.put("src-data-field", srcDatafield);

      String compress = tableElem.getAttribute("compress-src-data");
      if (compress != null && "false".equals(compress))
        tableObj.put("compress-src-data", false);
      else
        tableObj.put("compress-src-data", true);

      NodeList columns = tableElem.getElementsByTagName("column");
      JSONArray columnArray = new FastJSONArray();
      tableObj.put("columns", columnArray);

      for (int i = 0; i < columns.getLength(); ++i)
      {
        try
        {
          Element column = (Element) columns.item(i);
          JSONObject columnObj = new FastJSONObject();
          columnArray.put(columnObj);

          String n = column.getAttribute("name");
          String t = column.getAttribute("type");
          String frm = column.getAttribute("from");

          columnObj.put("name", n);
          columnObj.put("type", t);
          columnObj.put("from", frm);

          columnObj.put("multi", Boolean.parseBoolean(column.getAttribute("multi")));
          columnObj.put("activity", Boolean.parseBoolean(column.getAttribute("activity")));
          columnObj.put("wildcard", Boolean.parseBoolean(column.getAttribute("wildcard")));

            String delimString = column.getAttribute("delimiter");
          if (delimString != null && delimString.trim().length() > 0)
          {
            columnObj.put("delimiter", delimString);
          }

          String f = "";
          try
          {
            f = column.getAttribute("format");
          }
          catch (Exception ex)
          {
            logger.error(ex.getMessage(), ex);
          }
          if (!f.isEmpty())
            columnObj.put("format", f);

          String idxString = column.getAttribute("index");
          if (idxString != null)
          {
            columnObj.put("index", idxString);
          }
          String storeString = column.getAttribute("store");
          if (storeString != null)
          {
            columnObj.put("store", storeString);
          }
          String tvString = column.getAttribute("termvector");
          if (tvString != null)
          {
            columnObj.put("termvector", tvString);
          }

        }
        catch (Exception e)
        {
          throw new ConfigurationException("Error parsing schema: " + columns.item(i), e);
        }
      }
    }


    NodeList facets = schemaDoc.getElementsByTagName("facet");
    JSONArray facetArray = new FastJSONArray();
    jsonObj.put("facets", facetArray);

    for (int i = 0; i < facets.getLength(); ++i)
    {
      try
      {
        Element facet = (Element) facets.item(i);
        JSONObject facetObj = new FastJSONObject();
        facetArray.put(facetObj);

        facetObj.put("name", facet.getAttribute("name"));
        facetObj.put("type", facet.getAttribute("type"));
        String depends = facet.getAttribute("depends");
        if (depends!=null){
          String[] dependsList = depends.split(",");
          JSONArray dependsArr = new FastJSONArray();
          for (String dependName : dependsList)
          {
            if (dependName != null)
            {
              dependName = dependName.trim();
              if (dependName.length() != 0)
                dependsArr.put(dependName);
            }
          }
          facetObj.put("depends", dependsArr);
        }
        String column = facet.getAttribute("column");
        if (column!=null && column.length() > 0){
          facetObj.put("column", column);
        }
        String dynamic = facet.getAttribute("dynamic");
        if (dynamic!=null){
          facetObj.put("dynamic",dynamic);
        }

        NodeList paramList = facet.getElementsByTagName("param");
        if (paramList!=null){
          JSONArray params = new FastJSONArray();
          facetObj.put("params", params);
          for (int j = 0; j < paramList.getLength(); ++j) {
            Element param = (Element) paramList.item(j);
            String paramName = param.getAttribute("name");
            String paramValue = param.getAttribute("value");
            JSONObject paramObj = new FastJSONObject();
            paramObj.put("name", paramName);
            paramObj.put("value", paramValue);
            params.put(paramObj);
          }
        }
      }
      catch(Exception e){
View Full Code Here

          {
            logger.error("Cannot found original doc for and update event: " + obj);
            return null;
          }

          JSONObject newEvent = new FastJSONObject(new String(data, "UTF-8"));
          Iterator<String> keys = event.keys();
          while(keys.hasNext())
          {
            String key = keys.next();
            newEvent.put(key, event.get(key));
          }
          event = newEvent;
        }
        catch (Exception e)
        {
View Full Code Here

              (LinkedList<DataEvent<JSONObject>>) _dataCollectorMap.get(part_num);
            if (partDataSet != null)
            {
              if (partDataSet.size() == 0)
              {
                JSONObject markerObj = new FastJSONObject();
                //markerObj.put(_senseiSchema.getSkipField(), "true");
                markerObj.put(SenseiSchema.EVENT_TYPE_FIELD, SenseiSchema.EVENT_TYPE_SKIP);
                markerObj.put(_uidField, 0L); // Add a dummy uid
                partDataSet.add(new DataEvent<JSONObject>(markerObj, _currentVersion));
              }
              else if (_currentVersion != null && !_currentVersion.equals(partDataSet.getLast().getVersion()))
              {
                DataEvent<JSONObject> last = partDataSet.pollLast();
View Full Code Here

    return _innerFilter;
  }
 
  @Override
  protected JSONObject doFilter(String data) throws Exception {
    JSONObject json = new FastJSONObject(data);
    if (_innerFilter!=null){
      json = _innerFilter.doFilter(json);
    }
    return json;
  }
View Full Code Here

TOP

Related Classes of com.senseidb.util.JSONUtil.FastJSONObject

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.