Skip to content

Commit

Permalink
Fix #26, deleting mappings is now possible
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasJejkal committed Jul 25, 2023
1 parent dc05a13 commit 1bc653f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ public ResponseEntity getMappingDocumentById(
LOG.trace("Mapping document at path {} either does not exist or is no file or is not readable. Returning HTTP INTERNAL_SERVER_ERROR.", mappingDocumentPath);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Metadata document on server either does not exist or is no file or is not readable.");
}

LOG.trace("Get ETag of MappingRecord.");
String etag = record.getEtag();

LOG.trace("Mapping document found. Returning result.");
return ResponseEntity.ok().header(HttpHeaders.CONTENT_LENGTH, String.valueOf(mappingDocumentPath.toFile().length())).body(new FileSystemResource(mappingDocumentPath.toFile()));
return ResponseEntity.ok().eTag("\"" + etag + "\"").header(HttpHeaders.CONTENT_LENGTH, String.valueOf(mappingDocumentPath.toFile().length())).body(new FileSystemResource(mappingDocumentPath.toFile()));
}

@Override
Expand Down
62 changes: 32 additions & 30 deletions src/main/resources/static/JS/listSchemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,60 @@ function getRecords() {
http.open("GET", apiUrl);
http.send();
http.onprogress = () => {
document.getElementById("progress").hidden = false
document.getElementById("progress").hidden = false;
}
http.onload = (e) => {
const results = JSON.parse(http.responseText);
if (results.length > 0) {
document.getElementById("nothingHere").hidden = true;
document.getElementById("progress").hidden = true
document.getElementById("progress").hidden = true;
}
for (let i = 0; i < results.length; i++) {
document.getElementById("progress").hidden = false
console.log(results[i].mappingId)
const schemaHttp = new XMLHttpRequest()
document.getElementById("progress").hidden = false;
console.log(results[i].mappingId);
const schemaHttp = new XMLHttpRequest();
var schema
var ETAG

schemaHttp.open("GET", apiUrl + results[i].mappingId)
schemaHttp.setRequestHeader("Content-Type", "application/json")
schemaHttp.send()
schemaHttp.open("GET", apiUrl + results[i].mappingId);
schemaHttp.setRequestHeader("Content-Type", "application/json");
schemaHttp.send();
schemaHttp.onload = (e) => {
schema = JSON.parse(schemaHttp.responseText)
ETAG = '"' + schemaHttp.getResponseHeader("If-Match") + '"'
console.log("Received Data:" + {
schema = JSON.parse(schemaHttp.responseText);
ETAG = schemaHttp.getResponseHeader("ETag");
console.log("Received Data:");
console.log({
"record": results[i],
"schema": schema,
"ETAG": ETAG
})
});
records.set(results[i].mappingId, {
"record": results[i],
"schema": schema,
"ETAG": ETAG
})
console.log(records)
addListElement(results[i].mappingId, results[i].mappingType, results[i].title, results[i].description)
}
console.log(records);
addListElement(results[i].mappingId, results[i].mappingType, results[i].title, results[i].description);
};
}
document.getElementById("progress").hidden = true
}
document.getElementById("progress").hidden = true
document.getElementById("progress").hidden = true;
};
document.getElementById("progress").hidden = true;
}

function mapWithMapping(id) {
const data = {
id: id,
type: records.get(id).record.mappingType
}
window.sessionStorage.setItem("data", JSON.stringify(data))
window.location = "mapDocument.html"
};
window.sessionStorage.setItem("data", JSON.stringify(data));
window.location = "mapDocument.html";
}

function editMapping(id) {
let sessionData = JSON.stringify(records.get(id))
window.sessionStorage.setItem("data", sessionData)
window.location = "./addScheme.html"
window.location = "./addScheme.html";
}

function downloadMapping(id) {
Expand All @@ -74,22 +75,23 @@ function downloadMapping(id) {
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
};
}

function deleteMapping(id) {
let mapEntry = records.get(id);
if (mapEntry != null && mapEntry.record.mappingId === id) {
console.log("Deleting mapping with id " + id);
if (mapEntry !== null && mapEntry.record.mappingId === id) {
const http = new XMLHttpRequest();
http.open("DELETE", apiUrl + id)
http.setRequestHeader("If-Match", mapEntry.ETAG)
http.open("DELETE", apiUrl + id);
http.setRequestHeader("If-Match", mapEntry.ETAG);
http.send();
http.onload = (e) => {
records.delete(id)
document.getElementById(id).remove()
records.delete(id);
document.getElementById(id).remove();
if (records.size < 1) document.getElementById("nothingHere").hidden = false;
console.log("Successfully deleted mapping with id " + id)
}
console.log("Successfully deleted mapping with id " + id);
};
}
}

Expand Down

0 comments on commit 1bc653f

Please sign in to comment.