diff --git a/src/main/java/edu/kit/datamanager/mappingservice/rest/impl/MappingAdministrationController.java b/src/main/java/edu/kit/datamanager/mappingservice/rest/impl/MappingAdministrationController.java index 558560a..cdb1bff 100644 --- a/src/main/java/edu/kit/datamanager/mappingservice/rest/impl/MappingAdministrationController.java +++ b/src/main/java/edu/kit/datamanager/mappingservice/rest/impl/MappingAdministrationController.java @@ -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 diff --git a/src/main/java/edu/kit/datamanager/mappingservice/util/FileUtil.java b/src/main/java/edu/kit/datamanager/mappingservice/util/FileUtil.java index 01ad72d..aa38f02 100644 --- a/src/main/java/edu/kit/datamanager/mappingservice/util/FileUtil.java +++ b/src/main/java/edu/kit/datamanager/mappingservice/util/FileUtil.java @@ -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 @@ -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(); } } diff --git a/src/main/resources/static/JS/listSchemes.js b/src/main/resources/static/JS/listSchemes.js index c18cf50..56aef5b 100644 --- a/src/main/resources/static/JS/listSchemes.js +++ b/src/main/resources/static/JS/listSchemes.js @@ -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) { @@ -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); + }; } }