@Test public void setVisibilityWithNullVisibility() throws XWikiException { when(this.helper.getStringProperty(this.entityDoc1, VISIBILITY_CLASS_1, VISIBILITY)).thenReturn(PRIVATE); Assert.assertTrue(this.component.setVisibility(this.entity1, null)); verify(this.helper).setProperty(this.entityDoc1, VISIBILITY_CLASS_1, VISIBILITY, StringUtils.EMPTY); verify(this.xwiki).saveDocument(this.entityDoc1, "Set visibility: " + StringUtils.EMPTY, true, this.context); }
@Override public boolean setVisibility( @Nullable final PrimaryEntity entity, @Nullable final Visibility visibility) { if (entity == null || entity.getDocumentReference() == null) { return false; } final DocumentReference classReference = this.partialEntityResolver.resolve(Visibility.CLASS_REFERENCE, entity.getDocumentReference()); try { final String visibilityAsString = (visibility != null) ? visibility.getName() : StringUtils.EMPTY; final String currentVisibility = this.helper.getStringProperty(entity.getXDocument(), classReference, VISIBILITY); if (!visibilityAsString.equals(currentVisibility)) { this.helper.setProperty(entity.getXDocument(), classReference, VISIBILITY, visibilityAsString); final XWikiContext context = this.xcontextProvider.get(); context.getWiki().saveDocument(entity.getXDocument(), "Set visibility: " + visibilityAsString, true, context); } return true; } catch (Exception e) { return false; } }
DefaultEntityVisibilityManager implements EntityVisibilityManager { @Override public boolean setVisibility( @Nullable final PrimaryEntity entity, @Nullable final Visibility visibility) { if (entity == null || entity.getDocumentReference() == null) { return false; } final DocumentReference classReference = this.partialEntityResolver.resolve(Visibility.CLASS_REFERENCE, entity.getDocumentReference()); try { final String visibilityAsString = (visibility != null) ? visibility.getName() : StringUtils.EMPTY; final String currentVisibility = this.helper.getStringProperty(entity.getXDocument(), classReference, VISIBILITY); if (!visibilityAsString.equals(currentVisibility)) { this.helper.setProperty(entity.getXDocument(), classReference, VISIBILITY, visibilityAsString); final XWikiContext context = this.xcontextProvider.get(); context.getWiki().saveDocument(entity.getXDocument(), "Set visibility: " + visibilityAsString, true, context); } return true; } catch (Exception e) { return false; } } }
DefaultEntityVisibilityManager implements EntityVisibilityManager { @Override public boolean setVisibility( @Nullable final PrimaryEntity entity, @Nullable final Visibility visibility) { if (entity == null || entity.getDocumentReference() == null) { return false; } final DocumentReference classReference = this.partialEntityResolver.resolve(Visibility.CLASS_REFERENCE, entity.getDocumentReference()); try { final String visibilityAsString = (visibility != null) ? visibility.getName() : StringUtils.EMPTY; final String currentVisibility = this.helper.getStringProperty(entity.getXDocument(), classReference, VISIBILITY); if (!visibilityAsString.equals(currentVisibility)) { this.helper.setProperty(entity.getXDocument(), classReference, VISIBILITY, visibilityAsString); final XWikiContext context = this.xcontextProvider.get(); context.getWiki().saveDocument(entity.getXDocument(), "Set visibility: " + visibilityAsString, true, context); } return true; } catch (Exception e) { return false; } }  }
DefaultEntityVisibilityManager implements EntityVisibilityManager { @Override public boolean setVisibility( @Nullable final PrimaryEntity entity, @Nullable final Visibility visibility) { if (entity == null || entity.getDocumentReference() == null) { return false; } final DocumentReference classReference = this.partialEntityResolver.resolve(Visibility.CLASS_REFERENCE, entity.getDocumentReference()); try { final String visibilityAsString = (visibility != null) ? visibility.getName() : StringUtils.EMPTY; final String currentVisibility = this.helper.getStringProperty(entity.getXDocument(), classReference, VISIBILITY); if (!visibilityAsString.equals(currentVisibility)) { this.helper.setProperty(entity.getXDocument(), classReference, VISIBILITY, visibilityAsString); final XWikiContext context = this.xcontextProvider.get(); context.getWiki().saveDocument(entity.getXDocument(), "Set visibility: " + visibilityAsString, true, context); } return true; } catch (Exception e) { return false; } }  @Nonnull @Override Collection<Visibility> listVisibilityOptions(); @Nonnull @Override Collection<Visibility> listAllVisibilityOptions(); @Nonnull @Override Visibility getDefaultVisibility(); @Nonnull @Override Visibility resolveVisibility(@Nullable final String name); @Override boolean setVisibility(
        @Nullable final PrimaryEntity entity,
        @Nullable final Visibility visibility); @Nonnull @Override Visibility getVisibility(@Nullable final PrimaryEntity entity); @Nonnull @Override Collection<? extends PrimaryEntity> filterByVisibility(
        @Nullable final Collection<? extends PrimaryEntity> entities,
        @Nullable final Visibility requiredVisibility); @Nonnull @Override Iterator<? extends PrimaryEntity> filterByVisibility(
        @Nullable final Iterator<? extends PrimaryEntity> entities,
        @Nullable final Visibility requiredVisibility); }
DefaultEntityVisibilityManager implements EntityVisibilityManager { @Override public boolean setVisibility( @Nullable final PrimaryEntity entity, @Nullable final Visibility visibility) { if (entity == null || entity.getDocumentReference() == null) { return false; } final DocumentReference classReference = this.partialEntityResolver.resolve(Visibility.CLASS_REFERENCE, entity.getDocumentReference()); try { final String visibilityAsString = (visibility != null) ? visibility.getName() : StringUtils.EMPTY; final String currentVisibility = this.helper.getStringProperty(entity.getXDocument(), classReference, VISIBILITY); if (!visibilityAsString.equals(currentVisibility)) { this.helper.setProperty(entity.getXDocument(), classReference, VISIBILITY, visibilityAsString); final XWikiContext context = this.xcontextProvider.get(); context.getWiki().saveDocument(entity.getXDocument(), "Set visibility: " + visibilityAsString, true, context); } return true; } catch (Exception e) { return false; } }  @Nonnull @Override Collection<Visibility> listVisibilityOptions(); @Nonnull @Override Collection<Visibility> listAllVisibilityOptions(); @Nonnull @Override Visibility getDefaultVisibility(); @Nonnull @Override Visibility resolveVisibility(@Nullable final String name); @Override boolean setVisibility(
        @Nullable final PrimaryEntity entity,
        @Nullable final Visibility visibility); @Nonnull @Override Visibility getVisibility(@Nullable final PrimaryEntity entity); @Nonnull @Override Collection<? extends PrimaryEntity> filterByVisibility(
        @Nullable final Collection<? extends PrimaryEntity> entities,
        @Nullable final Visibility requiredVisibility); @Nonnull @Override Iterator<? extends PrimaryEntity> filterByVisibility(
        @Nullable final Iterator<? extends PrimaryEntity> entities,
        @Nullable final Visibility requiredVisibility);  }