Skip to content

Commit 752e40a

Browse files
committed
Removed redundant information from REST API
fixed bugs comments refactoring
1 parent fde9251 commit 752e40a

27 files changed

+599
-505
lines changed

plugins/gemma-plugin-0.1.0.jar

-78.7 KB
Binary file not shown.

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ public class MappingServiceApplication {
3131

3232
private static final Logger LOG = LoggerFactory.getLogger(MappingServiceApplication.class);
3333

34-
@Bean
35-
@Scope("prototype")
36-
public Logger logger(InjectionPoint injectionPoint) {
37-
Class<?> targetClass = injectionPoint.getMember().getDeclaringClass();
38-
return LoggerFactory.getLogger(targetClass.getCanonicalName());
39-
}
34+
// @Bean
35+
// @Scope("prototype")
36+
// public Logger logger(InjectionPoint injectionPoint) {
37+
// Class<?> targetClass = injectionPoint.getMember().getDeclaringClass();
38+
// return LoggerFactory.getLogger(targetClass.getCanonicalName());
39+
// }
4040

41-
@Bean(name = "OBJECT_MAPPER_BEAN")
42-
public ObjectMapper jsonObjectMapper() {
43-
return Jackson2ObjectMapperBuilder.json()
44-
.serializationInclusion(JsonInclude.Include.NON_EMPTY) // Don’t include null values
45-
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) //ISODate
46-
.modules(new JavaTimeModule())
47-
.build();
48-
}
41+
// @Bean(name = "OBJECT_MAPPER_BEAN")
42+
// public ObjectMapper jsonObjectMapper() {
43+
// return Jackson2ObjectMapperBuilder.json()
44+
// .serializationInclusion(JsonInclude.Include.NON_EMPTY) // Don’t include null values
45+
// .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) //ISODate
46+
// .modules(new JavaTimeModule())
47+
// .build();
48+
// }
4949

5050
@Bean
5151
@ConfigurationProperties("repo")

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package edu.kit.datamanager.mappingservice.configuration;
1717

18-
import org.slf4j.Logger;
19-
import org.springframework.beans.factory.annotation.Autowired;
2018
import org.springframework.boot.web.servlet.FilterRegistrationBean;
2119
import org.springframework.context.annotation.Bean;
2220
import org.springframework.context.annotation.Configuration;
@@ -41,9 +39,6 @@
4139
@EnableGlobalMethodSecurity(prePostEnabled = true)
4240
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
4341

44-
@Autowired
45-
private Logger logger;
46-
4742
public WebSecurityConfig() {
4843
}
4944

src/main/java/edu/kit/datamanager/mappingservice/dao/IMappingRecordDao.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@
3232
* @author maximilianiKIT
3333
*/
3434
public interface IMappingRecordDao extends JpaRepository<MappingRecord, String>, JpaSpecificationExecutor<MappingRecord> {
35-
Optional<MappingRecord> findByMappingId(String mappingId);
3635

37-
Optional<MappingRecord> findByMappingIdAndMappingType(String mappingId, String mappingType);
36+
/**
37+
* Find a MappingRecords by the given ID.
38+
*
39+
* @param mappingId The id to search for.
40+
* @return A optional of the matching MappingRecord.
41+
*/
42+
Optional<MappingRecord> findByMappingId(String mappingId);
3843

39-
Iterable<MappingRecord> findByMappingIdInOrMappingTypeIn(List<String> mappingId, List<String> mappingType);
44+
Iterable<MappingRecord> findByMappingIdIn(List<String> mappingId);
4045

41-
Page<MappingRecord> findByMappingIdInOrMappingTypeIn(List<String> mappingId, List<String> mappingType, Pageable pgbl);
46+
Page<MappingRecord> findByMappingIdIn(List<String> mappingId, Pageable pgbl);
4247
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ public boolean equals(Object obj) {
5050
if (!Objects.equals(this.mappingId, other.mappingId)) {
5151
return false;
5252
}
53-
if (!Objects.equals(this.mappingType, other.mappingType)) {
54-
return false;
55-
}
56-
return true;
53+
return Objects.equals(this.mappingType, other.mappingType);
5754
}
5855
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class MappingRecord implements EtagSupport, Serializable {
4545
@NotNull(message = "The unique identify of the record.")
4646
private String mappingId;
4747

48-
@Id
4948
@NotNull(message = "Type of the mapping, e.g. GEMMA, XSLT, handlebars, ....")
5049
private String mappingType;
5150

src/main/java/edu/kit/datamanager/mappingservice/exception/MappingException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 Karlsruhe Institute of Technology.
2+
* Copyright 2022 Karlsruhe Institute of Technology.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

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

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@
3232
import java.io.File;
3333
import java.io.IOException;
3434
import java.net.URI;
35-
import java.net.URISyntaxException;
3635
import java.nio.charset.StandardCharsets;
3736
import java.nio.file.Files;
3837
import java.nio.file.Path;
3938
import java.nio.file.Paths;
4039
import java.security.MessageDigest;
4140
import java.security.NoSuchAlgorithmException;
4241
import java.text.SimpleDateFormat;
43-
import java.util.*;
42+
import java.util.Collections;
43+
import java.util.Date;
44+
import java.util.Optional;
4445

4546
/**
4647
* Service for managing mappings.
@@ -63,7 +64,7 @@ public class MappingService {
6364
private final static Logger LOGGER = LoggerFactory.getLogger(MappingService.class);
6465

6566
@Autowired
66-
public MappingService(ApplicationProperties applicationProperties) throws URISyntaxException {
67+
public MappingService(ApplicationProperties applicationProperties) {
6768
init(applicationProperties);
6869
}
6970

@@ -74,9 +75,7 @@ public MappingService(ApplicationProperties applicationProperties) throws URISyn
7475
* @param mappingRecord record of the mapping
7576
*/
7677
public void createMapping(String content, MappingRecord mappingRecord) throws IOException {
77-
// Right now only one mapping per mappingID is allowed. May change in future.
78-
// Optional<MappingRecord> findMapping = mappingRepo.findByMappingIdAndMappingType(mappingRecord.getMappingId(), mappingRecord.getMappingType());
79-
Iterable<MappingRecord> findMapping = mappingRepo.findByMappingIdInOrMappingTypeIn(Arrays.asList(mappingRecord.getMappingId()), Arrays.asList((String) null));
78+
Iterable<MappingRecord> findMapping = mappingRepo.findByMappingIdIn(Collections.singletonList(mappingRecord.getMappingId()));
8079
if (findMapping.iterator().hasNext()) {
8180
mappingRecord = findMapping.iterator().next();
8281
throw new MappingException("Error: Mapping '" + mappingRecord.getMappingType() + "_" + mappingRecord.getMappingId() + "' already exists!");
@@ -92,8 +91,8 @@ public void createMapping(String content, MappingRecord mappingRecord) throws IO
9291
* @param mappingRecord record of the mapping
9392
*/
9493
public void updateMapping(String content, MappingRecord mappingRecord) throws IOException {
95-
Optional<MappingRecord> findMapping = mappingRepo.findByMappingIdAndMappingType(mappingRecord.getMappingId(), mappingRecord.getMappingType());
96-
if (!findMapping.isPresent()) {
94+
Optional<MappingRecord> findMapping = mappingRepo.findByMappingId(mappingRecord.getMappingId());
95+
if (findMapping.isEmpty()) {
9796
throw new MappingException("Error: Mapping '" + mappingRecord.getMappingType() + "_" + mappingRecord.getMappingId() + "' doesn't exist!");
9897
}
9998
mappingRecord.setMappingDocumentUri(findMapping.get().getMappingDocumentUri());
@@ -107,8 +106,8 @@ public void updateMapping(String content, MappingRecord mappingRecord) throws IO
107106
* @param mappingRecord record of the mapping
108107
*/
109108
public void deleteMapping(MappingRecord mappingRecord) throws IOException {
110-
Optional<MappingRecord> findMapping = mappingRepo.findByMappingIdAndMappingType(mappingRecord.getMappingId(), mappingRecord.getMappingType());
111-
if (!findMapping.isPresent()) {
109+
Optional<MappingRecord> findMapping = mappingRepo.findByMappingId(mappingRecord.getMappingId());
110+
if (findMapping.isEmpty()) {
112111
throw new MappingException("Error: Mapping '" + mappingRecord.getMappingType() + "_" + mappingRecord.getMappingId() + "' doesn't exist!");
113112
}
114113
mappingRecord = findMapping.get();
@@ -120,24 +119,22 @@ public void deleteMapping(MappingRecord mappingRecord) throws IOException {
120119
* Execute mapping and get the location of result file. If no according
121120
* mapping is found the src file will be returned.
122121
*
123-
* @param contentUrl Content of the src file.
124-
* @param mappingId filename of the mapping
125-
* @param mappingType type of the mapping.
122+
* @param contentUrl Content of the src file.
123+
* @param mappingId id of the mapping
126124
* @return Path to result file.
127125
*/
128-
public Optional<Path> executeMapping(URI contentUrl, String mappingId, String mappingType) throws MappingPluginException {
129-
Optional<Path> returnValue = Optional.empty();
126+
public Optional<Path> executeMapping(URI contentUrl, String mappingId) throws MappingPluginException {
127+
Optional<Path> returnValue;
130128
Optional<Path> download = FileUtil.downloadResource(contentUrl);
131-
MappingRecord mappingRecord = null;
129+
MappingRecord mappingRecord;
132130

133131
if (download.isPresent()) {
134-
LOGGER.trace("Execute Mapping for '{}', and mapping '{}/{}'.", contentUrl.toString(), mappingId, mappingType);
132+
LOGGER.trace("Execute Mapping for '{}', and mapping '{}'.", contentUrl.toString(), mappingId);
135133
Path srcFile = download.get();
136134
// Get mapping file
137-
Optional<MappingRecord> optionalMappingRecord = mappingRepo.findByMappingIdAndMappingType(mappingId, mappingType);
135+
Optional<MappingRecord> optionalMappingRecord = mappingRepo.findByMappingId(mappingId);
138136
if (optionalMappingRecord.isPresent()) {
139137
mappingRecord = optionalMappingRecord.get();
140-
// mappingRecord.getMappingDocumentUri();
141138
Path mappingFile = Paths.get(mappingRecord.getMappingDocumentUri());
142139
// execute mapping
143140
Path resultFile;
@@ -150,42 +147,18 @@ public Optional<Path> executeMapping(URI contentUrl, String mappingId, String ma
150147
returnValue = Optional.of(srcFile);
151148
}
152149
} else {
153-
String message = contentUrl != null ? "Error: Downloading content from '" + contentUrl.toString() + "'!" : "Error: No URL provided!";
150+
String message = contentUrl != null ? "Error: Downloading content from '" + contentUrl + "'!" : "Error: No URL provided!";
154151
throw new MappingException(message);
155152
}
156153
return returnValue;
157154
}
158155

159-
/**
160-
* Execute mapping(s) and get the location of result file.
161-
*
162-
* @param contentUrl Content of the src file.
163-
* @param mappingId filename of the mapping
164-
* @return List of paths to all result files.
165-
*/
166-
public List<Path> executeMapping(URI contentUrl, String mappingId) throws MappingPluginException {
167-
List<Path> returnValue = new ArrayList<>();
168-
String noMappingType = null;
169-
170-
Iterator<MappingRecord> findMapping = mappingRepo.findByMappingIdInOrMappingTypeIn(Arrays.asList(mappingId), Arrays.asList(noMappingType)).iterator();
171-
String mappingType = null;
172-
if (findMapping.hasNext()) {
173-
mappingType = findMapping.next().getMappingType();
174-
}
175-
Optional<Path> executeMapping = executeMapping(contentUrl, mappingId, mappingType);
176-
if (executeMapping.isPresent()) {
177-
returnValue.add(executeMapping.get());
178-
}
179-
180-
return returnValue;
181-
}
182-
183156
/**
184157
* Initalize mappings directory and mappingUtil instance.
185158
*
186159
* @param applicationProperties Properties holding mapping directory setting.
187160
*/
188-
private void init(ApplicationProperties applicationProperties) throws URISyntaxException {
161+
private void init(ApplicationProperties applicationProperties) {
189162
if ((applicationProperties != null) && (applicationProperties.getMappingsLocation() != null)) {
190163
try {
191164
mappingsDirectory = Files.createDirectories(new File(applicationProperties.getMappingsLocation().getPath()).getAbsoluteFile().toPath());
@@ -205,15 +178,15 @@ private void init(ApplicationProperties applicationProperties) throws URISyntaxE
205178
* @throws IOException error writing file.
206179
*/
207180
private void saveMappingFile(String content, MappingRecord mapping) throws IOException {
208-
Path newMappingFile = null;
181+
Path newMappingFile;
209182
if ((content != null) && (mapping != null) && (mapping.getMappingId() != null) && (mapping.getMappingType() != null)) {
210183
LOGGER.debug("Storing mapping file with id '{}' and type '{}'", mapping.getMappingId(), mapping.getMappingType());
211184
LOGGER.trace("Content of mapping: '{}'", content);
212185
try {
213186
// 'delete' old file
214187
deleteMappingFile(mapping);
215188
newMappingFile = Paths.get(mappingsDirectory.toString(), mapping.getMappingId() + "_" + mapping.getMappingType() + ".mapping");
216-
LOGGER.trace("Write content to '{}'", newMappingFile.toString());
189+
LOGGER.trace("Write content to '{}'", newMappingFile);
217190
FileUtils.writeStringToFile(newMappingFile.toFile(), content, StandardCharsets.UTF_8);
218191
mapping.setMappingDocumentUri(newMappingFile.toString());
219192
byte[] data = content.getBytes();
@@ -249,7 +222,7 @@ private void deleteMappingFile(MappingRecord mapping) throws IOException {
249222
Path deleteFile = Paths.get(mapping.getMappingDocumentUri());
250223
if (deleteFile.toFile().exists()) {
251224
Path newFileName = Paths.get(deleteFile.getParent().toString(), deleteFile.getFileName() + date2String());
252-
LOGGER.trace("Move mapping file fo '{}'", newFileName.toString());
225+
LOGGER.trace("Move mapping file fo '{}'", newFileName);
253226
FileUtils.moveFile(deleteFile.toFile(), newFileName.toFile());
254227
}
255228
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,58 @@
2222
/**
2323
* Interface for mapping plugins.
2424
* Every plugin which implements this interface and is placed in the plugins folder will be loaded and usable via the REST-API.
25+
*
26+
* @author maximilianiKIT
2527
*/
2628
public interface IMappingPlugin {
2729

2830
/**
2931
* Name of the plugin which gets displayed in the UI and is part of the id.
32+
*
3033
* @return The name of the plugin.
3134
*/
3235
String name();
3336

3437
/**
3538
* A short description of the plugin which gets displayed in the UI.
39+
*
3640
* @return The description of the plugin.
3741
*/
3842
String description();
3943

4044
/**
4145
* The version of the plugin which gets displayed in the UI and is part of the id.
46+
*
4247
* @return The version of the plugin.
4348
*/
4449
String version();
4550

4651
/**
4752
* A URI which refers to the plugin or the technology used by the plugin (e.g. a link to a GitHub repository).
4853
* This URI will be displayed in the UI.
54+
*
4955
* @return The URI of the plugin.
5056
*/
5157
String uri();
5258

5359
/**
5460
* The mime type of the input data.
61+
*
5562
* @return The mime type of the input data.
5663
*/
5764
MimeType[] inputTypes();
5865

5966
/**
6067
* The mime type of the output data.
68+
*
6169
* @return The mime type of the output data.
6270
*/
6371
MimeType[] outputTypes();
6472

6573
/**
6674
* The id of the plugin which is used to identify the plugin.
6775
* By default, the id is composed of the name and the version of the plugin (e.g. testPlugin_2.1.0).
76+
*
6877
* @return The id of the plugin.
6978
*/
7079
default String id() {
@@ -79,8 +88,9 @@ default String id() {
7988

8089
/**
8190
* The method which is called to execute the plugin.
82-
* @param inputFile The path to the output document.
83-
* @param outputFile The path to the output document.
91+
*
92+
* @param inputFile The path to the output document.
93+
* @param outputFile The path to the output document.
8494
* @param mappingFile The path to the mapping schema.
8595
* @return The exit code of the plugin.
8696
*/

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 Karlsruhe Institute of Technology.
2+
* Copyright 2022 Karlsruhe Institute of Technology.
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -18,6 +18,11 @@
1818
import java.io.File;
1919
import java.io.FileFilter;
2020

21+
/**
22+
* Filter for jar files.
23+
*
24+
* @author maximilianiKIT
25+
*/
2126
public class JARFileFilter implements FileFilter {
2227

2328
public boolean accept(File f) {

0 commit comments

Comments
 (0)