Skip to content

Commit d9b6511

Browse files
committed
Fix #19, cleanup of MappingService and controller code, harmonization of responses and their documentation, improved determination of result type and including this into the response to the client, fixed tests according to all changes
1 parent fad8eb6 commit d9b6511

File tree

12 files changed

+932
-781
lines changed

12 files changed

+932
-781
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#!gradle/wrapper/gradle-wrapper.jar
55
#!**/src/main/**/build/
66
#!**/src/test/**/build/
7+
lib/
78
#
89
#### Spring boot ###
910
**/application.properties

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ repositories {
3636
ext {
3737
set('snippetsDir', file('build/generated-snippets'))
3838
applicationProperties = System.getProperty('applicationProperties', './src/test/resources/test-config/application-test.properties')
39-
pythonLocation = System.getProperty('pythonLocation', 'file:///usr/bin/python3')
39+
pythonLocation = System.getProperty('pythonLocation', 'file:///c:/python310/python.exe')
4040
}
4141

4242
dependencies {

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

Lines changed: 201 additions & 194 deletions
Large diffs are not rendered by default.

src/main/java/edu/kit/datamanager/mappingservice/rest/IMappingAdministrationController.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ public interface IMappingAdministrationController {
5353
+ "the mapping identifier and mapping type, and the mapping document, which defines the rules for the mapping applied by the given mapping type. ",
5454
responses = {
5555
@ApiResponse(responseCode = "201", description = "CREATED is returned only if the record has been validated, persisted and the mapping document was successfully validated and stored.", content = @Content(schema = @Schema(implementation = MappingRecord.class))),
56-
@ApiResponse(responseCode = "400", description = "BAD_REQUEST is returned if the provided mapping record or the mapping document is invalid."),
57-
@ApiResponse(responseCode = "409", description = "CONFLICT is returned, if there is already a mapping for the provided mapping id.")})
56+
@ApiResponse(responseCode = "400", description = "BAD_REQUEST is returned if the provided mapping record or the mapping document are invalid."),
57+
@ApiResponse(responseCode = "409", description = "CONFLICT is returned, if there is already a mapping for the provided mapping id."),
58+
@ApiResponse(responseCode = "500", description = "INTERNAL_SERVER_ERROR is returned, an unexpected exception occured while persisting the mapping.")})
5859

5960
@RequestMapping(path = "", method = RequestMethod.POST, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
6061
@ResponseBody
6162
ResponseEntity<MappingRecord> createMapping(
6263
@Parameter(description = "JSON representation of the mapping record.", required = true) @RequestPart(name = "record") final MultipartFile record,
6364
@Parameter(description = "The mapping document associated with the record. "
6465
+ "The format of the document is defined by the mapping type, which is given by the mappingType attribute of the mapping record.", required = true) @RequestPart(name = "document") final MultipartFile document,
65-
final HttpServletRequest request,
66+
final WebRequest request,
6667
final HttpServletResponse response,
6768
final UriComponentsBuilder uriBuilder) throws URISyntaxException;
6869

@@ -73,17 +74,17 @@ ResponseEntity<MappingRecord> createMapping(
7374
@ApiResponse(responseCode = "404", description = "NOT_FOUND is returned if no record for the provided identifier was found.")})
7475
@RequestMapping(value = {"/{mappingId}"}, method = {RequestMethod.GET}, produces = {"application/vnd.datamanager.mapping-record+json"})
7576
@ResponseBody
76-
ResponseEntity<MappingRecord> getMappingById(
77+
ResponseEntity getMappingById(
7778
@Parameter(description = "The mapping identifier.", required = true) @PathVariable(value = "mappingId") String mappingId,
78-
Pageable pgbl,
7979
WebRequest wr,
8080
HttpServletResponse hsr);
8181

8282
@Operation(summary = "Get the mapping document associated with a given mapping identifier.", description = "Obtain a single mapping document identified by the mapping identifier. "
8383
+ "Depending on a user's role, accessing a specific record may be allowed or forbidden. ",
8484
responses = {
85-
@ApiResponse(responseCode = "200", description = "OK and the mapping document are returned if the mapping exists and the user has sufficient permission."),
86-
@ApiResponse(responseCode = "404", description = "NOT_FOUND is returned, if no record for the provided identifier was found.")})
85+
@ApiResponse(responseCode = "200", description = "OK and the mapping document are returned if the mapping exists and the user has sufficient permission.", content = @Content(schema = @Schema(implementation = MappingRecord.class))),
86+
@ApiResponse(responseCode = "404", description = "NOT_FOUND is returned, if no record for the provided identifier was found."),
87+
@ApiResponse(responseCode = "500", description = "INTERNAL_SERVER_ERROR is returned, if the mapping document could not be read from the local file system.")})
8788

8889
@RequestMapping(value = {"/{mappingId}"}, method = {RequestMethod.GET})
8990
@ResponseBody
@@ -110,8 +111,9 @@ ResponseEntity<List<MappingRecord>> getMappings(
110111
@Operation(summary = "Update a mapping record.", description = "Apply an update to the mapping record and/or the mapping document identified by provided identifier and/or its ",
111112
responses = {
112113
@ApiResponse(responseCode = "200", description = "OK is returned in case of a successful update, e.g. the record (if provided) was in the correct format and the document (if provided) matches the provided schema id. The updated record is returned in the response.", content = @Content(schema = @Schema(implementation = MappingRecord.class))),
113-
@ApiResponse(responseCode = "400", description = "BAD_REQUEST is returned if the provided metadata record is invalid or if the validation using the provided schema failed."),
114-
@ApiResponse(responseCode = "404", description = "NOT_FOUND is returned if no record for the provided identifier was found.")})
114+
@ApiResponse(responseCode = "400", description = "BAD_REQUEST is returned if the provided mapping record is invalid."),
115+
@ApiResponse(responseCode = "404", description = "NOT_FOUND is returned if no record for the provided identifier was found."),
116+
@ApiResponse(responseCode = "500", description = "INTERNAL_SERVER_ERROR is returned if the mapping could not be persisted for unknown reasons.")})
115117
@RequestMapping(value = "/{mappingId}", method = RequestMethod.PUT, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE}, produces = {"application/json"})
116118
@Parameters({
117119
@Parameter(name = "If-Match", description = "ETag of the current mapping record. Please use quotation marks!", required = true, in = ParameterIn.HEADER)})

src/main/java/edu/kit/datamanager/mappingservice/rest/IMappingExecutionController.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
1716
package edu.kit.datamanager.mappingservice.rest;
1817

19-
import edu.kit.datamanager.mappingservice.domain.MappingRecord;
2018
import io.swagger.v3.oas.annotations.Operation;
2119
import io.swagger.v3.oas.annotations.Parameter;
22-
import io.swagger.v3.oas.annotations.media.Content;
23-
import io.swagger.v3.oas.annotations.media.Schema;
2420
import io.swagger.v3.oas.annotations.responses.ApiResponse;
2521
import io.swagger.v3.oas.annotations.responses.ApiResponses;
2622
import org.springframework.http.MediaType;
@@ -39,28 +35,28 @@
3935
* @author maximilianiKIT
4036
*/
4137
@ApiResponses(value = {
42-
@ApiResponse(responseCode = "401", description = "UNAUTHORIZED is returned if authorization in required but was not provided."),
43-
@ApiResponse(responseCode = "403", description = "FORBIDDEN is returned if the caller has no sufficient privileges.")})
38+
@ApiResponse(responseCode = "401", description = "UNAUTHORIZED is returned if authorization in required but was not provided."),
39+
@ApiResponse(responseCode = "403", description = "FORBIDDEN is returned if the caller has no sufficient privileges.")})
4440
public interface IMappingExecutionController {
4541

46-
@Operation(summary = "Map a document with an existing mapping.", description = "This endpoint allows the mapping of documents via a file upload. " +
47-
"The prerequisite for this is a mapping that has already been created in advance via the \"/api/v1/mapping\" endpoint or the GUI. " +
48-
"The identifier of this mapping must then be passed to this endpoint as parameters together with the document to be mapped.", responses = {
49-
@ApiResponse(responseCode = "200", description = "OK is returned if the mapping was successful. " +
50-
"The result will also be returned in the response.", content = @Content(schema = @Schema(implementation = MappingRecord.class))),
51-
@ApiResponse(responseCode = "404", description = "NOT_FOUND is returned if no mapping for mappingID could be found."),
52-
@ApiResponse(responseCode = "400", description = "BAD_REQUEST is returned if a parameter is missing or the mapping could not be performed with the provided input. It is "
53-
+ "expected that a mapping plugin accepts a well defined input and produces results for proper inputs. Therefore, only a faulty input "
54-
+ "document should be the reason for a mapper to fail."),
55-
@ApiResponse(responseCode = "500", description = "INTERNAL_SERVER_ERROR is returned the mapping returned successfully, but the mapping result "
56-
+ "is not accessible. This is expected to be an error in the mapping implementation and should be fixed in there.")})
42+
@Operation(summary = "Map a document with an existing mapping.", description = "This endpoint allows the mapping of documents via a file upload. "
43+
+ "The prerequisite for this is a mapping that has already been created in advance via the \"/api/v1/mappingAdministration\" endpoint or the GUI. "
44+
+ "The identifier of this mapping must then be passed to this endpoint as parameters together with the document to be mapped.", responses = {
45+
@ApiResponse(responseCode = "200", description = "OK is returned if the mapping was successful. "
46+
+ "The result will also be returned in the response."),
47+
@ApiResponse(responseCode = "404", description = "NOT_FOUND is returned if no mapping for mappingID could be found."),
48+
@ApiResponse(responseCode = "400", description = "BAD_REQUEST is returned if a parameter is missing or the mapping could not be performed with the provided input. It is "
49+
+ "expected that a mapping plugin accepts a well defined input and produces results for proper inputs. Therefore, only a faulty input "
50+
+ "document should be the reason for a mapper to fail."),
51+
@ApiResponse(responseCode = "500", description = "INTERNAL_SERVER_ERROR is returned the mapping returned successfully, but the mapping result "
52+
+ "is not accessible. This is expected to be an error in the mapping implementation and should be fixed in there.")})
5753

5854
@RequestMapping(value = {"/{mappingID}"}, method = {RequestMethod.POST}, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
5955
@ResponseBody
6056
ResponseEntity mapDocument(
6157
@Parameter(description = "The document to be mapped.", required = true) @RequestPart(name = "document") final MultipartFile document,
62-
@Parameter(description = "The mappingID of the already defined mapping schema.", required = true) @PathVariable(value = "mappingID") String mappingID,
58+
@Parameter(description = "The mappingID of the already defined mapping.", required = true) @PathVariable(value = "mappingID") String mappingID,
6359
final HttpServletRequest request,
6460
final HttpServletResponse response,
6561
final UriComponentsBuilder uriBuilder) throws URISyntaxException;
66-
}
62+
}

0 commit comments

Comments
 (0)