Commit 51adac30 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

documentation of get configuration API call

parent fcea9830
Pipeline #22674 failed with stage
in 16 minutes and 27 seconds
......@@ -2,11 +2,12 @@ package lcsb.mapviewer.web;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -16,6 +17,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.restdocs.payload.FieldDescriptor;
import org.springframework.restdocs.payload.ResponseFieldsSnippet;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.RequestBuilder;
......@@ -42,6 +45,9 @@ public class ConfigurationControllerIntegrationTest extends ControllerIntegratio
private User user;
@Autowired
private ProjectSnippets snippets;
@Before
public void setup() {
user = createUser(TEST_USER_LOGIN, TEST_USER_PASSWORD);
......@@ -71,6 +77,8 @@ public class ConfigurationControllerIntegrationTest extends ControllerIntegratio
RequestBuilder request = get("/configuration/");
mockMvc.perform(request)
.andDo(document("projects/project_overlays/get_all_by_creator",
configurationFields()))
.andExpect(status().is2xxSuccessful());
}
......@@ -160,7 +168,6 @@ public class ConfigurationControllerIntegrationTest extends ControllerIntegratio
.andExpect(status().isForbidden());
}
@Test
public void testRegisterExistingUser() throws Exception {
MockHttpSession session = createSession(BUILT_IN_TEST_ADMIN_LOGIN, BUILT_IN_TEST_ADMIN_PASSWORD);
......@@ -169,8 +176,7 @@ public class ConfigurationControllerIntegrationTest extends ControllerIntegratio
user.setLogin("admin");
user.setPassword("admin");
user.setLogin("minerva@uni.lu");
RequestBuilder request = post("/configuration/dapi:registerUser")
.content(new ObjectMapper().writeValueAsString(user))
.contentType(MediaType.APPLICATION_JSON)
......@@ -180,5 +186,296 @@ public class ConfigurationControllerIntegrationTest extends ControllerIntegratio
.andExpect(status().isConflict());
}
private ResponseFieldsSnippet configurationFields() {
return responseFields(
fieldWithPath("annotators")
.description("list of annotators"),
fieldWithPath("bioEntityFields")
.description("list of bieEntity fields that are used by annotators"),
fieldWithPath("buildDate")
.description("when minerva platform was built")
.type("timestamp"),
fieldWithPath("gitHash")
.description("git hash used to build minerva platform")
.type("timestamp"),
fieldWithPath("version")
.description("version of the minerva platform")
.type("string"),
fieldWithPath("imageFormats")
.description("list of available export image formats"),
fieldWithPath("mapCanvasTypes")
.description("list of supported frontend map engines"),
fieldWithPath("mapTypes")
.description("list of submap types"),
subsectionWithPath("miriamTypes")
.description("map of miriam types supported by minerva. Types are defined on https://identifiers.org/"),
fieldWithPath("modelFormats")
.description("list of map formats"),
subsectionWithPath("modificationStateTypes")
.description("map with modification states"),
fieldWithPath("options")
.description("list of configuration options"),
fieldWithPath("overlayTypes")
.description("list of overlay types"),
subsectionWithPath("privilegeTypes")
.description("map with privilege type available in the system"),
fieldWithPath("reactionTypes")
.description("list of reaction types"),
fieldWithPath("unitTypes")
.description("list of basic unit types"),
fieldWithPath("elementTypes")
.description("list of element types"))
.andWithPrefix("annotators[].", annotatorFields())
.andWithPrefix("bioEntityFields[].", bioEntityFields())
.andWithPrefix("elementTypes[].", elementTypeFields())
.andWithPrefix("imageFormats[].", imageFormatFields())
.andWithPrefix("mapCanvasTypes[].", mapCanvasTypeFields())
.andWithPrefix("mapTypes[].", mapTypeFields())
.andWithPrefix("miriamTypes[].", miriamTypeFields())
.andWithPrefix("modelFormats[].", mapFormatFields())
.andWithPrefix("modificationStateTypes[].", modificationStateFields())
.andWithPrefix("options[].", configurationOptionFields())
.andWithPrefix("overlayTypes[].", overlayTypeFields())
.andWithPrefix("privilegeTypes[].", privilegeTypeFields())
.andWithPrefix("reactionTypes[].", elementTypeFields())
.andWithPrefix("unitTypes[].", unitTypeFields());
}
private List<FieldDescriptor> annotatorFields() {
List<FieldDescriptor> result = new ArrayList<>(Arrays.asList(
fieldWithPath("name")
.description("annotator name")
.type("string"),
fieldWithPath("url")
.description("url address of assoiated database")
.type("string"),
fieldWithPath("className")
.description("Java class responsible for annotating process")
.type("string"),
fieldWithPath("elementClassNames")
.description("Java classes that identify bioEntity types that can be annotated by the annotator")
.type("List<String>"),
fieldWithPath("description")
.description("short description of the annotator")
.type("string")
.optional(),
fieldWithPath("parameters")
.description(
"list of supported input fields, generated outputs that can be filled by annotator and configuration options")
.type("List<Object>")));
result.addAll(annotatorParameterFields("parameters[]."));
return result;
}
private List<FieldDescriptor> bioEntityFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("commonName")
.description("human readable name of the field")
.type("string"),
fieldWithPath("name")
.description("unique name of the field")
.type("string")));
}
private List<FieldDescriptor> elementTypeFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("className")
.description("Java class that identify type")
.type("string"),
fieldWithPath("name")
.description("human readable name of the type")
.type("string"),
fieldWithPath("parentClass")
.description("Java class that identify parent type")
.type("string")));
}
private List<FieldDescriptor> unitTypeFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("name")
.description("human readable name of the type")
.type("string"),
fieldWithPath("id")
.description("type identifier")
.type("string")));
}
private List<FieldDescriptor> imageFormatFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("extension")
.description("file extension")
.type("string"),
fieldWithPath("name")
.description("human readable name of the format")
.type("string"),
fieldWithPath("handler")
.description("Java class that is responsible for export")
.type("string")));
}
private List<FieldDescriptor> mapCanvasTypeFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("id")
.description("identifier of the map engine")
.type("string"),
fieldWithPath("name")
.description("human readable name of the map engine")
.type("string")));
}
private List<FieldDescriptor> mapTypeFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("id")
.description("identifier of the type")
.type("string"),
fieldWithPath("name")
.description("human readable name of the submap type")
.type("string")));
}
private List<FieldDescriptor> miriamTypeFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("commonName")
.description("human readable name of the identifier type")
.type("string")
.optional(),
fieldWithPath("homepage")
.description("url to database homepage")
.type("string")
.optional(),
fieldWithPath("registryIdentifier")
.description("unique identifier used by identifiers.org to reference this type")
.type("string")
.optional(),
fieldWithPath("registryIdentifier")
.description("list of uris used by this identifier type")
.type("Array<String>")
.optional()));
}
private List<FieldDescriptor> mapFormatFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("name")
.description("human readable name of map format")
.type("string"),
fieldWithPath("extension")
.description("file extension")
.type("string"),
fieldWithPath("handler")
.description("Java class that is used for import/export from the map format")
.type("string")));
}
private List<FieldDescriptor> modificationStateFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("commonName")
.description("human readable name of modification state type")
.type("string")
.optional(),
fieldWithPath("abbreviation")
.description("short name of the type")
.type("string")
.optional()));
}
private List<FieldDescriptor> configurationOptionFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("commonName")
.description("human readable name of configuration option")
.type("string"),
fieldWithPath("group")
.description("group of options where this configuration option belongs to")
.type("string"),
fieldWithPath("idObject")
.description("option identifier")
.type("number")
.ignored(),
fieldWithPath("isServerSide")
.description("TRUE/FALSE - is the option responsible for server side processing or frontend")
.type("boolean"),
fieldWithPath("type")
.description("option type")
.type("string"),
fieldWithPath("value")
.description("value of the configuration option")
.type("string")
.optional(),
fieldWithPath("valueType")
.description("type of the configuration option. Available options: "
+ snippets.getOptionsAsString(ConfigurationElementType.class))
.type("string")
));
}
private List<FieldDescriptor> overlayTypeFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("name")
.description("name of the type")
.type("string")
));
}
private List<FieldDescriptor> privilegeTypeFields() {
return new ArrayList<>(Arrays.asList(
fieldWithPath("commonName")
.description("human readable description of the privilege")
.type("string")
.optional(),
fieldWithPath("objectType")
.description("class of objects to which privilege applies")
.type("string")
.optional(),
fieldWithPath("valueType")
.description("type of the privilege value (ie. boolean)")
.type("string")
.optional()
));
}
private List<FieldDescriptor> annotatorParameterFields(String prefix) {
if (prefix == null) {
prefix = "";
}
List<FieldDescriptor> result = Arrays.asList(
fieldWithPath(prefix + "annotation_type")
.description("identifier type. Either this or 'field' is required for INPUT/OUTPUT parameter")
.type("MiriamType")
.optional(),
fieldWithPath(prefix + "field")
.description("bioEntity field. Either this or 'annotation_type' is required for INPUT/OUTPUT parameter")
.type("String")
.optional(),
fieldWithPath(prefix + "commonName")
.description("name of the CONFIG parameter")
.type("String")
.optional(),
fieldWithPath(prefix + "description")
.description("description of the parameter")
.type("String")
.optional(),
fieldWithPath(prefix + "inputType")
.description("type of the CONFIG parameter")
.type("String")
.optional(),
fieldWithPath(prefix + "name")
.description("name of the CONFIG parameter")
.type("String")
.optional(),
fieldWithPath(prefix + "value")
.description("default value of the CONFIG parameter")
.type("String")
.optional(),
fieldWithPath(prefix + "order")
.description("order position when listing parameters")
.type("number"),
fieldWithPath(prefix + "type")
.description("type of parameter (INPUT/OUTPUT/CONFIG)")
.type("String"));
return result;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment