com.atlassian.confluence.content.service
Class DefaultDraftService

java.lang.Object
  extended by com.atlassian.confluence.content.service.DefaultDraftService
All Implemented Interfaces:
DraftService

public class DefaultDraftService
extends java.lang.Object
implements DraftService

Note that this implementation of the DraftService does not perform any permission checking. This has always been the case in Confluence and needs to remain the case at the moment due to the way certain UI operations work such as copying a page. See CONFDEV-227 for more details.


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.atlassian.confluence.content.service.DraftService
DraftService.DraftType
 
Method Summary
 int countDrafts()
           
 Draft createDraftForEditor(AbstractPage page)
          Create and store a draft for the supplied AbstractPage for the current user.
 Draft createNewContentDraft(java.lang.String spaceKey, DraftService.DraftType type)
           
 Draft findDraftForEditor(long contentId, DraftService.DraftType type, java.lang.String spaceKey)
          Find and return a draft of the specified content Id and type for the current user.
 java.util.List<Draft> findDrafts(int limit, int offset)
          Finds the users drafts.
 Draft findOrCreateDraftForEditor(java.lang.String spaceKey, DraftService.DraftType type)
          Create the draft within the identified space for the current user.
 Draft getDraft(long draftId)
          gets the draft by id for the authenticated user
 boolean isDraftContentChanged(java.lang.Long draftId, java.lang.String title, java.lang.String content, java.lang.Long contentId)
          Compares the content of a draft to an existing page.
 java.lang.Long removeDraft(long draftId)
          Removes the draft with the specified ID if it is found, and returns the same ID passed.
 void removeDraft(long contentId, DraftService.DraftType type, java.lang.String spaceKey)
          Deprecated. 
 java.lang.Long removeDraft(long abstractPageId, long draftId)
          Removes the draft specified by the given page id or draft id for the current user.
 Draft saveDraftFromEditor(java.lang.Long draftId, java.lang.String title, DraftService.DraftType type, java.lang.String content, java.lang.Long contentId, java.lang.String spaceKey, int pageVersion)
          Create and store a draft for the current user with the supplied details.
 Draft saveDraftFromEditor(java.lang.String title, DraftService.DraftType type, java.lang.String content, java.lang.String contentId, java.lang.String spaceKey, int pageVersion)
          Deprecated. 
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

saveDraftFromEditor

public Draft saveDraftFromEditor(java.lang.Long draftId,
                                 java.lang.String title,
                                 DraftService.DraftType type,
                                 java.lang.String content,
                                 java.lang.Long contentId,
                                 java.lang.String spaceKey,
                                 int pageVersion)
                          throws NotAuthorizedException,
                                 NotValidException
Description copied from interface: DraftService
Create and store a draft for the current user with the supplied details.

Specified by:
saveDraftFromEditor in interface DraftService
content - the editor formatted content (will be converted into storage format).
contentId - as a String since NEW is taken to represent a new draft
Returns:
The Draft model object that was created and saved. The content of this draft will be in storage format
Throws:
NotAuthorizedException - if the current user is not able to save a draft (doesn't have edit permission)
NotValidException - if the data for the draft is incomplete or the content identified does not exist

saveDraftFromEditor

@Deprecated
public Draft saveDraftFromEditor(java.lang.String title,
                                            DraftService.DraftType type,
                                            java.lang.String content,
                                            java.lang.String contentId,
                                            java.lang.String spaceKey,
                                            int pageVersion)
                          throws NotAuthorizedException,
                                 NotValidException
Deprecated. 

Specified by:
saveDraftFromEditor in interface DraftService
Throws:
NotAuthorizedException
NotValidException

findDraftForEditor

public Draft findDraftForEditor(long contentId,
                                DraftService.DraftType type,
                                java.lang.String spaceKey)
                         throws NotAuthorizedException,
                                NotValidException
Description copied from interface: DraftService
Find and return a draft of the specified content Id and type for the current user. The draft will be returned in a format suitable for the Confluence editor

Specified by:
findDraftForEditor in interface DraftService
Returns:
the draft is found, otherwise null.
Throws:
NotAuthorizedException - if the current user is not permitted to view drafts for the identified content
NotValidException - if the content identified does not exist

createDraftForEditor

public Draft createDraftForEditor(AbstractPage page)
                           throws NotAuthorizedException,
                                  NotValidException
Description copied from interface: DraftService
Create and store a draft for the supplied AbstractPage for the current user. The draft will be created in storage format but the return object will contain editor format content.

Specified by:
createDraftForEditor in interface DraftService
Parameters:
page - the page to create a Draft from
Returns:
the Draft that was created. The content of this Draft will be in a format suitable for the editor.
Throws:
NotAuthorizedException - if the current user is not able to save a draft (doesn't have edit permission)
NotValidException - if the data for the draft is incomplete or the content identified does not exist

findOrCreateDraftForEditor

public Draft findOrCreateDraftForEditor(java.lang.String spaceKey,
                                        DraftService.DraftType type)
                                 throws NotAuthorizedException,
                                        NotValidException
Description copied from interface: DraftService
Create the draft within the identified space for the current user. If none is found then a new empty Draft is created, saved and returned. Any content within the draft will be suitable for use in the Confluence editor.

Specified by:
findOrCreateDraftForEditor in interface DraftService
Throws:
NotAuthorizedException - if the current user is not permitted to view or create drafts in the space
NotValidException - if the space identified does not exist.

createNewContentDraft

public Draft createNewContentDraft(java.lang.String spaceKey,
                                   DraftService.DraftType type)
                            throws NotAuthorizedException,
                                   NotValidException
Specified by:
createNewContentDraft in interface DraftService
Throws:
NotAuthorizedException
NotValidException

removeDraft

public java.lang.Long removeDraft(long abstractPageId,
                                  long draftId)
                           throws NotAuthorizedException,
                                  NotValidException
Description copied from interface: DraftService
Removes the draft specified by the given page id or draft id for the current user. Looks at the draftId by preference, and reverts to the abstractPageId if the draftId is 0. Throws IllegalStateException if the draftId is 0 and the abstract page cannot be found.

Specified by:
removeDraft in interface DraftService
Parameters:
abstractPageId - the id of the abstract page the draft is an edit for.
draftId - the draft of the id to remove, this is necessary if abstractPageId = 0.
Returns:
the id of the removed draft or null if neither a matching page nor draft could be found.
Throws:
NotAuthorizedException - if the current user does not have permission.
NotValidException

removeDraft

public java.lang.Long removeDraft(long draftId)
                           throws NotAuthorizedException,
                                  NotValidException
Description copied from interface: DraftService
Removes the draft with the specified ID if it is found, and returns the same ID passed.

Specified by:
removeDraft in interface DraftService
Parameters:
draftId - a draft to remove
Returns:
draftId removed or null.
Throws:
NotAuthorizedException
NotValidException

findDrafts

public java.util.List<Draft> findDrafts(int limit,
                                        int offset)
                                 throws NotAuthorizedException,
                                        NotValidException
Description copied from interface: DraftService
Finds the users drafts.

Specified by:
findDrafts in interface DraftService
Parameters:
limit - - the maximum number of drafts to return
offset - - the offset of results
Returns:
Throws:
NotAuthorizedException
NotValidException

countDrafts

public int countDrafts()
Specified by:
countDrafts in interface DraftService
Returns:
A count of the drafts for the authenticated user

getDraft

public Draft getDraft(long draftId)
               throws NotAuthorizedException,
                      NotValidException
Description copied from interface: DraftService
gets the draft by id for the authenticated user

Specified by:
getDraft in interface DraftService
Returns:
the draft with id draftId if it is owned by the authenticated user
Throws:
NotAuthorizedException - - if the owner of the draft is not the authenticated user
NotValidException - - if no draft exists with this id

removeDraft

@Deprecated
public void removeDraft(long contentId,
                                   DraftService.DraftType type,
                                   java.lang.String spaceKey)
                 throws NotAuthorizedException,
                        NotValidException
Deprecated. 

Description copied from interface: DraftService
Removes the draft specified by the given content id and type for the current user. Does nothing if no draft is found.

Specified by:
removeDraft in interface DraftService
spaceKey - since a new page draft is unique per space the spaceKey must be provided if the contentId is 0
Throws:
NotAuthorizedException - if the current user does not have permission.
NotValidException

isDraftContentChanged

public boolean isDraftContentChanged(java.lang.Long draftId,
                                     java.lang.String title,
                                     java.lang.String content,
                                     java.lang.Long contentId)
                              throws NotAuthorizedException,
                                     NotValidException
Description copied from interface: DraftService
Compares the content of a draft to an existing page. If the draft is for a new page returns true when Draft.isBlank() returns false and the draft has no attachments

Specified by:
isDraftContentChanged in interface DraftService
Returns:
true if the draft content is different to it's pages content, or not blank when a new draft.
Throws:
NotAuthorizedException
NotValidException


Copyright © 2003-2014 Atlassian. All Rights Reserved.