From 846f6dc82b578cee33c75cbc785590a3cfa1ff23 Mon Sep 17 00:00:00 2001 From: Mustapha Zorgati <15628173+mustaphazorgati@users.noreply.github.com> Date: Tue, 5 Oct 2021 16:56:50 +0200 Subject: [PATCH] TSK-1737: documented API --- .../common/api/ConfigurationService.java | 17 +++++++++ .../src/docs/asciidoc/rest-api.adoc | 2 ++ .../common/rest/TaskanaEngineController.java | 13 +++++++ .../CustomAttributesRepresentationModel.java | 1 + .../TaskanaEngineControllerRestDocTest.java | 36 +++++++++++++++++++ 5 files changed, 69 insertions(+) diff --git a/lib/taskana-core/src/main/java/pro/taskana/common/api/ConfigurationService.java b/lib/taskana-core/src/main/java/pro/taskana/common/api/ConfigurationService.java index ab4ffc8b2..fd8c16bca 100644 --- a/lib/taskana-core/src/main/java/pro/taskana/common/api/ConfigurationService.java +++ b/lib/taskana-core/src/main/java/pro/taskana/common/api/ConfigurationService.java @@ -3,11 +3,28 @@ package pro.taskana.common.api; import java.util.Map; import java.util.Optional; +/** The Configuration Service manages all custom configuration options. */ public interface ConfigurationService { + /** + * Retrieve all custom attributes from the database. + * + * @return the custom attributes from the database + */ Map getAllCustomAttributes(); + /** + * Override all custom attributes with the provided one. + * + * @param customAttributes the new custom attributes which should be persisted + */ void setAllCustomAttributes(Map customAttributes); + /** + * Retrieve a specific value from all custom attributes. + * + * @param attribute the attribute key + * @return the attribute value or nothing if the attribute does not exist + */ Optional getValue(String attribute); } diff --git a/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc b/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc index 1b1e76f95..75cd3e650 100644 --- a/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc +++ b/rest/taskana-rest-spring/src/docs/asciidoc/rest-api.adoc @@ -171,6 +171,8 @@ include::{snippets}/TaskanaEngineControllerRestDocTest/getClassificationCategori include::{snippets}/TaskanaEngineControllerRestDocTest/getCurrentUserInfoDocTest/auto-section.adoc[] include::{snippets}/TaskanaEngineControllerRestDocTest/getHistoryProviderIsEnabledDocTest/auto-section.adoc[] include::{snippets}/TaskanaEngineControllerRestDocTest/getCurrentVersionDocTest/auto-section.adoc[] +include::{snippets}/TaskanaEngineControllerRestDocTest/getCustomConfigurationAttributesDocTest/auto-section.adoc[] +include::{snippets}/TaskanaEngineControllerRestDocTest/setCustomConfigurationAttributesDocTest/auto-section.adoc[] == Import / Export diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/TaskanaEngineController.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/TaskanaEngineController.java index 06c703900..a20557ec6 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/TaskanaEngineController.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/TaskanaEngineController.java @@ -122,6 +122,12 @@ public class TaskanaEngineController { return ResponseEntity.ok(taskanaEngine.isHistoryEnabled()); } + /** + * This endpoint retrieves the saved custom configuration. + * + * @title Get custom configuration + * @return custom configuration + */ @GetMapping(path = RestEndpoints.URL_CUSTOM_ATTRIBUTES) @Transactional(readOnly = true, rollbackFor = Exception.class) public ResponseEntity getCustomAttributes() { @@ -129,6 +135,13 @@ public class TaskanaEngineController { return ResponseEntity.ok(new CustomAttributesRepresentationModel(allCustomAttributes)); } + /** + * This endpoint overrides the custom configuration. + * + * @param customAttributes the new custom configuration + * @title Set all custom configuration + * @return the new custom configuration + */ @PutMapping(path = RestEndpoints.URL_CUSTOM_ATTRIBUTES) @Transactional(rollbackFor = Exception.class) public ResponseEntity setCustomAttributes( diff --git a/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/models/CustomAttributesRepresentationModel.java b/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/models/CustomAttributesRepresentationModel.java index 8939ab342..142874b9d 100644 --- a/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/models/CustomAttributesRepresentationModel.java +++ b/rest/taskana-rest-spring/src/main/java/pro/taskana/common/rest/models/CustomAttributesRepresentationModel.java @@ -7,6 +7,7 @@ import org.springframework.hateoas.RepresentationModel; public class CustomAttributesRepresentationModel extends RepresentationModel { + /** The custom configuration attributes. */ private final Map customAttributes; @ConstructorProperties({"customAttributes"}) diff --git a/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/TaskanaEngineControllerRestDocTest.java b/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/TaskanaEngineControllerRestDocTest.java index 380ca84b7..748d6b29e 100644 --- a/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/TaskanaEngineControllerRestDocTest.java +++ b/rest/taskana-rest-spring/src/test/java/pro/taskana/common/rest/TaskanaEngineControllerRestDocTest.java @@ -1,10 +1,13 @@ package pro.taskana.common.rest; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.put; +import java.util.Map; import org.junit.jupiter.api.Test; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import pro.taskana.common.rest.models.CustomAttributesRepresentationModel; import pro.taskana.common.test.BaseRestDocTest; class TaskanaEngineControllerRestDocTest extends BaseRestDocTest { @@ -55,4 +58,37 @@ class TaskanaEngineControllerRestDocTest extends BaseRestDocTest { .perform(get(RestEndpoints.URL_VERSION)) .andExpect(MockMvcResultMatchers.status().isOk()); } + + @Test + void getCustomConfigurationAttributesDocTest() throws Exception { + mockMvc + .perform(get(RestEndpoints.URL_CUSTOM_ATTRIBUTES)) + .andExpect(MockMvcResultMatchers.status().isOk()); + } + + @Test + void setCustomConfigurationAttributesDocTest() throws Exception { + CustomAttributesRepresentationModel customAttributes2 = + new CustomAttributesRepresentationModel( + Map.of( + "filter", + "{ \"Tasks with state READY\": { \"state\": [\"READY\"]}, " + + "\"Tasks with state CLAIMED\": {\"state\": [\"CLAIMED\"] }}", + "schema", + Map.of( + "Filter", + Map.of( + "displayName", + "Filter for Task-Priority-Report", + "members", + Map.of( + "filter", + Map.of("displayName", "Filter values", "type", "json", "min", "1")))))); + + mockMvc + .perform( + put(RestEndpoints.URL_CUSTOM_ATTRIBUTES) + .content(objectMapper.writeValueAsString(customAttributes2))) + .andExpect(MockMvcResultMatchers.status().isOk()); + } }