Skip to content

Commit

Permalink
Merge pull request #27 from kit-data-manager/issue-26-Deletion_of_map…
Browse files Browse the repository at this point in the history
…ping_via_UI_fails

Deletion of mapping via UI fails
  • Loading branch information
ThomasJejkal authored Jul 25, 2023
2 parents 09a058d + fd56374 commit 74de485
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 41 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
28 changes: 18 additions & 10 deletions src/main/java/edu/kit/datamanager/mappingservice/util/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ public static Path cloneGitRepository(String repositoryUrl, String branch) {
}

/**
* This method clones a git repository into the 'lib' folder.
* This method clones a git repository into the 'lib' folder. If the folder
* already exists, a pull is performed.
*
* @param repositoryUrl the url of the repository to clone
* @param branch the branch to clone
Expand All @@ -301,17 +302,24 @@ public static Path cloneGitRepository(String repositoryUrl, String branch) {
*/
public static Path cloneGitRepository(String repositoryUrl, String branch, String targetFolder) {
File target = new File(targetFolder);
target.mkdirs();
if (target.exists()) {
try {
Git.open(target).pull().call();
} catch (IOException | JGitInternalException | GitAPIException e) {
LOGGER.error("Error pulling git repository at '" + target + "'!", e);
throw new MappingException("Error pulling git repository at '" + target + "'!", e);
}
} else {
target.mkdirs();

LOGGER.info("Cloning branch '{}' of repository '{}' to '{}'", branch, repositoryUrl, target.getPath());
try {
Git.cloneRepository().setURI(repositoryUrl).setBranch(branch).setDirectory(target).call();
} catch (JGitInternalException e) {
LOGGER.info(e.getMessage());
} catch (GitAPIException ex) {
throw new MappingException("Error cloning git repository '" + repositoryUrl + "' to '" + target + "'!", ex);
LOGGER.info("Cloning branch '{}' of repository '{}' to '{}'", branch, repositoryUrl, target.getPath());
try {
Git.cloneRepository().setURI(repositoryUrl).setBranch(branch).setDirectory(target).call();
} catch (JGitInternalException | GitAPIException e) {
LOGGER.error("Error cloning git repository '" + repositoryUrl + "' to '" + target + "'!", e);
throw new MappingException("Error cloning git repository '" + repositoryUrl + "' to '" + target + "'!", e);
}
}

return target.toPath();
}
}
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 74de485

Please sign in to comment.