@Test void getAverageRatingNotExisting() throws Exception { when(this.solr.getClient(AverageRatingSolrCoreInitializer.DEFAULT_AVERAGE_RATING_SOLR_CORE)) .thenReturn(this.solrClient); String managerId = "averageId1"; when(this.ratingsManager.getIdentifier()).thenReturn(managerId); when(this.ratingsManager.getScale()).thenReturn(7); EntityReference reference = new EntityReference("xwiki:FooBarBar", EntityType.PAGE); when(this.entityReferenceSerializer.serialize(reference)).thenReturn("xwiki:FooBarBar"); String filterQuery = "filter(managerId:averageId1) AND filter(reference:xwiki\\:FooBarBar) " + "AND filter(entityType:PAGE)"; SolrQuery solrQuery = new SolrQuery().addFilterQuery(filterQuery) .setStart(0) .setRows(1) .setSort("updatedAt", SolrQuery.ORDER.asc); QueryResponse response = prepareSolrClientQueryWhenStatement(this.solrClient, solrQuery); when(response.getResults()).thenReturn(this.documentList); when(this.documentList.isEmpty()).thenReturn(true); AverageRating averageRating = this.averageRatingManager.getAverageRating(reference); AverageRating expectedRating = new DefaultAverageRating(averageRating.getId()) .setAverageVote(0) .setTotalVote(0) .setUpdatedAt(averageRating.getUpdatedAt()) .setManagerId(managerId) .setScaleUpperBound(7) .setReference(reference); assertEquals(expectedRating, averageRating); }
@Override public AverageRating getAverageRating(EntityReference entityReference) throws RatingsException { SolrQuery solrQuery = new SolrQuery() .addFilterQuery(String.format("filter(%s:%s) AND filter(%s:%s) AND filter(%s:%s)", AverageRatingQueryField.MANAGER_ID.getFieldName(), solrUtils.toFilterQueryString(this.getIdentifier()), AverageRatingQueryField.ENTITY_REFERENCE.getFieldName(), solrUtils.toFilterQueryString(this.entityReferenceSerializer.serialize(entityReference)), AverageRatingQueryField.ENTITY_TYPE.getFieldName(), solrUtils.toFilterQueryString(entityReference.getType()))) .setStart(0) .setRows(1) .setSort(AverageRatingQueryField.UPDATED_AT.getFieldName(), this.getOrder(true)); try { QueryResponse query = this.getAverageRatingSolrClient().query(solrQuery); AverageRating result; if (!query.getResults().isEmpty()) { SolrDocument solrDocument = query.getResults().get(0); result = new DefaultAverageRating(solrUtils.getId(solrDocument)) .setManagerId(solrUtils.get(AverageRatingQueryField.MANAGER_ID.getFieldName(), solrDocument)) .setAverageVote(solrUtils.get(AverageRatingQueryField.AVERAGE_VOTE.getFieldName(), solrDocument)) .setReference(entityReference) .setTotalVote(solrUtils.get(AverageRatingQueryField.TOTAL_VOTE.getFieldName(), solrDocument)) .setScaleUpperBound(solrUtils.get(AverageRatingQueryField.SCALE.getFieldName(), solrDocument)) .setUpdatedAt(solrUtils.get(AverageRatingQueryField.UPDATED_AT.getFieldName(), solrDocument)); } else { return this.createAverageRating(entityReference, UUID.randomUUID().toString()); } return result; } catch (SolrServerException | IOException | SolrException e) { throw new RatingsException("Error while trying to get average ranking value.", e); } }
SolrAverageRatingManager extends AbstractAverageRatingManager { @Override public AverageRating getAverageRating(EntityReference entityReference) throws RatingsException { SolrQuery solrQuery = new SolrQuery() .addFilterQuery(String.format("filter(%s:%s) AND filter(%s:%s) AND filter(%s:%s)", AverageRatingQueryField.MANAGER_ID.getFieldName(), solrUtils.toFilterQueryString(this.getIdentifier()), AverageRatingQueryField.ENTITY_REFERENCE.getFieldName(), solrUtils.toFilterQueryString(this.entityReferenceSerializer.serialize(entityReference)), AverageRatingQueryField.ENTITY_TYPE.getFieldName(), solrUtils.toFilterQueryString(entityReference.getType()))) .setStart(0) .setRows(1) .setSort(AverageRatingQueryField.UPDATED_AT.getFieldName(), this.getOrder(true)); try { QueryResponse query = this.getAverageRatingSolrClient().query(solrQuery); AverageRating result; if (!query.getResults().isEmpty()) { SolrDocument solrDocument = query.getResults().get(0); result = new DefaultAverageRating(solrUtils.getId(solrDocument)) .setManagerId(solrUtils.get(AverageRatingQueryField.MANAGER_ID.getFieldName(), solrDocument)) .setAverageVote(solrUtils.get(AverageRatingQueryField.AVERAGE_VOTE.getFieldName(), solrDocument)) .setReference(entityReference) .setTotalVote(solrUtils.get(AverageRatingQueryField.TOTAL_VOTE.getFieldName(), solrDocument)) .setScaleUpperBound(solrUtils.get(AverageRatingQueryField.SCALE.getFieldName(), solrDocument)) .setUpdatedAt(solrUtils.get(AverageRatingQueryField.UPDATED_AT.getFieldName(), solrDocument)); } else { return this.createAverageRating(entityReference, UUID.randomUUID().toString()); } return result; } catch (SolrServerException | IOException | SolrException e) { throw new RatingsException("Error while trying to get average ranking value.", e); } } }
SolrAverageRatingManager extends AbstractAverageRatingManager { @Override public AverageRating getAverageRating(EntityReference entityReference) throws RatingsException { SolrQuery solrQuery = new SolrQuery() .addFilterQuery(String.format("filter(%s:%s) AND filter(%s:%s) AND filter(%s:%s)", AverageRatingQueryField.MANAGER_ID.getFieldName(), solrUtils.toFilterQueryString(this.getIdentifier()), AverageRatingQueryField.ENTITY_REFERENCE.getFieldName(), solrUtils.toFilterQueryString(this.entityReferenceSerializer.serialize(entityReference)), AverageRatingQueryField.ENTITY_TYPE.getFieldName(), solrUtils.toFilterQueryString(entityReference.getType()))) .setStart(0) .setRows(1) .setSort(AverageRatingQueryField.UPDATED_AT.getFieldName(), this.getOrder(true)); try { QueryResponse query = this.getAverageRatingSolrClient().query(solrQuery); AverageRating result; if (!query.getResults().isEmpty()) { SolrDocument solrDocument = query.getResults().get(0); result = new DefaultAverageRating(solrUtils.getId(solrDocument)) .setManagerId(solrUtils.get(AverageRatingQueryField.MANAGER_ID.getFieldName(), solrDocument)) .setAverageVote(solrUtils.get(AverageRatingQueryField.AVERAGE_VOTE.getFieldName(), solrDocument)) .setReference(entityReference) .setTotalVote(solrUtils.get(AverageRatingQueryField.TOTAL_VOTE.getFieldName(), solrDocument)) .setScaleUpperBound(solrUtils.get(AverageRatingQueryField.SCALE.getFieldName(), solrDocument)) .setUpdatedAt(solrUtils.get(AverageRatingQueryField.UPDATED_AT.getFieldName(), solrDocument)); } else { return this.createAverageRating(entityReference, UUID.randomUUID().toString()); } return result; } catch (SolrServerException | IOException | SolrException e) { throw new RatingsException("Error while trying to get average ranking value.", e); } }  }
SolrAverageRatingManager extends AbstractAverageRatingManager { @Override public AverageRating getAverageRating(EntityReference entityReference) throws RatingsException { SolrQuery solrQuery = new SolrQuery() .addFilterQuery(String.format("filter(%s:%s) AND filter(%s:%s) AND filter(%s:%s)", AverageRatingQueryField.MANAGER_ID.getFieldName(), solrUtils.toFilterQueryString(this.getIdentifier()), AverageRatingQueryField.ENTITY_REFERENCE.getFieldName(), solrUtils.toFilterQueryString(this.entityReferenceSerializer.serialize(entityReference)), AverageRatingQueryField.ENTITY_TYPE.getFieldName(), solrUtils.toFilterQueryString(entityReference.getType()))) .setStart(0) .setRows(1) .setSort(AverageRatingQueryField.UPDATED_AT.getFieldName(), this.getOrder(true)); try { QueryResponse query = this.getAverageRatingSolrClient().query(solrQuery); AverageRating result; if (!query.getResults().isEmpty()) { SolrDocument solrDocument = query.getResults().get(0); result = new DefaultAverageRating(solrUtils.getId(solrDocument)) .setManagerId(solrUtils.get(AverageRatingQueryField.MANAGER_ID.getFieldName(), solrDocument)) .setAverageVote(solrUtils.get(AverageRatingQueryField.AVERAGE_VOTE.getFieldName(), solrDocument)) .setReference(entityReference) .setTotalVote(solrUtils.get(AverageRatingQueryField.TOTAL_VOTE.getFieldName(), solrDocument)) .setScaleUpperBound(solrUtils.get(AverageRatingQueryField.SCALE.getFieldName(), solrDocument)) .setUpdatedAt(solrUtils.get(AverageRatingQueryField.UPDATED_AT.getFieldName(), solrDocument)); } else { return this.createAverageRating(entityReference, UUID.randomUUID().toString()); } return result; } catch (SolrServerException | IOException | SolrException e) { throw new RatingsException("Error while trying to get average ranking value.", e); } }  @Override AverageRating getAverageRating(EntityReference entityReference); }
SolrAverageRatingManager extends AbstractAverageRatingManager { @Override public AverageRating getAverageRating(EntityReference entityReference) throws RatingsException { SolrQuery solrQuery = new SolrQuery() .addFilterQuery(String.format("filter(%s:%s) AND filter(%s:%s) AND filter(%s:%s)", AverageRatingQueryField.MANAGER_ID.getFieldName(), solrUtils.toFilterQueryString(this.getIdentifier()), AverageRatingQueryField.ENTITY_REFERENCE.getFieldName(), solrUtils.toFilterQueryString(this.entityReferenceSerializer.serialize(entityReference)), AverageRatingQueryField.ENTITY_TYPE.getFieldName(), solrUtils.toFilterQueryString(entityReference.getType()))) .setStart(0) .setRows(1) .setSort(AverageRatingQueryField.UPDATED_AT.getFieldName(), this.getOrder(true)); try { QueryResponse query = this.getAverageRatingSolrClient().query(solrQuery); AverageRating result; if (!query.getResults().isEmpty()) { SolrDocument solrDocument = query.getResults().get(0); result = new DefaultAverageRating(solrUtils.getId(solrDocument)) .setManagerId(solrUtils.get(AverageRatingQueryField.MANAGER_ID.getFieldName(), solrDocument)) .setAverageVote(solrUtils.get(AverageRatingQueryField.AVERAGE_VOTE.getFieldName(), solrDocument)) .setReference(entityReference) .setTotalVote(solrUtils.get(AverageRatingQueryField.TOTAL_VOTE.getFieldName(), solrDocument)) .setScaleUpperBound(solrUtils.get(AverageRatingQueryField.SCALE.getFieldName(), solrDocument)) .setUpdatedAt(solrUtils.get(AverageRatingQueryField.UPDATED_AT.getFieldName(), solrDocument)); } else { return this.createAverageRating(entityReference, UUID.randomUUID().toString()); } return result; } catch (SolrServerException | IOException | SolrException e) { throw new RatingsException("Error while trying to get average ranking value.", e); } }  @Override AverageRating getAverageRating(EntityReference entityReference);  }