Index: xwiki-core/src/test/java/com/xpn/xwiki/api/XWikiTest.java =================================================================== --- xwiki-core/src/test/java/com/xpn/xwiki/api/XWikiTest.java (revision 27536) +++ xwiki-core/src/test/java/com/xpn/xwiki/api/XWikiTest.java (revision ) @@ -133,24 +133,22 @@ getContext().setUser("Earth"); } - public void testAuthorAfterDocumentCopy() throws XWikiException + public void testAuthorIsntChangedAfterDocumentCopy() throws XWikiException { String copyName = "Lyre"; - String currentUser = getContext().getUser(); this.apiXWiki.copyDocument(this.apiDocument.getName(), copyName); Document copy = this.apiXWiki.getDocument(copyName); - assertTrue(currentUser.equals(copy.getAuthor())); + assertEquals("XWiki.Earth", copy.getAuthor()); } - public void testCreatorAfterDocumentCopy() throws XWikiException + public void testCreatorIsntChangedAfterDocumentCopy() throws XWikiException { String copyName = "Sirius"; - String currentUser = getContext().getUser(); this.apiXWiki.copyDocument(this.apiDocument.getName(), copyName); Document copy = this.apiXWiki.getDocument(copyName); - assertTrue(currentUser.equals(copy.getCreator())); + assertEquals("XWiki.Earth", copy.getCreator()); } public void testCreationDateAfterDocumentCopy() throws XWikiException, InterruptedException Index: xwiki-core/src/test/java/com/xpn/xwiki/doc/XWikiDocumentTest.java =================================================================== --- xwiki-core/src/test/java/com/xpn/xwiki/doc/XWikiDocumentTest.java (revision 33367) +++ xwiki-core/src/test/java/com/xpn/xwiki/doc/XWikiDocumentTest.java (revision ) @@ -322,7 +322,7 @@ this.document.setAuthor(author); XWikiDocument copy = this.document.copyDocument(this.document.getName() + " Copy", getContext()); - assertTrue(author.equals(copy.getAuthor())); + assertEquals("XWiki.Albatross", copy.getAuthor()); } public void testCreatorAfterDocumentCopy() throws XWikiException @@ -331,7 +331,7 @@ this.document.setCreator(creator); XWikiDocument copy = this.document.copyDocument(this.document.getName() + " Copy", getContext()); - assertTrue(creator.equals(copy.getCreator())); + assertEquals("XWiki.Condor", copy.getCreator()); } public void testCreationDateAfterDocumentCopy() throws Exception @@ -340,7 +340,7 @@ Thread.sleep(1000); XWikiDocument copy = this.document.copyDocument(this.document.getName() + " Copy", getContext()); - assertTrue(copy.getCreationDate().equals(sourceCreationDate)); + assertEquals(sourceCreationDate, copy.getCreationDate()); } public void testObjectGuidsAfterDocumentCopy() throws Exception Index: xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java =================================================================== --- xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java (revision 34392) +++ xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java (revision ) @@ -198,12 +198,12 @@ /** * First author of the document. */ - private String creator; + private DocumentReference creatorReference; /** * The Author is changed when any part of the document changes (content, objects, attachments). */ - private String author; + private DocumentReference authorReference; /** * The last user that has changed the document's content (ie not object, attachments). The Content author is only @@ -211,7 +211,7 @@ * document and this is the reason we need to know the last author who's modified the content since programming * rights depend on this. */ - private String contentAuthor; + private DocumentReference contentAuthorReference; private String customClass; @@ -1387,43 +1387,181 @@ } } - public String getAuthor() + /** + * @since 3.0M2 + */ + public DocumentReference getAuthorReference() { - return this.author != null ? this.author.trim() : ""; + return this.authorReference; } - public String getContentAuthor() + /** + * @since 3.0M2 + */ + public void setAuthorReference(DocumentReference authorReference) { - return this.contentAuthor != null ? this.contentAuthor.trim() : ""; + this.authorReference = authorReference; } + /** + * Note that this method cannot be removed for now since it's used by Hibernate for saving a XWikiDocument. + * + * @deprecated since 3.0M2 use {@link #getAuthorReference()} instead + */ + @Deprecated + public String getAuthor() + { + String author; + DocumentReference authorReference = getAuthorReference(); + if (authorReference == null) { + author = ""; + } else { + author = this.compactWikiEntityReferenceSerializer.serialize(authorReference); + } + + return author; + } + + /** + * Note that this method cannot be removed for now since it's used by Hibernate for loading a XWikiDocument. + * + * @deprecated since 3.0M2 use {@link #setAuthorReference} instead + */ + @Deprecated public void setAuthor(String author) { - if (!getAuthor().equals(author)) { + // Note: Consider "" or null as the same, i.e. the author not being set + DocumentReference authorReference = null; + if (author != null && author.length() > 0) { + authorReference = this.currentReferenceDocumentReferenceResolver.resolve( + this.xClassEntityReferenceResolver.resolve(author, EntityType.DOCUMENT)); + } + + if ((getAuthorReference() == null && authorReference != null) + || (getAuthorReference() != null && !getAuthorReference().equals(authorReference))) + { setMetaDataDirty(true); } - this.author = author; + + setAuthorReference(authorReference); } + /** + * @since 3.0M2 + */ + public DocumentReference getContentAuthorReference() + { + return this.contentAuthorReference; + } + + /** + * @since 3.0M2 + */ + public void setContentAuthorReference(DocumentReference contentAuthorReference) + { + this.contentAuthorReference = contentAuthorReference; + } + + /** + * Note that this method cannot be removed for now since it's used by Hibernate for saving a XWikiDocument. + * + * @deprecated since 3.0M2 use {@link #getContentAuthorReference()} instead + */ + @Deprecated + public String getContentAuthor() + { + String contentAuthor; + DocumentReference contentAuthorReference = getContentAuthorReference(); + if (contentAuthorReference == null) { + contentAuthor = ""; + } else { + contentAuthor = this.compactWikiEntityReferenceSerializer.serialize(contentAuthorReference); + } + + return contentAuthor; + } + + /** + * Note that this method cannot be removed for now since it's used by Hibernate for loading a XWikiDocument. + * + * @deprecated since 3.0M2 use {@link #setContentAuthorReference} instead + */ + @Deprecated public void setContentAuthor(String contentAuthor) { - if (!getContentAuthor().equals(contentAuthor)) { + // Note: Consider "" or null as the same, i.e. the content author not being set + DocumentReference contentAuthorReference = null; + if (contentAuthor != null && contentAuthor.length() > 0) { + contentAuthorReference = this.currentReferenceDocumentReferenceResolver.resolve( + this.xClassEntityReferenceResolver.resolve(contentAuthor, EntityType.DOCUMENT)); + } + + if ((getContentAuthorReference() == null && contentAuthorReference != null) + || (getContentAuthorReference() != null && !getContentAuthorReference().equals(contentAuthorReference))) + { setMetaDataDirty(true); } - this.contentAuthor = contentAuthor; + + setContentAuthorReference(contentAuthorReference); } + /** + * @since 3.0M2 + */ + public DocumentReference getCreatorReference() + { + return this.creatorReference; + } + + /** + * @since 3.0M2 + */ + public void setCreatorReference(DocumentReference creatorReference) + { + this.creatorReference = creatorReference; + } + + /** + * Note that this method cannot be removed for now since it's used by Hibernate for saving a XWikiDocument. + * + * @deprecated since 3.0M2 use {@link #getCreatorReference()} instead + */ + @Deprecated public String getCreator() { - return this.creator != null ? this.creator.trim() : ""; + String creator; + DocumentReference creatorReference = getCreatorReference(); + if (creatorReference == null) { + creator = ""; + } else { + creator = this.compactWikiEntityReferenceSerializer.serialize(creatorReference); - } + } + return creator; + } + + /** + * Note that this method cannot be removed for now since it's used by Hibernate for loading a XWikiDocument. + * + * @deprecated since 3.0M2 use {@link #setCreatorReference} instead + */ + @Deprecated public void setCreator(String creator) { - if (!getCreator().equals(creator)) { + // Note: Consider "" or null as the same, i.e. the creator not being set + DocumentReference creatorReference = null; + if (creator != null && creator.length() > 0) { + creatorReference = this.currentReferenceDocumentReferenceResolver.resolve( + this.xClassEntityReferenceResolver.resolve(creator, EntityType.DOCUMENT)); + } + + if ((getCreatorReference() == null && creatorReference != null) + || (getCreatorReference() != null && !getCreatorReference().equals(creatorReference))) + { setMetaDataDirty(true); } - this.creator = creator; + + setCreatorReference(creatorReference); } public Date getDate() @@ -7345,7 +7483,7 @@ this.creationDate.setTime((this.creationDate.getTime() / 1000) * 1000); this.content = ""; this.format = ""; - this.author = ""; + this.authorReference = null; this.language = ""; this.defaultLanguage = ""; this.attachmentList = new ArrayList();