@Test void getRatings() throws Exception { UserReference userReference = mock(UserReference.class); Map<RatingQueryField, Object> queryParameters = new LinkedHashMap<>(); queryParameters.put(RatingQueryField.ENTITY_TYPE, EntityType.PAGE_ATTACHMENT); queryParameters.put(RatingQueryField.USER_REFERENCE, userReference); queryParameters.put(RatingQueryField.SCALE, "6"); String managerId = "otherId"; this.manager.setIdentifer(managerId); when(this.configuration.hasDedicatedCore()).thenReturn(false); when(this.solr.getClient(RatingSolrCoreInitializer.DEFAULT_RATING_SOLR_CORE)).thenReturn(this.solrClient); when(this.userReferenceSerializer.serialize(userReference)).thenReturn("user:barfoo"); when(this.userReferenceResolver.resolve("user:barfoo")).thenReturn(userReference); String query = "filter(entityType:PAGE_ATTACHMENT) AND filter(author:user\\:barfoo) " + "AND filter(scale:6) AND filter(managerId:otherId)"; int offset = 12; int limit = 42; String orderField = RatingQueryField.USER_REFERENCE.getFieldName(); boolean asc = false; SolrQuery expectedQuery = new SolrQuery().addFilterQuery(query) .setStart(offset) .setRows(limit) .addSort(orderField, SolrQuery.ORDER.desc); QueryResponse response = prepareSolrClientQueryWhenStatement(this.solrClient, expectedQuery); when(response.getResults()).thenReturn(this.documentList); Map<String, Object> documentResult = new HashMap<>(); documentResult.put("id", "result1"); documentResult.put(RatingQueryField.ENTITY_TYPE.getFieldName(), "PAGE_ATTACHMENT"); documentResult.put(RatingQueryField.MANAGER_ID.getFieldName(), "otherId"); documentResult.put(RatingQueryField.CREATED_DATE.getFieldName(), new Date(1)); documentResult.put(RatingQueryField.UPDATED_DATE.getFieldName(), new Date(1111)); documentResult.put(RatingQueryField.VOTE.getFieldName(), 8); documentResult.put(RatingQueryField.SCALE.getFieldName(), 10); documentResult.put(RatingQueryField.ENTITY_REFERENCE.getFieldName(), "attachment:Foo"); EntityReference reference1 = new EntityReference("Foo", EntityType.PAGE_ATTACHMENT); when(this.entityReferenceResolver.resolve("attachment:Foo", EntityType.PAGE_ATTACHMENT)).thenReturn(reference1); documentResult.put(RatingQueryField.USER_REFERENCE.getFieldName(), "user:barfoo"); SolrDocument result1 = new SolrDocument(documentResult); documentResult = new HashMap<>(); documentResult.put("id", "result2"); documentResult.put(RatingQueryField.ENTITY_TYPE.getFieldName(), "PAGE_ATTACHMENT"); documentResult.put(RatingQueryField.MANAGER_ID.getFieldName(), "otherId"); documentResult.put(RatingQueryField.CREATED_DATE.getFieldName(), new Date(2)); documentResult.put(RatingQueryField.UPDATED_DATE.getFieldName(), new Date(2222)); documentResult.put(RatingQueryField.VOTE.getFieldName(), 1); documentResult.put(RatingQueryField.SCALE.getFieldName(), 10); documentResult.put(RatingQueryField.ENTITY_REFERENCE.getFieldName(), "attachment:Bar"); EntityReference reference2 = new EntityReference("Bar", EntityType.PAGE_ATTACHMENT); when(this.entityReferenceResolver.resolve("attachment:Bar", EntityType.PAGE_ATTACHMENT)).thenReturn(reference2); documentResult.put(RatingQueryField.USER_REFERENCE.getFieldName(), "user:barfoo"); SolrDocument result2 = new SolrDocument(documentResult); documentResult = new HashMap<>(); documentResult.put("id", "result3"); documentResult.put(RatingQueryField.ENTITY_TYPE.getFieldName(), "PAGE_ATTACHMENT"); documentResult.put(RatingQueryField.MANAGER_ID.getFieldName(), "otherId"); documentResult.put(RatingQueryField.CREATED_DATE.getFieldName(), new Date(3)); documentResult.put(RatingQueryField.UPDATED_DATE.getFieldName(), new Date(3333)); documentResult.put(RatingQueryField.VOTE.getFieldName(), 3); documentResult.put(RatingQueryField.SCALE.getFieldName(), 10); documentResult.put(RatingQueryField.ENTITY_REFERENCE.getFieldName(), "attachment:Baz"); EntityReference reference3 = new EntityReference("Baz", EntityType.PAGE_ATTACHMENT); when(this.entityReferenceResolver.resolve("attachment:Baz", EntityType.PAGE_ATTACHMENT)).thenReturn(reference3); documentResult.put(RatingQueryField.USER_REFERENCE.getFieldName(), "user:barfoo"); SolrDocument result3 = new SolrDocument(documentResult); when(this.documentList.stream()).thenReturn(Arrays.asList(result1, result2, result3).stream()); List<Rating> expectedRatings = Arrays.asList( new DefaultRating("result1") .setManagerId("otherId") .setCreatedAt(new Date(1)) .setUpdatedAt(new Date(1111)) .setVote(8) .setReference(reference1) .setAuthor(userReference) .setScaleUpperBound(10), new DefaultRating("result2") .setManagerId("otherId") .setCreatedAt(new Date(2)) .setUpdatedAt(new Date(2222)) .setVote(1) .setReference(reference2) .setAuthor(userReference) .setScaleUpperBound(10), new DefaultRating("result3") .setManagerId("otherId") .setCreatedAt(new Date(3)) .setUpdatedAt(new Date(3333)) .setVote(3) .setReference(reference3) .setAuthor(userReference) .setScaleUpperBound(10) ); assertEquals(expectedRatings, this.manager.getRatings(queryParameters, offset, limit, RatingQueryField.USER_REFERENCE, asc)); }
@Override public List<Rating> getRatings(Map<RatingQueryField, Object> queryParameters, int offset, int limit, RatingQueryField orderBy, boolean asc) throws RatingsException { SolrQuery solrQuery = new SolrQuery() .addFilterQuery(this.mapToQuery(queryParameters)) .setStart(offset) .setRows(limit) .setSort(orderBy.getFieldName(), this.getOrder(asc)); try { QueryResponse query = this.getRatingSolrClient().query(solrQuery); return this.getRankingsFromQueryResult(query.getResults()); } catch (SolrServerException | IOException | SolrException e) { throw new RatingsException("Error while trying to get rankings", e); } }
SolrRatingsManager implements RatingsManager { @Override public List<Rating> getRatings(Map<RatingQueryField, Object> queryParameters, int offset, int limit, RatingQueryField orderBy, boolean asc) throws RatingsException { SolrQuery solrQuery = new SolrQuery() .addFilterQuery(this.mapToQuery(queryParameters)) .setStart(offset) .setRows(limit) .setSort(orderBy.getFieldName(), this.getOrder(asc)); try { QueryResponse query = this.getRatingSolrClient().query(solrQuery); return this.getRankingsFromQueryResult(query.getResults()); } catch (SolrServerException | IOException | SolrException e) { throw new RatingsException("Error while trying to get rankings", e); } } }
SolrRatingsManager implements RatingsManager { @Override public List<Rating> getRatings(Map<RatingQueryField, Object> queryParameters, int offset, int limit, RatingQueryField orderBy, boolean asc) throws RatingsException { SolrQuery solrQuery = new SolrQuery() .addFilterQuery(this.mapToQuery(queryParameters)) .setStart(offset) .setRows(limit) .setSort(orderBy.getFieldName(), this.getOrder(asc)); try { QueryResponse query = this.getRatingSolrClient().query(solrQuery); return this.getRankingsFromQueryResult(query.getResults()); } catch (SolrServerException | IOException | SolrException e) { throw new RatingsException("Error while trying to get rankings", e); } }  }
SolrRatingsManager implements RatingsManager { @Override public List<Rating> getRatings(Map<RatingQueryField, Object> queryParameters, int offset, int limit, RatingQueryField orderBy, boolean asc) throws RatingsException { SolrQuery solrQuery = new SolrQuery() .addFilterQuery(this.mapToQuery(queryParameters)) .setStart(offset) .setRows(limit) .setSort(orderBy.getFieldName(), this.getOrder(asc)); try { QueryResponse query = this.getRatingSolrClient().query(solrQuery); return this.getRankingsFromQueryResult(query.getResults()); } catch (SolrServerException | IOException | SolrException e) { throw new RatingsException("Error while trying to get rankings", e); } }  @Override String getIdentifier(); @Override void setIdentifer(String identifier); @Override int getScale(); @Override void setRatingConfiguration(RatingsConfiguration configuration); @Override RatingsConfiguration getRatingConfiguration(); @Override Rating saveRating(EntityReference reference, UserReference user, int vote); @Override List<Rating> getRatings(Map<RatingQueryField, Object> queryParameters, int offset, int limit,
        RatingQueryField orderBy, boolean asc); @Override long countRatings(Map<RatingQueryField, Object> queryParameters); @Override boolean removeRating(String ratingIdentifier); @Override AverageRating getAverageRating(EntityReference entityReference); @Override void saveRating(Rating rating); @Override AverageRating recomputeAverageRating(EntityReference entityReference); }
SolrRatingsManager implements RatingsManager { @Override public List<Rating> getRatings(Map<RatingQueryField, Object> queryParameters, int offset, int limit, RatingQueryField orderBy, boolean asc) throws RatingsException { SolrQuery solrQuery = new SolrQuery() .addFilterQuery(this.mapToQuery(queryParameters)) .setStart(offset) .setRows(limit) .setSort(orderBy.getFieldName(), this.getOrder(asc)); try { QueryResponse query = this.getRatingSolrClient().query(solrQuery); return this.getRankingsFromQueryResult(query.getResults()); } catch (SolrServerException | IOException | SolrException e) { throw new RatingsException("Error while trying to get rankings", e); } }  @Override String getIdentifier(); @Override void setIdentifer(String identifier); @Override int getScale(); @Override void setRatingConfiguration(RatingsConfiguration configuration); @Override RatingsConfiguration getRatingConfiguration(); @Override Rating saveRating(EntityReference reference, UserReference user, int vote); @Override List<Rating> getRatings(Map<RatingQueryField, Object> queryParameters, int offset, int limit,
        RatingQueryField orderBy, boolean asc); @Override long countRatings(Map<RatingQueryField, Object> queryParameters); @Override boolean removeRating(String ratingIdentifier); @Override AverageRating getAverageRating(EntityReference entityReference); @Override void saveRating(Rating rating); @Override AverageRating recomputeAverageRating(EntityReference entityReference);  }