Skip to content

Commit

Permalink
- update the traceability message according to the Json schema
Browse files Browse the repository at this point in the history
  • Loading branch information
alash325 committed Jun 2, 2017
1 parent 1830335 commit 2230a75
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 45 deletions.
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/FMI/ImportFMUModelDescriptionDialog.cpp
Expand Up @@ -130,7 +130,7 @@ void ImportFMUModelDescriptionDialog::importFMUModelDescription()
// Get the name of the file without the extension
QString base_name = file.baseName();
//Push traceability information automaticaly to Daemon
MainWindow::instance()->getCommitChangesDialog()->generateTraceabilityURI("ModelDescription Import", fmuFileName, base_name, mpFmuModelDescriptionTextBox->text());
MainWindow::instance()->getCommitChangesDialog()->generateTraceabilityURI("modelDescriptionImport", fmuFileName, base_name, mpFmuModelDescriptionTextBox->text());
}
accept();
}
59 changes: 34 additions & 25 deletions OMEdit/OMEditGUI/Git/CommitChangesDialog.cpp
Expand Up @@ -171,19 +171,19 @@ void CommitChangesDialog::addFile(QString fileStatus, QString fileName, bool che
QString CommitChangesDialog::getFileStatus(QString status)
{
if (status.trimmed().compare("M")== 0)
return "Model Modification";
return "modelModification";
else if (status.trimmed().compare("A")== 0)
return "Model Creation";
return "modelCreation";
else if (status.trimmed().compare("D")== 0)
return "Deleted";
else if (status.trimmed().compare("R")== 0)
return "Renamed";
else if (status.trimmed().compare("C")== 0)
return "Copied";
else if (status.trimmed().compare("??")== 0)
return "Model Creation";
return "modelCreation";
else if (status.trimmed().compare("AM")== 0)
return "Model Creation";
return "modelCreation";
else
// should never be reached
return "UnknownFileStatus";
Expand Down Expand Up @@ -218,20 +218,26 @@ void CommitChangesDialog::commitFiles()

void CommitChangesDialog::generateTraceabilityURI(QString activity, QString modelFileName, QString nameStructure, QString fmuFileName)
{
QString toolURI, activityURI, agentURI, sourceModelFileNameURI, fmuFileNameURI;
QString toolURI, activityURI, agentURI, sourceModelFileNameURI, fmuFileNameURI, entityType, path, gitHash;
QDir dir(OptionsDialog::instance()->getTraceabilityPage()->getGitRepository()->text());
QDateTime time = QDateTime::currentDateTime();
if(activity.compare("ModelDescription Import")== 0) {
fmuFileNameURI = "Entity.model: " + dir.relativeFilePath(modelFileName) + "#" + GitCommands::instance()->commitAndGetFileHash(modelFileName, activity);
sourceModelFileNameURI = "Entity.modelDescription xml:" + dir.relativeFilePath(fmuFileName) + "#" + GitCommands::instance()->getGitHash(fmuFileName);
if(activity.compare("modelDescriptionImport")== 0) {
entityType = "modelDescriptionFile";
path = dir.relativeFilePath(modelFileName);
gitHash = GitCommands::instance()->commitAndGetFileHash(modelFileName, activity);
fmuFileNameURI = "Entity.modelFile:" + path + "#" + gitHash ;
sourceModelFileNameURI = "Entity.modelDescriptionFile:" + dir.relativeFilePath(fmuFileName) + "#" + GitCommands::instance()->getGitHash(fmuFileName);
}else {
fmuFileNameURI = "Entity.fmu: " + dir.relativeFilePath(fmuFileName) + "#" + GitCommands::instance()->commitAndGetFileHash(fmuFileName, activity);
sourceModelFileNameURI = "Entity.model:" + dir.relativeFilePath(modelFileName) + "#" + GitCommands::instance()->getGitHash(modelFileName);
entityType = "fmu";
path = dir.relativeFilePath(fmuFileName);
gitHash = GitCommands::instance()->commitAndGetFileHash(fmuFileName, activity);
fmuFileNameURI = "Entity.fmu:" + path + "#" + gitHash;
sourceModelFileNameURI = "Entity.modelFile:" + dir.relativeFilePath(modelFileName) + "#" + GitCommands::instance()->getGitHash(modelFileName);
}
toolURI = "Entity.softwareTool: " + MainWindow::instance()->getOMCProxy()->getVersion();
agentURI = "Agent:" + OptionsDialog::instance()->getTraceabilityPage()->getUserName()->text();
activityURI = "Activity."+ activity +":" + time.toString("yyyy-MM-dd-hh-mm-ss");
MainWindow::instance()->getTraceabilityInformationURI()->translateURIToJsonMessageFormat(activity, toolURI, activityURI, agentURI, sourceModelFileNameURI, fmuFileNameURI);
toolURI = "Entity.softwareTool:OpenModelica: " + MainWindow::instance()->getOMCProxy()->getVersion();
agentURI = "Agent:" + OptionsDialog::instance()->getTraceabilityPage()->getEmail()->text();
activityURI = "Activity."+ activity +":" + time.toTimeSpec(Qt::OffsetFromUTC).toString(Qt::ISODate)+ "#" + QUuid::createUuid().toString().mid(1, 36);
MainWindow::instance()->getTraceabilityInformationURI()->translateURIToJsonMessageFormat(activity, toolURI, activityURI, agentURI, sourceModelFileNameURI, fmuFileNameURI, entityType, path, gitHash);
}

void CommitChangesDialog::commitAndGenerateTraceabilityURI(QString fileName)
Expand All @@ -243,20 +249,23 @@ void CommitChangesDialog::commitAndGenerateTraceabilityURI(QString fileName)
commitMessage = QInputDialog::getMultiLineText(MainWindow::instance(), tr("Commit Message "), "Please Enter Commit Description:");
#else // Qt4
#endif
QString toolURI, activityURI, agentURI, sourceModelFileNameURI, fmuFileNameURI;
QString toolURI, activityURI, agentURI, sourceModelFileNameURI, fmuFileNameURI, gitHash, path;
QDir dir(OptionsDialog::instance()->getTraceabilityPage()->getGitRepository()->text());
QDateTime time = QDateTime::currentDateTime();
toolURI = "Entity.softwareTool: " + MainWindow::instance()->getOMCProxy()->getVersion();
agentURI = "Agent:" + OptionsDialog::instance()->getTraceabilityPage()->getUserName()->text();
activityURI = "Activity."+ activity +":" + time.toString("yyyy-MM-dd-hh-mm-ss");
if(activity.compare("Model Modification")== 0) {
sourceModelFileNameURI = "Entity.model:" + dir.relativeFilePath(fileName) + "#" + GitCommands::instance()->getGitHash(fileName);
fmuFileNameURI = "Entity.model:" + dir.relativeFilePath(fileName) + "#" + GitCommands::instance()->commitAndGetFileHash(fileName, commitMessage);
MainWindow::instance()->getTraceabilityInformationURI()->translateURIToJsonMessageFormat(activity, toolURI, activityURI, agentURI, sourceModelFileNameURI, fmuFileNameURI);
toolURI = "Entity.softwareTool:OpenModelica: " + MainWindow::instance()->getOMCProxy()->getVersion();
agentURI = "Agent:" + OptionsDialog::instance()->getTraceabilityPage()->getEmail()->text();
activityURI = "Activity."+ activity +":" + time.toTimeSpec(Qt::OffsetFromUTC).toString(Qt::ISODate)+ "#" + QUuid::createUuid().toString().mid(1, 36);
path = dir.relativeFilePath(fileName);
if(activity.compare("modelModification")== 0) {
gitHash = GitCommands::instance()->getGitHash(fileName);
sourceModelFileNameURI = "Entity.modelFile:" + path + "#" + gitHash;
fmuFileNameURI = "Entity.modelFile:" + path + "#" + GitCommands::instance()->commitAndGetFileHash(fileName, commitMessage);
MainWindow::instance()->getTraceabilityInformationURI()->translateURIToJsonMessageFormat(activity, toolURI, activityURI, agentURI, sourceModelFileNameURI, fmuFileNameURI, "modelFile", path, gitHash);
}
else if(activity.compare("Model Creation")== 0) {
sourceModelFileNameURI = "Entity.model: " + dir.relativeFilePath(fileName) + "#" + GitCommands::instance()->commitAndGetFileHash(fileName, commitMessage);
MainWindow::instance()->getTraceabilityInformationURI()->translateModelCreationURIToJsonMessageFormat(activity, toolURI, activityURI, agentURI, sourceModelFileNameURI);
else if(activity.compare("modelCreation")== 0) {
gitHash = GitCommands::instance()->commitAndGetFileHash(fileName, commitMessage);
sourceModelFileNameURI = "Entity.modelFile:" + path + "#" + gitHash;
MainWindow::instance()->getTraceabilityInformationURI()->translateModelCreationURIToJsonMessageFormat(activity, toolURI, activityURI, agentURI, sourceModelFileNameURI, "modelFile", path, gitHash);
}
}

Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -831,7 +831,7 @@ void MainWindow::exportModelFMU(LibraryTreeItem *pLibraryTreeItem)
//trace export FMU
if (OptionsDialog::instance()->getTraceabilityPage()->getTraceabilityGroupBox()->isChecked() && !fmuFileName.isEmpty()) {
//Push traceability information automaticaly to Daemon
MainWindow::instance()->getCommitChangesDialog()->generateTraceabilityURI("FMU Export", pLibraryTreeItem->getFileName(), pLibraryTreeItem->getNameStructure(), fmuFileName);
MainWindow::instance()->getCommitChangesDialog()->generateTraceabilityURI("fmuExport", pLibraryTreeItem->getFileName(), pLibraryTreeItem->getNameStructure(), fmuFileName);
}
// hide progress bar
hideProgressBar();
Expand Down
39 changes: 23 additions & 16 deletions OMEdit/OMEditGUI/Traceability/TraceabilityInformationURI.cpp
Expand Up @@ -17,25 +17,27 @@ TraceabilityInformationURI::TraceabilityInformationURI()
{
}

void TraceabilityInformationURI::translateModelCreationURIToJsonMessageFormat(QString modelingActivity, QString toolURI, QString activityURI, QString agentURI, QString fileNameURI)
void TraceabilityInformationURI::translateModelCreationURIToJsonMessageFormat(QString modelingActivity, QString toolURI, QString activityURI, QString agentURI, QString fileNameURI, QString entityType, QString path, QString gitHash)
{
QString email, userName;
userName = OptionsDialog::instance()->getTraceabilityPage()->getUserName()->text();
email = OptionsDialog::instance()->getTraceabilityPage()->getEmail()->text();
QString jsonMessageFormat = QString("{\"rdf:RDF\" : {\n"
" \"xmlns:rdf\" : \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\",\n"
" \"xmlns:prov\": \"http://www.w3.org/ns/prov#\",\n"
" \"messageFormatVersion\": \"0.1\",\n"
" \"messageFormatVersion\": \"1.4\",\n"
" \"prov:Entity\": [\n"
" {\n"
" \"rdf:about\": \"%4\",\n"
" \"type\": \"softwareTool\",\n"
" \"type\": \"Simulation Tool\",\n"
" \"version\": \"OpenModelica\",\n"
" \"name\": \"OpenModelica\"\n"
" },\n"
" {\n"
" \"rdf:about\" : \"%1\",\n"
" \"path\" : \"%1\",\n"
" \"type\" : \"%7\",\n"
" \"path\" : \"%9\",\n"
" \"type\" : \"%8\",\n"
" \"hash\" : \"%10\",\n"
" \"prov:wasAttributedTo\": {\"prov:Agent\": {\"rdf:about\": \"%3\"}},\n"
" \"prov:wasGeneratedBy\": {\"prov:Activity\": {\"rdf:about\": \"%2\"}}\n"
" }\n"
Expand All @@ -44,22 +46,23 @@ void TraceabilityInformationURI::translateModelCreationURIToJsonMessageFormat(QS
" {\n"
" \"rdf:about\": \"%3\",\n"
" \"name\": \"%5\",\n"
" \"Email\": \"%6\"\n"
" \"email\": \"%6\"\n"
" }\n"
" ],\n"
" \"prov:Activity\": [\n"
" {\n"
" \"time\": \"2016-09-19T13:53:06Z\",\n"
" \"type\": \"%7\",\n"
" \"prov:wasAssociatedWith\": {\"prov:Agent\": {\"rdf:about\": \"%3\"}},\n"
" \"prov:used\": {\"prov:Entity\": {\"rdf:about\": \"%4\"}},\n"
" \"prov:used\": {\"prov:Entity\": [ {\"rdf:about\": \"%4\"}]},\n"
" \"rdf:about\": \"%2\"\n"
" }\n"
" ]\n"
"}}").arg(fileNameURI.simplified()).arg(activityURI.simplified()).arg(agentURI.simplified()).arg(toolURI.simplified()).arg(userName).arg(email).arg(modelingActivity);
"}}").arg(fileNameURI.simplified()).arg(activityURI.simplified()).arg(agentURI.simplified()).arg(toolURI.simplified()).arg(userName).arg(email).arg(modelingActivity).arg(entityType.simplified()).arg(path.simplified()).arg(gitHash.simplified());
sendTraceabilityInformation(jsonMessageFormat);
}

void TraceabilityInformationURI::translateURIToJsonMessageFormat(QString modelingActivity, QString toolURI, QString activityURI, QString agentURI, QString sourceModelFileNameURI, QString fmuFileNameURI)
void TraceabilityInformationURI::translateURIToJsonMessageFormat(QString modelingActivity, QString toolURI, QString activityURI, QString agentURI, QString sourceModelFileNameURI, QString fmuFileNameURI, QString entityType, QString path, QString gitHash)
{
QString email, userName;
userName = OptionsDialog::instance()->getTraceabilityPage()->getUserName()->text();
Expand All @@ -71,37 +74,41 @@ void TraceabilityInformationURI::translateURIToJsonMessageFormat(QString modelin
QString jsonMessageFormat = QString("{\"rdf:RDF\" : {\n"
" \"xmlns:rdf\" : \"http://www.w3.org/1999/02/22-rdf-syntax-ns#\",\n"
" \"xmlns:prov\": \"http://www.w3.org/ns/prov#\",\n"
" \"messageFormatVersion\": \"0.1\",\n"
" \"messageFormatVersion\": \"1.4\",\n"
" \"prov:Entity\": [\n"
" {\n"
" \"rdf:about\": \"%2\",\n"
" \"type\": \"softwareTool\",\n"
" \"type\": \"Simulation Tool\",\n"
" \"version\": \"OpenModelica\",\n"
" \"name\": \"OpenModelica\"\n"
" },\n"
" {\n"
" \"rdf:about\" : \"%3\",\n"
" \"type\" : \"%1\",\n"
" \"type\" : \"%9\",\n"
" \"path\" : \"%10\",\n"
" \"hash\" : \"%11\",\n"
" \"prov:wasAttributedTo\": {\"prov:Agent\": {\"rdf:about\": \"%4\"}},\n"
" \"prov:wasGeneratedBy\": {\"prov:Activity\": {\"rdf:about\": \"%5\"}},\n"
" \"prov:wasDerivedFrom\": [{\"prov:Entity\": {\"rdf:about\": \"%6\"}}]\n"
" \"prov:wasDerivedFrom\": {\"prov:Entity\": [{\"rdf:about\": \"%6\"}]}\n"
" }\n"
" ],\n "
" \"prov:Agent\": [\n"
" {\n"
" \"rdf:about\": \"%4\",\n"
" \"name\": \"%7\",\n"
" \"Email\": \"%8\"\n"
" \"email\": \"%8\"\n"
" }\n"
" ],\n"
" \"prov:Activity\": [\n"
" {\n"
" \"time\": \"2016-09-19T13:53:06Z\",\n"
" \"type\": \"%1\",\n"
" \"prov:wasAssociatedWith\": {\"prov:Agent\": {\"rdf:about\": \"%4\"}},\n"
" \"prov:used\": {\"prov:Entity\": {\"rdf:about\": \"%2\"}},\n"
" \"prov:used\": {\"prov:Entity\": [{\"rdf:about\": \"%2\"}]},\n"
" \"rdf:about\": \"%5\"\n"
" }\n"
" ]\n"
"}}").arg(modelingActivity.simplified()).arg(toolURI.simplified()).arg(fmuFileNameURI.simplified()).arg(agentURI.simplified()).arg(activityURI.simplified()).arg(sourceModelFileNameURI.simplified()).arg(userName).arg(email);
"}}").arg(modelingActivity.simplified()).arg(toolURI.simplified()).arg(fmuFileNameURI.simplified()).arg(agentURI.simplified()).arg(activityURI.simplified()).arg(sourceModelFileNameURI.simplified()).arg(userName).arg(email).arg(entityType.simplified()).arg(path.simplified()).arg(gitHash.simplified());
sendTraceabilityInformation(jsonMessageFormat);
}

Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditGUI/Traceability/TraceabilityInformationURI.h
Expand Up @@ -19,8 +19,8 @@ class TraceabilityInformationURI
{
public:
TraceabilityInformationURI();
void translateURIToJsonMessageFormat(QString modelingActivity, QString toolURI, QString activityURI, QString agentURI, QString sourceModelFileNameURI, QString fmuFileNameURI);
void translateModelCreationURIToJsonMessageFormat(QString modelingActivity, QString toolURI, QString activityURI, QString agentURI, QString fileNameURI);
void translateURIToJsonMessageFormat(QString modelingActivity, QString toolURI, QString activityURI, QString agentURI, QString sourceModelFileNameURI, QString fmuFileNameURI, QString entityType, QString path, QString gitHash);
void translateModelCreationURIToJsonMessageFormat(QString modelingActivity, QString toolURI, QString activityURI, QString agentURI, QString fileNameURI, QString entityType, QString path, QString gitHash);
void sendTraceabilityInformation(QString jsonMessageFormat);
private:
void translateURIToJsonMessageFormat();
Expand Down

0 comments on commit 2230a75

Please sign in to comment.