Skip to content

Commit 3cf0e87

Browse files
authored
Merge pull request #28 from kit-data-manager/development
PR for v1.0.2
2 parents be8b281 + 7d1d847 commit 3cf0e87

File tree

9 files changed

+178
-56
lines changed

9 files changed

+178
-56
lines changed

.github/workflows/CI.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
run: ./gradlew build -DapplicationProperties="src/test/resources/test-config/application-test.properties" -DpythonLocation=`which python3`
4949
- name: Generate report
5050
run: ./gradlew jacocoTestReport
51-
- name: Codecov
52-
uses: codecov/codecov-action@v1
53-
with:
54-
files: ./build/reports/jacoco/test/jacocoTestReport.xml
51+
# - name: Codecov
52+
# uses: codecov/codecov-action@v1
53+
# with:
54+
# files: ./build/reports/jacoco/test/jacocoTestReport.xml

echo.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
echo @1
1+
echo %*

src/main/java/edu/kit/datamanager/mappingservice/plugins/PluginLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static List<Class<IMappingPlugin>> extractClassesFromJAR(File jar, Class
128128
private static boolean isPluggableClass(Class<?> cls) {
129129
for (Class<?> i : cls.getInterfaces()) {
130130
LOG.trace("Checking {} against {}.", i, IMappingPlugin.class);
131-
LOG.trace("ASSIGN {}", IMappingPlugin.class.isAssignableFrom(cls));
131+
LOG.trace("ASSIGN {}", IMappingPlugin.class.isAssignableFrom(cls));
132132
if (i.equals(IMappingPlugin.class)) {
133133
LOG.trace("IMappingPlugin interface found.");
134134
return true;
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2023 Karlsruhe Institute of Technology.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package edu.kit.datamanager.mappingservice.plugins.impl;
17+
18+
import edu.kit.datamanager.mappingservice.plugins.*;
19+
import edu.kit.datamanager.mappingservice.util.*;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
import org.springframework.util.MimeType;
23+
import org.springframework.util.MimeTypeUtils;
24+
import java.nio.file.Path;
25+
26+
public class GemmaPlugin implements IMappingPlugin {
27+
28+
private final Logger LOGGER = LoggerFactory.getLogger(GemmaPlugin.class);
29+
private static final String GEMMA_REPOSITORY = "https://github.com/kit-data-manager/gemma.git";
30+
private static final String GEMMA_BRANCH = "master";
31+
private static Path gemmaDir;
32+
private boolean initialized = false;
33+
34+
@Override
35+
public String name() {
36+
return "GEMMA";
37+
}
38+
39+
@Override
40+
public String description() {
41+
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.";
42+
}
43+
44+
@Override
45+
public String version() {
46+
return "1.0.0";
47+
}
48+
49+
@Override
50+
public String uri() {
51+
return "https://github.com/kit-data-manager/gemma";
52+
}
53+
54+
@Override
55+
public MimeType[] inputTypes() {
56+
return new MimeType[]{MimeTypeUtils.APPLICATION_JSON, MimeTypeUtils.APPLICATION_XML};
57+
}
58+
59+
@Override
60+
public MimeType[] outputTypes() {
61+
return new MimeType[]{MimeTypeUtils.APPLICATION_JSON};
62+
}
63+
64+
@Override
65+
public void setup() {
66+
LOGGER.info("Checking and installing dependencies for Gemma: gemma, xmltodict, wget");
67+
try {
68+
PythonRunnerUtil.runPythonScript("-m", "pip", "install", "xmltodict", "wget");
69+
PythonRunnerUtil.runPythonScript("-m", new LoggerOutputStream(LOGGER, LoggerOutputStream.Level.DEBUG), new LoggerOutputStream(LOGGER, LoggerOutputStream.Level.DEBUG), "pip", "install", "xmltodict", "wget");
70+
gemmaDir = FileUtil.cloneGitRepository(GEMMA_REPOSITORY, GEMMA_BRANCH);
71+
initialized = true;
72+
} catch (MappingPluginException e) {
73+
LOGGER.error("Failed to setup plugin '" + name() + "' " + version() + ".", e);
74+
}
75+
}
76+
77+
@Override
78+
public MappingPluginState mapFile(Path mappingFile, Path inputFile, Path outputFile) throws MappingPluginException {
79+
if (initialized) {
80+
LOGGER.trace("Run gemma on '{}' with mapping '{}' -> '{}'", inputFile, mappingFile, outputFile);
81+
return PythonRunnerUtil.runPythonScript(gemmaDir + "/mapping_single.py", mappingFile.toString(), inputFile.toString(), outputFile.toString());
82+
} else {
83+
LOGGER.error("Plugin '" + name() + "' " + version() + " not initialized. Returning EXECUTION_ERROR.");
84+
return MappingPluginState.EXECUTION_ERROR;
85+
}
86+
}
87+
}

src/main/java/edu/kit/datamanager/mappingservice/plugins/impl/IdentifyPlugin.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
/*
2-
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3-
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
2+
* Copyright 2023 Karlsruhe Institute of Technology.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
415
*/
516
package edu.kit.datamanager.mappingservice.plugins.impl;
617

718
import edu.kit.datamanager.mappingservice.plugins.IMappingPlugin;
819
import edu.kit.datamanager.mappingservice.plugins.MappingPluginException;
920
import edu.kit.datamanager.mappingservice.plugins.MappingPluginState;
1021
import edu.kit.datamanager.mappingservice.util.ShellRunnerUtil;
11-
import java.io.FileNotFoundException;
1222
import java.io.FileOutputStream;
1323
import java.io.IOException;
1424
import java.nio.file.Path;

src/main/java/edu/kit/datamanager/mappingservice/plugins/impl/TestPlugin.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
/*
2-
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3-
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
2+
* Copyright 2023 Karlsruhe Institute of Technology.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
415
*/
516
package edu.kit.datamanager.mappingservice.plugins.impl;
617

src/main/java/edu/kit/datamanager/mappingservice/rest/impl/MappingAdministrationController.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,12 @@ public ResponseEntity getMappingDocumentById(
219219
LOG.trace("Mapping document at path {} either does not exist or is no file or is not readable. Returning HTTP INTERNAL_SERVER_ERROR.", mappingDocumentPath);
220220
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Metadata document on server either does not exist or is no file or is not readable.");
221221
}
222+
223+
LOG.trace("Get ETag of MappingRecord.");
224+
String etag = record.getEtag();
225+
222226
LOG.trace("Mapping document found. Returning result.");
223-
return ResponseEntity.ok().header(HttpHeaders.CONTENT_LENGTH, String.valueOf(mappingDocumentPath.toFile().length())).body(new FileSystemResource(mappingDocumentPath.toFile()));
227+
return ResponseEntity.ok().eTag("\"" + etag + "\"").header(HttpHeaders.CONTENT_LENGTH, String.valueOf(mappingDocumentPath.toFile().length())).body(new FileSystemResource(mappingDocumentPath.toFile()));
224228
}
225229

226230
@Override

src/main/java/edu/kit/datamanager/mappingservice/util/FileUtil.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ public static Path cloneGitRepository(String repositoryUrl, String branch) {
292292
}
293293

294294
/**
295-
* This method clones a git repository into the 'lib' folder.
295+
* This method clones a git repository into the 'lib' folder. If the folder
296+
* already exists, a pull is performed.
296297
*
297298
* @param repositoryUrl the url of the repository to clone
298299
* @param branch the branch to clone
@@ -301,17 +302,24 @@ public static Path cloneGitRepository(String repositoryUrl, String branch) {
301302
*/
302303
public static Path cloneGitRepository(String repositoryUrl, String branch, String targetFolder) {
303304
File target = new File(targetFolder);
304-
target.mkdirs();
305+
if (target.exists()) {
306+
try {
307+
Git.open(target).pull().call();
308+
} catch (IOException | JGitInternalException | GitAPIException e) {
309+
LOGGER.error("Error pulling git repository at '" + target + "'!", e);
310+
throw new MappingException("Error pulling git repository at '" + target + "'!", e);
311+
}
312+
} else {
313+
target.mkdirs();
305314

306-
LOGGER.info("Cloning branch '{}' of repository '{}' to '{}'", branch, repositoryUrl, target.getPath());
307-
try {
308-
Git.cloneRepository().setURI(repositoryUrl).setBranch(branch).setDirectory(target).call();
309-
} catch (JGitInternalException e) {
310-
LOGGER.info(e.getMessage());
311-
} catch (GitAPIException ex) {
312-
throw new MappingException("Error cloning git repository '" + repositoryUrl + "' to '" + target + "'!", ex);
315+
LOGGER.info("Cloning branch '{}' of repository '{}' to '{}'", branch, repositoryUrl, target.getPath());
316+
try {
317+
Git.cloneRepository().setURI(repositoryUrl).setBranch(branch).setDirectory(target).call();
318+
} catch (JGitInternalException | GitAPIException e) {
319+
LOGGER.error("Error cloning git repository '" + repositoryUrl + "' to '" + target + "'!", e);
320+
throw new MappingException("Error cloning git repository '" + repositoryUrl + "' to '" + target + "'!", e);
321+
}
313322
}
314-
315323
return target.toPath();
316324
}
317325
}

src/main/resources/static/JS/listSchemes.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,60 @@ function getRecords() {
77
http.open("GET", apiUrl);
88
http.send();
99
http.onprogress = () => {
10-
document.getElementById("progress").hidden = false
11-
}
10+
document.getElementById("progress").hidden = false;
11+
};
1212
http.onload = (e) => {
1313
const results = JSON.parse(http.responseText);
1414
if (results.length > 0) {
1515
document.getElementById("nothingHere").hidden = true;
16-
document.getElementById("progress").hidden = true
16+
document.getElementById("progress").hidden = true;
1717
}
1818
for (let i = 0; i < results.length; i++) {
19-
document.getElementById("progress").hidden = false
20-
console.log(results[i].mappingId)
21-
const schemaHttp = new XMLHttpRequest()
22-
var schema
19+
document.getElementById("progress").hidden = false;
20+
console.log(results[i].mappingId);
21+
const schemaHttp = new XMLHttpRequest();
22+
//var schema
2323
var ETAG
2424

25-
schemaHttp.open("GET", apiUrl + results[i].mappingId)
26-
schemaHttp.setRequestHeader("Content-Type", "application/json")
27-
schemaHttp.send()
25+
schemaHttp.open("GET", apiUrl + results[i].mappingId);
26+
schemaHttp.setRequestHeader("Accept", "application/vnd.datamanager.mapping-record+json");
27+
schemaHttp.send();
2828
schemaHttp.onload = (e) => {
29-
schema = JSON.parse(schemaHttp.responseText)
30-
ETAG = '"' + schemaHttp.getResponseHeader("If-Match") + '"'
31-
console.log("Received Data:" + {
29+
// schema = JSON.parse(schemaHttp.responseText);
30+
ETAG = schemaHttp.getResponseHeader("ETag");
31+
console.log("Received Data:");
32+
console.log({
3233
"record": results[i],
33-
"schema": schema,
34+
//"schema": schema,
3435
"ETAG": ETAG
35-
})
36+
});
3637
records.set(results[i].mappingId, {
3738
"record": results[i],
38-
"schema": schema,
39+
//"schema": schema,
3940
"ETAG": ETAG
4041
})
41-
console.log(records)
42-
addListElement(results[i].mappingId, results[i].mappingType, results[i].title, results[i].description)
43-
}
42+
console.log(records);
43+
addListElement(results[i].mappingId, results[i].mappingType, results[i].title, results[i].description);
44+
};
4445
}
45-
document.getElementById("progress").hidden = true
46-
}
47-
document.getElementById("progress").hidden = true
46+
document.getElementById("progress").hidden = true;
47+
};
48+
document.getElementById("progress").hidden = true;
4849
}
4950

5051
function mapWithMapping(id) {
5152
const data = {
5253
id: id,
5354
type: records.get(id).record.mappingType
54-
}
55-
window.sessionStorage.setItem("data", JSON.stringify(data))
56-
window.location = "mapDocument.html"
55+
};
56+
window.sessionStorage.setItem("data", JSON.stringify(data));
57+
window.location = "mapDocument.html";
5758
}
5859

5960
function editMapping(id) {
6061
let sessionData = JSON.stringify(records.get(id))
6162
window.sessionStorage.setItem("data", sessionData)
62-
window.location = "./addScheme.html"
63+
window.location = "./addScheme.html";
6364
}
6465

6566
function downloadMapping(id) {
@@ -74,22 +75,23 @@ function downloadMapping(id) {
7475
document.body.appendChild(element);
7576
element.click();
7677
document.body.removeChild(element);
77-
}
78+
};
7879
}
7980

8081
function deleteMapping(id) {
8182
let mapEntry = records.get(id);
82-
if (mapEntry != null && mapEntry.record.mappingId === id) {
83+
console.log("Deleting mapping with id " + id);
84+
if (mapEntry !== null && mapEntry.record.mappingId === id) {
8385
const http = new XMLHttpRequest();
84-
http.open("DELETE", apiUrl + id)
85-
http.setRequestHeader("If-Match", mapEntry.ETAG)
86+
http.open("DELETE", apiUrl + id);
87+
http.setRequestHeader("If-Match", mapEntry.ETAG);
8688
http.send();
8789
http.onload = (e) => {
88-
records.delete(id)
89-
document.getElementById(id).remove()
90+
records.delete(id);
91+
document.getElementById(id).remove();
9092
if (records.size < 1) document.getElementById("nothingHere").hidden = false;
91-
console.log("Successfully deleted mapping with id " + id)
92-
}
93+
console.log("Successfully deleted mapping with id " + id);
94+
};
9395
}
9496
}
9597

0 commit comments

Comments
 (0)