}
@Override
public UpdateContainer doIt(Workspace workspace) {
Worksheet worksheet = workspace.getWorksheet(worksheetId);
SuperSelection selection = getSuperSelection(worksheet);
String worksheetName = worksheet.getTitle();
try {
// preparing model file name
final String modelFileName = workspace.getCommandPreferencesId() + worksheetId + "-" +
worksheetName + "-model.ttl";
final String modelFileLocalPath = ServletContextParameterMap.getParameterValue(
ContextParameter.R2RML_PUBLISH_DIR) + modelFileName;
File f = new File(modelFileLocalPath);
// preparing the graphUri where the model is published in the triple store
String graphName = worksheet.getMetadataContainer().getWorksheetProperties().getPropertyValue(Property.graphName);
if(graphName == null || graphName.isEmpty()) {
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy-kkmmssS");
String ts = sdf.format(Calendar.getInstance().getTime());
graphName = "http://localhost/"+workspace.getCommandPreferencesId() + "/" + worksheetId + "/model/" + ts;
worksheet.getMetadataContainer().getWorksheetProperties().setPropertyValue(Property.graphName, graphName);
}
// If the model is not published, publish it!
if(!f.exists() || !f.isFile()) {
GenerateR2RMLModelCommandFactory factory = new GenerateR2RMLModelCommandFactory();
GenerateR2RMLModelCommand cmd = (GenerateR2RMLModelCommand)factory.createCommand(workspace, worksheetId, TripleStoreUtil.defaultModelsRepoUrl, graphName, selection.getName());
cmd.doIt(workspace);
} else {
// if the model was published 30 min ago, publish it again, just to be sure
long diff = Calendar.getInstance().getTimeInMillis() - f.lastModified();
if((diff / 1000L / 60L) > 30) {
f.delete();
GenerateR2RMLModelCommandFactory factory = new GenerateR2RMLModelCommandFactory();
GenerateR2RMLModelCommand cmd = (GenerateR2RMLModelCommand)factory.createCommand(workspace, worksheetId, TripleStoreUtil.defaultModelsRepoUrl, graphName, selection.getName());
cmd.doIt(workspace);
}
}
// TripleStoreUtil tUtil = new TripleStoreUtil();