ConvocationRestController { @JsonView(Views.ConvocationInternal.class) @PostMapping public ResponseEntity<?> create( @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights, @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid, @RequestAttribute("STELA-Current-Profile-UUID") String currentProfileUuid, @Valid @RequestBody Convocation params) { validateAccess(currentLocalAuthUuid, null, currentProfileUuid, null, rights, Collections.singletonList(Right.CONVOCATION_DEPOSIT), false); try { Convocation convocation = convocationService.create(params, currentLocalAuthUuid, currentProfileUuid); return new ResponseEntity<>(convocation, HttpStatus.CREATED); } catch (ConvocationException e) { return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST); } } @Autowired  ConvocationRestController(
            ConvocationService convocationService,
            RecipientService recipientService); @JsonView(Views.SearchSentConvocation.class) @GetMapping("/sent") ResponseEntity<SearchResultsUI> getSentConvocation(
            @RequestParam(value = "multifield", required = false) String multifield,
            @RequestParam(value = "sentDateFrom", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate sentDateFrom,
            @RequestParam(value = "sentDateTo", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate sentDateTo,
            @RequestParam(value = "meetingDateFrom", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate meetingDateFrom,
            @RequestParam(value = "meetingDateTo", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate meetingDateTo,
            @RequestParam(value = "assemblyType", required = false) String assemblyType,
            @RequestParam(value = "subject", required = false) String subject,
            @RequestParam(value = "filter", required = false) String filter,
            @RequestParam(value = "limit", required = false, defaultValue = "25") Integer limit,
            @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset,
            @RequestParam(value = "column", required = false, defaultValue = "meetingDate") String column,
            @RequestParam(value = "direction", required = false, defaultValue = "DESC") String direction,
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute("STELA-Current-Profile-UUID") String currentProfileUuid,
            @RequestAttribute("STELA-Current-Profile-Groups") Set<String> groups); @GetMapping("/received") ResponseEntity<SearchResultsUI> getReceivedConvocation(
            @RequestParam(value = "multifield", required = false) String multifield,
            @RequestParam(value = "meetingDateFrom", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate meetingDateFrom,
            @RequestParam(value = "meetingDateTo", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate meetingDateTo,
            @RequestParam(value = "assemblyType", required = false) String assemblyType,
            @RequestParam(value = "subject", required = false) String subject,
            @RequestParam(value = "filter", required = false) String filter,
            @RequestParam(value = "limit", required = false, defaultValue = "25") Integer limit,
            @RequestParam(value = "offset", required = false, defaultValue = "0") Integer offset,
            @RequestParam(value = "column", required = false, defaultValue = "meetingDate") String column,
            @RequestParam(value = "direction", required = false, defaultValue = "DESC") String direction,
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute(name = "STELA-Current-Profile-UUID", required = false) String currentProfileUuid,
            @RequestAttribute(name = "STELA-Current-Recipient", required = false) Recipient recipient); @JsonView(Views.ConvocationInternal.class) @GetMapping("/{uuid}") ResponseEntity<Convocation> getConvocation(
            @PathVariable String uuid,
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute("STELA-Current-Profile-UUID") String currentProfileUuid); @GetMapping("/received/{uuid}") ResponseEntity<ReceivedConvocationUI> openConvocation(
            @PathVariable String uuid,
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute(name = "STELA-Current-Profile-UUID", required = false) String profileUuid,
            @RequestAttribute(name = "STELA-Current-Recipient", required = false) Recipient recipient); @JsonView(Views.ConvocationInternal.class) @PostMapping ResponseEntity<?> create(
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute("STELA-Current-Profile-UUID") String currentProfileUuid,
            @Valid @RequestBody Convocation params); @JsonView(Views.Convocation.class) @PutMapping("/{uuid}") ResponseEntity<Convocation> update(
            @PathVariable String uuid,
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute("STELA-Current-Profile-UUID") String currentProfileUuid,
            @RequestBody Convocation params); @PostMapping("/{uuid}/upload") ResponseEntity<?> uploadFiles(
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute("STELA-Current-Profile-UUID") String currentProfileUuid,
            @PathVariable String uuid,
            @RequestParam(name = "file") MultipartFile file,
            @RequestParam(name = "procuration", required = false) MultipartFile procuration,
            @RequestParam(name = "annexes", required = false) MultipartFile[] annexes,
            @RequestParam(name = "tags", required = false) String[] tags); @PutMapping("/{uuid}/upload") ResponseEntity<?> uploadAdditionalFiles(
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute("STELA-Current-Profile-UUID") String currentProfileUuid,
            @PathVariable String uuid,
            @RequestParam(name = "annexes", required = false) MultipartFile[] annexes,
            @RequestParam(name = "tags", required = false) String[] tags); @PutMapping("/{uuid}/upload-minutes") ResponseEntity<?> uploadMinutes(
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute("STELA-Current-Profile-UUID") String currentProfileUuid,
            @PathVariable String uuid,
            @RequestParam MultipartFile minutes); @GetMapping("/{uuid}/file/{fileUuid}") ResponseEntity getFile(
            HttpServletResponse response,
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute(name = "STELA-Current-Profile-UUID", required = false) String currentProfileUuid,
            @RequestAttribute(name = "STELA-Current-Recipient", required = false) Recipient recipient,
            @PathVariable String uuid,
            @PathVariable String fileUuid,
            @RequestParam(required = false) Boolean stamped,
            @RequestParam(required = false) Integer x,
            @RequestParam(required = false) Integer y,
            @RequestParam(required = false, defaultValue = "inline") String disposition); @GetMapping("/{uuid}/archive") ResponseEntity getArchive(
            HttpServletResponse response,
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute(name = "STELA-Current-Profile-UUID", required = false) String currentProfileUuid,
            @PathVariable String uuid,
            @RequestParam(required = false, defaultValue = "inline") String disposition); @GetMapping("/{uuid}/presence.{extension}") ResponseEntity getPresenceList(
            HttpServletResponse response,
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @PathVariable String uuid,
            @PathVariable DocumentGeneratorFactory.Extension extension); @PutMapping("/received/{uuid}/{responseType}") ResponseEntity answerConvocation(
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute(name = "STELA-Current-Profile-UUID", required = false) String currentProfileUuid,
            @RequestAttribute(name = "STELA-Current-Recipient", required = false) Recipient recipient,
            @PathVariable String uuid,
            @PathVariable ResponseType responseType); @PutMapping("/received/{uuid}/{responseType}/{substituteUuid}") ResponseEntity answerConvocationWithProcuration(
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute(name = "STELA-Current-Profile-UUID", required = false) String currentProfileUuid,
            @RequestAttribute(name = "STELA-Current-Recipient", required = false) Recipient recipient,
            @PathVariable String uuid,
            @PathVariable ResponseType responseType,
            @PathVariable String substituteUuid); @PutMapping("/received/{uuid}/question/{questionUuid}/{value}") ResponseEntity answerQuestion(
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute(name = "STELA-Current-Profile-UUID", required = false) String currentProfileUuid,
            @RequestAttribute(name = "STELA-Current-Recipient", required = false) Recipient recipient,
            @PathVariable String uuid,
            @PathVariable String questionUuid,
            @PathVariable Boolean value); @PutMapping("/{uuid}/cancel") ResponseEntity cancelConvocation(
            @PathVariable String uuid,
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute("STELA-Current-Profile-UUID") String currentProfileUuid); @PostMapping("/{uuid}/file/{fileUuid}/tag/{tagUuid}") ResponseEntity addTag(
            @PathVariable String uuid,
            @PathVariable String fileUuid,
            @PathVariable String tagUuid,
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute("STELA-Current-Profile-UUID") String currentProfileUuid); @DeleteMapping("/{uuid}/file/{fileUuid}/tag/{tagUuid}") ResponseEntity removeTag(
            @PathVariable String uuid,
            @PathVariable String fileUuid,
            @PathVariable String tagUuid,
            @RequestAttribute("STELA-Current-Profile-Rights") Set<Right> rights,
            @RequestAttribute("STELA-Current-Local-Authority-UUID") String currentLocalAuthUuid,
            @RequestAttribute("STELA-Current-Profile-UUID") String currentProfileUuid); @ExceptionHandler(AccessNotGrantedException.class) ResponseEntity accessNotGrantedHandler(HttpServletRequest request, AccessNotGrantedException exception); @ExceptionHandler(NotFoundException.class) ResponseEntity notFoundHandler(HttpServletRequest request, NotFoundException exception); @ExceptionHandler(ConvocationCancelledException.class) ResponseEntity<String> convocationCancelledHandler(HttpServletRequest request,
            ConvocationCancelledException exception); @ExceptionHandler(ConvocationNotAvailableException.class) ResponseEntity<String> convocationNotAvailableHandler(HttpServletRequest request,
            ConvocationNotAvailableException exception);  }
@Test public void createSuccessfully() throws Exception { Set<Right> rights = Collections.singleton(Right.CONVOCATION_DEPOSIT); given(convocationService.create(createDummyConvocation(), "mairie-test", "profile-one")).willReturn(createDummyConvocation()); mockMvc.perform(post("/api/convocation") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(createDummyConvocationAsJsonString()) .requestAttr("STELA-Current-Profile-Rights", rights) .requestAttr("STELA-Current-Local-Authority-UUID", "mairie-test") .requestAttr("STELA-Current-Profile-UUID", "profile-one")) .andExpect(status().isCreated()); }
@Test public void creationMissingFields() throws Exception { Set<Right> rights = new HashSet<>(); rights.add(Right.CONVOCATION_DEPOSIT); ObjectMapper objectMapper = new ObjectMapper(); Map<String, String> body = new HashMap<>(); body.put("subject", "convocation test two"); body.put("comment", "comment convocation test two"); given(convocationService.create(createDummyConvocation(), "mairie-test", "profile-one")).willReturn(createDummyConvocation()); mockMvc.perform(post("/api/convocation") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(objectMapper.writeValueAsString(body)) .requestAttr("STELA-Current-Profile-Rights", rights) .requestAttr("STELA-Current-Local-Authority-UUID", "mairie-test") .requestAttr("STELA-Current-Profile-UUID", "profile-one")) .andExpect(status().isBadRequest()); }