Package edu.isi.karma.controller.update

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


  }

  @Override
  public UpdateContainer doIt(final Workspace workspace) throws CommandException {
    logger.info("Get Semantic Suggestions: " + worksheetId + "," + hNodeId);
    UpdateContainer uc = new UpdateContainer();
    final SuperSelection selection = getSuperSelection(workspace);
    uc.add(new AbstractUpdate() {

      @Override
      public void generateJson(String prefix, PrintWriter pw,
          VWorkspace vWorkspace) {
        HNodePath currentColumnPath = null;
View Full Code Here


    transformedRows.put(transformedRow);
  }

  @Override
  public UpdateContainer undoIt(Workspace workspace) {
    UpdateContainer c = (WorksheetUpdateFactory
        .createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(workspace)));
    // TODO is it necessary to compute alignment and semantic types for
    // everything?
    c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
    return c;
  }
View Full Code Here

  public CommandType getCommandType() {
    return CommandType.notUndoable;
  }
 
  private UpdateContainer processCSV(HttpEntity entity, Workspace workspace) {
    UpdateContainer uc = null;
    try {
          BufferedInputStream buf;
          byte[] buffer = new byte[10240];
          SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy_HmsS");
          String ts = sdf.format(Calendar.getInstance().getTime());
          final String fName = "table_service_results_"+ts;
          final String fileName = ServletContextParameterMap.getParameterValue(ContextParameter.CSV_PUBLISH_DIR) + fName;
          FileOutputStream fw = new FileOutputStream(fileName);
          // get the file from the service
          buf = new BufferedInputStream(entity.getContent());
          for (int length = 0; (length = buf.read(buffer)) > 0;) {
            fw.write(buffer, 0, length);
            }
          fw.close();
          buf.close();
          logger.info("Created : " + fileName + " by worksheet Id : " this.worksheetId) ;
          Import impCSV = new CSVFileImport(1, 2, ',', ' ', "UTF-8", -1, new File(fileName), workspace, null);
          Worksheet wsht = impCSV.generateWorksheet();
          uc = new UpdateContainer();
            uc.append(WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(wsht.getId(), SuperSelectionManager.DEFAULT_SELECTION));
            new File(fileName).delete();

        } catch (Exception e1) {
          logger.error(e1.getMessage(), e1);
          uc = new UpdateContainer(new ErrorUpdate(e1.getMessage()));
        }
    return uc;
   
  }
View Full Code Here

      index++;
    }
    Msg = String.format("end, Time,%d, Worksheet,%s",
        System.currentTimeMillis(), worksheetId);
    logger.info(Msg);
    return new UpdateContainer(new FetchResultUpdate(hNodeId, rows));
  }
View Full Code Here

   
  }
 
 
  private UpdateContainer processJSON(HttpEntity entity, Workspace workspace) {
    UpdateContainer uc = null;
    try {
          BufferedInputStream buf;
          byte[] buffer = new byte[10240];
          SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy_HmsS");
          String ts = sdf.format(Calendar.getInstance().getTime());
          final String fName = "table_service_results_"+ts;
          final String fileName = ServletContextParameterMap.getParameterValue(ContextParameter.CSV_PUBLISH_DIR) +  fName;
          FileOutputStream fw = new FileOutputStream(fileName);
          // get the file from the service
          buf = new BufferedInputStream(entity.getContent());
          for (int length = 0; (length = buf.read(buffer)) > 0;) {
            fw.write(buffer, 0, length);
            }
          fw.close();
          buf.close();
         
      Import impJson = new JsonImport(new File(fileName), fName, workspace, "UTF-8", -1, null);
            Worksheet wsht = impJson.generateWorksheet();
//            Worksheet wsht2, wsht3;
            logger.info("Creating worksheet with json : " + wsht.getId());
            uc = new UpdateContainer();
            uc.add(new WorksheetListUpdate());
            uc.append(WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(wsht.getId(), SuperSelectionManager.DEFAULT_SELECTION));
         
          logger.info("Created : " + fileName);
            new File(fileName).delete();

        } catch (Exception e1) {
          logger.error(e1.getMessage(), e1);
          uc = new UpdateContainer(new ErrorUpdate(e1.getMessage()));
        }
    return uc;
   
  }
View Full Code Here

  @Override
  public UpdateContainer doIt(Workspace workspace) {
   
    final String csvFileLocalPath = ServletContextParameterMap.getParameterValue(ContextParameter.CSV_PUBLISH_DIR)
        this.csvFileName;
    UpdateContainer uc = new UpdateContainer();
    try {
     
      // Prepare the headers
      HttpPost httpPost = new HttpPost(this.dataMiningURL);
 
      FileEntity file = new FileEntity(new File(csvFileLocalPath));
      httpPost.setEntity(file);
      HttpClient httpClient = new DefaultHttpClient();
      httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
     
      // Execute the request
      HttpResponse response = httpClient.execute(httpPost);
     
      // Parse the response and store it in a String
      HttpEntity entity = response.getEntity();
      Header contentTypeHeader = entity.getContentType();
      String contentType = contentTypeHeader.getValue();
     
     
      if(contentType.equalsIgnoreCase("application/json")) {
        uc = processJSON(entity, workspace);
      } else if(contentType.equalsIgnoreCase("text/csv")) {
        uc = processCSV(entity, workspace);
      } else {
        uc = new UpdateContainer(new ErrorUpdate("Could not parse content type : " + contentType));
      }
         
    } catch (Exception e) {
      logger.error(e.getMessage());
      uc = new UpdateContainer(new ErrorUpdate("Error ! " + e.getMessage()));
    }
    return uc;

  }
View Full Code Here

      MultipleValueEditColumnCommand mvecc = (MultipleValueEditColumnCommand) mfc.createCommand(multiCellEditInput, workspace);
      mvecc.doIt(workspace);
     
    } catch (Exception e) {
      logger.error("Error occured during python transformation.",e);
      return new UpdateContainer(new ErrorUpdate("Error occured while applying Python transformation to the column."));
    }

    worksheet.getMetadataContainer().getColumnMetadata().addColumnPythonTransformation(newHNodeId, this.transformationCode);
    worksheet.getMetadataContainer().getColumnMetadata().addPreviousCommandId(newHNodeId, this.id);
    worksheet.getMetadataContainer().getColumnMetadata().addColumnDerivedFrom(newHNodeId, hNodeId);
    // Prepare the output container
    UpdateContainer c = new UpdateContainer();
    c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet)));
   
    /** Add the alignment update **/
    c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace, workspace.getFactory().getHNode(newHNodeId).getHNodePath(workspace.getFactory())));
   
    c.add(new InfoUpdate("Transformation complete"));
    return c;
  }
View Full Code Here

      }
      final JSONObject sprqlOutput = new JSONObject(sData);
//      final JSONObject sprqlOutput = TripleStoreUtil.invokeSparqlQuery(sparqlQuery,
//          TripleStoreUtil.defaultModelsRepoUrl);
     
      return new UpdateContainer(new AbstractUpdate() {
       
        @Override
        public void generateJson(String prefix, PrintWriter pw,
            VWorkspace vWorkspace) {
          JSONObject response = new JSONObject();
          JSONArray list = new JSONArray();
         
          try {
            JSONArray values = sprqlOutput.getJSONObject(sparqlKeys.results.name())
                .getJSONArray(sparqlKeys.bindings.name());
           
            // prepare the output
            for (int i=0; i<values.length(); i++) {
              JSONObject modelObj = new JSONObject();
              JSONObject binding = values.getJSONObject(i);
              String sourceName = binding.getJSONObject(sparqlKeys.sourceName.name())
                  .getString(sparqlKeys.value.name());
              String modelName = binding.getJSONObject(sparqlKeys.modelName.name())
                  .getString(sparqlKeys.value.name());
             
              modelObj.put(JsonKeys.modelName.name(), modelName);
              modelObj.put(JsonKeys.sourceName.name(), sourceName);
              list.put(modelObj);
            }
           
            response.put(JsonKeys.updateType.name(), "ExistingModelsList");
            response.put(JsonKeys.existingModelNames.name(), list);
            response.put(JsonKeys.worksheetName.name(), wkName);
           
            pw.print(response.toString());
          } catch (JSONException e) {
            logger.error("Error creating JSON response for model names!", e);
          }
        }
      });
    } catch (Exception e1) {
      logger.error("Error creating JSON response for model names!", e1);
      return new UpdateContainer(new ErrorUpdate("Error occured while getting models!"));
    }
  }
View Full Code Here

          JSONArray a = (JSONArray) t;
          ndid = addColumn(workspace, worksheet, newColumnName, a);
        }
      }
      WorksheetUpdateFactory.detectSelectionStatusChange(worksheetId, workspace, this);
      UpdateContainer c =  new UpdateContainer(new AddColumnUpdate(newHNodeId, worksheetId));   
      c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet)));
      if (ndid == null) {
        System.err.println("error: ndid");
      }
      c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace, ndid.getHNodePath(workspace.getFactory())));
      return c;
    } catch (Exception e) {
      logger.error("Error in AddColumnCommand" + e.toString());
      Util.logException(logger, e);
      e.printStackTrace();
      return new UpdateContainer(new ErrorUpdate(e.getMessage()));
    }
  }
View Full Code Here

    }
  }

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

    HTable currentTable = workspace.getFactory().getHTable(hTableId);
    HNode ndid = workspace.getFactory().getHNode(newHNodeId);
    ndid.removeNestedTable();
    //remove the new column
    currentTable.removeHNode(newHNodeId, worksheet);
    c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet)));
    c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
    return c;
  }
View Full Code Here

TOP

Related Classes of edu.isi.karma.controller.update.UpdateContainer

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.