Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for v1.0.2 #28

Merged
merged 10 commits into from
Jul 27, 2023
8 changes: 4 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: ./gradlew build -DapplicationProperties="src/test/resources/test-config/application-test.properties" -DpythonLocation=`which python3`
- name: Generate report
run: ./gradlew jacocoTestReport
- name: Codecov
uses: codecov/codecov-action@v1
with:
files: ./build/reports/jacoco/test/jacocoTestReport.xml
# - name: Codecov
# uses: codecov/codecov-action@v1
# with:
# files: ./build/reports/jacoco/test/jacocoTestReport.xml
2 changes: 1 addition & 1 deletion echo.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
echo @1
echo %*
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static List<Class<IMappingPlugin>> extractClassesFromJAR(File jar, Class
private static boolean isPluggableClass(Class<?> cls) {
for (Class<?> i : cls.getInterfaces()) {
LOG.trace("Checking {} against {}.", i, IMappingPlugin.class);
LOG.trace("ASSIGN {}", IMappingPlugin.class.isAssignableFrom(cls));
LOG.trace("ASSIGN {}", IMappingPlugin.class.isAssignableFrom(cls));
if (i.equals(IMappingPlugin.class)) {
LOG.trace("IMappingPlugin interface found.");
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2023 Karlsruhe Institute of Technology.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.kit.datamanager.mappingservice.plugins.impl;

import edu.kit.datamanager.mappingservice.plugins.*;
import edu.kit.datamanager.mappingservice.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.MimeType;
import org.springframework.util.MimeTypeUtils;
import java.nio.file.Path;

public class GemmaPlugin implements IMappingPlugin {

private final Logger LOGGER = LoggerFactory.getLogger(GemmaPlugin.class);
private static final String GEMMA_REPOSITORY = "https://github.com/kit-data-manager/gemma.git";
private static final String GEMMA_BRANCH = "master";
private static Path gemmaDir;
private boolean initialized = false;

@Override
public String name() {
return "GEMMA";
}

@Override
public String description() {
return "GEMMA is a tool written in Python that allows to map from JSON and XML to JSON. Furthermore, it allows to map with a mapping schema.";
}

@Override
public String version() {
return "1.0.0";
}

@Override
public String uri() {
return "https://github.com/kit-data-manager/gemma";
}

@Override
public MimeType[] inputTypes() {
return new MimeType[]{MimeTypeUtils.APPLICATION_JSON, MimeTypeUtils.APPLICATION_XML};
}

@Override
public MimeType[] outputTypes() {
return new MimeType[]{MimeTypeUtils.APPLICATION_JSON};
}

@Override
public void setup() {
LOGGER.info("Checking and installing dependencies for Gemma: gemma, xmltodict, wget");
try {
PythonRunnerUtil.runPythonScript("-m", "pip", "install", "xmltodict", "wget");
PythonRunnerUtil.runPythonScript("-m", new LoggerOutputStream(LOGGER, LoggerOutputStream.Level.DEBUG), new LoggerOutputStream(LOGGER, LoggerOutputStream.Level.DEBUG), "pip", "install", "xmltodict", "wget");
gemmaDir = FileUtil.cloneGitRepository(GEMMA_REPOSITORY, GEMMA_BRANCH);
initialized = true;
} catch (MappingPluginException e) {
LOGGER.error("Failed to setup plugin '" + name() + "' " + version() + ".", e);
}
}

@Override
public MappingPluginState mapFile(Path mappingFile, Path inputFile, Path outputFile) throws MappingPluginException {
if (initialized) {
LOGGER.trace("Run gemma on '{}' with mapping '{}' -> '{}'", inputFile, mappingFile, outputFile);
return PythonRunnerUtil.runPythonScript(gemmaDir + "/mapping_single.py", mappingFile.toString(), inputFile.toString(), outputFile.toString());
} else {
LOGGER.error("Plugin '" + name() + "' " + version() + " not initialized. Returning EXECUTION_ERROR.");
return MappingPluginState.EXECUTION_ERROR;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
* Copyright 2023 Karlsruhe Institute of Technology.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.kit.datamanager.mappingservice.plugins.impl;

import edu.kit.datamanager.mappingservice.plugins.IMappingPlugin;
import edu.kit.datamanager.mappingservice.plugins.MappingPluginException;
import edu.kit.datamanager.mappingservice.plugins.MappingPluginState;
import edu.kit.datamanager.mappingservice.util.ShellRunnerUtil;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
* Copyright 2023 Karlsruhe Institute of Technology.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package edu.kit.datamanager.mappingservice.plugins.impl;

Expand Down
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();
}
}
70 changes: 36 additions & 34 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()
var schema
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("Accept", "application/vnd.datamanager.mapping-record+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,
//"schema": schema,
"ETAG": ETAG
})
});
records.set(results[i].mappingId, {
"record": results[i],
"schema": schema,
//"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
Loading