@Test void removeLike() throws Exception { when(this.authorizationManager.hasAccess(this.likeRight, this.userDocReference, target)).thenReturn(true); assertFalse(this.defaultLikeManager.removeLike(this.userReference, target)); Map<RatingsManager.RatingQueryField, Object> queryMap = new LinkedHashMap<>(); queryMap.put(RatingsManager.RatingQueryField.ENTITY_TYPE, target.getType()); queryMap.put(RatingsManager.RatingQueryField.ENTITY_REFERENCE, target); queryMap.put(RatingsManager.RatingQueryField.USER_REFERENCE, this.userReference); Rating grading = mock(Rating.class); when(grading.getId()).thenReturn("grading423"); when(this.ratingsManager.getRatings(queryMap, 0, 1, RatingsManager.RatingQueryField.UPDATED_DATE, false)) .thenReturn(Collections.singletonList(grading)); when(this.ratingsManager.removeRating("grading423")).thenReturn(true); assertTrue(this.defaultLikeManager.removeLike(this.userReference, target)); verify(this.ratingsManager).removeRating("grading423"); verify(this.observationManager).notify(any(UnlikeEvent.class), eq(this.userReference), eq(this.target)); verify(this.likeExistCache).set("xwiki:XWiki.User_xwiki:Foo.WebHome", false); verify(this.likedEntityCache).remove("xwiki:Foo.WebHome"); }
@Override public boolean removeLike(UserReference source, EntityReference target) throws LikeException { String serializedTarget = this.entityReferenceSerializer.serialize(target); DocumentReference userDoc = this.userReferenceDocumentSerializer.serialize(source); boolean result = false; if (this.authorizationManager.hasAccess(this.getLikeRight(), userDoc, target)) { Map<RatingsManager.RatingQueryField, Object> queryMap = new LinkedHashMap<>(); queryMap.put(RatingsManager.RatingQueryField.ENTITY_TYPE, target.getType()); queryMap.put(RatingsManager.RatingQueryField.ENTITY_REFERENCE, target); queryMap.put(RatingsManager.RatingQueryField.USER_REFERENCE, source); try { List<Rating> gradings = this.ratingsManager .getRatings(queryMap, 0, 1, RatingsManager.RatingQueryField.UPDATED_DATE, false); if (!gradings.isEmpty()) { result = this.ratingsManager.removeRating(gradings.get(0).getId()); this.likeCountCache.remove(serializedTarget); this.likeExistCache.set(getExistCacheKey(source, target), false); this.observationManager.notify(new UnlikeEvent(), source, target); } } catch (RatingsException e) { throw new LikeException("Error while removing grading", e); } } else { throw new LikeException( String.format("User [%s] is not authorized to remove a like on [%s].", userDoc, target)); } return result; }
DefaultLikeManager implements LikeManager, Initializable, Disposable { @Override public boolean removeLike(UserReference source, EntityReference target) throws LikeException { String serializedTarget = this.entityReferenceSerializer.serialize(target); DocumentReference userDoc = this.userReferenceDocumentSerializer.serialize(source); boolean result = false; if (this.authorizationManager.hasAccess(this.getLikeRight(), userDoc, target)) { Map<RatingsManager.RatingQueryField, Object> queryMap = new LinkedHashMap<>(); queryMap.put(RatingsManager.RatingQueryField.ENTITY_TYPE, target.getType()); queryMap.put(RatingsManager.RatingQueryField.ENTITY_REFERENCE, target); queryMap.put(RatingsManager.RatingQueryField.USER_REFERENCE, source); try { List<Rating> gradings = this.ratingsManager .getRatings(queryMap, 0, 1, RatingsManager.RatingQueryField.UPDATED_DATE, false); if (!gradings.isEmpty()) { result = this.ratingsManager.removeRating(gradings.get(0).getId()); this.likeCountCache.remove(serializedTarget); this.likeExistCache.set(getExistCacheKey(source, target), false); this.observationManager.notify(new UnlikeEvent(), source, target); } } catch (RatingsException e) { throw new LikeException("Error while removing grading", e); } } else { throw new LikeException( String.format("User [%s] is not authorized to remove a like on [%s].", userDoc, target)); } return result; } }
DefaultLikeManager implements LikeManager, Initializable, Disposable { @Override public boolean removeLike(UserReference source, EntityReference target) throws LikeException { String serializedTarget = this.entityReferenceSerializer.serialize(target); DocumentReference userDoc = this.userReferenceDocumentSerializer.serialize(source); boolean result = false; if (this.authorizationManager.hasAccess(this.getLikeRight(), userDoc, target)) { Map<RatingsManager.RatingQueryField, Object> queryMap = new LinkedHashMap<>(); queryMap.put(RatingsManager.RatingQueryField.ENTITY_TYPE, target.getType()); queryMap.put(RatingsManager.RatingQueryField.ENTITY_REFERENCE, target); queryMap.put(RatingsManager.RatingQueryField.USER_REFERENCE, source); try { List<Rating> gradings = this.ratingsManager .getRatings(queryMap, 0, 1, RatingsManager.RatingQueryField.UPDATED_DATE, false); if (!gradings.isEmpty()) { result = this.ratingsManager.removeRating(gradings.get(0).getId()); this.likeCountCache.remove(serializedTarget); this.likeExistCache.set(getExistCacheKey(source, target), false); this.observationManager.notify(new UnlikeEvent(), source, target); } } catch (RatingsException e) { throw new LikeException("Error while removing grading", e); } } else { throw new LikeException( String.format("User [%s] is not authorized to remove a like on [%s].", userDoc, target)); } return result; }  }
DefaultLikeManager implements LikeManager, Initializable, Disposable { @Override public boolean removeLike(UserReference source, EntityReference target) throws LikeException { String serializedTarget = this.entityReferenceSerializer.serialize(target); DocumentReference userDoc = this.userReferenceDocumentSerializer.serialize(source); boolean result = false; if (this.authorizationManager.hasAccess(this.getLikeRight(), userDoc, target)) { Map<RatingsManager.RatingQueryField, Object> queryMap = new LinkedHashMap<>(); queryMap.put(RatingsManager.RatingQueryField.ENTITY_TYPE, target.getType()); queryMap.put(RatingsManager.RatingQueryField.ENTITY_REFERENCE, target); queryMap.put(RatingsManager.RatingQueryField.USER_REFERENCE, source); try { List<Rating> gradings = this.ratingsManager .getRatings(queryMap, 0, 1, RatingsManager.RatingQueryField.UPDATED_DATE, false); if (!gradings.isEmpty()) { result = this.ratingsManager.removeRating(gradings.get(0).getId()); this.likeCountCache.remove(serializedTarget); this.likeExistCache.set(getExistCacheKey(source, target), false); this.observationManager.notify(new UnlikeEvent(), source, target); } } catch (RatingsException e) { throw new LikeException("Error while removing grading", e); } } else { throw new LikeException( String.format("User [%s] is not authorized to remove a like on [%s].", userDoc, target)); } return result; }  @Override void initialize(); @Override void dispose(); @Override long saveLike(UserReference source, EntityReference target); @Override List<EntityReference> getUserLikes(UserReference source, int offset, int limit); @Override long getEntityLikes(EntityReference target); @Override boolean removeLike(UserReference source, EntityReference target); @Override boolean isLiked(UserReference source, EntityReference target); @Override List<UserReference> getLikers(EntityReference target, int offset, int limit); @Override Right getLikeRight(); }
DefaultLikeManager implements LikeManager, Initializable, Disposable { @Override public boolean removeLike(UserReference source, EntityReference target) throws LikeException { String serializedTarget = this.entityReferenceSerializer.serialize(target); DocumentReference userDoc = this.userReferenceDocumentSerializer.serialize(source); boolean result = false; if (this.authorizationManager.hasAccess(this.getLikeRight(), userDoc, target)) { Map<RatingsManager.RatingQueryField, Object> queryMap = new LinkedHashMap<>(); queryMap.put(RatingsManager.RatingQueryField.ENTITY_TYPE, target.getType()); queryMap.put(RatingsManager.RatingQueryField.ENTITY_REFERENCE, target); queryMap.put(RatingsManager.RatingQueryField.USER_REFERENCE, source); try { List<Rating> gradings = this.ratingsManager .getRatings(queryMap, 0, 1, RatingsManager.RatingQueryField.UPDATED_DATE, false); if (!gradings.isEmpty()) { result = this.ratingsManager.removeRating(gradings.get(0).getId()); this.likeCountCache.remove(serializedTarget); this.likeExistCache.set(getExistCacheKey(source, target), false); this.observationManager.notify(new UnlikeEvent(), source, target); } } catch (RatingsException e) { throw new LikeException("Error while removing grading", e); } } else { throw new LikeException( String.format("User [%s] is not authorized to remove a like on [%s].", userDoc, target)); } return result; }  @Override void initialize(); @Override void dispose(); @Override long saveLike(UserReference source, EntityReference target); @Override List<EntityReference> getUserLikes(UserReference source, int offset, int limit); @Override long getEntityLikes(EntityReference target); @Override boolean removeLike(UserReference source, EntityReference target); @Override boolean isLiked(UserReference source, EntityReference target); @Override List<UserReference> getLikers(EntityReference target, int offset, int limit); @Override Right getLikeRight();  }