Examples of ErrorUpdate


Examples of edu.isi.karma.controller.update.ErrorUpdate

    MDBFileExport mdbFileExport = new MDBFileExport(worksheet);

    try {
      final String csvFileName = csvFileExport.publishCSV();
      if(csvFileName == null)
        return new UpdateContainer(new ErrorUpdate(
            "No data to export! Have you aligned the worksheet?"));
      final String fileName = mdbFileExport.publishMDB(csvFileName);

      return new UpdateContainer(new AbstractUpdate() {
        @Override
        public void generateJson(String prefix, PrintWriter pw,
            VWorkspace vWorkspace) {
          JSONObject outputObject = new JSONObject();
          try {
            outputObject.put(JsonKeys.updateType.name(),
                "PublishMDBUpdate");
            outputObject.put(JsonKeys.fileUrl.name(),
                fileName);
            outputObject.put(JsonKeys.worksheetId.name(),
                worksheetId);
            pw.println(outputObject.toString(4));
           
          } catch (JSONException e) {
            logger.error("Error occured while generating JSON!");
          }
        }
      });
    } catch (FileNotFoundException e) {
      logger.error("MDB folder not found!", e);
      return new UpdateContainer(new ErrorUpdate(
          "Error occurred while exporting MDB file!"));
    }
   
  }
View Full Code Here

Examples of edu.isi.karma.controller.update.ErrorUpdate

    Worksheet worksheet = workspace.getWorksheet(worksheetId);

    //for now don't save a nested table (we may want to save it as multiple tables with foreign keys)
    if (worksheet.getHeaders().hasNestedTables()) {
      return new UpdateContainer(new ErrorUpdate("Saving of nested tables not supported!"));       
    }
   
    Connection conn = null;
    try{
      conn = dbUtil.getConnection(hostName, Integer.valueOf(port).intValue(), userName, password, dbName);

      //get a map of corresponding hNodeIds with their semantic types
      //if more than one sem type with same name append indices
      Map<String,String> colNamesMap = getDbColumnNames(worksheet);
      //all semanticTypes
      Collection<String> colNames = colNamesMap.values();
      //ONLY columns with given semantic types will be saved; unassigned columns are ignored
      if(colNames.isEmpty()){
        //no columns were modeled
        return new UpdateContainer(new ErrorUpdate("Please align the worksheet before saving."));       
      }
     
      //see if table exists
      if (dbUtil.tableExists(tableName, conn)) {
        if(!overwrite && !insert){
          if(conn!=null)
            conn.close();
          return new UpdateContainer(new ErrorUpdate(
          "Table exists! Please check one of \"Overwrite Table\" or \"Insert in Table\"."));         
        }
        else if(overwrite){
          logger.info("Overwrite table: " + tableName);
          //delete old table & create a new table
          dropTable(tableName,conn);
          createTable(tableName, colNames, conn);
          numRowsNotInserted= insertInTable(worksheet, tableName, colNamesMap,conn);
        }
        else if(insert){
          logger.info("Insert in table: " + tableName);
          //insert in existing table
          numRowsNotInserted=insertInTable(worksheet, tableName, colNamesMap,conn);
        }
      }
      else{
        logger.info("Create new table: " + tableName);
        //create a new table
        createTable(tableName, colNames, conn);
        numRowsNotInserted=insertInTable(worksheet, tableName, colNamesMap,conn);
      }

      if(conn!=null)
        conn.close();
     
      return new UpdateContainer(new AbstractUpdate() {
        @Override
        public void generateJson(String prefix, PrintWriter pw,
            VWorkspace vWorkspace) {
          JSONObject outputObject = new JSONObject();
          try {
            outputObject.put(JsonKeys.updateType.name(),
                "PublishDatabaseUpdate");
            outputObject.put(JsonKeys.worksheetId.name(),
                worksheetId);
            outputObject.put(JsonKeys.numRowsNotInserted.name(),
                numRowsNotInserted);
            pw.println(outputObject.toString(4));
          } catch (JSONException e) {
            logger.error("Error occured while generating JSON!");
          }
        }
      });
    } catch (Exception e) {
      try{
      if(conn!=null)
        conn.close();
      }catch(SQLException ex){}
      e.printStackTrace();
      return new UpdateContainer(new ErrorUpdate(e.getMessage()));
    }
  }
View Full Code Here

Examples of edu.isi.karma.controller.update.ErrorUpdate

    uc.add(new WorksheetSuperSelectionListUpdate(worksheetId));
    return uc;
  }

  public UpdateContainer getErrorUpdate(String msg) {
    return new UpdateContainer(new ErrorUpdate(msg));
  }
View Full Code Here

Examples of edu.isi.karma.controller.update.ErrorUpdate

      c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
      return c;
    } catch (Exception e) {
      logger.error("Error in AddRowCommand" + e.toString());
      Util.logException(logger, e);
      return new UpdateContainer(new ErrorUpdate(e.getMessage()));
    }
  }
View Full Code Here

Examples of edu.isi.karma.controller.update.ErrorUpdate

        props.setPropertyValue(Property.baseURI,
            propertiesJson.getString(Property.baseURI.name()));
      }
    } catch (JSONException e) {
      e.printStackTrace();
      return new UpdateContainer(new ErrorUpdate("Malformed properties object received"));
    }
   
    return new UpdateContainer(new InfoUpdate("Properties set successfully"));
  }
View Full Code Here

Examples of edu.isi.karma.controller.update.ErrorUpdate

      }

    } catch (Exception e) {
      logger.error("Error in ExtractEntitiesCommand" + e.toString());
      Util.logException(logger, e);
      return new UpdateContainer(new ErrorUpdate(e.getMessage()));
    }

    // print result
    logger.info("Got extractions:");
    logger.info(extractions);

    JSONArray result = (JSONArray) JSONUtil.createJson(extractions);

    //Final Data for AddValuesCommand
    JSONArray rowData = new JSONArray();

    // index for result iteration
    int index = 0;

    for(Table table : tables) {
      ArrayList<Row> rows = table.getRows(0, table.getNumRows(), selection);
      for (Row row : rows) {
 
        if (index < result.length()) {
          JSONObject extraction = (JSONObject) result.getJSONObject(index++).get("extractions");
         
          JSONObject extractionValues = new JSONObject();
         
          //Check if the user wants People entities
          if(entitiesReqd.contains("People")) {
          //***Extracting People***
          JSONArray peopleExtract = (JSONArray) extraction.get("people");
          JSONArray peopleValues = new JSONArray();
         
         
          for(int i=0; i<peopleExtract.length(); i++) {
            peopleValues.put(new JSONObject().put("extraction", ((JSONObject)peopleExtract.get(i)).getString("extraction")));
          }
         
          extractionValues.put("People", peopleValues);
          }
                 
         
          //Check if the user wants Places entities
          if(entitiesReqd.contains("Places")) {
          //***Extracting Places***
         
          JSONArray placesExtract = (JSONArray) extraction.get("places");
          JSONArray placesValues = new JSONArray();
         
         
          for(int i=0; i<placesExtract.length(); i++) {
            placesValues.put(new JSONObject().put("extraction", ((JSONObject)placesExtract.get(i)).getString("extraction")));
          }
         
         
          extractionValues.put("Places", placesValues);
          }
         
          //Check if the user wants Date entities
          if(entitiesReqd.contains("Dates")) {
          //***Extracting People***
         
          JSONArray datesExtract = (JSONArray) extraction.get("dates");
          JSONArray datesValues = new JSONArray();
           
         
          for(int i=0; i<datesExtract.length(); i++) {
            datesValues.put(new JSONObject().put("extraction", ((JSONObject)datesExtract.get(i)).getString("extraction")));
          }
         
          extractionValues.put("Dates", datesValues);
          }
         
          JSONObject extractionsObj = new JSONObject();
          extractionsObj.put("extractions", extractionValues);
         
          JSONObject rowDataObject = new JSONObject();
          rowDataObject.put("values", extractionsObj);
          rowDataObject.put("rowId", row.getId());
          rowData.put(rowDataObject);
        }
      }
    }

    JSONObject addValuesObj = new JSONObject();
    addValuesObj.put("name", "AddValues");
    addValuesObj.put("value", rowData.toString());
    addValuesObj.put("type", "other");
    JSONArray addValues = new JSONArray();
    addValues.put(addValuesObj);

    System.out.println(JSONUtil.prettyPrintJson(addValues.toString()));

   
    try {
      AddValuesCommandFactory factory = new AddValuesCommandFactory();
      cmd = (AddValuesCommand) factory.createCommand(addValues, workspace, hNodeId, worksheetId,
          ht.getId(), HNodeType.Transformation, selection.getName());
     
      HNode hnode = repFactory.getHNode(hNodeId);
      cmd.setColumnName(hnode.getColumnName()+" Extractions");
      cmd.doIt(workspace);

      newHNodeId = cmd.getNewHNodeId();
     
      UpdateContainer c = new UpdateContainer(new InfoUpdate("Extracted Entities"));
      c.append(WorksheetUpdateFactory
          .createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet)));
      c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
      //c.append(new InfoUpdate("Extracted Entities"));
      return c;
    } catch (Exception e) {
      logger.error("Error in ExtractEntitiesCommand" + e.toString());
      Util.logException(logger, e);
      return new UpdateContainer(new ErrorUpdate(e.getMessage()));
    }


    // return new UpdateContainer(new InfoUpdate("Extracted Entities"));

View Full Code Here

Examples of edu.isi.karma.controller.update.ErrorUpdate

  public UpdateContainer undoIt(Workspace workspace) {
    return null;
  }

  public UpdateContainer getErrorUpdate(String msg) {
    return new UpdateContainer(new ErrorUpdate(msg));
  }
View Full Code Here

Examples of edu.isi.karma.controller.update.ErrorUpdate

                String newDomainValue = domainValue.substring(0, len-1);
                label = ontMgr.getUriLabel(newDomainValue);
              }
              if (label == null) {
                logger.error("No graph node found for the node: " + domainValue);
                return new UpdateContainer(new ErrorUpdate("" +
                "Error occured while setting semantic type!"));
              }
            }
          }
          domain = alignment.addInternalNode(label);
View Full Code Here

Examples of edu.isi.karma.controller.update.ErrorUpdate

    try {
      c.add(new SemanticTypesUpdate(worksheet, worksheetId, oldAlignment));
      c.add(new AlignmentSVGVisualizationUpdate(worksheetId, oldAlignment));
    } catch (Exception e) {
      logger.error("Error occured while unsetting the semantic type!", e);
      return new UpdateContainer(new ErrorUpdate(
          "Error occured while unsetting the semantic type!"));
    }
    return c;
  }
View Full Code Here

Examples of edu.isi.karma.controller.update.ErrorUpdate

          }
        }
      });
    } catch (JSONException e) {
      logger.error("Error occurred while fetching worksheet properties!", e);
      return new UpdateContainer(new ErrorUpdate("Error occurred while fetching " +
          "worksheet properties!"));
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.