UserSelectionsApi { @ApiOperation(value = "Get list of user selection sets", nickname = "getUserSelectionType") @RequestMapping( method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) public @ResponseBody @ResponseStatus(HttpStatus.OK) List<Selection> get( @ApiIgnore HttpSession httpSession ) throws Exception { return selectionRepository.findAll(); }  @ApiOperation(value = "Get list of user selection sets", nickname = "getUserSelectionType") @RequestMapping( method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody @ResponseStatus(HttpStatus.OK) List<Selection> get(
        @ApiIgnore
            HttpSession httpSession
    ); @ApiOperation(value = "Add a user selection set", nickname = "createUserSelectionType") @RequestMapping( method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @ApiResponses(value = { @ApiResponse(code = 201, message = "Selection created."), @ApiResponse(code = 400, message = "A selection with that id or name already exist."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) @PreAuthorize("hasRole('UserAdmin')") @ResponseBody ResponseEntity createPersistentSelectionType(
        @ApiParam(
            name = "selection"
        )
        @RequestBody
            Selection selection
    ); @ApiOperation( value = "Update a user selection set", notes = "", nickname = "updateUserSelection") @RequestMapping( value = "/{selectionIdentifier}", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.NO_CONTENT) @ApiResponses(value = { @ApiResponse(code = 204, message = "Selection updated."), @ApiResponse(code = 404, message = "Selection not found."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) @PreAuthorize("hasRole('UserAdmin')") ResponseEntity updateUserSelection(
        @ApiParam(
            value = "Selection identifier",
            required = true
        )
        @PathVariable
            Integer selectionIdentifier,
        @ApiParam(
            name = "selection"
        )
        @RequestBody
            Selection selection
    ); @ApiOperation( value = "Remove a user selection set", notes = "", nickname = "deleteUserSelection") @RequestMapping( value = "/{selectionIdentifier}", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.NO_CONTENT) @ApiResponses(value = { @ApiResponse(code = 204, message = "Selection removed."), @ApiResponse(code = 404, message = "Selection not found."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) @PreAuthorize("hasRole('UserAdmin')") ResponseEntity deleteUserSelection(
        @ApiParam(
            value = "Selection identifier",
            required = true
        )
        @PathVariable
            Integer selectionIdentifier
    ); @ApiOperation(value = "Get record in a user selection set", nickname = "getSelection") @RequestMapping( method = RequestMethod.GET, value = "/{selectionIdentifier}/{userIdentifier}", produces = { MediaType.APPLICATION_JSON_VALUE }) @PreAuthorize("hasRole('Guest')") @ResponseBody @ResponseStatus(HttpStatus.OK) List<String> get(
        @ApiParam(value = "Selection identifier",
            required = true)
        @PathVariable
            Integer selectionIdentifier,
        @ApiParam(value = "User identifier",
            required = true)
        @PathVariable
            Integer userIdentifier,
        @ApiIgnore
        HttpSession httpSession
    ); @ApiOperation(value = "Add items to a user selection set", nickname = "addToUserSelection") @RequestMapping( method = RequestMethod.PUT, value = "/{selectionIdentifier}/{userIdentifier}", produces = { MediaType.APPLICATION_JSON_VALUE }) @PreAuthorize("hasRole('Guest')") @ResponseBody @ApiResponses(value = { @ApiResponse(code = 201, message = "Records added to selection set."), @ApiResponse(code = 404, message = "Selection or user or at least one UUID not found."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) ResponseEntity<String> addToUserSelection(
        @ApiParam(value = "Selection identifier",
            required = true)
        @PathVariable
            Integer selectionIdentifier,
        @ApiParam(value = "User identifier",
            required = true)
        @PathVariable
            Integer userIdentifier,
        @ApiParam(value = "One or more record UUIDs.",
            required = false)
        @RequestParam(required = false)
            String[] uuid,
        @ApiIgnore
            HttpSession httpSession
    ); @ApiOperation(value = "Remove items to a user selection set", nickname = "deleteFromUserSelection") @RequestMapping( method = RequestMethod.DELETE, value = "/{selectionIdentifier}/{userIdentifier}", produces = { MediaType.APPLICATION_JSON_VALUE }) @PreAuthorize("hasRole('Guest')") @ResponseBody @ApiResponses(value = { @ApiResponse(code = 204, message = "Items removed from a set."), @ApiResponse(code = 404, message = "Selection or user not found."), @ApiResponse(code = 403, message = ApiParams.API_RESPONSE_NOT_ALLOWED_ONLY_USER_ADMIN) }) ResponseEntity deleteFromUserSelection(
        @ApiParam(value = "Selection identifier",
            required = true)
        @PathVariable
            Integer selectionIdentifier,
        @ApiParam(value = "User identifier",
            required = true)
        @PathVariable
            Integer userIdentifier,
        @ApiParam(value = "One or more record UUIDs. If null, remove all.",
            required = false)
        @RequestParam(required = false)
            String[] uuid,
        @ApiIgnore
            HttpSession httpSession
    );  }
@Test public void getSelection() throws Exception { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockMvc.perform(get("/srv/api/userselections") .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().isOk()) .andExpect(content().contentType(API_JSON_EXPECTED_ENCODING)) .andExpect(jsonPath("$", hasSize(2))); }
@Test public void addDeleteSelection() throws Exception { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); String name = "notification"; Selection selection = selectionRepository.findOneByName(name); assertNull(selection); Selection newSelection = new Selection(); newSelection.setId(10); newSelection.setName(name); newSelection.setWatchable(true); Map<String, String> t = new HashMap<>(); t.put("fre", "french"); newSelection.setLabelTranslations(t); Gson gson = new GsonBuilder() .setFieldNamingStrategy(new JsonFieldNamingStrategy()) .setExclusionStrategies(new FieldNameExclusionStrategy("_labelTranslations", "watchable")) .create(); String json = gson.toJson(newSelection); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockHttpSession = loginAsAdmin(); MvcResult r = this.mockMvc.perform(put("/srv/api/userselections") .content(json) .contentType(API_JSON_EXPECTED_ENCODING) .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().is(201)) .andExpect(content().contentType(API_JSON_EXPECTED_ENCODING)) .andReturn(); Selection createdSelection = selectionRepository.findOneByName(name); assertNotNull(createdSelection); assertEquals(name, createdSelection.getName()); assertEquals(false, createdSelection.isWatchable()); this.mockMvc.perform(put("/srv/api/userselections/11111/11111") .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().isNotFound()); this.mockMvc.perform(put("/srv/api/userselections/" + createdSelection.getId() + "/11111") .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().isNotFound()); this.mockMvc.perform(put("/srv/api/userselections/" + createdSelection.getId() + "/1?uuid=ABCD") .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().isNotFound()); String metadataId = importMetadata(context); String metadataUuid = _dataManager.getMetadataUuid(metadataId); this.mockMvc.perform(put("/srv/api/userselections/" + createdSelection.getId() + "/1?uuid=" + metadataUuid) .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().isCreated()); this.mockMvc.perform(get("/srv/api/userselections/" + createdSelection.getId() + "/1") .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().isOk()) .andExpect(content().contentType(API_JSON_EXPECTED_ENCODING)) .andExpect(jsonPath("$", hasSize(1))) .andExpect(jsonPath("$[*]", hasItem(metadataUuid))); this.mockMvc.perform(delete("/srv/api/userselections/" + createdSelection.getId() + "/1?uuid=" + metadataUuid) .session(this.mockHttpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().isNoContent()); this.mockMvc.perform(delete("/srv/api/userselections/" + createdSelection.getId()) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().is(204)); assertFalse(selectionRepository.exists(createdSelection.getId())); ; }