@Test public void testGetAnnotationsPage() { String query = "comment"; String motivation = null; String date = null; String user = null; String queryString = "http: boolean isW3c = false; String page = null; long totalHits = 10; String type = null; String within = null; when(template.getClient()).thenReturn(client); SearchHits searchHits = mock(SearchHits.class); when(searchHits.getTotalHits()).thenReturn(totalHits); SearchHit[] hits = new SearchHit[1]; SearchHit hit = mock(SearchHit.class); hits[0] = hit; when(searchHits.iterator()).thenReturn(Iterators.forArray(hits)); when(hit.getSourceAsString()).thenReturn(null); SearchResponse response = mock(SearchResponse.class); when(response.getHits()).thenReturn(searchHits); ListenableActionFuture<SearchResponse> action = mock(ListenableActionFuture.class); when(action.actionGet()).thenReturn(response); SearchRequestBuilder builder = mock(SearchRequestBuilder.class); when(builder.setQuery(anyObject())).thenReturn(builder); when(builder.setPostFilter(anyObject())).thenReturn(builder); when(builder.setFrom(anyInt())).thenReturn(builder); when(builder.setSize(anyInt())).thenReturn(builder); when(builder.execute()).thenReturn(action); when(client.prepareSearch("w3cannotation")).thenReturn(builder); Parameters params = new Parameters(query, motivation, date, user); String[] results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); motivation = "non-painting"; params.setMotivation(motivation); results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); motivation = "non-painting non-tagging"; params.setMotivation(motivation); try{ results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); }catch (Exception e){ assertNotNull(e.getMessage()); } motivation = "painting"; params.setMotivation(motivation); results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); date = "1970-06-13T12:09:56+01:00/1970-06-13T16:09:56+01:00"; params.setDate(date); results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); date = "1970-06-13T12:09:56+01:00"; params.setDate(date); try{ results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); }catch (Exception e){ assertNotNull(e.getMessage()); } date = "1970-06-13T12:09:5601:00/1970-06-13T16:09:56+01:00"; params.setDate(date); try{ results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); }catch (Exception e){ assertNotNull(e.getMessage()); } date = null; motivation = null; type = "topic"; params.setDate(date); params.setMotivation(motivation); results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); type = null; page ="2"; results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); page = null; user = "Frank"; params.setUser(user); results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); user = null; query = null; motivation = "painting"; params.setUser(user); params.setQuery(query); params.setMotivation(motivation); results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); isW3c = false; results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); within = Base64.getEncoder().encodeToString("test".getBytes(StandardCharsets.UTF_8)); LOG.info(within); results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); query = "comment"; motivation = "painting"; date = "1970-06-13T12:09:56+01:00/1970-06-13T16:09:56+01:00"; type = "topic"; page ="2"; user = "Frank"; isW3c = true; params.setUser(user); params.setQuery(query); params.setMotivation(motivation); params.setDate(date); within = Base64.getEncoder().encodeToString("test".getBytes(StandardCharsets.UTF_8)); results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); type = null; results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); query = "https: motivation = null; date = null; type = null; page = null; user = null; isW3c = true; params.setUser(user); params.setQuery(query); params.setMotivation(motivation); params.setDate(date); within = Base64.getEncoder().encodeToString("test".getBytes(StandardCharsets.UTF_8)); results = annotationSearchServiceImpl.getAnnotationsPage(params, queryString, isW3c, page, within, type); LOG.info(results); }
public String[] getAnnotationsPage(Parameters parameters, String queryString, boolean isW3c, String page, String within, String type) { totalHits = 0; pagingParameters = null; int pagingSize = DEFAULT_PAGING_NUMBER; int from = DEFAULT_STARTING_PAGING_NUMBER; if (!StringUtils.isEmpty(page)) { Integer pagingInteger = Integer.parseInt(page); from = (pagingInteger.intValue() - 1) * pagingSize; } QueryBuilder builder = buildAllThings(parameters.getQuery(), parameters.getMotivation(), parameters.getDate(), parameters.getUser(), type, within); LOG.info(builder.toString()); Page<W3CSearchAnnotation> annotationPage; annotationPage = formQuery(builder, from, pagingSize, within); if (null == annotationPage) { return new String[0]; } List<String> annoSearchList = new ArrayList<>(); LOG.info(String.format("Our paged search returned [%s] items ", annotationPage.getNumberOfElements())); for (W3CSearchAnnotation w3CAnnotation : annotationPage) { if (isW3c) { annoSearchList.add(w3CAnnotation.getW3cJsonLd()); } else { if (USE_PARED_DOWN_OA) { List<String> annoList = w3CAnnotation.getParedDownOaJsonLd(); if (null != annoList && !annoList.isEmpty()) { for (String anno : annoList) { annoSearchList.add(anno); } } } else { annoSearchList.add(w3CAnnotation.getOaJsonLd()); } } } String[] annoSearchArray = new String[annoSearchList.size()]; annoSearchArray = annoSearchList.toArray(annoSearchArray); pagingParameters = annotationUtils.getAnnotationPageParameters(annotationPage, queryString, DEFAULT_PAGING_NUMBER, totalHits); return annoSearchArray; }
AnnotationSearchServiceImpl { public String[] getAnnotationsPage(Parameters parameters, String queryString, boolean isW3c, String page, String within, String type) { totalHits = 0; pagingParameters = null; int pagingSize = DEFAULT_PAGING_NUMBER; int from = DEFAULT_STARTING_PAGING_NUMBER; if (!StringUtils.isEmpty(page)) { Integer pagingInteger = Integer.parseInt(page); from = (pagingInteger.intValue() - 1) * pagingSize; } QueryBuilder builder = buildAllThings(parameters.getQuery(), parameters.getMotivation(), parameters.getDate(), parameters.getUser(), type, within); LOG.info(builder.toString()); Page<W3CSearchAnnotation> annotationPage; annotationPage = formQuery(builder, from, pagingSize, within); if (null == annotationPage) { return new String[0]; } List<String> annoSearchList = new ArrayList<>(); LOG.info(String.format("Our paged search returned [%s] items ", annotationPage.getNumberOfElements())); for (W3CSearchAnnotation w3CAnnotation : annotationPage) { if (isW3c) { annoSearchList.add(w3CAnnotation.getW3cJsonLd()); } else { if (USE_PARED_DOWN_OA) { List<String> annoList = w3CAnnotation.getParedDownOaJsonLd(); if (null != annoList && !annoList.isEmpty()) { for (String anno : annoList) { annoSearchList.add(anno); } } } else { annoSearchList.add(w3CAnnotation.getOaJsonLd()); } } } String[] annoSearchArray = new String[annoSearchList.size()]; annoSearchArray = annoSearchList.toArray(annoSearchArray); pagingParameters = annotationUtils.getAnnotationPageParameters(annotationPage, queryString, DEFAULT_PAGING_NUMBER, totalHits); return annoSearchArray; } }
AnnotationSearchServiceImpl { public String[] getAnnotationsPage(Parameters parameters, String queryString, boolean isW3c, String page, String within, String type) { totalHits = 0; pagingParameters = null; int pagingSize = DEFAULT_PAGING_NUMBER; int from = DEFAULT_STARTING_PAGING_NUMBER; if (!StringUtils.isEmpty(page)) { Integer pagingInteger = Integer.parseInt(page); from = (pagingInteger.intValue() - 1) * pagingSize; } QueryBuilder builder = buildAllThings(parameters.getQuery(), parameters.getMotivation(), parameters.getDate(), parameters.getUser(), type, within); LOG.info(builder.toString()); Page<W3CSearchAnnotation> annotationPage; annotationPage = formQuery(builder, from, pagingSize, within); if (null == annotationPage) { return new String[0]; } List<String> annoSearchList = new ArrayList<>(); LOG.info(String.format("Our paged search returned [%s] items ", annotationPage.getNumberOfElements())); for (W3CSearchAnnotation w3CAnnotation : annotationPage) { if (isW3c) { annoSearchList.add(w3CAnnotation.getW3cJsonLd()); } else { if (USE_PARED_DOWN_OA) { List<String> annoList = w3CAnnotation.getParedDownOaJsonLd(); if (null != annoList && !annoList.isEmpty()) { for (String anno : annoList) { annoSearchList.add(anno); } } } else { annoSearchList.add(w3CAnnotation.getOaJsonLd()); } } } String[] annoSearchArray = new String[annoSearchList.size()]; annoSearchArray = annoSearchList.toArray(annoSearchArray); pagingParameters = annotationUtils.getAnnotationPageParameters(annotationPage, queryString, DEFAULT_PAGING_NUMBER, totalHits); return annoSearchArray; } @Autowired /** * * @param annotationUtils * {@code AnnotationUtils} helper for annotations * @param template * {@code ElasticsearchTemplate} what we use to get the * elasticsearch client * @param textSearchService * {@code TextSearchService} our text search service * @param cacheManager * {@code CacheManager} our cache manager */  AnnotationSearchServiceImpl(AnnotationUtils annotationUtils, ElasticsearchTemplate template,
	    TextSearchService textSearchService, CacheManager cacheManager); }
AnnotationSearchServiceImpl { public String[] getAnnotationsPage(Parameters parameters, String queryString, boolean isW3c, String page, String within, String type) { totalHits = 0; pagingParameters = null; int pagingSize = DEFAULT_PAGING_NUMBER; int from = DEFAULT_STARTING_PAGING_NUMBER; if (!StringUtils.isEmpty(page)) { Integer pagingInteger = Integer.parseInt(page); from = (pagingInteger.intValue() - 1) * pagingSize; } QueryBuilder builder = buildAllThings(parameters.getQuery(), parameters.getMotivation(), parameters.getDate(), parameters.getUser(), type, within); LOG.info(builder.toString()); Page<W3CSearchAnnotation> annotationPage; annotationPage = formQuery(builder, from, pagingSize, within); if (null == annotationPage) { return new String[0]; } List<String> annoSearchList = new ArrayList<>(); LOG.info(String.format("Our paged search returned [%s] items ", annotationPage.getNumberOfElements())); for (W3CSearchAnnotation w3CAnnotation : annotationPage) { if (isW3c) { annoSearchList.add(w3CAnnotation.getW3cJsonLd()); } else { if (USE_PARED_DOWN_OA) { List<String> annoList = w3CAnnotation.getParedDownOaJsonLd(); if (null != annoList && !annoList.isEmpty()) { for (String anno : annoList) { annoSearchList.add(anno); } } } else { annoSearchList.add(w3CAnnotation.getOaJsonLd()); } } } String[] annoSearchArray = new String[annoSearchList.size()]; annoSearchArray = annoSearchList.toArray(annoSearchArray); pagingParameters = annotationUtils.getAnnotationPageParameters(annotationPage, queryString, DEFAULT_PAGING_NUMBER, totalHits); return annoSearchArray; } @Autowired /** * * @param annotationUtils * {@code AnnotationUtils} helper for annotations * @param template * {@code ElasticsearchTemplate} what we use to get the * elasticsearch client * @param textSearchService * {@code TextSearchService} our text search service * @param cacheManager * {@code CacheManager} our cache manager */  AnnotationSearchServiceImpl(AnnotationUtils annotationUtils, ElasticsearchTemplate template,
	    TextSearchService textSearchService, CacheManager cacheManager); PageParameters getPageParameters(); long getTotalHits(); String[] getAnnotationsPage(Parameters parameters, String queryString, boolean isW3c, String page,
	    String within, String type); }
AnnotationSearchServiceImpl { public String[] getAnnotationsPage(Parameters parameters, String queryString, boolean isW3c, String page, String within, String type) { totalHits = 0; pagingParameters = null; int pagingSize = DEFAULT_PAGING_NUMBER; int from = DEFAULT_STARTING_PAGING_NUMBER; if (!StringUtils.isEmpty(page)) { Integer pagingInteger = Integer.parseInt(page); from = (pagingInteger.intValue() - 1) * pagingSize; } QueryBuilder builder = buildAllThings(parameters.getQuery(), parameters.getMotivation(), parameters.getDate(), parameters.getUser(), type, within); LOG.info(builder.toString()); Page<W3CSearchAnnotation> annotationPage; annotationPage = formQuery(builder, from, pagingSize, within); if (null == annotationPage) { return new String[0]; } List<String> annoSearchList = new ArrayList<>(); LOG.info(String.format("Our paged search returned [%s] items ", annotationPage.getNumberOfElements())); for (W3CSearchAnnotation w3CAnnotation : annotationPage) { if (isW3c) { annoSearchList.add(w3CAnnotation.getW3cJsonLd()); } else { if (USE_PARED_DOWN_OA) { List<String> annoList = w3CAnnotation.getParedDownOaJsonLd(); if (null != annoList && !annoList.isEmpty()) { for (String anno : annoList) { annoSearchList.add(anno); } } } else { annoSearchList.add(w3CAnnotation.getOaJsonLd()); } } } String[] annoSearchArray = new String[annoSearchList.size()]; annoSearchArray = annoSearchList.toArray(annoSearchArray); pagingParameters = annotationUtils.getAnnotationPageParameters(annotationPage, queryString, DEFAULT_PAGING_NUMBER, totalHits); return annoSearchArray; } @Autowired /** * * @param annotationUtils * {@code AnnotationUtils} helper for annotations * @param template * {@code ElasticsearchTemplate} what we use to get the * elasticsearch client * @param textSearchService * {@code TextSearchService} our text search service * @param cacheManager * {@code CacheManager} our cache manager */  AnnotationSearchServiceImpl(AnnotationUtils annotationUtils, ElasticsearchTemplate template,
	    TextSearchService textSearchService, CacheManager cacheManager); PageParameters getPageParameters(); long getTotalHits(); String[] getAnnotationsPage(Parameters parameters, String queryString, boolean isW3c, String page,
	    String within, String type); static final String SERVICE_NAME; }