| Chunk |
|---|
| Conflicting content |
|---|
import java.io.Writer;
public class GenerateR2RMLModelCommand extends Command {
<<<<<<< HEAD
private final String worksheetId;
private String worksheetName;
private String tripleStoreUrl;
private String graphContext;
private static Logger logger = LoggerFactory.getLogger(GenerateR2RMLModelCommand.class);
public enum JsonKeys {
updateType, fileUrl, worksheetId
}
public enum PreferencesKeys {
rdfPrefix, rdfNamespace, modelSparqlEndPoint
}
protected GenerateR2RMLModelCommand(String id, String worksheetId, String url, String context) {
super(id);
this.worksheetId = worksheetId;
this.tripleStoreUrl = url;
this.graphContext = context;
}
public String getTripleStoreUrl() {
return tripleStoreUrl;
}
public void setTripleStoreUrl(String tripleStoreUrl) {
this.tripleStoreUrl = tripleStoreUrl;
}
public String getGraphContext() {
return graphContext;
}
public void setGraphContext(String graphContext) {
this.graphContext = graphContext;
}
@Override
public String getCommandName() {
return this.getClass().getSimpleName();
}
@Override
public String getTitle() {
return "Generate R2RML Model";
}
@Override
public String getDescription() {
return this.worksheetName;
}
@Override
public CommandType getCommandType() {
return CommandType.notUndoable;
}
@Override
public UpdateContainer doIt(Workspace workspace) throws CommandException {
//save the preferences
savePreferences(workspace);
Worksheet worksheet = workspace.getWorksheet(worksheetId);
this.worksheetName = worksheet.getTitle();
// Prepare the model file path and names
final String modelFileName = workspace.getCommandPreferencesId() + worksheetId + "-"
+ this.worksheetName + "-model.ttl";
final String modelFileLocalPath = ServletContextParameterMap.getParameterValue(
ContextParameter.USER_DIRECTORY_PATH) + "publish/R2RML/" + modelFileName;
try {
KR2RMLModelGenerator modelGenerator = new KR2RMLModelGenerator();
KR2RMLMappingGenerator mappingGen = modelGenerator.generateModel(workspace, worksheet);
// Write the model
PrintWriter writer = new PrintWriter(modelFileLocalPath, "UTF-8");
modelGenerator.writeModel(workspace, mappingGen, worksheet, writer);
// Write the model to the triple store
TripleStoreUtil utilObj = new TripleStoreUtil();
// Get the graph name from properties
String graphName = worksheet.getMetadataContainer().getWorksheetProperties()
.getPropertyValue(Property.graphName);
if (graphName == null || graphName.isEmpty()) {
// Set to default
worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
Property.graphName, WorksheetProperties.createDefaultGraphName(worksheet.getTitle()));
graphName = WorksheetProperties.createDefaultGraphName(worksheet.getTitle());
}
boolean result = utilObj.saveToStore(modelFileLocalPath, tripleStoreUrl, graphName, true);
if (result) {
logger.info("Saved model to triple store");
return new UpdateContainer(new AbstractUpdate() {
}
public void generateJson(String prefix, PrintWriter pw,
VWorkspace vWorkspace) {
JSONObject outputObject = new JSONObject();
try {
outputObject.put(JsonKeys.updateType.name(), "PublishR2RMLUpdate");
outputObject.put(JsonKeys.fileUrl.name(), "publish/R2RML/" + modelFileName);
outputObject.put(JsonKeys.worksheetId.name(), worksheetId);
pw.println(outputObject.toString());
} catch (JSONException e) {
logger.error("Error occured while generating JSON!");
}
}
});
}
return new UpdateContainer(new ErrorUpdate("Error occured while generating R2RML model!"));
} catch (NullPointerException e) {
logger.info("Alignment is NULL for " + worksheet.getId());
return new UpdateContainer(new ErrorUpdate(e.getMessage()));
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
return new UpdateContainer(new ErrorUpdate("Error occured while generating R2RML model!"));
}
}
@Override
public UpdateContainer undoIt(Workspace workspace) {
// Not required
return null;
}
private void savePreferences(Workspace workspace) {
try {
JSONObject prefObject = new JSONObject();
prefObject.put(PreferencesKeys.modelSparqlEndPoint.name(), tripleStoreUrl);
workspace.getCommandPreferences().setCommandPreferences(
"GenerateR2RMLModelCommandPreferences", prefObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
=======
private final String worksheetId;
private String worksheetName;
private String tripleStoreUrl;
private String graphContext;
private static Logger logger = LoggerFactory.getLogger(GenerateR2RMLModelCommand.class);
public enum JsonKeys {
updateType, fileUrl, worksheetId
}
public enum PreferencesKeys {
rdfPrefix, rdfNamespace, modelSparqlEndPoint
}
protected GenerateR2RMLModelCommand(String id, String worksheetId, String url, String context) {
super(id);
this.worksheetId = worksheetId;
this.tripleStoreUrl = url;
this.graphContext = context;
}
public String getTripleStoreUrl() {
return tripleStoreUrl;
}
public void setTripleStoreUrl(String tripleStoreUrl) {
this.tripleStoreUrl = tripleStoreUrl;
}
public String getGraphContext() {
return graphContext;
}
public void setGraphContext(String graphContext) {
this.graphContext = graphContext;
}
@Override
public String getCommandName() {
return this.getClass().getSimpleName();
}
@Override
public String getTitle() {
return "Generate R2RML Model";
}
@Override
public String getDescription() {
return this.worksheetName;
}
@Override
public CommandType getCommandType() {
return CommandType.notUndoable;
@Override
public UpdateContainer doIt(Workspace workspace) throws CommandException {
//save the preferences
savePreferences(workspace);
Worksheet worksheet = workspace.getWorksheet(worksheetId);
this.worksheetName = worksheet.getTitle();
// Prepare the model file path and names
final String modelFileName = workspace.getCommandPreferencesId() + worksheetId + "-" +
this.worksheetName + "-model.ttl";
final String modelFileLocalPath = ServletContextParameterMap.getParameterValue(
ContextParameter.USER_DIRECTORY_PATH) + "publish/R2RML/" + 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!"));
}
try {
// Get the namespace and prefix from the preferences
String namespace = "";
String prefix = "";
JSONObject prefObject = workspace.getCommandPreferences().getCommandPreferencesJSONObject(
PublishRDFCommand.class.getSimpleName()+"Preferences");
if (prefObject != null) {
namespace = prefObject.getString(PreferencesKeys.rdfNamespace.name());
prefix = prefObject.getString(PreferencesKeys.rdfPrefix.name());
namespace = ((namespace == null) || (namespace.equals(""))) ?
Namespaces.KARMA_DEV : namespace;
prefix = ((prefix == null) || (prefix.equals(""))) ?
Prefixes.KARMA_DEV : prefix;
} else {
namespace = Namespaces.KARMA_DEV;
prefix = Prefixes.KARMA_DEV;
}
// Generate the KR2RML data structures for the RDF generation
final ErrorReport errorReport = new ErrorReport();
OntologyManager ontMgr = workspace.getOntologyManager();
KR2RMLMappingGenerator mappingGen = new KR2RMLMappingGenerator(ontMgr, alignment,
worksheet.getSemanticTypes(), prefix, namespace, true, errorReport);
// Write the model
writeModel(workspace, ontMgr, mappingGen, worksheet, modelFileLocalPath);
// Write the model to the triple store
TripleStoreUtil utilObj = new TripleStoreUtil();
// Get the graph name from properties
String graphName = worksheet.getMetadataContainer().getWorksheetProperties()
.getPropertyValue(Property.graphName);
if (graphName == null || graphName.isEmpty()) {
// Set to default
worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
Property.graphName, WorksheetProperties.createDefaultGraphName(worksheet.getTitle()));
graphName = WorksheetProperties.createDefaultGraphName(worksheet.getTitle());
}
boolean result = utilObj.saveToStore(modelFileLocalPath, tripleStoreUrl, graphName, true);
if (result) {
logger.info("Saved model to triple store");
return new UpdateContainer(new AbstractUpdate() {
public void generateJson(String prefix, PrintWriter pw,
VWorkspace vWorkspace) {
JSONObject outputObject = new JSONObject();
try {
outputObject.put(JsonKeys.updateType.name(), "PublishR2RMLUpdate");
outputObject.put(JsonKeys.fileUrl.name(), "publish/R2RML/" + modelFileName);
outputObject.put(JsonKeys.worksheetId.name(), worksheetId);
pw.println(outputObject.toString());
} catch (JSONException e) {
logger.error("Error occured while generating JSON!");
}
}
});
}
return new UpdateContainer(new ErrorUpdate("Error occured while generating R2RML model!"));
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
return new UpdateContainer(new ErrorUpdate("Error occured while generating R2RML model!"));
}
}
@Override
public UpdateContainer undoIt(Workspace workspace) {
// Not required
return null;
}
private void writeModel(Workspace workspace, OntologyManager ontMgr,
KR2RMLMappingGenerator mappingGen, Worksheet worksheet, String modelFileLocalPath)
throws RepositoryException, FileNotFoundException,
UnsupportedEncodingException, JSONException {
File f = new File(modelFileLocalPath);
File parentDir = f.getParentFile();
parentDir.mkdirs();
PrintWriter writer = new PrintWriter(f, "UTF-8");
WorksheetModelWriter modelWriter = new WorksheetModelWriter(writer,
workspace.getFactory(), ontMgr, worksheet.getTitle());
// Writer worksheet properties such as Service URL
modelWriter.writeWorksheetProperties(worksheet);
// Write the worksheet history
String historyFilePath = HistoryJsonUtil.constructWorksheetHistoryJsonFilePath(
worksheet.getTitle(), workspace.getCommandPreferencesId());
modelWriter.writeCompleteWorksheetHistory(historyFilePath);
// Write the R2RML mapping
modelWriter.writeR2RMLMapping(ontMgr, mappingGen);
modelWriter.close();
writer.flush();
writer.close();
}
private void savePreferences(Workspace workspace){
try{
JSONObject prefObject = new JSONObject();
prefObject.put(PreferencesKeys.modelSparqlEndPoint.name(), tripleStoreUrl);
workspace.getCommandPreferences().setCommandPreferences(
"GenerateR2RMLModelCommandPreferences", prefObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
>>>>>>> 99310c12a19df26ef84f4ed4f48909015ebb8809
} |
| Solution content |
|---|
import java.io.Writer;
public class GenerateR2RMLModelCommand extends Command {
private final String worksheetId;
private String worksheetName;
private String tripleStoreUrl;
private String graphContext;
private static Logger logger = LoggerFactory.getLogger(GenerateR2RMLModelCommand.class);
public enum JsonKeys {
updateType, fileUrl, worksheetId
}
public enum PreferencesKeys {
rdfPrefix, rdfNamespace, modelSparqlEndPoint
}
protected GenerateR2RMLModelCommand(String id, String worksheetId, String url, String context) {
super(id);
this.worksheetId = worksheetId;
this.tripleStoreUrl = url;
this.graphContext = context;
}
public String getTripleStoreUrl() {
return tripleStoreUrl;
}
public void setTripleStoreUrl(String tripleStoreUrl) {
this.tripleStoreUrl = tripleStoreUrl;
}
public String getGraphContext() {
return graphContext;
}
public void setGraphContext(String graphContext) {
this.graphContext = graphContext;
}
@Override
public String getCommandName() {
return this.getClass().getSimpleName();
}
@Override
public String getTitle() {
return "Generate R2RML Model";
}
@Override
public String getDescription() {
return this.worksheetName;
}
@Override
public CommandType getCommandType() {
return CommandType.notUndoable;
}
@Override
public UpdateContainer doIt(Workspace workspace) throws CommandException {
//save the preferences
savePreferences(workspace);
Worksheet worksheet = workspace.getWorksheet(worksheetId);
this.worksheetName = worksheet.getTitle();
// Prepare the model file path and names
final String modelFileName = workspace.getCommandPreferencesId() + worksheetId + "-" +
this.worksheetName + "-model.ttl";
final String modelFileLocalPath = ServletContextParameterMap.getParameterValue(
ContextParameter.USER_DIRECTORY_PATH) + "publish/R2RML/" + 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!"));
}
try {
// Get the namespace and prefix from the preferences
String namespace = "";
String prefix = "";
JSONObject prefObject = workspace.getCommandPreferences().getCommandPreferencesJSONObject(
PublishRDFCommand.class.getSimpleName()+"Preferences");
if (prefObject != null) {
namespace = prefObject.getString(PreferencesKeys.rdfNamespace.name());
prefix = prefObject.getString(PreferencesKeys.rdfPrefix.name());
namespace = ((namespace == null) || (namespace.equals(""))) ?
Namespaces.KARMA_DEV : namespace;
prefix = ((prefix == null) || (prefix.equals(""))) ?
Prefixes.KARMA_DEV : prefix;
} else {
namespace = Namespaces.KARMA_DEV;
prefix = Prefixes.KARMA_DEV;
}
// Generate the KR2RML data structures for the RDF generation
final ErrorReport errorReport = new ErrorReport();
OntologyManager ontMgr = workspace.getOntologyManager();
KR2RMLMappingGenerator mappingGen = new KR2RMLMappingGenerator(ontMgr, alignment,
worksheet.getSemanticTypes(), prefix, namespace, true, errorReport);
// Write the model
writeModel(workspace, ontMgr, mappingGen, worksheet, modelFileLocalPath);
// Write the model to the triple store
TripleStoreUtil utilObj = new TripleStoreUtil();
// Get the graph name from properties
String graphName = worksheet.getMetadataContainer().getWorksheetProperties()
.getPropertyValue(Property.graphName);
if (graphName == null || graphName.isEmpty()) {
// Set to default
worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(
Property.graphName, WorksheetProperties.createDefaultGraphName(worksheet.getTitle()));
graphName = WorksheetProperties.createDefaultGraphName(worksheet.getTitle());
}
boolean result = utilObj.saveToStore(modelFileLocalPath, tripleStoreUrl, graphName, true);
if (result) {
logger.info("Saved model to triple store");
return new UpdateContainer(new AbstractUpdate() {
public void generateJson(String prefix, PrintWriter pw,
VWorkspace vWorkspace) {
JSONObject outputObject = new JSONObject();
try {
outputObject.put(JsonKeys.updateType.name(), "PublishR2RMLUpdate");
outputObject.put(JsonKeys.fileUrl.name(), "publish/R2RML/" + modelFileName);
outputObject.put(JsonKeys.worksheetId.name(), worksheetId);
pw.println(outputObject.toString());
} catch (JSONException e) {
logger.error("Error occured while generating JSON!");
}
}
});
}
return new UpdateContainer(new ErrorUpdate("Error occured while generating R2RML model!"));
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
return new UpdateContainer(new ErrorUpdate("Error occured while generating R2RML model!"));
}
}
@Override
public UpdateContainer undoIt(Workspace workspace) {
// Not required
return null;
}
private void writeModel(Workspace workspace, OntologyManager ontMgr,
KR2RMLMappingGenerator mappingGen, Worksheet worksheet, String modelFileLocalPath)
throws RepositoryException, FileNotFoundException,
UnsupportedEncodingException, JSONException {
File f = new File(modelFileLocalPath);
File parentDir = f.getParentFile();
parentDir.mkdirs();
PrintWriter writer = new PrintWriter(f, "UTF-8");
WorksheetModelWriter modelWriter = new WorksheetModelWriter(writer,
workspace.getFactory(), ontMgr, worksheet.getTitle());
// Writer worksheet properties such as Service URL
modelWriter.writeWorksheetProperties(worksheet);
// Write the worksheet history
String historyFilePath = HistoryJsonUtil.constructWorksheetHistoryJsonFilePath(
worksheet.getTitle(), workspace.getCommandPreferencesId());
modelWriter.writeCompleteWorksheetHistory(historyFilePath);
// Write the R2RML mapping
modelWriter.writeR2RMLMapping(ontMgr, mappingGen);
modelWriter.close();
writer.flush();
writer.close();
}
private void savePreferences(Workspace workspace) {
try {
JSONObject prefObject = new JSONObject();
prefObject.put(PreferencesKeys.modelSparqlEndPoint.name(), tripleStoreUrl);
workspace.getCommandPreferences().setCommandPreferences(
"GenerateR2RMLModelCommandPreferences", prefObject);
} catch (JSONException e) {
e.printStackTrace();
}
}
} |
| File |
|---|
| GenerateR2RMLModelCommand.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Annotation |
| Attribute |
| Enum declaration |
| Method declaration |
| Method invocation |
| Chunk |
|---|
| Conflicting content |
|---|
import edu.isi.karma.controller.command.Command; import edu.isi.karma.controller.command.CommandException; <<<<<<< HEAD import edu.isi.karma.controller.command.WorksheetCommand; import edu.isi.karma.controller.history.WorksheetCommandHistoryReader; ======= >>>>>>> 99310c12a19df26ef84f4ed4f48909015ebb8809 import edu.isi.karma.controller.update.ErrorUpdate; import edu.isi.karma.controller.update.InfoUpdate; import edu.isi.karma.controller.update.UpdateContainer; |
| Solution content |
|---|
import edu.isi.karma.controller.command.Command; import edu.isi.karma.controller.command.CommandException; import edu.isi.karma.controller.history.WorksheetCommandHistoryExecutor; import edu.isi.karma.controller.history.WorksheetCommandHistoryReader; import edu.isi.karma.controller.update.ErrorUpdate; import edu.isi.karma.controller.update.InfoUpdate; import edu.isi.karma.controller.update.UpdateContainer; |
| File |
|---|
| ImportCommand.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Import |
| Chunk |
|---|
| Conflicting content |
|---|
import edu.isi.karma.controller.update.WorksheetListUpdate; import edu.isi.karma.controller.update.WorksheetUpdateFactory; import edu.isi.karma.imp.Import; <<<<<<< HEAD import edu.isi.karma.kr2rml.KR2RMLMappingGenerator; import edu.isi.karma.kr2rml.KR2RMLModelGenerator; import edu.isi.karma.modeling.alignment.Alignment; import edu.isi.karma.modeling.alignment.AlignmentManager; import edu.isi.karma.modeling.semantictypes.SemanticTypeUtil; import edu.isi.karma.rep.Worksheet; import edu.isi.karma.rep.Workspace; import edu.isi.karma.webserver.KarmaException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.sql.SQLException; import org.json.JSONArray; import org.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; ======= import edu.isi.karma.rep.Worksheet; import edu.isi.karma.rep.Workspace; import edu.isi.karma.webserver.KarmaException; >>>>>>> 99310c12a19df26ef84f4ed4f48909015ebb8809 /** * This abstract class in an interface to all Commands that Import data |
| Solution content |
|---|
import edu.isi.karma.controller.update.WorksheetListUpdate; import edu.isi.karma.controller.update.WorksheetUpdateFactory; import edu.isi.karma.imp.Import; import edu.isi.karma.kr2rml.ErrorReport; import edu.isi.karma.kr2rml.KR2RMLMappingGenerator; import edu.isi.karma.kr2rml.R2RMLMapping; import edu.isi.karma.modeling.Uris; import edu.isi.karma.modeling.alignment.Alignment; import edu.isi.karma.modeling.alignment.AlignmentManager; import edu.isi.karma.modeling.semantictypes.SemanticTypeUtil; import edu.isi.karma.rep.Worksheet; import edu.isi.karma.rep.Workspace; import edu.isi.karma.webserver.KarmaException; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.StringWriter; import org.json.JSONArray; import org.json.JSONException; import org.openrdf.model.Statement; import org.openrdf.model.URI; import org.openrdf.model.Value; import org.openrdf.model.ValueFactory; import org.openrdf.repository.Repository; import org.openrdf.repository.RepositoryConnection; import org.openrdf.repository.RepositoryException; import org.openrdf.repository.RepositoryResult; import org.openrdf.repository.sail.SailRepository; import org.openrdf.rio.RDFFormat; import org.openrdf.rio.RDFParseException; import org.openrdf.sail.memory.MemoryStore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * This abstract class in an interface to all Commands that Import data |
| File |
|---|
| ImportCommand.java |
| Developer's decision |
|---|
| Manual |
| Kind of conflict |
|---|
| Import |
| Chunk |
|---|
| Conflicting content |
|---|
@Override
public UpdateContainer doIt(Workspace workspace) throws CommandException {
<<<<<<< HEAD
WorksheetCommandHistoryReader histReader = new WorksheetCommandHistoryReader(
worksheetId, workspace);
KR2RMLModelGenerator modelGenerator = new KR2RMLModelGenerator();
=======
UpdateContainer c = WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId);
>>>>>>> 99310c12a19df26ef84f4ed4f48909015ebb8809
try {
FileInputStream fis = new FileInputStream(r2rmlModelFile);
String historyStr = modelGenerator.extractHistoryFromModel(fis); |
| Solution content |
|---|
@Override
public UpdateContainer doIt(Workspace workspace) throws CommandException {
UpdateContainer c = WorksheetUpdateFactory.createRegenerateWorksheetUpdates(worksheetId);
try { |
| File |
|---|
| ApplyHistoryFromR2RMLModelCommand.java |
| Developer's decision |
|---|
| Version 2 |
| Kind of conflict |
|---|
| Method invocation |
| Variable |