@Test public void setOwnerPreviousOwnerIsNotNullOneCollaboratorIsAddedAndOneDeleted() throws XWikiException { when(this.entityDoc.getXObject(COLLABORATOR_CLASS, COLLABORATOR_LABEL, COLLABORATOR_STR, false)) .thenReturn(this.collaboratorObject1); final boolean ownerSet = this.component.setOwner(this.entity, COLLABORATOR); verify(this.entityDoc, times(1)).getXObject(COLLABORATOR_CLASS, COLLABORATOR_LABEL, COLLABORATOR_STR, false); verify(this.entityDoc, times(1)).getXObject(COLLABORATOR_CLASS, COLLABORATOR_LABEL, OWNER_STR, false); verify(this.entityDoc, times(1)).removeXObject(this.collaboratorObject1); verify(this.entityDoc, times(1)).newXObject(COLLABORATOR_CLASS, this.context); verify(this.xwiki, times(1)).saveDocument(this.entityDoc, "Set owner: " + COLLABORATOR_STR, true, this.context); Assert.assertTrue(ownerSet); }
@Override public boolean setOwner(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup) { if (entity == null || entity.getDocumentReference() == null) { return false; } final DocumentReference classReference = this.partialEntityResolver.resolve(Owner.CLASS_REFERENCE, entity.getDocumentReference()); try { final Owner owner = getOwner(entity); return classReference != null && changeOwnership(entity, classReference, owner == null ? null : owner.getUser(), userOrGroup); } catch (Exception e) { return false; } }
DefaultEntityAccessManager implements EntityAccessManager { @Override public boolean setOwner(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup) { if (entity == null || entity.getDocumentReference() == null) { return false; } final DocumentReference classReference = this.partialEntityResolver.resolve(Owner.CLASS_REFERENCE, entity.getDocumentReference()); try { final Owner owner = getOwner(entity); return classReference != null && changeOwnership(entity, classReference, owner == null ? null : owner.getUser(), userOrGroup); } catch (Exception e) { return false; } } }
DefaultEntityAccessManager implements EntityAccessManager { @Override public boolean setOwner(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup) { if (entity == null || entity.getDocumentReference() == null) { return false; } final DocumentReference classReference = this.partialEntityResolver.resolve(Owner.CLASS_REFERENCE, entity.getDocumentReference()); try { final Owner owner = getOwner(entity); return classReference != null && changeOwnership(entity, classReference, owner == null ? null : owner.getUser(), userOrGroup); } catch (Exception e) { return false; } }  }
DefaultEntityAccessManager implements EntityAccessManager { @Override public boolean setOwner(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup) { if (entity == null || entity.getDocumentReference() == null) { return false; } final DocumentReference classReference = this.partialEntityResolver.resolve(Owner.CLASS_REFERENCE, entity.getDocumentReference()); try { final Owner owner = getOwner(entity); return classReference != null && changeOwnership(entity, classReference, owner == null ? null : owner.getUser(), userOrGroup); } catch (Exception e) { return false; } }  @Nonnull @Override Collection<AccessLevel> listAccessLevels(); @Nonnull @Override Collection<AccessLevel> listAllAccessLevels(); @Nonnull @Override AccessLevel resolveAccessLevel(@Nullable final String name); @Nonnull @Override AccessLevel getAccessLevel(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup); @Override boolean isAdministrator(@Nullable final PrimaryEntity entity); @Override boolean isAdministrator(@Nullable final PrimaryEntity entity, @Nullable final DocumentReference user); @Nullable @Override Owner getOwner(@Nullable final PrimaryEntity entity); @Override boolean setOwner(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup); @Nonnull @Override Collection<Collaborator> getCollaborators(@Nullable final PrimaryEntity entity); @Override boolean setCollaborators(
        @Nullable final PrimaryEntity entity,
        @Nullable final Collection<Collaborator> newCollaborators); @Override boolean addCollaborator(@Nullable final PrimaryEntity entity, @Nullable final Collaborator collaborator); @Override boolean removeCollaborator(@Nullable final PrimaryEntity entity, @Nullable final Collaborator collaborator); }
DefaultEntityAccessManager implements EntityAccessManager { @Override public boolean setOwner(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup) { if (entity == null || entity.getDocumentReference() == null) { return false; } final DocumentReference classReference = this.partialEntityResolver.resolve(Owner.CLASS_REFERENCE, entity.getDocumentReference()); try { final Owner owner = getOwner(entity); return classReference != null && changeOwnership(entity, classReference, owner == null ? null : owner.getUser(), userOrGroup); } catch (Exception e) { return false; } }  @Nonnull @Override Collection<AccessLevel> listAccessLevels(); @Nonnull @Override Collection<AccessLevel> listAllAccessLevels(); @Nonnull @Override AccessLevel resolveAccessLevel(@Nullable final String name); @Nonnull @Override AccessLevel getAccessLevel(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup); @Override boolean isAdministrator(@Nullable final PrimaryEntity entity); @Override boolean isAdministrator(@Nullable final PrimaryEntity entity, @Nullable final DocumentReference user); @Nullable @Override Owner getOwner(@Nullable final PrimaryEntity entity); @Override boolean setOwner(@Nullable final PrimaryEntity entity, @Nullable final EntityReference userOrGroup); @Nonnull @Override Collection<Collaborator> getCollaborators(@Nullable final PrimaryEntity entity); @Override boolean setCollaborators(
        @Nullable final PrimaryEntity entity,
        @Nullable final Collection<Collaborator> newCollaborators); @Override boolean addCollaborator(@Nullable final PrimaryEntity entity, @Nullable final Collaborator collaborator); @Override boolean removeCollaborator(@Nullable final PrimaryEntity entity, @Nullable final Collaborator collaborator);  }