Skip to content

Commit

Permalink
Landing page + client page + relationship bug correction
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-ennahdi committed Nov 18, 2024
1 parent 6a9f115 commit 560f7c0
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
66 changes: 66 additions & 0 deletions objectmorph-app/src/main/resources/public/client.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Objectmorph-Sample-Client</title>
</head>
<body>
<h1>Objectmorph Sample Client</h1>
<h3>
This page executes client side code. It can be downloaded and executed locally.
</h3>
<div align="center" >
<textarea id="notepad" placeholder="drag and drop Java source code files here" cols="64" rows="16"></textarea>
</div>
</body>
<script>
var notepad = document.getElementById('notepad');
var files = [];
function dropfile(file) {
var reader = new FileReader();
reader.onload = function(e) {
files.push(e.target.result);
};
reader.readAsText(file, "UTF-8");
}

notepad.ondrop = function(e) {
e.preventDefault();
e.dataTransfer.setData("text/plain","data set in dragstart");
for (const file of e.dataTransfer.files) {
if (!file.name.includes(".java")) {
continue;
}
dropfile(file);
}
setTimeout(() => {
UserAction(files);
}, 250);
files = [];
};

function UserAction(file) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
const winUrl = URL.createObjectURL(
new Blob([this.responseText], { type: "text/html" })
);

const win = window.open(
winUrl,
"win",
`width=512,height=512`
);
}
};
// var url = "https://objectmorph-app.onrender.com/html";
var url = "http://localhost:8080/html";
xhttp.open("POST", url, true);
var data = new FormData();
data.append('sourceCode', file);
xhttp.send(data);
}
</script>
</html>
16 changes: 11 additions & 5 deletions objectmorph-app/src/main/resources/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@
</head>
<body>
<h1>ObjectMorph application</h1>

The HTML endpoint: <a href="/html" >HTML Renderer</a>.

<br /><br />
The Swagger page: <a href="/swagger-ui/index.html" >HTML Renderer</a>
<div>
<p>
The HTML endpoint: <a href="/html" >HTML Renderer</a>.
</p>
<p>
The Swagger page <a href="/swagger-ui/index.html" >here</a>.
</p>
<p>
Access to the sample client <a href="/client.html" >here</a>.
</p>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public List<Relation> getGeneralizationRelations() {
JavaClassInterpreter interpreter2 = interpreters.get(j);

if (interpreter1.getSuperClassName().equals(interpreter2.getClassName())) {
relations.add(new Relation(interpreter2.getClassName(), interpreter1.getSuperClassName(), LinkTypes.GENERALIZATION));
relations.add(new Relation(interpreter1.getClassName(), interpreter2.getClassName(), LinkTypes.GENERALIZATION));
} else if (interpreter2.getSuperClassName().equals(interpreter1.getClassName())) {
relations.add(new Relation(interpreter2.getClassName(), interpreter1.getClassName(), LinkTypes.GENERALIZATION));
}
Expand Down Expand Up @@ -60,14 +60,16 @@ private List<Relation> establishRelation(JavaClassInterpreter interpreter1, Java
for (FieldDeclaration fieldDeclaration : fields1) {
VariableDeclarator varDecl = fieldDeclaration.getVariables().get(0);
if (varDecl.getTypeAsString().equalsIgnoreCase(interpreter2.getClassName())) {
relations.add(new Relation(interpreter1.getClassName(), interpreter2.getClassName(), LinkTypes.ASSOCIATION));
if (!relations.stream().anyMatch(e -> e.getFrom().equals(interpreter1.getClassName())))
relations.add(new Relation(interpreter1.getClassName(), interpreter2.getClassName(), LinkTypes.ASSOCIATION));
}
}

for (FieldDeclaration fieldDeclaration : fields2) {
VariableDeclarator varDecl = fieldDeclaration.getVariables().get(0);
if (varDecl.getTypeAsString().equalsIgnoreCase(interpreter1.getClassName())) {
relations.add(new Relation(interpreter2.getClassName(), interpreter1.getClassName(), LinkTypes.ASSOCIATION));
if (!relations.stream().anyMatch(e -> e.getFrom().equals(interpreter2.getClassName())))
relations.add(new Relation(interpreter2.getClassName(), interpreter1.getClassName(), LinkTypes.ASSOCIATION));
}
}

Expand Down

0 comments on commit 560f7c0

Please sign in to comment.