LinksApi { private Page<Link> getLinks( JSONObject filter, Integer[] groupIdFilter, Integer[] groupOwnerIdFilter, Pageable pageRequest, UserSession userSession) throws SQLException, JSONException { Integer[] editingGroups = null; if (userSession.getProfile() != Profile.Administrator) { final List<Integer> editingGroupList = AccessManager.getGroups(userSession, Profile.Editor); if (editingGroupList.size() > 0) { editingGroups = editingGroupList.toArray(new Integer[editingGroupList.size()]); } } if (filter == null && (groupIdFilter != null || groupOwnerIdFilter != null || editingGroups != null)) { return linkRepository.findAll(LinkSpecs.filter(null, null, null, groupIdFilter, groupOwnerIdFilter, editingGroups), pageRequest); } if (filter != null) { Integer stateToMatch = null; String url = null; String associatedRecord = null; if (filter.has("lastState")) { stateToMatch = 0; if (filter.getString("lastState").equalsIgnoreCase("ok")) { stateToMatch = 1; } else if (filter.getString("lastState").equalsIgnoreCase("ko")) { stateToMatch = -1; } } if (filter.has("url")) { url = filter.getString("url"); } if (filter.has("records")) { associatedRecord = filter.getString("records"); } return linkRepository.findAll(LinkSpecs.filter(url, stateToMatch, associatedRecord, groupIdFilter, groupOwnerIdFilter, editingGroups), pageRequest); } else { return linkRepository.findAll(pageRequest); } }  @PostConstruct void iniMBeansSlidingWindowWithEmptySlot(); @ApiOperation( value = "Get record links", notes = "", nickname = "getRecordLinks") @ApiImplicitParams({ @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query", value = "Results page you want to retrieve (0..N)"), @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query", value = "Number of records per page."), @ApiImplicitParam(name = "sort", allowMultiple = false, dataType = "string", paramType = "query", value = "Sorting criteria in the format: property(,asc|desc). " + "Default sort order is ascending. ") }) @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize("isAuthenticated()") Page<Link> getRecordLinks(
        @ApiParam(value = "Filter, e.g. \"{url: 'png', lastState: 'ko', records: 'e421', groupId: 12}\", lastState being 'ok'/'ko'/'unknown'", required = false) @RequestParam(required = false) JSONObject filter,
        @ApiParam(value = "Optional, filter links to records published in that group.", required = false)
        @RequestParam(required = false) Integer[] groupIdFilter,
        @ApiParam(value = "Optional, filter links to records created in that group.", required = false)
        @RequestParam(required = false) Integer[] groupOwnerIdFilter,
        @ApiIgnore Pageable pageRequest,
        @ApiParam(hidden = true)
        @ApiIgnore
            HttpSession session,
        @ApiParam(hidden = true)
        @ApiIgnore
            HttpServletRequest request); @ApiOperation( value = "Get record links as CSV", notes = "", nickname = "getRecordLinksAsCSV") @ApiImplicitParams({ @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query", value = "Results page you want to retrieve (0..N)"), @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query", value = "Number of records per page."), @ApiImplicitParam(name = "sort", allowMultiple = false, dataType = "string", paramType = "query", value = "Sorting criteria in the format: property(,asc|desc). " + "Default sort order is ascending. ") }) @RequestMapping( path = "/csv", method = RequestMethod.GET, produces = MediaType.TEXT_PLAIN_VALUE ) @PreAuthorize("isAuthenticated()") @ResponseBody void getRecordLinksAsCsv(
        @ApiParam(value = "Filter, e.g. \"{url: 'png', lastState: 'ko', records: 'e421', groupId: 12}\", lastState being 'ok'/'ko'/'unknown'", required = false) @RequestParam(required = false) JSONObject filter,
        @ApiParam(value = "Optional, filter links to records published in that group.", required = false)
        @RequestParam(required = false) Integer[] groupIdFilter,
        @ApiParam(value = "Optional, filter links to records created in that group.", required = false)
        @RequestParam(required = false) Integer[] groupOwnerIdFilter,
        @ApiIgnore
            Pageable pageRequest,
        @ApiParam(hidden = true)
        @ApiIgnore
            HttpSession session,
        @ApiParam(hidden = true)
        @ApiIgnore
            HttpServletResponse response); @ApiOperation( value = "Analyze records links", notes = "One of uuids or bucket parameter is required if not an Administrator. Only records that you can edit will be validated.", nickname = "analyzeRecordLinks") @RequestMapping( produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST) @PreAuthorize("hasRole('Editor')") @ResponseStatus(HttpStatus.CREATED) @ResponseBody SimpleMetadataProcessingReport analyzeRecordLinks(
        @ApiParam(value = API_PARAM_RECORD_UUIDS_OR_SELECTION,
            required = false,
            example = "")
        @RequestParam(required = false)
            String[] uuids,
        @ApiParam(
            value = ApiParams.API_PARAM_BUCKET_NAME,
            required = false)
        @RequestParam(
            required = false
        )
            String bucket,
        @ApiParam(
            value = "Only allowed if Administrator."
        )
        @RequestParam(
            required = false,
            defaultValue = "true")
            boolean removeFirst,
        @RequestParam(
            required = false,
            defaultValue = "false")
            boolean analyze,
        @ApiIgnore
            HttpSession httpSession,
        @ApiIgnore
            HttpServletRequest request
    ); @ApiOperation( value = "Remove all links and status history", notes = "", nickname = "purgeAll") @RequestMapping( produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.DELETE) @ResponseStatus(value = HttpStatus.OK) @PreAuthorize("hasRole('Administrator')") @ResponseBody ResponseEntity purgeAll();  }
@Test public void getLinks() throws Exception { Long operationsCount = linkRepository.count(); final MockHttpSession httpSession = this.loginAsAdmin(); this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); this.mockMvc.perform(post("/srv/api/records/links?uuid=" + this.uuid) .session(httpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().isCreated()); Assert.assertEquals(1, linkRepository.count()); this.mockMvc.perform(get("/srv/api/records/links") .session(httpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().isOk()) .andExpect(content().contentType(API_JSON_EXPECTED_ENCODING)) .andExpect(jsonPath("$.content", hasSize(1))) .andExpect(jsonPath("$.content[0].url").value(equalTo("http: .andExpect(jsonPath("$.content[0].records", hasSize(1))) .andExpect(jsonPath("$.content[0].records[0].metadataId").value(equalTo(this.id))) .andExpect(jsonPath("$.content[0].records[0].metadataUuid").value(equalTo(md.getUuid())));; this.mockMvc.perform(delete("/srv/api/records/links") .session(httpSession) .accept(MediaType.parseMediaType("application/json"))) .andExpect(status().isNoContent()); Assert.assertEquals(0, linkRepository.count()); }