Skip to content

Commit

Permalink
Fix windows bug by refactoring the creation step (no csv anymore) and…
Browse files Browse the repository at this point in the history
… use of MS Edge browser
  • Loading branch information
plglaser committed Oct 3, 2022
1 parent 3de86f6 commit 22dca56
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 46 deletions.
13 changes: 5 additions & 8 deletions kganalysis/files/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
Expand All @@ -8,10 +8,9 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/yeti/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
</head>
<body onload="draw()">
<body>
<div class="container-fluid main-container">
<div class="row panel-row">

<!-- Left Panel -->
<div class="col-8" id="leftPanel">
<div id="toolbar">
Expand All @@ -31,7 +30,6 @@
<!-- neovis visualization -->
<div id="viz">Loading...</div>
</div>

<!-- Right Panel -->
<div class="col-4 mt-2 justify-content-between">
<ul class="nav nav-pills mb-3 nav-justified" id="pills-tab" role="tablist">
Expand All @@ -44,7 +42,6 @@
</ul>
<hr>
<div class="tab-content mb-5" id="pills-tabContent">

<!-- General Tab -->
<div class="tab-pane fade show active" id="general-tab" role="tabpanel" aria-labelledby="general-container-tab">
<!-- Filters -->
Expand Down Expand Up @@ -156,8 +153,8 @@ <h5><i class="bi bi-card-list"></i> Smells</h5>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-fQybjgWLrvvRgtW6bFlB7jaZrFsaBXjsOMm/tB9LTS58ONXgqbR9W8oWht/amnpF" crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected].0-alpha.9"></script>
<script type="text/javascript" src="smells.js"></script>
<script type="text/javascript" src="index.js"></script>
<script src="https://unpkg.com/[email protected].2"></script>
<script src="smells.js"></script>
<script src="index.js"></script>
</body>
</html>
34 changes: 17 additions & 17 deletions kganalysis/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,27 @@ function drawSmells() {
viz.render();
}

$(document).ready(function() {
$(window).ready(function() {
// Update EA Smells tab with data from smells.js
smells.forEach(function(currentValue, index) {
var $card = $("<div>", {class: "list-group-item d-flex justify-content-between align-items-center"});
var $smellName = $("<h6>", {class: "ml-2", text: smells[index].name});
var $button = $("<button>", {class: "btn btn-sm btn-warning mr-2", text: "Detect"});
smells.forEach(function(currentValue, index) {
var $card = $("<div>", {class: "list-group-item d-flex justify-content-between align-items-center"});
var $smellName = $("<h6>", {class: "ml-2", text: smells[index].name});
var $button = $("<button>", {class: "btn btn-sm btn-warning mr-2", text: "Detect"});

// event listener to update info once smell is clicked
$button.click(function() {
$("#cypher").val(smells[index].query);
drawSmells();
$("#smellName").text(smells[index].name);
$("#smellDescription").text("Description: " + smells[index].description);
$("#smellSolution").text("Solution: " + smells[index].solution);
});

$card.append($smellName, $button);
$("#smells-list").append($card);
// event listener to update info once smell is clicked
$button.click(function() {
$("#cypher").val(smells[index].query);
drawSmells();
$("#smellName").text(smells[index].name);
$("#smellDescription").text("Description: " + smells[index].description);
$("#smellSolution").text("Solution: " + smells[index].solution);
});

$card.append($smellName, $button);
$("#smells-list").append($card);
});
draw();
});

// -- Show Graph --
$("#getAll").click(async function () {
Expand Down Expand Up @@ -248,7 +249,6 @@ $("#apply").click(async function () {
});
query = query.slice(0, query.length - 4);
query += ") OPTIONAL MATCH (n)-[r]->(m) RETURN n, r";
console.log(query);
$("#cypher").val(query);
viz.stabilize();
draw();
Expand Down
8 changes: 4 additions & 4 deletions kganalysis/files/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@
color: lightgray;
}
.vis-button.vis-up:after {
content: "";
content: "";
}
.vis-button.vis-down:after {
content: "";
content: "";
}
.vis-button.vis-left:after {
content: "";
content: "";
}
.vis-button.vis-right:after {
content: "";
content: "";
}
.vis-button.vis-zoomIn:after {
content: "+";
Expand Down
84 changes: 79 additions & 5 deletions kganalysis/src/kganalysis/db/KGExporter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package kganalysis.db;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
Expand All @@ -9,15 +8,29 @@
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import com.archimatetool.editor.ui.ColorFactory;
import com.archimatetool.editor.utils.PlatformUtils;
import com.archimatetool.model.FolderType;
import com.archimatetool.model.IAccessRelationship;
import com.archimatetool.model.IActiveStructureElement;
import com.archimatetool.model.IArchimateConcept;
import com.archimatetool.model.IArchimateElement;
import com.archimatetool.model.IArchimateModel;
import com.archimatetool.model.IArchimateRelationship;
import com.archimatetool.model.IAssignmentRelationship;
import com.archimatetool.model.IAssociationRelationship;
import com.archimatetool.model.IBehaviorElement;
import com.archimatetool.model.ICompositionRelationship;
import com.archimatetool.model.IDependendencyRelationship;
import com.archimatetool.model.IDynamicRelationship;
import com.archimatetool.model.IFolder;
import com.archimatetool.model.IInfluenceRelationship;
import com.archimatetool.model.IMotivationElement;
import com.archimatetool.model.IOtherRelationship;
import com.archimatetool.model.IPassiveStructureElement;
import com.archimatetool.model.IRealizationRelationship;
import com.archimatetool.model.IServingRelationship;
import com.archimatetool.model.ISpecializationRelationship;
import com.archimatetool.model.IStructuralRelationship;
import com.archimatetool.model.ITriggeringRelationship;
import kganalysis.KGPlugin;


Expand All @@ -39,7 +52,7 @@ public void export(IArchimateModel model) {

// Use the model folders to retrieve and store the elements/relations
model.getFolders().stream().forEach(e -> storeNodes(e));
storeRelationships();
storeRelationships2(model.getFolder(FolderType.RELATIONS));

// Run graph algorithms on all nodes
KGDatabase db = KGPlugin.INSTANCE.getKGDatabase();
Expand Down Expand Up @@ -72,7 +85,37 @@ private void storeNodes(IFolder folder) {
tx.commit();
}
}


private void storeRelationships2(IFolder folder) {
List<IArchimateConcept> concepts = getConcepts(folder);
if (concepts.isEmpty()) {
return;
}

for (IArchimateConcept concept : concepts) {
if (concept instanceof IArchimateRelationship) {
String relId = concept.getId();
String doc = concept.getDocumentation();
String name = concept.eClass().getName();
String type = getType(((IArchimateRelationship) concept));
String sourceId = ((IArchimateRelationship) concept).getSource().getId();
String targetId = ((IArchimateRelationship) concept).getTarget().getId();
if (sourceId.isEmpty() || targetId.isEmpty()) {
continue;
}

try (Transaction tx = graphDb.beginTx()) {
tx.execute("MATCH (n {id:'" + sourceId + "'}), (m {id:'" + targetId + "'}) WITH n, m\n" +
"CREATE (n)-[:RELATIONSHIP {id:'" + relId + "', type:'" + type + "', documentation:'" + doc + "', name:'" + name + "'}]->(m)");
tx.commit();
}
}
}

}

// Old method to store relationships by using the CSV export. TODO: Remove this
/*
private void storeRelationships() {
File folder = KGPlugin.KG_FOLDER;
File relationsFile = new File(folder.getAbsolutePath(), "relations.csv");
Expand All @@ -90,8 +133,8 @@ private void storeRelationships() {
+ " CREATE (n)-[:RELATIONSHIP {id:line.ID, type:line.Type, documentation:line.Documentation, name:line.Name}]->(m)");
tx.commit();
}

}
*/

// Adapted from {@link CSVExporter} to return the concepts (elements) of a folder
private List<IArchimateConcept> getConcepts(IFolder folder) {
Expand Down Expand Up @@ -125,5 +168,36 @@ else if (element instanceof IMotivationElement)

return "other";
}

private String getType(IArchimateRelationship relationship) {
if (relationship instanceof IAccessRelationship)
return "AccessRelationship";
else if (relationship instanceof IAssignmentRelationship)
return "AssignmentRelationship";
else if (relationship instanceof IAssociationRelationship)
return "AssociationRelationship";
else if (relationship instanceof ICompositionRelationship)
return "CompositionRelationship";
else if (relationship instanceof IDependendencyRelationship)
return "DependencyRelationship";
else if (relationship instanceof IDynamicRelationship)
return "DynamicRelationship";
else if (relationship instanceof IInfluenceRelationship)
return "InfluenceRelationship";
else if (relationship instanceof IOtherRelationship)
return "OtherRelationship";
else if (relationship instanceof IRealizationRelationship)
return "RealizationRelationship";
else if (relationship instanceof IServingRelationship)
return "ServingRelationship";
else if (relationship instanceof ISpecializationRelationship)
return "SpecializationRelationship";
else if (relationship instanceof IStructuralRelationship)
return "StructuralRelationship";
else if (relationship instanceof ITriggeringRelationship)
return "TriggeringRelationship";

return "Other";
}

}
21 changes: 16 additions & 5 deletions kganalysis/src/kganalysis/handlers/ShowKGHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,35 @@
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.browser.Browser;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.handlers.HandlerUtil;

import com.archimatetool.editor.ArchiPlugin;
import com.archimatetool.editor.browser.BrowserEditorInput;
import com.archimatetool.editor.browser.IBrowserEditor;
import com.archimatetool.editor.browser.IBrowserEditorInput;
import com.archimatetool.editor.preferences.IPreferenceConstants;
import com.archimatetool.editor.ui.services.EditorManager;
import com.archimatetool.editor.utils.PlatformUtils;

import kganalysis.KGPlugin;


public class ShowKGHandler extends AbstractHandler {

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (PlatformUtils.isWindows() && !ArchiPlugin.PREFERENCES.getBoolean(IPreferenceConstants.EDGE_BROWSER)) {
MessageDialog.openError(HandlerUtil.getActiveShell(event), "Error opening Visualization", "Please enable the 'Use MS Edge' option in the Preferences to open the Knowledge Graph Visualization");
return null;
}

File file = new File(KGPlugin.KG_FOLDER, "index.html");
BrowserEditorInput input = new BrowserEditorInput(file.getPath(), "Knowledge Graph");
IBrowserEditorInput input = new BrowserEditorInput("file:///" + file.getPath(), "Knowledge Graph");
IBrowserEditor editor = (IBrowserEditor) EditorManager.openEditor(input, IBrowserEditor.ID);
final Browser browser = editor.getBrowser();

if (editor != null && browser != null) {
browser.refresh();
if (editor != null && editor.getBrowser() != null) {
editor.getBrowser().refresh();
}

return null;
Expand Down
11 changes: 4 additions & 7 deletions kganalysis/src/kganalysis/views/KnowledgeGraphWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.swt.widgets.Display;
import com.archimatetool.csv.export.CSVExporter;
import com.archimatetool.editor.Logger;
import com.archimatetool.model.IArchimateModel;
import kganalysis.KGPlugin;
Expand Down Expand Up @@ -58,20 +57,18 @@ public void runWithProgress() throws InvocationTargetException, InterruptedExcep
// 1) Create and start new neo4j Graph DB
KGDatabase db = KGPlugin.INSTANCE.getKGDatabase();
db.createDb();

// 2) Export model as CSV (used for relationships)
CSVExporter csvExporter = new CSVExporter(model);
csvExporter.export(KGPlugin.KG_FOLDER);

// 3) Copy files for browser
// 2) Copy files for browser
copyFile("index.html");
copyFile("index.js");
copyFile("smells.js");
copyFile("styles.css");

// 4) Transform ArchiMate model and store in DB
// 3) Create nodes and relationships from ArchiMate model and run graph algorithms
KGExporter kgExporter = KGPlugin.INSTANCE.getExporter();
kgExporter.export(model);

// 4) EA Smell Detection
// TODO: fix this
new SmellDetectionProvider();

Expand Down

0 comments on commit 22dca56

Please sign in to comment.