Package edu.isi.karma.rep

Examples of edu.isi.karma.rep.HNode


 
  private ArrayList<VHNode> initHeaderViewNodes(HTable table) {
    ArrayList<VHNode> vNodes = new ArrayList<>();
    for(String hNodeId : table.getOrderedNodeIds()) {
      HNode node = table.getHNode(hNodeId);
      VHNode vNode = new VHNode(node.getId(), node.getColumnName());
      if(node.hasNestedTable()) {
        HTable nestedTable = node.getNestedTable();
        ArrayList<VHNode> nestedNodes = initHeaderViewNodes(nestedTable);
        for(VHNode nestedVNode : nestedNodes) {
          vNode.addNestedNode(nestedVNode);
        }
      }
View Full Code Here


        for (int j = 0; j < hnodes.length(); j++) {
          JSONObject obj = (JSONObject)hnodes.get(j);
          Object value = obj.get(ClientJsonKeys.value.name());
          if (value instanceof String) {
            String hNodeId = (String) value;
            HNode node = workspace.getFactory().getHNode(hNodeId);
            JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory());
            obj.put(ClientJsonKeys.value.name(), hNodeRepresentation);
          }
        }
        inpP.put(ClientJsonKeys.value.name(), hnodes);
      } else if(HistoryJsonUtil.getParameterType(inpP) == ParameterType.orderedColumns) {
        Object tmp = inpP.get(ClientJsonKeys.value.name());
        JSONArray hnodes = (JSONArray) JSONUtil.createJson(tmp.toString());
        for (int j = 0; j < hnodes.length(); j++) {
          JSONObject obj = (JSONObject)hnodes.get(j);
          String hNodeId = obj.getString(ClientJsonKeys.id.name());
          HNode node = workspace.getFactory().getHNode(hNodeId);
          JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory());
          obj.put(ClientJsonKeys.id.name(), hNodeRepresentation);
          if (obj.has(ClientJsonKeys.children.name()))
            obj.put(ClientJsonKeys.children.name(), parseChildren(obj.get(ClientJsonKeys.children.name()).toString(), workspace));
        }
        inpP.put(ClientJsonKeys.value.name(), hnodes);
      } else if(HistoryJsonUtil.getParameterType(inpP) == ParameterType.hNodeId) {
        String hNodeId = inpP.getString(ClientJsonKeys.value.name());
        HNode node = workspace.getFactory().getHNode(hNodeId);
        JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory());
        inpP.put(ClientJsonKeys.value.name(), hNodeRepresentation);

      } else if (HistoryJsonUtil.getParameterType(inpP) == ParameterType.worksheetId) {
        inpP.put(ClientJsonKeys.value.name(), "W");
      } else {
        // do nothing
      }
    }
    if (comm instanceof Command) {
      Command tmp = (Command)comm;
      JSONArray inputArray = new JSONArray();
      for (String hNodeId : tmp.getInputColumns()) {
        HNode node = workspace.getFactory().getHNode(hNodeId);
        JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory());
        JSONObject obj1 = new JSONObject();
        obj1.put(ClientJsonKeys.value.name(), hNodeRepresentation);
        inputArray.put(obj1);
      }
      JSONObject obj = HistoryJsonUtil.getJSONObjectWithName("inputColumns", inputArr);     
      if (obj == null) {
        obj = new JSONObject();
        obj.put(ClientJsonKeys.name.name(), "inputColumns");
        obj.put(ClientJsonKeys.value.name(), inputArray.toString());
        obj.put(ClientJsonKeys.type.name(), ParameterType.hNodeIdList.name());
        inputArr.put(obj);
      }
      else {
        obj.put(ClientJsonKeys.value.name(), inputArray.toString());
      }

      JSONArray outputArray = new JSONArray();
      for (String hNodeId : tmp.getOutputColumns()) {
        HNode node = workspace.getFactory().getHNode(hNodeId);
        JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory());
        JSONObject obj1 = new JSONObject();
        obj1.put(ClientJsonKeys.value.name(), hNodeRepresentation);
        outputArray.put(obj1);
      }
      obj = HistoryJsonUtil.getJSONObjectWithName("outputColumns", inputArr);           
View Full Code Here

  private String parseChildren(String inputJSON, Workspace workspace) {
    JSONArray array = (JSONArray) JSONUtil.createJson(inputJSON);
    for (int i = 0; i < array.length(); i++) {
      JSONObject obj = array.getJSONObject(i);
      String hNodeId = obj.getString(ClientJsonKeys.id.name());
      HNode node = workspace.getFactory().getHNode(hNodeId);
      JSONArray hNodeRepresentation = node.getJSONArrayRepresentation(workspace.getFactory());
      obj.put(ClientJsonKeys.id.name(), hNodeRepresentation);
      if (obj.has(ClientJsonKeys.children.name()))
        obj.put(ClientJsonKeys.children.name(), parseChildren(obj.get(ClientJsonKeys.children.name()).toString(), workspace));
    }
    return array.toString();
View Full Code Here

    HTable headers = worksheet.getHeaders();
    List<String> headersList = new ArrayList<String>();
   
    for (int i = 0; i < tableHeader.size(); i++) {
      Attribute att = tableHeader.get(i);
      HNode hNode = headers.addHNode(att.getName(), HNodeType.Regular, worksheet, factory);
      headersList.add(hNode.getId());
     
      // very important
      // update the hNodeId of the input/output attributes
      att.sethNodeId(hNode.getId());
    }
    return headersList;
  }
View Full Code Here

            reader.close();
            return addEmptyHeaders(worksheet, fac, br);
        }

        for (int i = 0; i < rowValues.length; i++) {
            HNode hNode = null;
            if (headerRowIndex == 0) {
              if (isVisible("Column_" + (i + 1)))
                hNode = headers.addHNode("Column_" + (i + 1), HNodeType.Regular, worksheet, fac);
            } else {
              if (isVisible(rowValues[i]))
                hNode = headers.addHNode(rowValues[i], HNodeType.Regular, worksheet, fac);
            }
            if (hNode != null)
              headersMap.put(i, hNode.getId());
        }
        reader.close();
        return headersMap;
    }
View Full Code Here

                } catch (IOException e) {
                    logger.error("Error reading Line:" + line, e);
                }
                for (int i = 0; i < rowValues.length; i++) {
                 
                    HNode hNode = null;
                    if (isVisible("Column_" + (i + 1)))
                      hNode = headers.addHNode("Column_" + (i + 1), HNodeType.Regular,
                            worksheet, fac);
                    if (hNode != null)
                      headersMap.put(i, hNode.getId());
                }
                reader.close();
                break;
            }
            rowCount++;
View Full Code Here

    this.worksheet = worksheet;
    this.columnsJson = columnsJson;
  }
  public void addObjectElement(String key, Object value, HTable headers,
      Row row) throws JSONException {
    HNode hNode = addHNode(headers, key, DataStructure.OBJECT, factory, worksheet);

    String hNodeId = hNode.getId();

    if (value instanceof String) {
     
      if (((String) value).isEmpty() && hNode.hasNestedTable()) {
        addEmptyRow(row.getNode(hNodeId).getNestedTable(), hNode);
      }
      row.setValue(hNodeId, (String) value, factory);
    } else if (value instanceof Integer) {
      row.setValue(hNodeId, value.toString(), factory);
View Full Code Here

    }
  }

  public void addObjectElement(String key, JSONTokener token, HTable headers,
      Row row) throws JSONException {
    HNode hNode = addHNode(headers, key, DataStructure.OBJECT, factory, worksheet);

    String hNodeId = hNode == null ? null : hNode.getId();
    char c = token.nextClean();
    if (maxNumLines > 0 && numObjects >= maxNumLines)
      return;
    if (c != '{' && c != '[') {
      token.back();
      Object tokenObj = token.nextValue();
      String value;
      if(tokenObj == null || tokenObj == JSONObject.NULL)
        value = "";
      else
        value = tokenObj.toString();
       
      if (value.isEmpty() && hNode != null && hNode.hasNestedTable()) {
        addEmptyRow(row.getNode(hNodeId).getNestedTable(), hNode);
      }
      if (hNodeId != null)
        row.setValue(hNodeId, value, factory);
    }
View Full Code Here

          String key = it.next();
          addObjectElement(key, o.get(key), headers, row);
        }
      }
    } else if (isPrimitiveValue(listValue)) {
      HNode hNode = addHNode(headers, HTable.VALUES_COLUMN, DataStructure.PRIMITIVE, factory, worksheet);
      String hNodeId = hNode.getId();
      Row row = dataTable.addRow(factory);
      numObjects++;
      // TODO, conserve the types of the primitive types.
      String value = "";
      if (listValue instanceof String || listValue instanceof Boolean) {
        value = (String) listValue;
      } else if (listValue instanceof Double) {
        value = Double.toString((Double) listValue);
      } else if (listValue instanceof Integer) {
        value = Integer.toString((Integer) listValue);
      } else if (listValue instanceof Long) {
        value = Long.toString((Long) listValue);
      } else {
        // Pedro 2012/09/14
        logger.error("Unexpected value in JSON array:"
            + listValue.toString());
      }

      row.setValue(hNodeId, value, factory);
    } else if (listValue instanceof JSONArray) {
      if (maxNumLines <= 0 || numObjects < maxNumLines) {
        HNode hNode = addHNode(headers, "nested array", DataStructure.COLLECTION, factory, worksheet);
        String hNodeId = hNode.getId();
        Row row = dataTable.addRow(factory);
        numObjects++;
        if (maxNumLines > 0 && numObjects >= maxNumLines)
          return;
        HTable nestedHTable = addNestedHTable(hNode,
View Full Code Here

              uc.add(update);
            continue;
          }
          String nameObjColumnName = cNameObj.getString("columnName");
          logger.debug("Column being normalized: "+ nameObjColumnName);
          HNode node = hTable.getHNodeFromColumnName(nameObjColumnName);
          if(node == null) { //Because add column can happen even if the column after which it is to be added is not present
            AbstractUpdate update = new TrivialErrorUpdate(nameObjColumnName + " does not exist, using empty values");
            if (uc == null)
              uc = new UpdateContainer(update);
            else
              uc.add(update);
            if (addIfNonExist) {
              node = hTable.addHNode(nameObjColumnName, HNodeType.Regular, workspace.getWorksheet(worksheetId), workspace.getFactory());   
            }
            else {
              continue;
            }
          }

          if (j == hNodeJSONRep.length()-1) {    // Found!
            if(node != null)
              inpP.put(ClientJsonKeys.value.name(), node.getId());
            else {
              //Get the id of the last node in the table
              ArrayList<String> allNodeIds = hTable.getOrderedNodeIds();
              //TODO check for allNodeIds.size == 0
              String lastNodeId = allNodeIds.get(allNodeIds.size()-1);
              inpP.put(ClientJsonKeys.value.name(), lastNodeId);
            }
            hTable = workspace.
                getWorksheet(worksheetId).getHeaders();
          } else if(node != null) {
            hTable = node.getNestedTable();
            if (hTable == null && addIfNonExist) {
              hTable = node.addNestedTable("NestedTable", workspace.getWorksheet(worksheetId), workspace.getFactory());
            }
          }
        }
      } else if(HistoryJsonUtil.getParameterType(inpP) == ParameterType.worksheetId) {
        inpP.put(ClientJsonKeys.value.name(), worksheetId);
      } else if (HistoryJsonUtil.getParameterType(inpP) == ParameterType.hNodeIdList) {
        JSONArray hNodes = new JSONArray(inpP.get(ClientJsonKeys.value.name()).toString());
        for (int k = 0; k < hNodes.length(); k++) {
          JSONObject hnodeJSON = hNodes.getJSONObject(k);
          JSONArray hNodeJSONRep = new JSONArray(hnodeJSON.get(ClientJsonKeys.value.name()).toString());
          for (int j=0; j<hNodeJSONRep.length(); j++) {
            JSONObject cNameObj = (JSONObject) hNodeJSONRep.get(j);
            if(hTable == null) {
              AbstractUpdate update = new TrivialErrorUpdate("null HTable while normalizing JSON input for the command " + commandName);
              if (uc == null)
                uc = new UpdateContainer(update);
              else
                uc.add(update);
              continue;
            }
            String nameObjColumnName = cNameObj.getString("columnName");
            logger.debug("Column being normalized: "+ nameObjColumnName);
            HNode node = hTable.getHNodeFromColumnName(nameObjColumnName);
            if(node == null) { //Because add column can happen even if the column after which it is to be added is not present
              AbstractUpdate update = new TrivialErrorUpdate(nameObjColumnName + " does not exist, using empty values");
              if (uc == null)
                uc = new UpdateContainer(update);
              else
                uc.add(update);
              if (addIfNonExist) {
                hTable.addHNode(nameObjColumnName, HNodeType.Regular, workspace.getWorksheet(worksheetId), workspace.getFactory());
              }
              else {
                continue;
              }
            }

            if (j == hNodeJSONRep.length()-1) {    // Found!
              if(node != null)
                hnodeJSON.put(ClientJsonKeys.value.name(), node.getId());
              else {
                //Get the id of the last node in the table
                ArrayList<String> allNodeIds = hTable.getOrderedNodeIds();
                String lastNodeId = allNodeIds.get(allNodeIds.size()-1);
                hnodeJSON.put(ClientJsonKeys.value.name(), lastNodeId);
              }
              hTable = workspace.
                  getWorksheet(worksheetId).getHeaders();
            } else if(node != null) {
              hTable = node.getNestedTable();
              if (hTable == null && addIfNonExist) {
                hTable = node.addNestedTable("NestedTable", workspace.getWorksheet(worksheetId), workspace.getFactory());
              }
            }
          }
        }
        inpP.put(ClientJsonKeys.value.name(), hNodes.toString());
View Full Code Here

TOP

Related Classes of edu.isi.karma.rep.HNode

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.