Package edu.isi.karma.rep

Examples of edu.isi.karma.rep.HTable


      if(hNodeId==null)
        hTableId = worksheet.getHeaders().getId();
      else
        hTableId = workspace.getFactory().getHNode(hNodeId).getHTableId();
    }
    HTable hTable = workspace.getFactory().getHTable(hTableId);
    if(hTable == null)
    {
      logger.error("No HTable for id "+ hTableId);
      throw new KarmaException("No HTable for id "+ hTableId );
    }

    //add new column to this table
    //add column after the column with hNodeId
    HNode ndid = null;
    if (newColumnName != null && !newColumnName.trim().isEmpty()) {
      if (hTable.getHNodeFromColumnName(newColumnName) != null) {
        ndid = hTable.getHNodeFromColumnName(newColumnName);
        outputColumns.add(ndid.getId());
      }
      else {
        ndid = hTable.addNewHNodeAfter(hNodeId, type, workspace.getFactory(), newColumnName, worksheet,true);
        outputColumns.add(ndid.getId());
        isNewNode = true;
      }
    }
    else {
      ndid = hTable.addNewHNodeAfter(hNodeId, type, workspace.getFactory(), hTable.getNewColumnName("default"), worksheet,true);
      outputColumns.add(ndid.getId());
      isNewNode = true;
    }
    newHNodeId = ndid.getId();
    //add as first column in the table if hNodeId is null
View Full Code Here


        newhnode = newht.addHNode(hnode.getColumnName(), HNodeType.Transformation, newws, factory);
      else
        newhnode = newht.addHNode(newht.getNewColumnName(hnode.getColumnName()), HNodeType.Transformation, newws, factory);
      tmp.put(hnode.getId(), newhnode.getId());
      if (hnode.hasNestedTable()) {
        HTable oldnested = hnode.getNestedTable();
        HTable newnested = newhnode.addNestedTable(hnode.getNestedTable().getTableName(), newws, factory);   
        tmp.putAll(cloneHTable(oldnested, newnested, newws, factory, new ArrayList<HNode>(oldnested.getHNodes()), sel));
      }
    }
    return tmp;
  }
View Full Code Here

    }
  }

  public static Object cloneNodeToJSON(HNode hn, Node node, SuperSelection sel) {
    if (node.hasNestedTable()) {
      HTable nestHT = hn.getNestedTable();
      Table dataTable = node.getNestedTable();
      JSONArray array = new JSONArray();
      for (Row row : dataTable.getRows(0, dataTable.getNumRows(), sel)) {
        JSONObject obj = new JSONObject();
        for (HNode hnode : nestHT.getHNodes()) {
          Node n = row.getNode(hnode.getId());
          obj.put(hnode.getColumnName(),cloneNodeToJSON(hnode, n, sel));
        }
        array.put(obj);
      }
View Full Code Here

        worksheetId);
    SuperSelection selection = getSuperSelection(worksheet);
    inputColumns.clear();
    outputColumns.clear();
    Object para = JSONUtil.createJson(this.getInputParameterJson());
    HTable htable;
    if (hNodeId.compareTo("") != 0)
      htable = Repfactory.getHTable(Repfactory.getHNode(hNodeId).getHTableId());
    else
      htable = worksheet.getHeaders();
    hnodes.clear();
    //List<String> HNodeIds = new ArrayList<String>();
    JSONArray checked = (JSONArray) JSONUtil.createJson(CommandInputJSONUtil.getStringValue("values", (JSONArray)para));
    for (int i = 0; i < checked.length(); i++) {
      JSONObject t = (checked.getJSONObject(i));
      hnodes.add(htable.getHNode((String) t.get("value")));
      inputColumns.add(t.getString("value"));
    }
    ArrayList<Row> rows = worksheet.getDataTable().getRows(0, worksheet.getDataTable().getNumRows(), selection);
    if (htable != worksheet.getHeaders()) {
      HTable parentHT = htable.getParentHNode().getHTable(Repfactory);
      List<Table> parentTables = new ArrayList<Table>();
      CloneTableUtils.getDatatable(worksheet.getDataTable(), parentHT,parentTables, selection);
      ArrayList<Row> parentRows = new ArrayList<Row>();
      rows.clear();
      for (Table tmp : parentTables) {
View Full Code Here

        //get table id based on the hNodeId
        if(hNodeId==null)
          throw new KarmaException("TableId and NodeId are empty. Can't add column.");
        hTableId = workspace.getFactory().getHNode(hNodeId).getHTableId();
      }
      HTable hTable = workspace.getFactory().getHTable(hTableId);
      if(hTable == null)
      {
        logger.error("No HTable for id "+ hTableId);
        throw new KarmaException("No HTable for id "+ hTableId );
      }
      if (null != hTable.getHNodeFromColumnName(newColumnName)) {
        logger.error("Add column failed to create " + newColumnName
            + " because it already exists!");
        return new UpdateContainer(new ErrorUpdate(
            "Add column failed to create " + newColumnName
                + " because it already exists!"));
      }  
      //add new column to this table
      //add column after the column with hNodeId
      HNode ndid = hTable.addNewHNodeAfter(hNodeId, HNodeType.Transformation, workspace.getFactory(), newColumnName, worksheet,true);
      if(ndid == null)
      {
        logger.error("Unable to add new HNode!");
        throw new KarmaException("Unable to add new HNode!");
      }
View Full Code Here

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);

    HTable currentTable = workspace.getFactory().getHTable(hTableId);
    //remove the new column
    currentTable.removeHNode(newHNodeId, worksheet);

    return WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet));
  }
View Full Code Here

//    outputColumns.add(targetHNodeId);
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    RepFactory f = workspace.getFactory();
    HNode hNode = f.getHNode(hNodeId);
    String hTableId = hNode.getHTableId();
    HTable hTable = hNode.getHTable(f);
    String nodeId = hTable.getHNodeIdFromColumnName(newColumnName);
    inputColumns.clear();
    ExecutionController ctrl = WorkspaceRegistry.getInstance().getExecutionController(
        workspace.getId());

    // Invoke the add column command
    logger.debug("SubmitPythonTranformation: " + hNodeId + ":" + nodeId);
    try
    {
      HNode newColumnNameHNode = hTable.getHNodeFromColumnName(newColumnName);
      if(null != newColumnNameHNode ) //Column name already exists
      {
        pythonNodeId = nodeId;

        saveOrResetColumnValues(workspace, ctrl);

        logger.debug("SubmitPythonTranformation: Tranform Existing Column" + hNodeId + ":" + nodeId);
        UpdateContainer c = applyPythonTransformation(workspace, worksheet, f,
            newColumnNameHNode, ctrl, nodeId);
        return c;
      } else {
        saveColumnValues(workspace);
      }

      if (null == addColCmd) {
        JSONArray addColumnInput = getAddColumnCommandInputJSON(hTableId);
        AddColumnCommandFactory addColumnFac = (AddColumnCommandFactory) ctrl
            .getCommandFactoryMap().get(
                AddColumnCommand.class.getSimpleName());
        addColCmd = (AddColumnCommand) addColumnFac.createCommand(
            addColumnInput, workspace);
        addColCmd.saveInHistory(false);
        addColCmd.doIt(workspace);
      }
      else if(null == hTable.getHNode(addColCmd.getNewHNodeId()))
      {
        addColCmd.doIt(workspace);
      }

    }
View Full Code Here

  }

  public UpdateContainer normalizeCommandHistoryJsonInput(Workspace workspace, String worksheetId,
      JSONArray inputArr, String commandName, boolean addIfNonExist) throws JSONException {
    UpdateContainer uc = null;
    HTable hTable = workspace.getWorksheet(worksheetId).getHeaders();
    for (int i = 0; i < inputArr.length(); i++) {
      JSONObject inpP = inputArr.getJSONObject(i);
      if (inpP.getString(ClientJsonKeys.name.name()).equals("outputColumns") || inpP.getString(ClientJsonKeys.name.name()).equals("inputColumns"))
        continue;
      /*** Check the input parameter type and accordingly make changes ***/
      if(HistoryJsonUtil.getParameterType(inpP) == ParameterType.hNodeId) {
        JSONArray hNodeJSONRep = new JSONArray(inpP.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) {
              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();
View Full Code Here

      row.setValue(hNodeId, value.toString(), factory);
    } else if (value instanceof Boolean) {
      row.setValue(hNodeId, value.toString(), factory);
    } else if (value instanceof JSONObject) {
      if (maxNumLines <= 0 || numObjects < maxNumLines) {
        HTable nestedHTable = addNestedHTable(hNode, key, row);
        Table nestedTable = row.getNode(hNodeId).getNestedTable();
        addKeysAndValues((JSONObject) value, nestedHTable, nestedTable);
      }
    } else if (value instanceof JSONArray) {
      if (maxNumLines <= 0 || numObjects < maxNumLines) {
        HTable nestedHTable = addNestedHTable(hNode, key, row);
        Table nestedTable = row.getNode(hNodeId).getNestedTable();
        JSONArray a = (JSONArray) value;
        for (int i = 0; i < a.length(); i++) {
          addListElement(a.get(i), nestedHTable, nestedTable);
        }
View Full Code Here

        row.setValue(hNodeId, value, factory);
    }
    else if (c == '{') {
      if (maxNumLines <= 0 || numObjects < maxNumLines) {
        if (hNode != null) {
          HTable nestedHTable = addNestedHTable(hNode, key, row);
          Table nestedTable = row.getNode(hNodeId).getNestedTable();
          addKeysAndValues(token, nestedHTable, nestedTable);
        }
        else
          addKeysAndValues(token, null, null);
      }
    } else if (c == '[') {
      if (maxNumLines <= 0 || numObjects < maxNumLines) {
        if (hNode != null) {
          HTable nestedHTable = addNestedHTable(hNode, key, row);
          Table nestedTable = row.getNode(hNodeId).getNestedTable();
          addListElement(token, nestedHTable, nestedTable);
        }
        else
          addListElement(token, null, null);
View Full Code Here

TOP

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

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.