Skip to content

Commit

Permalink
Merge pull request #121 from InformationIntegrationGroup/development
Browse files Browse the repository at this point in the history
Merge 2.025 into Master
  • Loading branch information
jasonslepicka committed Jul 29, 2014
2 parents da5d2c2 + e279352 commit ad4ce60
Show file tree
Hide file tree
Showing 170 changed files with 4,804 additions and 6,751 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ src/main/webapp/RDF/*.n3
src/main/webapp/repository/dataset/*.*
src/main/webapp/repository/services/*.*
src/main/webapp/repository/sources/*.*
src/main/webapp/CRF_Models/WSP1_CRFModel.txt.zip
karma-web/src/main/webapp/publish/CSV/*
tmp/*
src/main/webapp/CRF_Models/WSP1_CRFModel.txt
src/main/webapp/CRF_Models/*
src/main/scripts/Lib/*.class
bin/
*.kml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

package edu.isi.karma.controller.command.worksheet;

import edu.isi.karma.controller.command.CommandType;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import org.json.JSONArray;
import org.json.JSONException;
Expand All @@ -31,12 +33,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import edu.isi.karma.controller.command.CommandException;
import edu.isi.karma.controller.command.CommandType;
import edu.isi.karma.controller.command.WorksheetCommand;
import edu.isi.karma.controller.history.HistoryJSONEditor;
import edu.isi.karma.controller.history.WorksheetCommandHistoryExecutor;
import edu.isi.karma.controller.update.AbstractUpdate;
import edu.isi.karma.controller.update.ErrorUpdate;
Expand All @@ -50,7 +50,6 @@
import edu.isi.karma.kr2rml.mapping.WorksheetR2RMLJenaModelParser;
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.rep.metadata.WorksheetProperties;
Expand All @@ -61,17 +60,18 @@
public class ApplyHistoryFromR2RMLModelCommand extends WorksheetCommand {
private final File r2rmlModelFile;
private final String worksheetId;

private boolean override;
private static Logger logger = LoggerFactory.getLogger(ApplyHistoryFromR2RMLModelCommand.class);

protected ApplyHistoryFromR2RMLModelCommand(String id, File uploadedFile, String worksheetId) {
protected ApplyHistoryFromR2RMLModelCommand(String id, File uploadedFile, String worksheetId, boolean override) {
super(id, worksheetId);
this.r2rmlModelFile = uploadedFile;
this.worksheetId = worksheetId;
this.override = override;
}

private enum JsonKeys {
updateType, worksheetId, baseURI, prefix, graphName
updateType, worksheetId, baseURI, prefix, graphLabel
}

@Override
Expand Down Expand Up @@ -104,14 +104,28 @@ public UpdateContainer doIt(Workspace workspace) throws CommandException {
{
c.append(rwu);
}

try {
JSONArray historyJson = extractHistoryFromModel(workspace, c);
HistoryJSONEditor editor = new HistoryJSONEditor(new JSONArray(historyJson.toString()), workspace, worksheetId);
if (null == historyJson || historyJson.length() == 0) {
return new UpdateContainer(new ErrorUpdate("No history found in R2RML Model!"));
}
WorksheetCommandHistoryExecutor histExecutor = new WorksheetCommandHistoryExecutor(
worksheetId, workspace);
AlignmentManager alignMgr = AlignmentManager.Instance();
Alignment alignment = alignMgr.getAlignment(workspace.getId(), worksheetId);
if (override || alignment == null || alignment.GetTreeRoot() == null) {
alignMgr.removeWorkspaceAlignments(workspace.getId());
alignMgr.getAlignmentOrCreateIt(workspace.getId(), worksheetId, workspace.getOntologyManager());
editor.deleteExistingTransformationCommands();
historyJson = editor.getHistoryJSON();
}
else {
editor.deleteExistingTransformationAndModelingCommands();
historyJson = editor.getHistoryJSON();
}
System.out.println(editor.getHistoryJSON().toString(4));
UpdateContainer hc = histExecutor.executeAllCommands(historyJson);
if(hc != null)
c.append(hc);
Expand All @@ -120,14 +134,12 @@ public UpdateContainer doIt(Workspace workspace) throws CommandException {
logger.error(msg, e);
return new UpdateContainer(new ErrorUpdate(msg));
}

// Add worksheet updates that could have resulted out of the transformation commands
for (Worksheet newws : workspace.getWorksheets()) {
if (newws.getId().compareTo(worksheetId) != 0) {
c.append(WorksheetUpdateFactory.createRegenerateWorksheetUpdates(newws.getId()));
Alignment alignment = AlignmentManager.Instance().getAlignmentOrCreateIt(workspace.getId(), newws.getId(), workspace.getOntologyManager());
SemanticTypeUtil.computeSemanticTypesSuggestion(workspace.getWorksheet(newws.getId()), workspace
.getCrfModelHandler(), workspace.getOntologyManager());
c.append(WorksheetUpdateFactory.createSemanticTypesAndSVGAlignmentUpdates(newws.getId(), workspace, alignment));
}
}
Expand All @@ -147,23 +159,23 @@ public void generateJson(String prefix, PrintWriter pw,
outputObject.put(JsonKeys.baseURI.name(), props.getPropertyValue(Property.baseURI));
if (props.getPropertyValue(Property.prefix) != null)
outputObject.put(JsonKeys.prefix.name(), props.getPropertyValue(Property.prefix));
if (props.getPropertyValue(Property.graphName) != null && !props.getPropertyValue(Property.graphName).trim().isEmpty())
outputObject.put(JsonKeys.graphName.name(), props.getPropertyValue(Property.graphName));
if (props.getPropertyValue(Property.graphLabel) != null && !props.getPropertyValue(Property.graphLabel).trim().isEmpty())
outputObject.put(JsonKeys.graphLabel.name(), props.getPropertyValue(Property.graphLabel));
pw.println(outputObject.toString());
} catch (JSONException e) {
e.printStackTrace();
logger.error("Error occured while generating JSON!");
}

}

});
return c;
}

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);
Expand All @@ -174,7 +186,7 @@ private JSONArray extractHistoryFromModel(Workspace workspace, UpdateContainer u
uc.add(new InfoUpdate("Model version is " + version.toString() + ". Current version is " + KR2RMLVersion.current.toString() + ". Please publish it again."));
}
return mapping.getWorksheetHistory();

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@

public class ApplyHistoryFromR2RMLModelCommandFactory extends CommandFactory {
private enum Arguments {
worksheetId
worksheetId, override
}

@Override
public Command createCommand(HttpServletRequest request,
Workspace workspace) {
String worksheetId = request.getParameter(Arguments.worksheetId.name());
File uploadedFile = FileUtil.downloadFileFromHTTPRequest(request);
return new ApplyHistoryFromR2RMLModelCommand(getNewId(workspace), uploadedFile, worksheetId);
boolean override = Boolean.parseBoolean(request.getParameter(Arguments.override.name()));
return new ApplyHistoryFromR2RMLModelCommand(getNewId(workspace), uploadedFile, worksheetId, override);
}

public Command createCommandFromFile(String worksheetId, File uploadedFile,
Workspace workspace) {
return new ApplyHistoryFromR2RMLModelCommand(getNewId(workspace), uploadedFile, worksheetId);
Workspace workspace, boolean override) {
return new ApplyHistoryFromR2RMLModelCommand(getNewId(workspace), uploadedFile, worksheetId, override);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ public class ApplyModelFromURLCommand extends WorksheetCommand{
private String modelContext;
private String modelRepository;
private String baseUrl = "http://localhost:8080/R2RMLMapping/local/repository/";

private boolean override;
private static Logger logger = LoggerFactory.getLogger(ApplyModelFromURLCommand.class);
public ApplyModelFromURLCommand(String id, String worksheetId, String modelURL, String modelContext, String modelRepository, String baseURL) {
public ApplyModelFromURLCommand(String id, String worksheetId, String modelURL, String modelContext, String modelRepository, String baseURL, boolean override) {
super(id, worksheetId);
this.modelURL = modelURL;
this.modelContext = modelContext;
this.modelRepository = modelRepository;
this.baseUrl = baseURL;
this.override = override;
}

@Override
Expand Down Expand Up @@ -62,7 +63,7 @@ public UpdateContainer doIt(Workspace workspace) throws CommandException {

File file = new File("tmp.ttl");
FileUtils.copyURLToFile(url, file);
Command cmd = factory.createCommandFromFile(worksheetId, file, workspace);
Command cmd = factory.createCommandFromFile(worksheetId, file, workspace, override);
UpdateContainer uc = cmd.doIt(workspace);
workspace.getWorksheet(worksheetId).getMetadataContainer().getWorksheetProperties().setPropertyValue(Property.modelUrl, modelURL);
workspace.getWorksheet(worksheetId).getMetadataContainer().getWorksheetProperties().setPropertyValue(Property.modelContext, modelContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
public class ApplyModelFromURLCommandFactory extends CommandFactory{

private enum Arguments {
worksheetId, modelUrl, modelContext, modelRepository
worksheetId, modelUrl, modelContext, modelRepository, override
}
@Override
public Command createCommand(HttpServletRequest request, Workspace workspace) {
String worksheetId = request.getParameter(Arguments.worksheetId.name());
String modelUrl = request.getParameter(Arguments.modelUrl.name());
String modelContext = request.getParameter(Arguments.modelContext.name());
String modelRepository = request.getParameter(Arguments.modelRepository.name());
String baseURL = request.getRequestURL().substring(0, request.getRequestURL().lastIndexOf("RequestController")) + "R2RMLMapping/local/repository/";
return new ApplyModelFromURLCommand(getNewId(workspace), worksheetId, modelUrl, modelContext,modelRepository, baseURL);
boolean override = Boolean.parseBoolean(request.getParameter(Arguments.override.name()));
String baseURL = request.getRequestURL().substring(0, request.getRequestURL().lastIndexOf("RequestController")) + "R2RMLMapping/local/repository/";
return new ApplyModelFromURLCommand(getNewId(workspace), worksheetId, modelUrl, modelContext,modelRepository, baseURL, override);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,24 @@ private Resource addKR2RMLMappingResource(Worksheet worksheet, KR2RMLMapping map

// Add the timestamp
con.add(mappingRes, repoURIs.get(Uris.KM_MODEL_PUBLICATION_TIME_URI), f.createLiteral(new Date().getTime()));

String inputColumns = worksheet.getMetadataContainer().getWorksheetProperties().getPropertyValue(
Property.inputColumns);
String outputColumns = worksheet.getMetadataContainer().getWorksheetProperties().getPropertyValue(
Property.outputColumns);
String graphLabel = worksheet.getMetadataContainer().getWorksheetProperties().getPropertyValue(
Property.graphLabel);
String baseURI = worksheet.getMetadataContainer().getWorksheetProperties().getPropertyValue(
Property.baseURI);
// Add the version
con.add(mappingRes, repoURIs.get(Uris.KM_MODEL_VERSION_URI), f.createLiteral(KR2RMLVersion.getCurrent().toString()));

if (inputColumns != null && !inputColumns.trim().isEmpty())
con.add(mappingRes, repoURIs.get(Uris.KM_HAS_INPUTCOLUMNS), f.createLiteral(inputColumns));
if (outputColumns != null && !outputColumns.trim().isEmpty())
con.add(mappingRes, repoURIs.get(Uris.KM_HAS_OUTPUTCOLUMNS), f.createLiteral(outputColumns));
if (graphLabel != null && !graphLabel.trim().isEmpty())
con.add(mappingRes, repoURIs.get(Uris.KM_HAS_MODELLABEL), f.createLiteral(graphLabel));
if (baseURI != null && !baseURI.trim().isEmpty())
con.add(mappingRes, repoURIs.get(Uris.KM_HAS_BASEURI), f.createLiteral(baseURI));
addWorksheetProperties(worksheet, mappingRes);
addCompleteWorksheetHistory(mapping, mappingRes);
return mappingRes;
Expand All @@ -107,41 +121,9 @@ private void initializeTripleStore() throws RepositoryException {
protected void initializeURIs()
{
repoURIs = new HashMap<String, URI>();
repoURIs.put(Uris.KM_R2RML_MAPPING_URI, f.createURI(Uris.KM_R2RML_MAPPING_URI));
repoURIs.put(Uris.KM_MODEL_VERSION_URI, f.createURI(Uris.KM_MODEL_VERSION_URI));
repoURIs.put(Uris.KM_SOURCE_NAME_URI, f.createURI(Uris.KM_SOURCE_NAME_URI));
repoURIs.put(Uris.KM_MODEL_PUBLICATION_TIME_URI, f.createURI(Uris.KM_MODEL_PUBLICATION_TIME_URI));

repoURIs.put(Uris.RR_TRIPLESMAP_CLASS_URI, f.createURI(Uris.RR_TRIPLESMAP_CLASS_URI));
repoURIs.put(Uris.RR_SUBJECTMAP_CLASS_URI, f.createURI(Uris.RR_SUBJECTMAP_CLASS_URI));
repoURIs.put(Uris.RR_PREDICATEOBJECTMAP_CLASS_URI, f.createURI(Uris.RR_PREDICATEOBJECTMAP_CLASS_URI));
repoURIs.put(Uris.RR_REF_OBJECT_MAP_CLASS_URI, f.createURI(Uris.RR_REF_OBJECT_MAP_CLASS_URI));
repoURIs.put(Uris.RR_OBJECTMAP_CLASS_URI, f.createURI(Uris.RR_OBJECTMAP_CLASS_URI));
repoURIs.put(Uris.RR_LOGICAL_TABLE_CLASS_URI, f.createURI(Uris.RR_LOGICAL_TABLE_CLASS_URI));
repoURIs.put(Uris.RR_TEMPLATE_URI, f.createURI(Uris.RR_TEMPLATE_URI));
repoURIs.put(Uris.RR_SUBJECTMAP_URI, f.createURI(Uris.RR_SUBJECTMAP_URI));
repoURIs.put(Uris.RR_PREDICATE_URI, f.createURI(Uris.RR_PREDICATE_URI));
repoURIs.put(Uris.RR_OBJECTMAP_URI, f.createURI(Uris.RR_OBJECTMAP_URI));
repoURIs.put(Uris.RR_COLUMN_URI, f.createURI(Uris.RR_COLUMN_URI));
repoURIs.put(Uris.RR_DATATYPE_URI, f.createURI(Uris.RR_DATATYPE_URI));
repoURIs.put(Uris.RR_PARENT_TRIPLE_MAP_URI, f.createURI(Uris.RR_PARENT_TRIPLE_MAP_URI));
repoURIs.put(Uris.RR_PRED_OBJ_MAP_URI, f.createURI(Uris.RR_PRED_OBJ_MAP_URI));
repoURIs.put(Uris.RR_BLANK_NODE_URI, f.createURI(Uris.RR_BLANK_NODE_URI));
repoURIs.put(Uris.RR_TERM_TYPE_URI, f.createURI(Uris.RR_TERM_TYPE_URI));
repoURIs.put(Uris.RR_LOGICAL_TABLE_URI, f.createURI(Uris.RR_LOGICAL_TABLE_URI));
repoURIs.put(Uris.RR_TABLENAME_URI, f.createURI(Uris.RR_TABLENAME_URI));
repoURIs.put(Uris.RR_CLASS_URI, f.createURI(Uris.RR_CLASS_URI));
repoURIs.put(Uris.RR_LITERAL_URI, f.createURI(Uris.RR_LITERAL_URI));

repoURIs.put(Uris.KM_BLANK_NODE_PREFIX_URI, f.createURI(Uris.KM_BLANK_NODE_PREFIX_URI));
repoURIs.put(Uris.KM_NODE_ID_URI, f.createURI(Uris.KM_NODE_ID_URI));
repoURIs.put(Uris.KM_STEINER_TREE_ROOT_NODE, f.createURI(Uris.KM_STEINER_TREE_ROOT_NODE));
repoURIs.put(Uris.KM_HAS_TRIPLES_MAP_URI, f.createURI(Uris.KM_HAS_TRIPLES_MAP_URI));
repoURIs.put(Uris.KM_HAS_OBJECT_MAP_URI, f.createURI(Uris.KM_HAS_OBJECT_MAP_URI));
repoURIs.put(Uris.KM_HAS_PREDICATE_OBJECT_MAP_URI, f.createURI(Uris.KM_HAS_PREDICATE_OBJECT_MAP_URI));
repoURIs.put(Uris.KM_HAS_SUBJECT_MAP_URI, f.createURI(Uris.KM_HAS_SUBJECT_MAP_URI));
repoURIs.put(Uris.KM_HAS_LOGICAL_TABLE_URI, f.createURI(Uris.KM_HAS_LOGICAL_TABLE_URI));
repoURIs.put(Uris.KM_IS_PART_OF_MAPPING_URI, f.createURI(Uris.KM_IS_PART_OF_MAPPING_URI));
for (String uri : Uris.Uris) {
repoURIs.put(uri, f.createURI(uri));
}

}

Expand Down Expand Up @@ -174,7 +156,7 @@ public void writeR2RMLMapping(PrintWriter writer) {
private void addPrefixes(KR2RMLMapping mapping) throws RepositoryException {
for (Prefix p : mapping.getPrefixes())
{
con.setNamespace(p.getNamespace(), p.getPrefix());
con.setNamespace(p.getPrefix(), p.getNamespace());
}
con.setNamespace(Prefixes.RR, Namespaces.RR);
con.setNamespace(Prefixes.KARMA_DEV, Namespaces.KARMA_DEV);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ public CommandType getCommandType() {

@Override
public UpdateContainer doIt(Workspace workspace) throws CommandException {
// TODO Auto-generated method stub
appliedCommands.clear();
inputColumns.clear();
outputColumns.clear();
UpdateContainer c = new UpdateContainer();
alignmentId = AlignmentManager.Instance().constructAlignmentId(workspace.getId(), worksheetId);
Alignment alignment = AlignmentManager.Instance().getAlignment(alignmentId);
Expand All @@ -120,6 +121,7 @@ public UpdateContainer doIt(Workspace workspace) throws CommandException {
HNode hnode = factory.getHNode(hNodeId);
List<String> hNodeIds = new LinkedList<String>();
hNodeIds.add(hNodeId);
inputColumns.addAll(hNodeIds);
List<Table> dataTables = new ArrayList<Table>();
CloneTableUtils.getDatatable(worksheet.getDataTable(), factory.getHTable(hnode.getHTableId()), dataTables);
Map<String, String> rowHashToSubjectURI = new HashMap<String, String>();
Expand Down Expand Up @@ -230,6 +232,7 @@ public UpdateContainer doIt(Workspace workspace) throws CommandException {
Label label = ontMgr.getUriLabel(incoming ? otherClass : predicate);
AddValuesCommand command = (AddValuesCommand) addFactory.createCommand(input, workspace, hNodeId, worksheetId, hnode.getHTableId(), label.getDisplayName(), HNodeType.AugmentData);
command.doIt(workspace);
outputColumns.addAll(command.getOutputColumns());
isNewNode |= command.isNewNode();
if (command.isNewNode())
appliedCommands.push(command);
Expand Down
Loading

0 comments on commit ad4ce60

Please sign in to comment.