@Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    UpdateContainer c = new UpdateContainer();
    UpdateContainer rwu = WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId);
    if (rwu != null) {
      c.append(rwu);
    }

    try {
      JSONArray historyJson = extractHistoryFromModel(workspace, c);
      if (null == historyJson || historyJson.length() == 0) {
        return new UpdateContainer(new ErrorUpdate("No history found in R2RML Model!"));
      }
      WorksheetCommandHistoryExecutor histExecutor =
          new WorksheetCommandHistoryExecutor(worksheetId, workspace);
      UpdateContainer hc = histExecutor.executeAllCommands(historyJson);
      if (hc != null) c.append(hc);
    } catch (Exception e) {
      String msg = "Error occured while applying history!";
      logger.error(msg, e);
      return new UpdateContainer(new ErrorUpdate(msg));
    }

    // Add worksheet updates that could have resulted out of the transformation commands

    c.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
    c.add(new InfoUpdate("Model successfully applied!"));
    return c;
  }
示例#2
0
 @Override
 public UpdateContainer doIt(Workspace workspace) throws CommandException {
   UpdateContainer undoEffects =
       workspace.getCommandHistory().undoOrRedoCommandsUntil(workspace, commandIdArg);
   UpdateContainer result = new UpdateContainer(new HistoryUpdate(workspace.getCommandHistory()));
   result.append(undoEffects);
   return result;
 }
示例#3
0
 @Override
 public UpdateContainer undoIt(Workspace workspace) {
   Node node = workspace.getFactory().getNode(nodeIdArg);
   SuperSelection sel = getSuperSelection(workspace);
   node.setValue(previousValue, previousStatus, workspace.getFactory());
   UpdateContainer uc =
       WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(
           worksheetId, sel);
   uc.add(new NodeChangedUpdate(worksheetId, nodeIdArg, previousValue, previousStatus));
   return uc;
 }
  @Override
  public UpdateContainer doIt(VWorkspace vWorkspace) throws CommandException {
    /*
    System.out.println("FetchPreferences....");

    System.out.println("I get 1.....");
    ViewPreferences prefs = vWorkspace.getPreferences();
    JSONObject prefObject1 = prefs.getCommandPreferencesJSONObject("PublishRDFCommandPreferences");
    System.out.println("I get 1....."+prefObject1);
     */
    UpdateContainer c = new UpdateContainer();
    c.add(new FetchPreferencesUpdate(vWorkspace, commandName + "Preferences"));
    return c;
  }
 @Override
 public UpdateContainer showPreview() throws CommandException {
   UpdateContainer c = new UpdateContainer();
   c.add(
       new CSVImportPreviewUpdate(
           delimiter,
           quoteCharacter,
           escapeCharacter,
           getFile(),
           headerRowIndex,
           dataStartRowIndex,
           id));
   return c;
 }
  @Override
  public UpdateContainer doIt(Workspace workspace) throws CommandException {
    Worksheet worksheet = workspace.getWorksheet(worksheetId);
    RepFactory factory = workspace.getFactory();
    SuperSelection superSel = getSuperSelection(worksheet);
    HTable hTable = factory.getHTable(factory.getHNode(hNodeId).getHTableId());
    Selection currentSel = superSel.getSelection(hTable.getId());
    if (currentSel != null) {
      currentSel.updateSelection();
    }
    CommandHistory history = workspace.getCommandHistory();
    List<Command> tmp =
        gatherAllOperateSelectionCommands(
            history.getCommandsFromWorksheetId(worksheetId), workspace);
    if (tmp.size() > 0) {
      JSONArray inputJSON = new JSONArray();
      inputJSON.put(
          CommandInputJSONUtil.createJsonObject(
              "worksheetId", worksheetId, ParameterType.worksheetId));
      inputJSON.put(
          CommandInputJSONUtil.createJsonObject("hNodeId", hNodeId, ParameterType.hNodeId));
      inputJSON.put(
          CommandInputJSONUtil.createJsonObject(
              "operation", Operation.Intersect.name(), ParameterType.other));
      inputJSON.put(
          CommandInputJSONUtil.createJsonObject(
              "pythonCode", SelectionManager.defaultCode, ParameterType.other));
      inputJSON.put(CommandInputJSONUtil.createJsonObject("onError", "false", ParameterType.other));
      inputJSON.put(
          CommandInputJSONUtil.createJsonObject(
              "selectionName", superSel.getName(), ParameterType.other));
      Command t = null;
      try {
        t = new OperateSelectionCommandFactory().createCommand(inputJSON, workspace);
      } catch (Exception e) {

      }
      if (t != null) history._getHistory().add(t);
      history._getHistory().addAll(tmp);
    }
    UpdateContainer uc =
        WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(
            worksheetId, superSel);
    uc.add(new HistoryUpdate(history));
    return uc;
  }
  @Override
  public UpdateContainer doIt(VWorkspace vWorkspace) throws CommandException {
    UpdateContainer c = new UpdateContainer();
    Worksheet worksheet = vWorkspace.getViewFactory().getVWorksheet(vWorksheetId).getWorksheet();

    worksheetName = worksheet.getTitle();

    // Generate the semantic types for the worksheet
    OntologyManager ontMgr = vWorkspace.getWorkspace().getOntologyManager();
    if (ontMgr.isEmpty()) return new UpdateContainer(new ErrorUpdate("No ontology loaded."));

    SemanticTypeUtil.computeSemanticTypesForAutoModel(
        worksheet, vWorkspace.getWorkspace().getCrfModelHandler(), ontMgr);

    String alignmentId =
        AlignmentManager.Instance()
            .constructAlignmentId(vWorkspace.getWorkspace().getId(), vWorksheetId);
    Alignment alignment = AlignmentManager.Instance().getAlignment(alignmentId);
    if (alignment == null) {
      alignment = new Alignment(ontMgr);
      AlignmentManager.Instance().addAlignmentToMap(alignmentId, alignment);
    }
    try {
      // Save the semantic types in the input parameter JSON
      saveSemanticTypesInformation(
          worksheet, vWorkspace, worksheet.getSemanticTypes().getListOfTypes());

      // Add the visualization update
      c.add(new SemanticTypesUpdate(worksheet, vWorksheetId, alignment));
      c.add(
          new SVGAlignmentUpdate_ForceKarmaLayout(
              vWorkspace.getViewFactory().getVWorksheet(vWorksheetId), alignment));
    } catch (Exception e) {
      logger.error("Error occured while generating the model Reason:.", e);
      return new UpdateContainer(
          new ErrorUpdate("Error occured while generating the model for the source."));
    }
    c.add(new TagsUpdate());
    return c;
  }
示例#8
0
 @Override
 public UpdateContainer doIt(Workspace workspace) throws CommandException {
   Node node = workspace.getFactory().getNode(nodeIdArg);
   SuperSelection sel = getSuperSelection(workspace);
   inputColumns.clear();
   outputColumns.clear();
   inputColumns.add(node.getHNodeId());
   outputColumns.add(node.getHNodeId());
   previousValue = node.getValue();
   previousStatus = node.getStatus();
   if (node.hasNestedTable()) {
     throw new CommandException(
         this, "Cell " + nodeIdArg + " has a nested table. It cannot be edited.");
   }
   node.setValue(newValueArg, Node.NodeStatus.edited, workspace.getFactory());
   WorksheetUpdateFactory.detectSelectionStatusChange(worksheetId, workspace, this);
   UpdateContainer uc =
       WorksheetUpdateFactory.createWorksheetHierarchicalAndCleaningResultsUpdates(
           worksheetId, sel);
   uc.add(new NodeChangedUpdate(worksheetId, nodeIdArg, newValueArg, Node.NodeStatus.edited));
   return uc;
 }
 @Override
 public UpdateContainer doIt(Workspace workspace) throws CommandException {
   UpdateContainer uc = new UpdateContainer();
   SuperSelection sel = this.getSuperSelection(workspace);
   for (int i = 0; i < updates.length(); i++) {
     String update = updates.getString(i);
     switch (update) {
       case "headers":
         uc.add(new WorksheetHeadersUpdate(worksheetId));
         break;
       case "list":
         uc.add(new WorksheetListUpdate());
         break;
       case "data":
         uc.add(new WorksheetDataUpdate(worksheetId, sel));
         break;
       case "alignment":
         {
           Alignment alignment =
               AlignmentManager.Instance()
                   .getAlignmentOrCreateIt(
                       workspace.getId(), worksheetId, workspace.getOntologyManager());
           uc.add(new AlignmentSVGVisualizationUpdate(worksheetId, alignment));
           break;
         }
       case "semanticTypes":
         {
           Alignment alignment =
               AlignmentManager.Instance()
                   .getAlignmentOrCreateIt(
                       workspace.getId(), worksheetId, workspace.getOntologyManager());
           uc.add(
               new SemanticTypesUpdate(
                   workspace.getWorksheet(worksheetId), worksheetId, alignment));
           break;
         }
       case "regenerate":
         uc.add(new RegenerateWorksheetUpdate(worksheetId));
         break;
       case "all":
         uc = WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, sel);
         break;
       case "cleaning":
         uc.add(new WorksheetCleaningUpdate(worksheetId, false, sel));
         break;
     }
   }
   return uc;
 }
  private JSONArray extractHistoryFromModel(Workspace workspace, UpdateContainer uc)
      throws RepositoryException, RDFParseException, IOException, JSONException, KarmaException {

    Worksheet ws = workspace.getFactory().getWorksheet(worksheetId);
    R2RMLMappingIdentifier id =
        new R2RMLMappingIdentifier(ws.getTitle(), r2rmlModelFile.toURI().toURL());
    WorksheetR2RMLJenaModelParser parser = new WorksheetR2RMLJenaModelParser(id);
    KR2RMLMapping mapping = parser.parse();
    KR2RMLVersion version = mapping.getVersion();
    if (version.compareTo(KR2RMLVersion.current) < 0) {
      uc.add(
          new InfoUpdate(
              "Model version is "
                  + version.toString()
                  + ".  Current version is "
                  + KR2RMLVersion.current.toString()
                  + ".  Please publish it again."));
    }
    return mapping.getWorksheetHistory();
  }