Class ActorAdminController

java.lang.Object
de.gustavblass.fsu.fmi.roombooking.controller.admin.ActorAdminController

@Controller public class ActorAdminController extends Object
Defines the behaviour of the web server for the path /admin/users.
  • Field Details

    • actorService

      private final ActorService actorService
      Used to retrieve and save Actors from the database.
    • pathLocaliser

      @NonNull private final @NonNull PathLocaliser pathLocaliser
      Used to resolve the URL paths in the correct Locale.
  • Constructor Details

  • Method Details

    • getAdminArea

      @GetMapping({"/admin","/en/admin"}) @NonNull public @NonNull String getAdminArea()
      Handles GET requests to /admin and returns teh main administrators' interface.
      Returns:
      The ActorAdminController.Template.ADMIN_MAIN page.
    • getActors

      @GetMapping({"/admin/benutzer","/en/admin/users"}) @NonNull public @NonNull String getActors(@RequestParam(name="page",defaultValue="0") int page, @Max(20L) @RequestParam(name="size",defaultValue="2") @Max(20L) int size, @Pattern(regexp="^(?!password).+$",message="{users.sort-by.error.password}") @RequestParam(name="sortBy",defaultValue="id") @NonNull @Pattern(regexp="^(?!password).+$",message="{users.sort-by.error.password}") @NonNull String sortBy, @RequestParam(name="ascending",defaultValue="true") boolean ascending, @NonNull @NonNull org.springframework.ui.Model model)
      Handles GET requests to /users. Retrieves a paginated subset of all Actors according to the URL parameters given.
      Parameters:
      page - The index of the page requested.
      size - How many Actor items each page in the pagination has.
      sortBy - Which of the Actors' fields shall be used to sort the items. Determines the order of the items and thereby also which items are present on the requested page. Must not be the password.
      ascending - Whether to count from the start or from the end of the list sorted using sortBy.
      model - Will be filled with the data for the Thymeleaf template.
      Returns:
      The users.html template filled with the requested Actors.
    • getCreateActorForm

      @GetMapping({"/admin/benutzer/hinzuf\u00fcgen","/en/admin/users/add"}) @PreAuthorize("hasRole('FACULTY_ADMINISTRATION')") public String getCreateActorForm(LocalActorCreatedByAdminDTO actor)
      Handles GET requests to /admin/users/add.
      Parameters:
      actor - An empty ActorCreatedByAdminDTO only used for binding in the Thymeleaf template.
      Returns:
      The admins' create-user form.
    • createActor

      @PostMapping({"/admin/benutzer/hinzuf\u00fcgen","/en/admin/users/add"}) @PreAuthorize("hasRole('FACULTY_ADMINISTRATION')") public String createActor(@Valid @Valid LocalActorCreatedByAdminDTO dto, @NonNull @NonNull org.springframework.validation.BindingResult bindingResult, @NonNull @NonNull jakarta.servlet.http.HttpServletResponse response) throws de.gustavblass.commons.exceptions.IllegalArgumentException, IllegalStateException

      Handles POST requests to /admin/users/add and saves a new Actor based on the form input (represented as an ActorCreatedByAdminDTO) to the database.

      Validates the input according to the annotations in ActorCreatedByAdminDTO. If there are errors, localised error messages are displayed next to the corresponding input fields.

      If the given user name already exists, a localised error message is shown to the admin.

      If the admin's ActorRole does not suffice to create a user of the specified role, a localised error message is shown next to the role input field.

      Parameters:
      dto - The form input by the admin, represented as a data-transfer object.
      bindingResult - The result of the DTO validation.
      response - The web server's response to the admin's HTTP request.
      Returns:
      In case of success: The user page (e.g. /users/@jason). Otherwise: The form, with the original input preserved and with error messages shown.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If no LocalActorCreatedByAdminDTO.password is set.
      IllegalStateException - If the user path is malformed.