uc.append(historyUtil.replayHistory());
uc.removeUpdateByClass(HistoryAddCommandUpdate.class);
uc.removeUpdateByClass(InfoUpdate.class);
uc.removeUpdateByClass(ErrorUpdate.class);
historyUtil.consolidateHistory();
uc.add(new HistoryUpdate(workspace.getCommandHistory()));
}
Set<String> inputColumns = historyUtil.generateInputColumns();
Set<String> outputColumns = historyUtil.generateOutputColumns();
JSONArray inputColumnsArray = new JSONArray();
JSONArray outputColumnsArray = new JSONArray();
for (String hNodeId : inputColumns) {
HNode hnode = workspace.getFactory().getHNode(hNodeId);
JSONArray hNodeRepresentation = hnode.getJSONArrayRepresentation(workspace.getFactory());
inputColumnsArray.put(hNodeRepresentation);
}
for (String hNodeId : outputColumns) {
HNode hnode = workspace.getFactory().getHNode(hNodeId);
JSONArray hNodeRepresentation = hnode.getJSONArrayRepresentation(workspace.getFactory());
outputColumnsArray.put(hNodeRepresentation);
}
worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
Property.inputColumns, inputColumnsArray.toString());
worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
Property.outputColumns, outputColumnsArray.toString());
this.worksheetName = worksheet.getTitle();
String graphLabel = worksheet.getMetadataContainer().getWorksheetProperties().
getPropertyValue(Property.graphLabel);
if (graphLabel == null || graphLabel.isEmpty()) {
worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
Property.graphLabel, worksheet.getTitle());
graphLabel = worksheet.getTitle();
worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
Property.graphName, WorksheetProperties.createDefaultGraphName(graphLabel));
}
// Prepare the model file path and names
final String modelFileName = graphLabel + "-model.ttl";
final String modelFileLocalPath = ServletContextParameterMap.getParameterValue(
ContextParameter.R2RML_PUBLISH_DIR) + modelFileName;
// Get the alignment for this Worksheet
Alignment alignment = AlignmentManager.Instance().getAlignment(AlignmentManager.
Instance().constructAlignmentId(workspace.getId(), worksheetId));
if (alignment == null) {
logger.info("Alignment is NULL for " + worksheetId);
return new UpdateContainer(new ErrorUpdate(
"Please align the worksheet before generating R2RML Model!"));
}
Set<LabeledLink> links = new HashSet<LabeledLink>();
if (alignment.getSteinerTree() != null) {
for (LabeledLink link : alignment.getSteinerTree().edgeSet()) {
if ((link.getStatus() == LinkStatus.Normal || link.getStatus() == LinkStatus.PreferredByUI) && (link.getType() == LinkType.ObjectPropertyLink)) {
links.add(link);
}
}
}
JSONArray newEdges = new JSONArray();
JSONArray initialEdges = new JSONArray();
ChangeInternalNodeLinksCommandFactory cinlcf = new ChangeInternalNodeLinksCommandFactory();
for (LabeledLink link : links) {
JSONObject newEdge = new JSONObject();
JSONObject initialEdge = new JSONObject();
newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeSourceId.name(), link.getSource().getId());
newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeTargetId.name(), link.getTarget().getId());
newEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeId.name(), link.getUri());
initialEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeSourceId.name(), link.getSource().getId());
initialEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeTargetId.name(), link.getTarget().getId());
initialEdge.put(ChangeInternalNodeLinksCommand.JsonKeys.edgeId.name(), link.getUri());
newEdges.put(newEdge);
initialEdges.put(initialEdge);
}
JSONArray inputJSON = new JSONArray();
JSONObject t = new JSONObject();
t.put("name", "worksheetId");
t.put("type", HistoryJsonUtil.ParameterType.worksheetId.name());
t.put("value", worksheetId);
inputJSON.put(t);
t = new JSONObject();
t.put("name", "initialEdges");
t.put("type", HistoryJsonUtil.ParameterType.other.name());
t.put("value", initialEdges);
inputJSON.put(t);
t = new JSONObject();
t.put("name", "newEdges");
t.put("type", HistoryJsonUtil.ParameterType.other.name());
t.put("value", newEdges);
inputJSON.put(t);
if (newEdges.length() > 0 || initialEdges.length() > 0) {
try {
Command changeInternalNodeLinksCommand = cinlcf.createCommand(inputJSON, workspace);
workspace.getCommandHistory().doCommand(changeInternalNodeLinksCommand, workspace);
uc.add(new HistoryUpdate(workspace.getCommandHistory()));
uc.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId, getSuperSelection(worksheet)));
uc.append(computeAlignmentAndSemanticTypesAndCreateUpdates(workspace));
}catch(Exception e)
{
e.printStackTrace();