SEBSERV-140 merged from api-docu branch.

This commit is contained in:
anhefti 2022-04-14 16:13:40 +02:00
parent eb46de835a
commit 5b56e6e1b9
11 changed files with 286 additions and 0 deletions

View file

@ -310,6 +310,15 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- Springdoc-openapi -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.10</version>
</dependency>
<!-- Flyway -->
<dependency>

View file

@ -37,6 +37,8 @@ public class GuiWebsecurityConfig extends WebSecurityConfigurerAdapter {
private String remoteProctoringEndpoint;
@Value("${sebserver.gui.remote.proctoring.api-servler.endpoint:/remote-view-servlet}")
private String remoteProctoringViewServletEndpoint;
@Value("${springdoc.api-docs.enabled:false}")
private boolean springDocsAPIEnabled;
/** Gui-service related public URLS from spring web security perspective */
public static final RequestMatcher PUBLIC_URLS = new OrRequestMatcher(
@ -57,6 +59,10 @@ public class GuiWebsecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers(this.guiEntryPoint)
.antMatchers(this.remoteProctoringEndpoint)
.antMatchers(this.remoteProctoringEndpoint + this.remoteProctoringViewServletEndpoint + "/*");
if (this.springDocsAPIEnabled) {
web.ignoring().antMatchers("/swagger-ui.html", "/swagger-ui/**", "/v3/api-docs/**");
}
}
@Override

View file

@ -33,6 +33,10 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ActivatableEntityDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.UserActivityLogDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.validation.BeanValidationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
/** Abstract Entity-Controller that defines generic Entity rest API endpoints that are supported
* by all entity types that has activation feature and can be activated or deactivated.
@ -58,6 +62,29 @@ public abstract class ActivatableEntityController<T extends GrantEntity & Activa
beanValidationService);
}
@Operation(
summary = "Get a page of all specific domain entity that are currently active.",
description = "Sorting: the sort parameter to sort the list of entities before paging\n"
+ "the sort parameter is the name of the entity-model attribute to sort with a leading '-' sign for\n"
+ "descending sort order. Note that not all entity-model attribute are suited for sorting while the most\n"
+ "are.\n",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = Page.ATTR_PAGE_NUMBER,
description = "The number of the page to get from the whole list. If the page does not exists, the API retruns with the first page."),
@Parameter(
name = Page.ATTR_PAGE_SIZE,
description = "The size of the page to get."),
@Parameter(
name = Page.ATTR_SORT,
description = "the sort parameter to sort the list of entities before paging"),
@Parameter(
name = API.PARAM_INSTITUTION_ID,
description = "The institution identifier of the request.\n"
+ "Default is the institution identifier of the institution of the current user"),
})
@RequestMapping(
path = API.ACTIVE_PATH_SEGMENT,
method = RequestMethod.GET,
@ -86,6 +113,30 @@ public abstract class ActivatableEntityController<T extends GrantEntity & Activa
() -> getAll(filterMap)).getOrThrow();
}
@Operation(
summary = "Get a page of all specific domain entity that are currently inactive.",
description = "Sorting: the sort parameter to sort the list of entities before paging\n"
+ "the sort parameter is the name of the entity-model attribute to sort with a leading '-' sign for\n"
+ "descending sort order. Note that not all entity-model attribute are suited for sorting while the most\n"
+ "are.\n",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = Page.ATTR_PAGE_NUMBER,
description = "The number of the page to get from the whole list. If the page does not exists, the API retruns with the first page."),
@Parameter(
name = Page.ATTR_PAGE_SIZE,
description = "The size of the page to get."),
@Parameter(
name = Page.ATTR_SORT,
description = "the sort parameter to sort the list of entities before paging"),
@Parameter(
name = API.PARAM_INSTITUTION_ID,
description = "The institution identifier of the request.\n"
+ "Default is the institution identifier of the institution of the current user"),
})
@RequestMapping(
path = API.INACTIVE_PATH_SEGMENT,
method = RequestMethod.GET,
@ -114,6 +165,16 @@ public abstract class ActivatableEntityController<T extends GrantEntity & Activa
() -> getAll(filterMap)).getOrThrow();
}
@Operation(
summary = "Activate a single entity by its modelId.",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = API.PARAM_MODEL_ID,
description = "The model identifier of the entity object to activate.",
in = ParameterIn.PATH)
})
@RequestMapping(
path = API.PATH_VAR_ACTIVE,
method = RequestMethod.POST,
@ -124,6 +185,16 @@ public abstract class ActivatableEntityController<T extends GrantEntity & Activa
.getOrThrow();
}
@Operation(
summary = "Dectivate a single entity by its modelId.",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = API.PARAM_MODEL_ID,
description = "The model identifier of the entity object to deactivate.",
in = ParameterIn.PATH)
})
@RequestMapping(
value = API.PATH_VAR_INACTIVE,
method = RequestMethod.POST,

View file

@ -53,10 +53,12 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.UserService;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.UserActivityLogDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.CertificateService;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@WebServiceProfile
@RestController
@RequestMapping("${sebserver.webservice.api.admin.endpoint}" + API.CERTIFICATE_ENDPOINT)
@SecurityRequirement(name = "oauth2")
public class CertificateController {
private final AuthorizationService authorization;

View file

@ -56,12 +56,18 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.dao.EntityDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.UserActivityLogDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.validation.BeanValidationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
/** Abstract Entity-Controller that defines generic Entity rest API endpoints that are supported
* by all entity types.
*
* @param <T> The concrete Entity domain-model type used on all GET, PUT
* @param <M> The concrete Entity domain-model type used for POST methods (new) */
@SecurityRequirement(name = "oauth2")
public abstract class EntityController<T extends Entity, M extends Entity> {
private static final Logger log = LoggerFactory.getLogger(EntityController.class);
@ -133,6 +139,41 @@ public abstract class EntityController<T extends Entity, M extends Entity> {
* descending sort order.
* @param allRequestParams a MultiValueMap of all request parameter that is used for filtering.
* @return Page of domain-model-entities of specified type */
@Operation(
summary = "Get a page of the specific domain entity. Sorting and filtering is applied before paging",
description = "Sorting: the sort parameter to sort the list of entities before paging\n"
+ "the sort parameter is the name of the entity-model attribute to sort with a leading '-' sign for\n"
+ "descending sort order. Note that not all entity-model attribute are suited for sorting while the most\n"
+ "are.\n"
+ "</p>\n"
+ "Filter: The filter attributes accepted by this API depend on the actual entity model (domain object)\n"
+ "and are of the form [domain-attribute-name]=[filter-value]. E.g.: name=abc or type=EXAM. Usually\n"
+ "filter attributes of text type are treated as SQL wildcard with %[text]% to filter all text containing\n"
+ "a given text-snippet.",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = Page.ATTR_PAGE_NUMBER,
description = "The number of the page to get from the whole list. If the page does not exists, the API retruns with the first page."),
@Parameter(
name = Page.ATTR_PAGE_SIZE,
description = "The size of the page to get."),
@Parameter(
name = Page.ATTR_SORT,
description = "the sort parameter to sort the list of entities before paging"),
@Parameter(
name = API.PARAM_INSTITUTION_ID,
description = "The institution identifier of the request.\n"
+ "Default is the institution identifier of the institution of the current user"),
@Parameter(
name = "filterCriteria",
description = "Additional filter criterias \n" +
"For OpenAPI 3 input please use the form: {\"columnName\":\"filterValue\"}",
example = "{\"name\":\"ethz\"}",
required = false,
allowEmptyValue = true)
})
@RequestMapping(
method = RequestMethod.GET,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
@ -182,6 +223,29 @@ public abstract class EntityController<T extends Entity, M extends Entity> {
// * GET (names)
// ******************
@Operation(
summary = "Get a filtered list of specific entity name keys.",
description = "An entity name key is a minimal entity data object with the entity-type, modelId and the name of the entity."
+ "</p>\n"
+ "Filter: The filter attributes accepted by this API depend on the actual entity model (domain object)\n"
+ "and are of the form [domain-attribute-name]=[filter-value]. E.g.: name=abc or type=EXAM. Usually\n"
+ "filter attributes of text type are treated as SQL wildcard with %[text]% to filter all text containing\n"
+ "a given text-snippet.",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = API.PARAM_INSTITUTION_ID,
description = "The institution identifier of the request.\n"
+ "Default is the institution identifier of the institution of the current user"),
@Parameter(
name = "filterCriteria",
description = "Additional filter criterias \n" +
"For OpenAPI 3 input please use the form: {\"columnName\":\"filterValue\"}",
example = "{\"name\":\"ethz\"}",
required = false,
allowEmptyValue = true)
})
@RequestMapping(
path = API.NAMES_PATH_SEGMENT,
method = RequestMethod.GET,
@ -219,6 +283,34 @@ public abstract class EntityController<T extends Entity, M extends Entity> {
// * GET (dependency)
// ******************
@Operation(
summary = "Get a list of dependency keys of all dependent entity objects for a "
+ "specified source entity and bulk action.",
description = "Get a list of dependency keys of all dependent entity objects for a "
+ "specified source entity and bulk action.\n " +
"This can be used to verify depended objects for a certain bulk action to "
+ "give a report of affected objects beforehand.\n " +
"For example for a delete action of a certain object, this gives all objects "
+ "that will also be deleted within the deletion of the source object",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = API.PARAM_MODEL_ID,
description = "The model identifier of the source entity object to geht the dependencies for.",
in = ParameterIn.PATH),
@Parameter(
name = API.PARAM_BULK_ACTION_TYPE,
description = "The bulk action type defining the type of action to get the dependencies for.\n"
+ "This is the name of the enumeration "),
@Parameter(
name = API.PARAM_BULK_ACTION_ADD_INCLUDES,
description = "Indicates if the following 'includes' paramerer shall be processed or not.\n The default is false "),
@Parameter(
name = API.PARAM_BULK_ACTION_INCLUDES,
description = "A comma separated list of names of the EntityType enummeration that defines all entity types that shall be included in the result.")
})
@RequestMapping(
path = API.MODEL_ID_VAR_PATH_SEGMENT + API.DEPENDENCY_PATH_SEGMENT,
method = RequestMethod.GET,
@ -248,6 +340,16 @@ public abstract class EntityController<T extends Entity, M extends Entity> {
// * GET (single)
// ******************
@Operation(
summary = "Get a single entity by its modelId.",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = API.PARAM_MODEL_ID,
description = "The model identifier of the entity object to get.",
in = ParameterIn.PATH)
})
@RequestMapping(
path = API.MODEL_ID_VAR_PATH_SEGMENT,
method = RequestMethod.GET,
@ -265,6 +367,15 @@ public abstract class EntityController<T extends Entity, M extends Entity> {
// * GET (list)
// ******************
@Operation(
summary = "Get a list of entity objects by a given list of model identifiers of entities.",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = API.PARAM_MODEL_ID_LIST,
description = "Comma separated list of model identifiers.")
})
@RequestMapping(
path = API.LIST_PATH_SEGMENT,
method = RequestMethod.GET,
@ -286,6 +397,27 @@ public abstract class EntityController<T extends Entity, M extends Entity> {
// * POST (create)
// ******************
@Operation(
summary = "Create a new entity object of specifies type by using the given form parameter",
description = "This expects " + MediaType.APPLICATION_FORM_URLENCODED_VALUE +
" format for the form parameter" +
" and tries to create a new entity object from this form parameter, " +
"resulting in an error if there are missing" +
" or incorrect form paramter. The needed form paramter " +
"can be verified within the specific entity object.",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = "formParams",
description = "The from paramter value map that is been used to create a new entity object.",
in = ParameterIn.DEFAULT),
@Parameter(
name = API.PARAM_INSTITUTION_ID,
description = "The institution identifier of the request.\n"
+ "Default is the institution identifier of the institution of the current user"),
})
@RequestMapping(
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
@ -318,6 +450,14 @@ public abstract class EntityController<T extends Entity, M extends Entity> {
// * PUT (save)
// ****************
@Operation(
summary = "Modifies an already existing entity object of the specific type.",
description = "This expects " + MediaType.APPLICATION_JSON_VALUE +
" format for the response data and verifies consistencies " +
"within the definition of the specific entity object type. " +
"Missing (NULL) parameter that are not mandatory will be ignored and the original value will not be affected",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_JSON_VALUE) }))
@RequestMapping(
method = RequestMethod.PUT,
consumes = MediaType.APPLICATION_JSON_VALUE,
@ -335,6 +475,25 @@ public abstract class EntityController<T extends Entity, M extends Entity> {
// * DELETE (hard-delete)
// ************************
@Operation(
summary = "Deletes a single entity (and all its dependencies) by its modelId.",
description = "To check or report what dependent object also would be deleted for a certain entity object, "
+
"please use the dependency endpoint to get a report of all dependend entity objects.",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = API.PARAM_MODEL_ID,
description = "The model identifier of the entity object to get.",
in = ParameterIn.PATH),
@Parameter(
name = API.PARAM_BULK_ACTION_ADD_INCLUDES,
description = "Indicates if the following 'includes' paramerer shall be processed or not.\n The default is false "),
@Parameter(
name = API.PARAM_BULK_ACTION_INCLUDES,
description = "A comma separated list of names of the EntityType enummeration that defines all entity types that shall be included in the result.")
})
@RequestMapping(
path = API.MODEL_ID_VAR_PATH_SEGMENT,
method = RequestMethod.DELETE,
@ -358,6 +517,25 @@ public abstract class EntityController<T extends Entity, M extends Entity> {
// * DELETE ALL (hard-delete)
// **************************
@Operation(
summary = "Deletes all given entity (and all its dependencies) by a given list of model identifiers.",
description = "To check or report what dependent object also would be deleted for a certain entity object, "
+
"please use the dependency endpoint to get a report of all dependend entity objects.",
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
parameters = {
@Parameter(
name = API.PARAM_MODEL_ID_LIST,
description = "The list of model identifiers of specific entity type to delete.",
in = ParameterIn.QUERY),
@Parameter(
name = API.PARAM_BULK_ACTION_ADD_INCLUDES,
description = "Indicates if the following 'includes' paramerer shall be processed or not.\n The default is false "),
@Parameter(
name = API.PARAM_BULK_ACTION_INCLUDES,
description = "A comma separated list of names of the EntityType enummeration that defines all entity types that shall be included in the result.")
})
@RequestMapping(
method = RequestMethod.DELETE,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,

View file

@ -63,10 +63,12 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamSessionService;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.SEBClientConnectionService;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.SEBClientInstructionService;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.SEBClientNotificationService;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@WebServiceProfile
@RestController
@RequestMapping("${sebserver.webservice.api.admin.endpoint}" + API.EXAM_MONITORING_ENDPOINT)
@SecurityRequirement(name = "oauth2")
public class ExamMonitoringController {
private static final Logger log = LoggerFactory.getLogger(ExamMonitoringController.class);

View file

@ -37,10 +37,12 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.UserService;
import ch.ethz.seb.sebserver.webservice.servicelayer.exam.ExamAdminService;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamProctoringRoomService;
import ch.ethz.seb.sebserver.webservice.servicelayer.session.ExamSessionService;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@WebServiceProfile
@RestController
@RequestMapping("${sebserver.webservice.api.admin.endpoint}" + API.EXAM_PROCTORING_ENDPOINT)
@SecurityRequirement(name = "oauth2")
public class ExamProctoringController {
private static final Logger log = LoggerFactory.getLogger(ExamProctoringController.class);

View file

@ -24,10 +24,12 @@ import ch.ethz.seb.sebserver.gbl.model.EntityName;
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.AuthorizationService;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.InstitutionDAO;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@WebServiceProfile
@RestController
@RequestMapping("${sebserver.webservice.api.admin.endpoint}" + API.INFO_ENDPOINT)
@SecurityRequirement(name = "oauth2")
public class InfoController {
private final InstitutionDAO institutionDAO;

View file

@ -32,10 +32,12 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.Authorization
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.UserService;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.FilterMap;
import ch.ethz.seb.sebserver.webservice.servicelayer.lms.LmsAPIService;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@WebServiceProfile
@RestController
@RequestMapping("${sebserver.webservice.api.admin.endpoint}" + API.QUIZ_DISCOVERY_ENDPOINT)
@SecurityRequirement(name = "oauth2")
public class QuizController {
private final int defaultPageSize;

View file

@ -53,6 +53,9 @@ sebserver.webservice.lms.openedx.api.token.request.paths=/oauth2/access_token
sebserver.webservice.lms.moodle.api.token.request.paths=
sebserver.webservice.lms.address.alias=lms.mockup.com=lms.address.alias
springdoc.api-docs.enabled=true
springdoc.swagger-ui.enabled=true
# actuator configuration
management.server.port=${server.port}
management.endpoints.web.base-path=/management

View file

@ -45,6 +45,15 @@ sebserver.webservice.http.external.servername=
sebserver.webservice.http.external.port=
sebserver.webservice.http.redirect.gui=/gui
### Open API Documentation
springdoc.api-docs.enabled=false
springdoc.swagger-ui.enabled=false
springdoc.swagger-ui.oauth.clientId=guiClient
springdoc.swagger-ui.oauth.clientSecret=${sebserver.password}
#springdoc.consumes-to-match=application/json,application/x-www-form-urlencoded
#springdoc.default-consumes-media-type=application/x-www-form-urlencoded
springdoc.paths-to-exclude=/exam-api,/exam-api/discovery,/sebserver/error,/sebserver/check,/oauth,/exam-api/v1/*
### webservice API
sebserver.webservice.api.admin.clientId=guiClient
sebserver.webservice.api.admin.endpoint=/admin-api/v1