@Test public void searchObjectByType_oneDocumentFound() throws Exception { String objectType = "COMPLAINT"; int firstRow = 0; int maxRows = 10; String sort = ""; String params = ""; String query = "object_type_s:" + objectType + " AND -status_s:COMPLETE AND -status_s:DELETE AND -status_s:CLOSED AND -status_s:CLOSE" + " AND -status_lcs:INVALID AND -status_lcs:DELETE AND -status_lcs:INACTIVE"; String solrResponse = "{\"responseHeader\":{\"status\":0,\"QTime\":3,\"params\":{\"sort\":\"\",\"indent\":\"true\",\"start\":\"0\",\"q\":\"object_type_s:Complaint\",\"wt\":\"json\",\"rows\":\"10\"}},\"response\":{\"numFound\":5,\"start\":0,\"docs\":[{\"id\":\"142-Complaint\",\"status_s\":\"DRAFT\",\"author\":\"tester\",\"author_s\":\"tester\",\"modifier_s\":\"testModifier\",\"last_modified\":\"2014-08-15T17:13:55Z\",\"create_tdt\":\"2014-08-15T17:13:55Z\",\"title_t\":\"testTitle\",\"name\":\"20140815_142\",\"object_id_s\":\"142\",\"owner_s\":\"tester\",\"object_type_s\":\"Complaint\",\"_version_\":1477062417430085632}]}}"; Capture<ApplicationSearchEvent> capturedEvent = new Capture<>(); expect(mockAuthentication.getName()).andReturn("user").atLeastOnce(); expect(mockExecuteSolrQuery.getResultsByPredefinedQuery(mockAuthentication, SolrCore.QUICK_SEARCH, query, firstRow, maxRows, sort, params)).andReturn(solrResponse); mockSearchEventPublisher.publishSearchEvent(capture(capturedEvent)); replayAll(); MvcResult result = mockMvc.perform( get("/api/v1/plugin/search/{objectType}", objectType) .session(mockHttpSession) .principal(mockAuthentication)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andReturn(); verifyAll(); String jsonString = result.getResponse().getContentAsString(); log.debug("Got JSON [{}]", jsonString); assertEquals(solrResponse, jsonString); }
protected void publishSearchEvent(Authentication authentication, HttpSession httpSession, boolean succeeded, String jsonPayload) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); SolrResponse solrResponse = gson.fromJson(jsonPayload, SolrResponse.class); if (solrResponse.getResponse() != null) { List<SolrDocument> solrDocs = solrResponse.getResponse().getDocs(); String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); Long objectId = null; for (SolrDocument doc : solrDocs) { try { objectId = Long.parseLong(doc.getObject_id_s()); } catch (NumberFormatException e) { objectId = new Long(-1); } ApplicationSearchEvent event = new ApplicationSearchEvent(objectId, doc.getObject_type_s(), authentication.getName(), succeeded, ipAddress); getSearchEventPublisher().publishSearchEvent(event); } } }
SearchObjectByTypeAPIController { protected void publishSearchEvent(Authentication authentication, HttpSession httpSession, boolean succeeded, String jsonPayload) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); SolrResponse solrResponse = gson.fromJson(jsonPayload, SolrResponse.class); if (solrResponse.getResponse() != null) { List<SolrDocument> solrDocs = solrResponse.getResponse().getDocs(); String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); Long objectId = null; for (SolrDocument doc : solrDocs) { try { objectId = Long.parseLong(doc.getObject_id_s()); } catch (NumberFormatException e) { objectId = new Long(-1); } ApplicationSearchEvent event = new ApplicationSearchEvent(objectId, doc.getObject_type_s(), authentication.getName(), succeeded, ipAddress); getSearchEventPublisher().publishSearchEvent(event); } } } }
SearchObjectByTypeAPIController { protected void publishSearchEvent(Authentication authentication, HttpSession httpSession, boolean succeeded, String jsonPayload) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); SolrResponse solrResponse = gson.fromJson(jsonPayload, SolrResponse.class); if (solrResponse.getResponse() != null) { List<SolrDocument> solrDocs = solrResponse.getResponse().getDocs(); String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); Long objectId = null; for (SolrDocument doc : solrDocs) { try { objectId = Long.parseLong(doc.getObject_id_s()); } catch (NumberFormatException e) { objectId = new Long(-1); } ApplicationSearchEvent event = new ApplicationSearchEvent(objectId, doc.getObject_type_s(), authentication.getName(), succeeded, ipAddress); getSearchEventPublisher().publishSearchEvent(event); } } }  }
SearchObjectByTypeAPIController { protected void publishSearchEvent(Authentication authentication, HttpSession httpSession, boolean succeeded, String jsonPayload) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); SolrResponse solrResponse = gson.fromJson(jsonPayload, SolrResponse.class); if (solrResponse.getResponse() != null) { List<SolrDocument> solrDocs = solrResponse.getResponse().getDocs(); String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); Long objectId = null; for (SolrDocument doc : solrDocs) { try { objectId = Long.parseLong(doc.getObject_id_s()); } catch (NumberFormatException e) { objectId = new Long(-1); } ApplicationSearchEvent event = new ApplicationSearchEvent(objectId, doc.getObject_type_s(), authentication.getName(), succeeded, ipAddress); getSearchEventPublisher().publishSearchEvent(event); } } }  @RequestMapping(value = "/{objectType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String searchObjectByType(
            @PathVariable("objectType") String objectType,
            @RequestParam(value = "objectSubTypes", required = false, defaultValue = "") List<String> objectSubTypes,
            @RequestParam(value = "s", required = false, defaultValue = "") String sort,
            @RequestParam(value = "start", required = false, defaultValue = "0") int startRow,
            @RequestParam(value = "n", required = false, defaultValue = "10") int maxRows,
            @RequestParam(value = "assignee", required = false, defaultValue = "") String assignee,
            @RequestParam(value = "activeOnly", required = false, defaultValue = "true") boolean activeOnly,
            @RequestParam(value = "filters", required = false, defaultValue = "") String filters,
            @RequestParam(value = "searchQuery", required = false, defaultValue = "") String searchQuery,
            Authentication authentication,
            HttpSession httpSession); @RequestMapping(value = "/advanced/{objectType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String searchAdvancedObjectByType(
            @PathVariable("objectType") String objectType,
            @RequestParam(value = "s", required = false, defaultValue = "") String sort,
            @RequestParam(value = "start", required = false, defaultValue = "0") int startRow,
            @RequestParam(value = "n", required = false, defaultValue = "10") int maxRows,
            @RequestParam(value = "assignee", required = false, defaultValue = "") String assignee,
            @RequestParam(value = "activeOnly", required = false, defaultValue = "true") boolean activeOnly,
            Authentication authentication,
            HttpSession httpSession); @RequestMapping(value = "/advanced/{objectType}/all", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<String> searchAllAdvancedObjectByType(
            @PathVariable("objectType") String objectType,
            @RequestParam(value = "s", required = false, defaultValue = "") String sort,
            @RequestParam(value = "start", required = false, defaultValue = "0") int startRow,
            @RequestParam(value = "n", required = false, defaultValue = "10") int maxRows,
            @RequestParam(value = "assignee", required = false, defaultValue = "") String assignee,
            @RequestParam(value = "activeOnly", required = false, defaultValue = "true") boolean activeOnly,
            Authentication authentication,
            HttpSession httpSession); AcmPluginManager getAcmPluginManager(); void setAcmPluginManager(AcmPluginManager acmPluginManager); ExecuteSolrQuery getExecuteSolrQuery(); void setExecuteSolrQuery(ExecuteSolrQuery executeSolrQuery); SearchEventPublisher getSearchEventPublisher(); void setSearchEventPublisher(SearchEventPublisher searchEventPublisher); }
SearchObjectByTypeAPIController { protected void publishSearchEvent(Authentication authentication, HttpSession httpSession, boolean succeeded, String jsonPayload) { Gson gson = new GsonBuilder().setPrettyPrinting().create(); SolrResponse solrResponse = gson.fromJson(jsonPayload, SolrResponse.class); if (solrResponse.getResponse() != null) { List<SolrDocument> solrDocs = solrResponse.getResponse().getDocs(); String ipAddress = (String) httpSession.getAttribute("acm_ip_address"); Long objectId = null; for (SolrDocument doc : solrDocs) { try { objectId = Long.parseLong(doc.getObject_id_s()); } catch (NumberFormatException e) { objectId = new Long(-1); } ApplicationSearchEvent event = new ApplicationSearchEvent(objectId, doc.getObject_type_s(), authentication.getName(), succeeded, ipAddress); getSearchEventPublisher().publishSearchEvent(event); } } }  @RequestMapping(value = "/{objectType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String searchObjectByType(
            @PathVariable("objectType") String objectType,
            @RequestParam(value = "objectSubTypes", required = false, defaultValue = "") List<String> objectSubTypes,
            @RequestParam(value = "s", required = false, defaultValue = "") String sort,
            @RequestParam(value = "start", required = false, defaultValue = "0") int startRow,
            @RequestParam(value = "n", required = false, defaultValue = "10") int maxRows,
            @RequestParam(value = "assignee", required = false, defaultValue = "") String assignee,
            @RequestParam(value = "activeOnly", required = false, defaultValue = "true") boolean activeOnly,
            @RequestParam(value = "filters", required = false, defaultValue = "") String filters,
            @RequestParam(value = "searchQuery", required = false, defaultValue = "") String searchQuery,
            Authentication authentication,
            HttpSession httpSession); @RequestMapping(value = "/advanced/{objectType}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody String searchAdvancedObjectByType(
            @PathVariable("objectType") String objectType,
            @RequestParam(value = "s", required = false, defaultValue = "") String sort,
            @RequestParam(value = "start", required = false, defaultValue = "0") int startRow,
            @RequestParam(value = "n", required = false, defaultValue = "10") int maxRows,
            @RequestParam(value = "assignee", required = false, defaultValue = "") String assignee,
            @RequestParam(value = "activeOnly", required = false, defaultValue = "true") boolean activeOnly,
            Authentication authentication,
            HttpSession httpSession); @RequestMapping(value = "/advanced/{objectType}/all", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody List<String> searchAllAdvancedObjectByType(
            @PathVariable("objectType") String objectType,
            @RequestParam(value = "s", required = false, defaultValue = "") String sort,
            @RequestParam(value = "start", required = false, defaultValue = "0") int startRow,
            @RequestParam(value = "n", required = false, defaultValue = "10") int maxRows,
            @RequestParam(value = "assignee", required = false, defaultValue = "") String assignee,
            @RequestParam(value = "activeOnly", required = false, defaultValue = "true") boolean activeOnly,
            Authentication authentication,
            HttpSession httpSession); AcmPluginManager getAcmPluginManager(); void setAcmPluginManager(AcmPluginManager acmPluginManager); ExecuteSolrQuery getExecuteSolrQuery(); void setExecuteSolrQuery(ExecuteSolrQuery executeSolrQuery); SearchEventPublisher getSearchEventPublisher(); void setSearchEventPublisher(SearchEventPublisher searchEventPublisher);  }