@Test public void testSearchGet() throws UnsupportedEncodingException { String queryNotFound = "not found"; String motivation = null; String date = null; String user = null; String page = null; ServiceResponse notFoundResponse = new ServiceResponse(Status.NOT_FOUND, null); Parameters params = new Parameters(queryNotFound, motivation, date, user); when(textSearchService.getTextPositions(queryNotFound, "http: when(oaAnnotationSearchService.getAnnotationPage(params, "http: when(oaSearchService.getAnnotationPage(queryNotFound, "http: ResponseEntity<Map<String, Object>> responseEntity = controller.searchOAMixedGet(queryNotFound, motivation, date, user, page, null, null,request); assertEquals(responseEntity.getStatusCode().NOT_FOUND, HttpStatus.NOT_FOUND); Map<String, Object> map = new HashMap<>(); ServiceResponse foundResponse = new ServiceResponse(Status.OK, map); String queryFound = "found"; params.setQuery(queryFound); when(textSearchService.getTextPositions(queryFound, "http: when(oaAnnotationSearchService.getAnnotationPage(params, "http: when(oaSearchService.getAnnotationPage(queryFound, "http: responseEntity = controller.searchOAMixedGet(queryFound, motivation, date, user, page, null, null, request); assertEquals(responseEntity.getStatusCode().OK, HttpStatus.OK); String queryEmpty = ""; try{ responseEntity = controller.searchOAMixedGet(queryEmpty,motivation, date, user, page, null, null,request); }catch (SearchQueryException sqe){ assertNotNull(sqe); } }
@CrossOrigin @RequestMapping(value = OA_MIXED_SEARCH_REQUEST_PATH, method = RequestMethod.GET) public ResponseEntity<Map<String, Object>> searchOAMixedGet( @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = false) String query, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_PAGE, required = false) String page, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_WIDTH, required = false) String width, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_HEIGHT, required = false) String height, HttpServletRequest request) { String queryString = controllerUtility.createQueryString(request); String type = null; String widthHeight = null; if (!StringUtils.isEmpty(width) && !StringUtils.isEmpty(height)) { widthHeight = width + "|" + height; } ServiceResponse<Map<String, Object>> serviceResponse; if (!controllerUtility.validateParameters(query, motivation, date, user)) { throw new SearchQueryException(AnnotationSearchConstants.EMPTY_QUERY_MESSAGE); } if (StringUtils.isEmpty(motivation) && StringUtils.isEmpty(date) && StringUtils.isEmpty(user)) { serviceResponse = oaSearchService.getAnnotationPage(query, queryString, page, null, type, widthHeight); } else { if (AnnotationSearchConstants.PAINTING_MOTIVATION.equals(motivation)) { serviceResponse = textSearchService.getTextPositions(query, queryString, false, page, false, null, widthHeight); } else if (motivation.indexOf(AnnotationSearchConstants.PAINTING_MOTIVATION) < 0 || motivation.indexOf(AnnotationSearchConstants.NON_PAINTING_MOTIVATION) >= 0) { serviceResponse = oaAnnotationSearchService.getAnnotationPage( new Parameters(query, motivation, date, user), queryString, page, null, type); } else { serviceResponse = oaSearchService.getAnnotationPage(query, queryString, page, null, type, widthHeight); } } Status serviceResponseStatus = serviceResponse.getStatus(); if (serviceResponseStatus.equals(Status.OK)) { return new ResponseEntity<Map<String, Object>>(serviceResponse.getObj(), controllerUtility.getResponseHeaders(), HttpStatus.OK); } if (serviceResponseStatus.equals(Status.NOT_FOUND)) { Map<String, Object> emptyMap = textUtils.returnEmptyResultSet(queryString, false, new PageParameters(), true); return new ResponseEntity<Map<String, Object>>(emptyMap, controllerUtility.getResponseHeaders(), HttpStatus.OK); } throw new SearchException(String.format("Unexpected service response status [%s]", serviceResponseStatus)); }
OASearchController { @CrossOrigin @RequestMapping(value = OA_MIXED_SEARCH_REQUEST_PATH, method = RequestMethod.GET) public ResponseEntity<Map<String, Object>> searchOAMixedGet( @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = false) String query, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_PAGE, required = false) String page, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_WIDTH, required = false) String width, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_HEIGHT, required = false) String height, HttpServletRequest request) { String queryString = controllerUtility.createQueryString(request); String type = null; String widthHeight = null; if (!StringUtils.isEmpty(width) && !StringUtils.isEmpty(height)) { widthHeight = width + "|" + height; } ServiceResponse<Map<String, Object>> serviceResponse; if (!controllerUtility.validateParameters(query, motivation, date, user)) { throw new SearchQueryException(AnnotationSearchConstants.EMPTY_QUERY_MESSAGE); } if (StringUtils.isEmpty(motivation) && StringUtils.isEmpty(date) && StringUtils.isEmpty(user)) { serviceResponse = oaSearchService.getAnnotationPage(query, queryString, page, null, type, widthHeight); } else { if (AnnotationSearchConstants.PAINTING_MOTIVATION.equals(motivation)) { serviceResponse = textSearchService.getTextPositions(query, queryString, false, page, false, null, widthHeight); } else if (motivation.indexOf(AnnotationSearchConstants.PAINTING_MOTIVATION) < 0 || motivation.indexOf(AnnotationSearchConstants.NON_PAINTING_MOTIVATION) >= 0) { serviceResponse = oaAnnotationSearchService.getAnnotationPage( new Parameters(query, motivation, date, user), queryString, page, null, type); } else { serviceResponse = oaSearchService.getAnnotationPage(query, queryString, page, null, type, widthHeight); } } Status serviceResponseStatus = serviceResponse.getStatus(); if (serviceResponseStatus.equals(Status.OK)) { return new ResponseEntity<Map<String, Object>>(serviceResponse.getObj(), controllerUtility.getResponseHeaders(), HttpStatus.OK); } if (serviceResponseStatus.equals(Status.NOT_FOUND)) { Map<String, Object> emptyMap = textUtils.returnEmptyResultSet(queryString, false, new PageParameters(), true); return new ResponseEntity<Map<String, Object>>(emptyMap, controllerUtility.getResponseHeaders(), HttpStatus.OK); } throw new SearchException(String.format("Unexpected service response status [%s]", serviceResponseStatus)); } }
OASearchController { @CrossOrigin @RequestMapping(value = OA_MIXED_SEARCH_REQUEST_PATH, method = RequestMethod.GET) public ResponseEntity<Map<String, Object>> searchOAMixedGet( @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = false) String query, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_PAGE, required = false) String page, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_WIDTH, required = false) String width, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_HEIGHT, required = false) String height, HttpServletRequest request) { String queryString = controllerUtility.createQueryString(request); String type = null; String widthHeight = null; if (!StringUtils.isEmpty(width) && !StringUtils.isEmpty(height)) { widthHeight = width + "|" + height; } ServiceResponse<Map<String, Object>> serviceResponse; if (!controllerUtility.validateParameters(query, motivation, date, user)) { throw new SearchQueryException(AnnotationSearchConstants.EMPTY_QUERY_MESSAGE); } if (StringUtils.isEmpty(motivation) && StringUtils.isEmpty(date) && StringUtils.isEmpty(user)) { serviceResponse = oaSearchService.getAnnotationPage(query, queryString, page, null, type, widthHeight); } else { if (AnnotationSearchConstants.PAINTING_MOTIVATION.equals(motivation)) { serviceResponse = textSearchService.getTextPositions(query, queryString, false, page, false, null, widthHeight); } else if (motivation.indexOf(AnnotationSearchConstants.PAINTING_MOTIVATION) < 0 || motivation.indexOf(AnnotationSearchConstants.NON_PAINTING_MOTIVATION) >= 0) { serviceResponse = oaAnnotationSearchService.getAnnotationPage( new Parameters(query, motivation, date, user), queryString, page, null, type); } else { serviceResponse = oaSearchService.getAnnotationPage(query, queryString, page, null, type, widthHeight); } } Status serviceResponseStatus = serviceResponse.getStatus(); if (serviceResponseStatus.equals(Status.OK)) { return new ResponseEntity<Map<String, Object>>(serviceResponse.getObj(), controllerUtility.getResponseHeaders(), HttpStatus.OK); } if (serviceResponseStatus.equals(Status.NOT_FOUND)) { Map<String, Object> emptyMap = textUtils.returnEmptyResultSet(queryString, false, new PageParameters(), true); return new ResponseEntity<Map<String, Object>>(emptyMap, controllerUtility.getResponseHeaders(), HttpStatus.OK); } throw new SearchException(String.format("Unexpected service response status [%s]", serviceResponseStatus)); } @Autowired  OASearchController(OAAnnotationSearchService oaAnnotationSearchService,
			AnnotationAutocompleteService annotationAutocompleteService, TextSearchService textSearchService,
			OASearchService searchService); }
OASearchController { @CrossOrigin @RequestMapping(value = OA_MIXED_SEARCH_REQUEST_PATH, method = RequestMethod.GET) public ResponseEntity<Map<String, Object>> searchOAMixedGet( @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = false) String query, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_PAGE, required = false) String page, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_WIDTH, required = false) String width, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_HEIGHT, required = false) String height, HttpServletRequest request) { String queryString = controllerUtility.createQueryString(request); String type = null; String widthHeight = null; if (!StringUtils.isEmpty(width) && !StringUtils.isEmpty(height)) { widthHeight = width + "|" + height; } ServiceResponse<Map<String, Object>> serviceResponse; if (!controllerUtility.validateParameters(query, motivation, date, user)) { throw new SearchQueryException(AnnotationSearchConstants.EMPTY_QUERY_MESSAGE); } if (StringUtils.isEmpty(motivation) && StringUtils.isEmpty(date) && StringUtils.isEmpty(user)) { serviceResponse = oaSearchService.getAnnotationPage(query, queryString, page, null, type, widthHeight); } else { if (AnnotationSearchConstants.PAINTING_MOTIVATION.equals(motivation)) { serviceResponse = textSearchService.getTextPositions(query, queryString, false, page, false, null, widthHeight); } else if (motivation.indexOf(AnnotationSearchConstants.PAINTING_MOTIVATION) < 0 || motivation.indexOf(AnnotationSearchConstants.NON_PAINTING_MOTIVATION) >= 0) { serviceResponse = oaAnnotationSearchService.getAnnotationPage( new Parameters(query, motivation, date, user), queryString, page, null, type); } else { serviceResponse = oaSearchService.getAnnotationPage(query, queryString, page, null, type, widthHeight); } } Status serviceResponseStatus = serviceResponse.getStatus(); if (serviceResponseStatus.equals(Status.OK)) { return new ResponseEntity<Map<String, Object>>(serviceResponse.getObj(), controllerUtility.getResponseHeaders(), HttpStatus.OK); } if (serviceResponseStatus.equals(Status.NOT_FOUND)) { Map<String, Object> emptyMap = textUtils.returnEmptyResultSet(queryString, false, new PageParameters(), true); return new ResponseEntity<Map<String, Object>>(emptyMap, controllerUtility.getResponseHeaders(), HttpStatus.OK); } throw new SearchException(String.format("Unexpected service response status [%s]", serviceResponseStatus)); } @Autowired  OASearchController(OAAnnotationSearchService oaAnnotationSearchService,
			AnnotationAutocompleteService annotationAutocompleteService, TextSearchService textSearchService,
			OASearchService searchService); @CrossOrigin @RequestMapping(value = OA_MIXED_SEARCH_REQUEST_PATH, method = RequestMethod.GET) ResponseEntity<Map<String, Object>> searchOAMixedGet(
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = false) String query,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_PAGE, required = false) String page,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_WIDTH, required = false) String width,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_HEIGHT, required = false) String height,
			HttpServletRequest request); @CrossOrigin @RequestMapping(value = WITHIN_OA_MIXED_SEARCH_REQUEST_PATH, method = RequestMethod.GET) ResponseEntity<Map<String, Object>> searchOAWithinMixedGet(@PathVariable String withinId,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = false) String query,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_PAGE, required = false) String page,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_WIDTH, required = false) String width,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_HEIGHT, required = false) String height,
			HttpServletRequest request); @CrossOrigin @RequestMapping(value = OA_MIXED_AUTOCOMPLETE_REQUEST_PATH, method = RequestMethod.GET) ResponseEntity<Map<String, Object>> autocompleteOAMixedGet(
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = true) String query,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user,
			@RequestParam(value = PARAM_MIN, required = false) String min, HttpServletRequest request); @CrossOrigin @RequestMapping(value = WITHIN_OA_MIXED_AUTOCOMPLETE_REQUEST_PATH, method = RequestMethod.GET) ResponseEntity<Map<String, Object>> autocompleteOAWithinMixedGet(@PathVariable String withinId,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = true) String query,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user,
			@RequestParam(value = PARAM_MIN, required = false) String min, HttpServletRequest request); }
OASearchController { @CrossOrigin @RequestMapping(value = OA_MIXED_SEARCH_REQUEST_PATH, method = RequestMethod.GET) public ResponseEntity<Map<String, Object>> searchOAMixedGet( @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = false) String query, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_PAGE, required = false) String page, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_WIDTH, required = false) String width, @RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_HEIGHT, required = false) String height, HttpServletRequest request) { String queryString = controllerUtility.createQueryString(request); String type = null; String widthHeight = null; if (!StringUtils.isEmpty(width) && !StringUtils.isEmpty(height)) { widthHeight = width + "|" + height; } ServiceResponse<Map<String, Object>> serviceResponse; if (!controllerUtility.validateParameters(query, motivation, date, user)) { throw new SearchQueryException(AnnotationSearchConstants.EMPTY_QUERY_MESSAGE); } if (StringUtils.isEmpty(motivation) && StringUtils.isEmpty(date) && StringUtils.isEmpty(user)) { serviceResponse = oaSearchService.getAnnotationPage(query, queryString, page, null, type, widthHeight); } else { if (AnnotationSearchConstants.PAINTING_MOTIVATION.equals(motivation)) { serviceResponse = textSearchService.getTextPositions(query, queryString, false, page, false, null, widthHeight); } else if (motivation.indexOf(AnnotationSearchConstants.PAINTING_MOTIVATION) < 0 || motivation.indexOf(AnnotationSearchConstants.NON_PAINTING_MOTIVATION) >= 0) { serviceResponse = oaAnnotationSearchService.getAnnotationPage( new Parameters(query, motivation, date, user), queryString, page, null, type); } else { serviceResponse = oaSearchService.getAnnotationPage(query, queryString, page, null, type, widthHeight); } } Status serviceResponseStatus = serviceResponse.getStatus(); if (serviceResponseStatus.equals(Status.OK)) { return new ResponseEntity<Map<String, Object>>(serviceResponse.getObj(), controllerUtility.getResponseHeaders(), HttpStatus.OK); } if (serviceResponseStatus.equals(Status.NOT_FOUND)) { Map<String, Object> emptyMap = textUtils.returnEmptyResultSet(queryString, false, new PageParameters(), true); return new ResponseEntity<Map<String, Object>>(emptyMap, controllerUtility.getResponseHeaders(), HttpStatus.OK); } throw new SearchException(String.format("Unexpected service response status [%s]", serviceResponseStatus)); } @Autowired  OASearchController(OAAnnotationSearchService oaAnnotationSearchService,
			AnnotationAutocompleteService annotationAutocompleteService, TextSearchService textSearchService,
			OASearchService searchService); @CrossOrigin @RequestMapping(value = OA_MIXED_SEARCH_REQUEST_PATH, method = RequestMethod.GET) ResponseEntity<Map<String, Object>> searchOAMixedGet(
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = false) String query,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_PAGE, required = false) String page,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_WIDTH, required = false) String width,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_HEIGHT, required = false) String height,
			HttpServletRequest request); @CrossOrigin @RequestMapping(value = WITHIN_OA_MIXED_SEARCH_REQUEST_PATH, method = RequestMethod.GET) ResponseEntity<Map<String, Object>> searchOAWithinMixedGet(@PathVariable String withinId,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = false) String query,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_PAGE, required = false) String page,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_WIDTH, required = false) String width,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_HEIGHT, required = false) String height,
			HttpServletRequest request); @CrossOrigin @RequestMapping(value = OA_MIXED_AUTOCOMPLETE_REQUEST_PATH, method = RequestMethod.GET) ResponseEntity<Map<String, Object>> autocompleteOAMixedGet(
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = true) String query,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user,
			@RequestParam(value = PARAM_MIN, required = false) String min, HttpServletRequest request); @CrossOrigin @RequestMapping(value = WITHIN_OA_MIXED_AUTOCOMPLETE_REQUEST_PATH, method = RequestMethod.GET) ResponseEntity<Map<String, Object>> autocompleteOAWithinMixedGet(@PathVariable String withinId,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_QUERY, required = true) String query,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_MOTIVATION, required = false) String motivation,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_DATE, required = false) String date,
			@RequestParam(value = AnnotationSearchConstants.PARAM_FIELD_USER, required = false) String user,
			@RequestParam(value = PARAM_MIN, required = false) String min, HttpServletRequest request); static final String CONTROLLER_NAME; static final String PARAM_MIN; }