TSK-1737: documented API

This commit is contained in:
Mustapha Zorgati 2021-10-05 16:56:50 +02:00
parent a73b80c59d
commit 846f6dc82b
5 changed files with 69 additions and 0 deletions

View File

@ -3,11 +3,28 @@ package pro.taskana.common.api;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
/** The Configuration Service manages all custom configuration options. */
public interface ConfigurationService { public interface ConfigurationService {
/**
* Retrieve all custom attributes from the database.
*
* @return the custom attributes from the database
*/
Map<String, Object> getAllCustomAttributes(); Map<String, Object> getAllCustomAttributes();
/**
* Override all custom attributes with the provided one.
*
* @param customAttributes the new custom attributes which should be persisted
*/
void setAllCustomAttributes(Map<String, ?> customAttributes); void setAllCustomAttributes(Map<String, ?> 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<Object> getValue(String attribute); Optional<Object> getValue(String attribute);
} }

View File

@ -171,6 +171,8 @@ include::{snippets}/TaskanaEngineControllerRestDocTest/getClassificationCategori
include::{snippets}/TaskanaEngineControllerRestDocTest/getCurrentUserInfoDocTest/auto-section.adoc[] include::{snippets}/TaskanaEngineControllerRestDocTest/getCurrentUserInfoDocTest/auto-section.adoc[]
include::{snippets}/TaskanaEngineControllerRestDocTest/getHistoryProviderIsEnabledDocTest/auto-section.adoc[] include::{snippets}/TaskanaEngineControllerRestDocTest/getHistoryProviderIsEnabledDocTest/auto-section.adoc[]
include::{snippets}/TaskanaEngineControllerRestDocTest/getCurrentVersionDocTest/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 == Import / Export

View File

@ -122,6 +122,12 @@ public class TaskanaEngineController {
return ResponseEntity.ok(taskanaEngine.isHistoryEnabled()); 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) @GetMapping(path = RestEndpoints.URL_CUSTOM_ATTRIBUTES)
@Transactional(readOnly = true, rollbackFor = Exception.class) @Transactional(readOnly = true, rollbackFor = Exception.class)
public ResponseEntity<CustomAttributesRepresentationModel> getCustomAttributes() { public ResponseEntity<CustomAttributesRepresentationModel> getCustomAttributes() {
@ -129,6 +135,13 @@ public class TaskanaEngineController {
return ResponseEntity.ok(new CustomAttributesRepresentationModel(allCustomAttributes)); 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) @PutMapping(path = RestEndpoints.URL_CUSTOM_ATTRIBUTES)
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ResponseEntity<CustomAttributesRepresentationModel> setCustomAttributes( public ResponseEntity<CustomAttributesRepresentationModel> setCustomAttributes(

View File

@ -7,6 +7,7 @@ import org.springframework.hateoas.RepresentationModel;
public class CustomAttributesRepresentationModel public class CustomAttributesRepresentationModel
extends RepresentationModel<CustomAttributesRepresentationModel> { extends RepresentationModel<CustomAttributesRepresentationModel> {
/** The custom configuration attributes. */
private final Map<String, Object> customAttributes; private final Map<String, Object> customAttributes;
@ConstructorProperties({"customAttributes"}) @ConstructorProperties({"customAttributes"})

View File

@ -1,10 +1,13 @@
package pro.taskana.common.rest; package pro.taskana.common.rest;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; 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.junit.jupiter.api.Test;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import pro.taskana.common.rest.models.CustomAttributesRepresentationModel;
import pro.taskana.common.test.BaseRestDocTest; import pro.taskana.common.test.BaseRestDocTest;
class TaskanaEngineControllerRestDocTest extends BaseRestDocTest { class TaskanaEngineControllerRestDocTest extends BaseRestDocTest {
@ -55,4 +58,37 @@ class TaskanaEngineControllerRestDocTest extends BaseRestDocTest {
.perform(get(RestEndpoints.URL_VERSION)) .perform(get(RestEndpoints.URL_VERSION))
.andExpect(MockMvcResultMatchers.status().isOk()); .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());
}
} }