Skip to content

Commit 4a7a149

Browse files
committed
Fixed problem with title
some cleanup
1 parent 2f2bbfa commit 4a7a149

File tree

12 files changed

+72
-92
lines changed

12 files changed

+72
-92
lines changed

src/main/java/edu/kit/datamanager/mappingservice/MappingServiceApplication.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,7 @@ public static void main(String[] args) {
5555
SpringApplication.run(MappingServiceApplication.class, args);
5656
System.out.println("Mapping service is running! Access it at http://localhost:8095");
5757

58-
// PluginManager.reloadPlugins();
59-
6058
PluginManager.soleInstance().getListOfAvailableValidators().forEach(System.out::println);
6159
PythonRunnerUtil.printPythonVersion();
62-
// try {
63-
// ShellRunnerUtil.run(new String[]{"ls", "-la"});
64-
// } catch (MappingPluginException e) {
65-
// e.printStackTrace();
66-
// }
6760
}
6861
}

src/main/java/edu/kit/datamanager/mappingservice/configuration/ApplicationProperties.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ public class ApplicationProperties extends GenericPluginProperties {
4141
@Value("${mapping-service.pythonLocation}")
4242
private URL pythonLocation;
4343

44-
/**
45-
* The path to the gemma mapping script 'mapping_single.py'
46-
*/
47-
@edu.kit.datamanager.annotations.LocalFileURL
48-
@Value("${mapping-service.gemmaLocation}")
49-
private URL gemmaLocation;
44+
// /**
45+
// * The path to the gemma mapping script 'mapping_single.py'
46+
// */
47+
// @edu.kit.datamanager.annotations.LocalFileURL
48+
// @Value("${mapping-service.gemmaLocation}")
49+
// private URL gemmaLocation;
5050

5151
/**
5252
* The absolute path where the mappings are stored.
5353
*/
5454
@edu.kit.datamanager.annotations.LocalFolderURL
55-
@Value("${mapping-service.mappingsLocation}")
55+
@Value("${mapping-service.mappingSchemasLocation}")
5656
private URL mappingsLocation;
5757
}

src/main/java/edu/kit/datamanager/mappingservice/domain/MappingRecord.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,27 @@ public class MappingRecord implements EtagSupport, Serializable {
4242
public final static MediaType MAPPING_RECORD_MEDIA_TYPE = MediaType.valueOf("application/vnd.datamanager.mapping-record+json");
4343

4444
@Id
45-
// @NotBlank(message = "The unique identify of the record.")
45+
@NotNull(message = "The unique identify of the record.")
4646
private String mappingId;
47+
4748
@Id
48-
// @NotBlank(message = "Type of the mapping, e.g. GEMMA, XSLT, handlebars, ....")
49+
@NotNull(message = "Type of the mapping, e.g. GEMMA, XSLT, handlebars, ....")
4950
private String mappingType;
51+
52+
@NotNull(message = "Title of the mapping.")
53+
private String title;
54+
55+
@NotNull(message = "Description of the mapping.")
56+
private String description;
57+
5058
@NotNull(message = "A list of access control entries for resticting access.")
5159
@OneToMany(cascade = javax.persistence.CascadeType.ALL, orphanRemoval = true)
5260
private final Set<AclEntry> acl = new HashSet<>();
53-
// @NotBlank(message = "The metadata document uri, e.g. pointing to a local file.")
61+
62+
@NotNull(message = "The metadata document uri, e.g. pointing to a local file.")
5463
private String mappingDocumentUri;
55-
// @NotBlank(message = "The SHA-1 hash of the associated metadata file. The hash is used for comparison while updating.")
64+
65+
@NotNull(message = "The SHA-1 hash of the associated metadata file. The hash is used for comparison while updating.")
5666
private String documentHash;
5767

5868
/**

src/main/java/edu/kit/datamanager/mappingservice/impl/MappingService.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void createMapping(String content, MappingRecord mappingRecord) throws IO
7979
Iterable<MappingRecord> findMapping = mappingRepo.findByMappingIdInOrMappingTypeIn(Arrays.asList(mappingRecord.getMappingId()), Arrays.asList((String) null));
8080
if (findMapping.iterator().hasNext()) {
8181
mappingRecord = findMapping.iterator().next();
82-
throw new MappingException("Error: Mapping '" + mappingRecord.getMappingId() + "/" + mappingRecord.getMappingType() + "' already exists!");
82+
throw new MappingException("Error: Mapping '" + mappingRecord.getMappingType() + "_" + mappingRecord.getMappingId() + "' already exists!");
8383
}
8484
saveMappingFile(content, mappingRecord);
8585
mappingRepo.save(mappingRecord);
@@ -94,7 +94,7 @@ public void createMapping(String content, MappingRecord mappingRecord) throws IO
9494
public void updateMapping(String content, MappingRecord mappingRecord) throws IOException {
9595
Optional<MappingRecord> findMapping = mappingRepo.findByMappingIdAndMappingType(mappingRecord.getMappingId(), mappingRecord.getMappingType());
9696
if (!findMapping.isPresent()) {
97-
throw new MappingException("Error: Mapping '" + mappingRecord.getMappingId() + "/" + mappingRecord.getMappingType() + "' doesn't exist!");
97+
throw new MappingException("Error: Mapping '" + mappingRecord.getMappingType() + "_" + mappingRecord.getMappingId() + "' doesn't exist!");
9898
}
9999
mappingRecord.setMappingDocumentUri(findMapping.get().getMappingDocumentUri());
100100
saveMappingFile(content, mappingRecord);
@@ -109,7 +109,7 @@ public void updateMapping(String content, MappingRecord mappingRecord) throws IO
109109
public void deleteMapping(MappingRecord mappingRecord) throws IOException {
110110
Optional<MappingRecord> findMapping = mappingRepo.findByMappingIdAndMappingType(mappingRecord.getMappingId(), mappingRecord.getMappingType());
111111
if (!findMapping.isPresent()) {
112-
throw new MappingException("Error: Mapping '" + mappingRecord.getMappingId() + "/" + mappingRecord.getMappingType() + "' doesn't exist!");
112+
throw new MappingException("Error: Mapping '" + mappingRecord.getMappingType() + "_" + mappingRecord.getMappingId() + "' doesn't exist!");
113113
}
114114
mappingRecord = findMapping.get();
115115
deleteMappingFile(mappingRecord);
@@ -187,8 +187,6 @@ public List<Path> executeMapping(URI contentUrl, String mappingId) throws Mappin
187187
*/
188188
private void init(ApplicationProperties applicationProperties) throws URISyntaxException {
189189
if ((applicationProperties != null) && (applicationProperties.getMappingsLocation() != null)) {
190-
PluginManager.reloadPlugins();
191-
// mappingUtil = new MappingUtil(applicationProperties);
192190
try {
193191
mappingsDirectory = Files.createDirectories(new File(applicationProperties.getMappingsLocation().getPath()).getAbsoluteFile().toPath());
194192
} catch (IOException e) {
@@ -212,7 +210,6 @@ private void saveMappingFile(String content, MappingRecord mapping) throws IOExc
212210
LOGGER.debug("Storing mapping file with id '{}' and type '{}'", mapping.getMappingId(), mapping.getMappingType());
213211
LOGGER.trace("Content of mapping: '{}'", content);
214212
try {
215-
// Mapping.valueOf(mapping.getMappingType());
216213
// 'delete' old file
217214
deleteMappingFile(mapping);
218215
newMappingFile = Paths.get(mappingsDirectory.toString(), mapping.getMappingId() + "_" + mapping.getMappingType() + ".mapping");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ public ResponseEntity reloadAllAvailableMappingTypes(WebRequest wr, HttpServletR
358358
PluginManager.reloadPlugins();
359359
return ResponseEntity.noContent().build();
360360
}
361+
361362
/**
362363
* Get the record of given id / type.
363364
*

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.apache.commons.io.FilenameUtils;
2222
import org.eclipse.jgit.api.Git;
2323
import org.eclipse.jgit.api.errors.GitAPIException;
24+
import org.eclipse.jgit.api.errors.JGitInternalException;
2425
import org.slf4j.Logger;
2526
import org.slf4j.LoggerFactory;
2627
import org.springframework.http.MediaType;
@@ -182,6 +183,8 @@ public static void cloneGitRepository(String repositoryUrl, String targetDirecto
182183
target.mkdirs();
183184
try {
184185
Git.cloneRepository().setURI(repositoryUrl).setBranch(branch).setDirectory(target).call();
186+
} catch (JGitInternalException e){
187+
LOGGER.info(e.getMessage());
185188
} catch (GitAPIException ex) {
186189
throw new MappingException("Error cloning git repository '" + repositoryUrl + "' to '" + targetDirectory + "'!", ex);
187190
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public PythonRunnerUtil(ApplicationProperties configuration) {
4040

4141
public static void printPythonVersion() {
4242
try {
43+
LOGGER.info("Configured Python version:");
4344
ShellRunnerUtil.run(new String[]{configuration.getPythonLocation().getPath(), "--version"}, new LoggerOutputStream(LOGGER, LoggerOutputStream.Level.INFO), new LoggerOutputStream(LOGGER, LoggerOutputStream.Level.WARN));
4445
} catch (MappingPluginException e) {
4546
e.printStackTrace();
@@ -56,6 +57,7 @@ public static MappingPluginState runPythonScript(String script, String... args)
5657
}
5758

5859
public static MappingPluginState runPythonScript(String script, OutputStream output, OutputStream error, String... args) throws MappingPluginException {
60+
if (configuration == null || configuration.getPythonLocation() == null) return MappingPluginState.UNKNOWN_ERROR;
5961
ArrayList<String> command = new ArrayList<>();
6062
command.add(configuration.getPythonLocation().getPath());
6163
command.add(script);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.slf4j.LoggerFactory;
2222

2323
import java.io.*;
24-
import java.util.Arrays;
2524
import java.util.List;
2625
import java.util.concurrent.*;
2726
import java.util.stream.Collectors;
@@ -54,7 +53,7 @@ public static MappingPluginState run(String[] command, OutputStream output, Outp
5453
ExecutorService pool = Executors.newSingleThreadExecutor();
5554
int result;
5655
MappingPluginState returnValue = MappingPluginState.SUCCESS;
57-
Arrays.stream(command).toList().forEach(LOGGER::info);
56+
// Arrays.stream(command).toList().forEach(LOGGER::info);
5857

5958
try {
6059
ProcessBuilder pb = new ProcessBuilder(command);

src/main/resources/application.properties

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ repo.auth.jwtSecret:test123
4242
#mapping-service.pythonLocation:file:///usr/bin/python3
4343
mapping-service.pythonLocation=file:///opt/homebrew/bin/python3
4444

45-
# Absolute path to the local gemma mapping script mapping_single.py'
46-
mapping-service.gemmaLocation:file:src/test/resources/python/mapping_single.py
47-
4845
# Absolute path to the local gemma mappings folder
49-
#metastore.indexer.mappingsLocation:file:src/test/resources/mapping/gemma
50-
mapping-service.mappingsLocation:file:///tmp/mapping-service/
46+
#mapping-service.mappingsLocation:file://tmp/mappings
47+
mapping-service.mappingSchemasLocation:file:///Users/maximilian/mappingSchemas

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@ let isEdit = false
1212
let aclEdit
1313
let data
1414
let selectedType = null
15+
let isJSONInput = true
1516
load()
1617

1718
function loadFile() {
1819
const reader = new FileReader();
1920
reader.onload = (event) => {
20-
const obj = JSON.parse(event.target.result);
21-
console.log(obj)
22-
editor.set(obj)
23-
editor.expandAll()
21+
try {
22+
const obj = JSON.parse(event.target.result);
23+
console.log(obj)
24+
editor.set(obj)
25+
editor.expandAll()
26+
} catch (e) {
27+
console.log("Error parsing JSON: " + e)
28+
editor.set({})
29+
isJSONInput = false
30+
}
2431
};
2532
reader.readAsText(document.getElementById("schema").files[0]);
2633
}
@@ -43,6 +50,8 @@ function load() {
4350
document.getElementById("id").value = data.record.mappingId
4451
// document.getElementById("type").value = data.record.mappingType
4552
selectType(data.record.mappingType)
53+
document.getElementById("title").value = data.record.title
54+
document.getElementById("descr").value = data.record.description
4655
for (let i = 0; i < data.record.acl.length; i++) {
4756
acl.push({
4857
"id": data.record.acl[i].id,
@@ -122,8 +131,10 @@ function deleteACL(index) {
122131
function createMapping() {
123132
const id = document.getElementById("id").value
124133
const type = selectedType
134+
const title = document.getElementById("title").value
135+
const description = document.getElementById("descr").value
125136
const file = document.getElementById("schema").files[0]
126-
if (editor.getText() === "{}") {
137+
if (editor.getText() === "{}" && isJSONInput) {
127138
document.getElementById("errorMessage").textContent = "Please define a schema document."
128139
document.getElementById("errorMessage").hidden = false
129140
return
@@ -136,10 +147,14 @@ function createMapping() {
136147
const record = {
137148
"mappingId": id,
138149
"mappingType": type,
150+
"title": title,
151+
"description": description,
139152
"acl": resultACLs
140153
}
141154
const recordBlob = new Blob([JSON.stringify(record)], {type: "application/json"});
142-
const documentBlob = new Blob([editor.getText()], {type: "application/json"})
155+
let documentBlob
156+
if(isJSONInput) documentBlob = new Blob([editor.getText()], {type: "application/json"})
157+
else documentBlob = file
143158

144159
console.log("Sending record:" + JSON.stringify(record))
145160
console.log("Sending document:" + editor.getText())
@@ -156,14 +171,6 @@ function createMapping() {
156171
document.getElementById("submit").disabled = false
157172
if (http.status <= 300) {
158173
document.getElementById("errorMessage").hidden = true
159-
// const element = document.createElement('a');
160-
// element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(editor.getText()));
161-
// if (file != null) element.setAttribute('download', file.name);
162-
// else element.setAttribute('download', id + "_schema.json");
163-
// element.style.display = 'none';
164-
// document.body.appendChild(element);
165-
// element.click();
166-
// document.body.removeChild(element);
167174
document.getElementById("successDisplay").hidden = false
168175
setTimeout(() => {
169176
clearForm()
@@ -195,6 +202,8 @@ function createMapping() {
195202
function updateMapping() {
196203
const id = document.getElementById("id").value
197204
const type = selectedType
205+
const title = document.getElementById("title").value
206+
const description = document.getElementById("descr").value
198207
const file = document.getElementById("schema").files[0]
199208
if (editor.getText() === "{}") {
200209
document.getElementById("errorMessage").textContent = "Please define a schema document."
@@ -209,6 +218,8 @@ function updateMapping() {
209218
const record = {
210219
"mappingId": id,
211220
"mappingType": type,
221+
"title": title,
222+
"description": description,
212223
"acl": resultACLs
213224
}
214225
const recordBlob = new Blob([JSON.stringify(record)], {type: "application/json"});
@@ -271,6 +282,7 @@ function clearForm() {
271282
document.getElementById("successDisplay").hidden = true
272283
document.getElementById("editSuccessDisplay").hidden = true
273284
document.getElementById("errorMessage").hidden = true
285+
unselect()
274286
acl.forEach((value, key) => {
275287
deleteACL(key)
276288
})

0 commit comments

Comments
 (0)