Nuxeo Enterprise Platform 5.1

org.nuxeo.ecm.core.api
Class AbstractSession

java.lang.Object
  extended by org.nuxeo.ecm.core.api.AbstractSession
All Implemented Interfaces:
Serializable, CoreSession, SecurityConstants
Direct Known Subclasses:
DocumentManagerBean, LocalSession

public abstract class AbstractSession
extends Object
implements CoreSession, SecurityConstants, Serializable

Abstract implementation of the client interface.

This handles all the aspects that are independent on the final implementation (like running inside a J2EE platform or not).

The only aspect not implemented is the session management that should be handled by subclasses.

Author:
Bogdan Stefanescu
See Also:
Serialized Form

Field Summary
static NuxeoPrincipal ADMINISTRATOR
           
static NuxeoPrincipal ANONYMOUS
           
protected  DocumentResolver documentResolver
          Used to resolve core documents based on session.
protected  String repositoryName
           
protected  Map<String,Serializable> sessionContext
           
 
Fields inherited from interface org.nuxeo.ecm.core.api.security.SecurityConstants
ADD_CHILDREN, ADMINISTRATORS, BROWSE, EVERYONE, EVERYTHING, MANAGE_WORKFLOWS, MEMBERS, READ, READ_CHILDREN, READ_LIFE_CYCLE, READ_PROPERTIES, READ_SECURITY, READ_WRITE, REMOVE, REMOVE_CHILDREN, RESTRICTED_READ, VERSION, VIEW_WORKLFOW, WRITE, WRITE_LIFE_CYCLE, WRITE_PROPERTIES, WRITE_SECURITY
 
Constructor Summary
AbstractSession()
           
 
Method Summary
 void applyDefaultPermissions(String userOrGroupName)
          Applies default Read permissions on root JCR Document for the given user or group name.
 void cancel()
          Cancels any pending change made through this session.
 void checkIn(DocumentRef docRef, VersionModel version)
          Checks in a modified document, creating a new version.
 void checkOut(DocumentRef docRef)
          Checks out a versioned document.
protected  void checkPermission(Document doc, String permission)
           
 String connect(String repositoryName, Map<String,Serializable> context)
          Connects to the repository given its URI.
 DocumentModel copy(DocumentRef src, DocumentRef dst, String name)
          Copies the source document to the destination folder under the given name.
 List<DocumentModel> copy(List<DocumentRef> src, DocumentRef dst)
          Bulk copy.
 DocumentModel createDocument(DocumentModel docModel)
          Creates a document using given document model for initialization.
 DocumentModel[] createDocument(DocumentModel[] docModels)
          Bulk creation of documents.
 DocumentModel createDocumentModel(String typeName)
          Creates a document model using type name.
 DocumentModel createDocumentModel(String typeName, Map<String,Object> options)
          Creates a document model using required information.
 DocumentModel createDocumentModel(String parentPath, String id, String typeName)
          Creates a document model using required information.
 DocumentModel createProxy(DocumentRef parentRef, DocumentRef docRef, VersionModel version, boolean overwriteExistingProxy)
          Creates a proxy for the given version of the given document.
protected  String createSessionId()
          Default implementation for session ID generation.
 void destroy()
          Destroys any system resources held by this instance.
 void disconnect()
          Closes the current session and disconnects from the repository.
 boolean exists(DocumentRef docRef)
          Tests if the document pointed by the given reference exists and is accessible.
 boolean followTransition(DocumentRef docRef, String transition)
          Follows a given life cycle transition.
 String generateDocumentName(Document parent, String name)
          Generate a non-null unique name within given parent's children.
 String generateVersionLabelFor(DocumentRef docRef)
          Utility method to generate VersionModel labels.
 ACP getACP(DocumentRef docRef)
          Gets the document access control policy.
 Collection<String> getAllowedStateTransitions(DocumentRef docRef)
          Gets the allowed state transitions for this document.
 List<String> getAvailableSecurityPermissions()
          Retrieves the available security permissions existing in the system.
 DocumentModel getChild(DocumentRef parent, String name)
          Gets a child document given its name and the parent reference.
 DocumentModelList getChildren(DocumentRef parent)
          Gets the children of the given parent.
 DocumentModelList getChildren(DocumentRef parent, String type)
          Gets the children of the given parent filtered according to the given document type.
 DocumentModelList getChildren(DocumentRef parent, String type, Filter filter, Sorter sorter)
          Same as the previous method without specific permission filtering.
 DocumentModelList getChildren(DocumentRef parent, String type, String perm)
          Gets the children of the given parent filtered according to the given document type and permission.
 DocumentModelList getChildren(DocumentRef parent, String type, String perm, Filter filter, Sorter sorter)
          Same as the previous method but the result is filtered and then sorted using the specified filter and sorter.
 DocumentModelIterator getChildrenIterator(DocumentRef parent)
          Gets the children of the given parent.
 DocumentModelIterator getChildrenIterator(DocumentRef parent, String type)
           
 DocumentModelIterator getChildrenIterator(DocumentRef parent, String type, String perm, Filter filter)
          Gets the children of the given parent filtered according to the given document type and permission.
 byte[] getContentData(DocumentRef docRef, String path)
          Gets the full content of the given field in the given document from the given session.
 SerializableInputStream getContentData(String key)
          Gets the data input stream given its key.
 String getCurrentLifeCycleState(DocumentRef docRef)
          Returns the life cycle of the document.
 DataModel getDataModel(DocumentRef docRef, String schema)
          Retrieves the data model given its schema and the reference of the owner document.
 Object getDataModelField(DocumentRef docRef, String schema, String field)
          Retrieves the given field value from the given schema for the given document.
 Object[] getDataModelFields(DocumentRef docRef, String schema, String[] fields)
          The bulk version of the above method.
 Object[] getDataModelsField(DocumentRef[] docRefs, String schema, String field)
          Retrieves the given field value from the given schema for all the given documents.
 Object[] getDataModelsFieldUp(DocumentRef docRef, String schema, String field)
          Retrieves the given field value from the given schema for the given document along with all its parent documents.
 DocumentModelsChunk getDocsResultChunk(DocsQueryProviderDef def, String type, String perm, Filter filter, int start, int max)
          Method used internally to retrieve frames of a long result.
 DocumentModel getDocument(DocumentRef docRef)
          Gets a document model given its reference.
 DocumentModel getDocument(DocumentRef docRef, String[] schemas)
          Gets a document model given its reference and the initial set of schemas to use.
 DocumentModelList getDocuments(DocumentRef[] docRefs)
          Gets a a list of documents given their references.
<T extends Serializable>
T
getDocumentSystemProp(DocumentRef ref, String systemProperty, Class<T> type)
          Gets system property of the specified type for the document ref.
 DocumentType getDocumentType(String type)
          Gets the document type object given its type name.
 DocumentModel getDocumentWithVersion(DocumentRef docRef, VersionModel version)
          Returns a document that represents the specified version of the document.
 DocumentModelList getFiles(DocumentRef parent)
          Same as CoreSession.getChildren(DocumentRef) but returns a lazy loading iterator over the list of children.
 DocumentModelList getFiles(DocumentRef parent, Filter filter, Sorter sorter)
          Same as the previous method but uses an optional filter and sorter on the result.
 DocumentModelIterator getFilesIterator(DocumentRef parent)
          Same as CoreSession.getFiles(DocumentRef) but returns only non-folder documents.
 DocumentModelList getFolders(DocumentRef parent)
          Same as CoreSession.getChildren(DocumentRef) but returns only folder documents.
 DocumentModelList getFolders(DocumentRef parent, Filter filter, Sorter sorter)
          Same as the previous method but use an optional filter and sorter on the result.
 DocumentModelIterator getFoldersIterator(DocumentRef parent)
          Same as CoreSession.getFolders(DocumentRef) but returns a lazy loading iterator over the list of children.
 DocumentModel getLastDocumentVersion(DocumentRef docRef)
          Gets the document corresponding to the last version for the given document.
 VersionModel getLastVersion(DocumentRef docRef)
          Gets the last version of a document.
 String getLifeCyclePolicy(DocumentRef docRef)
          Returns the life cycle policy of the document.
 String getLock(DocumentRef docRef)
          Gets the lock key on the given document if a lock exists or null otherwise.
 DocumentModel getParentDocument(DocumentRef docRef)
          Gets the parent document or null if this is the root document.
 DocumentRef[] getParentDocumentRefs(DocumentRef docRef)
          Creates an array with all parent refs starting from the given document up to the root.
 List<DocumentModel> getParentDocuments(DocumentRef docRef)
          Gets the parent documents in path from the root to the given document or empty list if this is the root document.
 Principal getPrincipal()
          Gets the principal that created the client session.
 DocumentModelList getProxies(DocumentRef docRef, DocumentRef folderRef)
          Gets all proxies to document docRef inside folder folderRef.
 String[] getProxyVersions(DocumentRef docRef, DocumentRef folderRef)
          Gets all proxy versions to document docRef inside folder folderRef.
 String getRepositoryName()
          Returns the repository name against which this core session is bound.
 DocumentModel getRootDocument()
          Gets the root document of this repository.
protected  SecurityService getSecurityService()
           
 List<SecuritySummaryEntry> getSecuritySummary(DocumentModel docModel, Boolean includeParents)
          Returns security descriptors of doc and all it's children that hold explicit security.
protected abstract  Session getSession()
          Gets the current session based on the client session id.
 String getSessionId()
          Gets the current session id.
 DocumentModel getSourceDocument(DocumentRef docRef)
          Gets the head (live) document for this document.
 String getStreamURI(String blobPropertyId)
          Returns an URI identifying the stream given the blob property id.
 String getSuperParentType(DocumentModel doc)
          Returns the type of his parent SuperSpace (workspace, section, etc.).
 DocumentModel getSuperSpace(DocumentModel doc)
          Returns the parent SuperSpace (workspace, section, etc.).
 List<DocumentModel> getVersions(DocumentRef docRef)
          Retrieves all the versions for a specified document.
 List<VersionModel> getVersionsForDocument(DocumentRef docRef)
          Retrieves all the versions for a specified document.
 boolean hasChildren(DocumentRef docRef)
          Tests if the document has any children.
 boolean hasPermission(DocumentRef docRef, String permission)
          Checks if the principal that created the client session has the given privilege on the referred document.
protected  boolean hasPermission(Document doc, String permission)
           
protected  boolean isAdministrator()
           
 boolean isCheckedOut(DocumentRef docRef)
          Returns whether the current document is checked-out or not.
 boolean isDirty(DocumentRef docRef)
          Checks if the given document is dirty.
 VersionModel isPublished(DocumentModel document, DocumentModel section)
          Checks if the document is already published in the section and retrieves it's version.
abstract  boolean isSessionAlive()
           
 DocumentModel move(DocumentRef src, DocumentRef dst, String name)
          Moves the source document to the destination folder under the given name.
 void move(List<DocumentRef> src, DocumentRef dst)
          Bulk move.
protected  void notifyEvent(String eventId, DocumentModel source, Map<String,Object> options, String category, String comment, boolean withLifeCycle)
           
 void orderBefore(DocumentRef parent, String src, String dest)
          Given a parent document, order the source child before the destination child.
 DocumentModel publishDocument(DocumentModel docToPublish, DocumentModel section)
          Publishes the document in a section overwriting any existing proxy to the same document.
 DocumentModel publishDocument(DocumentModel docToPublish, DocumentModel section, boolean overwriteExistingProxy)
          Publishes the document in a section.
 DocumentModelList query(String query)
          Deprecated. 
 DocumentModelList query(String query, Filter filter)
          Deprecated. 
 DocumentModelList query(String query, Filter filter, int max)
          Deprecated. 
 DocumentModelList query(String query, int max)
          Deprecated. 
 DocumentModelIterator queryIt(String query, Filter filter, int max)
          Deprecated. 
 DocumentModelList querySimpleFts(String keywords)
          Deprecated. 
 DocumentModelList querySimpleFts(String keywords, Filter filter)
          Deprecated. 
 DocumentModelIterator querySimpleFtsIt(String query, Filter filter, int pageSize)
          Deprecated. 
 DocumentModelIterator querySimpleFtsIt(String query, String startingPath, Filter filter, int pageSize)
          Deprecated. 
protected  DocumentModel readModel(Document doc, String[] schemas)
          Gets the document model for the given core document.
 void removeChildren(DocumentRef docRef)
          Removes all children from the given document.
protected  void removeDocument(Document doc)
           
 void removeDocument(DocumentRef docRef)
          Removes this document and all its children, if any.
 void removeDocuments(DocumentRef[] docRefs)
          Implementation uses the fact that the lexicographic ordering of paths is a refinement of the "contains" partial ordering.
protected  void removeNotifyOneDoc(Document doc)
           
protected  Document resolveReference(DocumentRef docRef)
           
 DocumentModel restoreToVersion(DocumentRef docRef, VersionModel version)
          Restores the given document to the specified version.
 void save()
          Saves any pending changes done until now through this session.
 DocumentModel saveDocument(DocumentModel docModel)
          Saves changes done on the given document model.
 DocumentModel saveDocumentAsNewVersion(DocumentModel doc)
          Deprecated. instead use saveDocument with VersioningDocument.CREATE_SNAPSHOT_ON_SAVE_KEY in contextData
 void saveDocuments(DocumentModel[] docModels)
          Bulk document saving.
 void setACP(DocumentRef docRef, ACP acp, boolean overwrite)
          Sets the ACP for this document.
<T extends Serializable>
void
setDocumentSystemProp(DocumentRef ref, String systemProperty, T value)
          Sets given value as a system property.
 void setLock(DocumentRef docRef, String key)
          Sets a lock on the given document using the given key.
 String unlock(DocumentRef docRef)
          Removes the lock if one exists.
protected  void writeDocumentPart(DocumentPart part)
           
protected  DocumentModel writeModel_OLD(Document doc, DocumentModel docModel)
          Writes the model as modified by the used in the corresponding document.
protected  DocumentModel writeModel(Document doc, DocumentModel docModel)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANONYMOUS

public static final NuxeoPrincipal ANONYMOUS

ADMINISTRATOR

public static final NuxeoPrincipal ADMINISTRATOR

repositoryName

protected String repositoryName

sessionContext

protected Map<String,Serializable> sessionContext

documentResolver

protected final DocumentResolver documentResolver
Used to resolve core documents based on session.

Constructor Detail

AbstractSession

public AbstractSession()
Method Detail

getSecurityService

protected SecurityService getSecurityService()

getSession

protected abstract Session getSession()
                               throws ClientException
Gets the current session based on the client session id.

Returns:
the repository session
Throws:
ClientException

connect

public String connect(String repositoryName,
                      Map<String,Serializable> context)
               throws ClientException
Description copied from interface: CoreSession
Connects to the repository given its URI. This opens a new session on the specified repository.

This method must never be called by users. Is is indirectly called from CoreInstance.open(String, Map) when creating the client.

Specified by:
connect in interface CoreSession
Parameters:
repositoryName - the repository URI (unique in the platform)
context - a map of properties used to initialize the session. Can be null if no context properties are specified.
Returns:
the session ID if the connection succeed, null otherwise
Throws:
ClientException

createSessionId

protected String createSessionId()
Default implementation for session ID generation.

The ID has the following format: <repository-name>-<JVM-Unique-ID> where the JVM-Unique-ID is an unique ID on a running JVM and repository-name is a used to avoid name clashes with sessions on different machines (the repository name should be unique in the system)

Returns:

getDocumentType

public DocumentType getDocumentType(String type)
Description copied from interface: CoreSession
Gets the document type object given its type name.

Specified by:
getDocumentType in interface CoreSession
Parameters:
type - the document type name
Returns:
the type the doc type object

generateVersionLabelFor

public String generateVersionLabelFor(DocumentRef docRef)
                               throws ClientException
Utility method to generate VersionModel labels.

Specified by:
generateVersionLabelFor in interface CoreSession
Returns:
the String representation of an auto-incremented counter that not used in any label of docRef
Throws:
ClientException

getSessionId

public String getSessionId()
Description copied from interface: CoreSession
Gets the current session id.

If the client is not connected returns null.

Specified by:
getSessionId in interface CoreSession
Returns:
the session id or null if not connected

getPrincipal

public Principal getPrincipal()
Description copied from interface: CoreSession
Gets the principal that created the client session.

Specified by:
getPrincipal in interface CoreSession
Returns:
the principal

checkPermission

protected final void checkPermission(Document doc,
                                     String permission)
                              throws DocumentException
Throws:
DocumentException

notifyEvent

protected void notifyEvent(String eventId,
                           DocumentModel source,
                           Map<String,Object> options,
                           String category,
                           String comment,
                           boolean withLifeCycle)

hasPermission

public boolean hasPermission(DocumentRef docRef,
                             String permission)
                      throws ClientException
Description copied from interface: CoreSession
Checks if the principal that created the client session has the given privilege on the referred document.

Specified by:
hasPermission in interface CoreSession
Returns:
Throws:
ClientException

hasPermission

protected final boolean hasPermission(Document doc,
                                      String permission)
                               throws DocumentException
Throws:
DocumentException

resolveReference

protected final Document resolveReference(DocumentRef docRef)
                                   throws DocumentException,
                                          ClientException
Throws:
DocumentException
ClientException

readModel

protected DocumentModel readModel(Document doc,
                                  String[] schemas)
                           throws ClientException
Gets the document model for the given core document.

If no schemas are specified (schemas are null) use the default schemas as configured in the document type manager.

Parameters:
doc - the document
schemas - the schemas if any, null otherwise
Returns:
the document model
Throws:
ClientException

writeModel_OLD

protected DocumentModel writeModel_OLD(Document doc,
                                       DocumentModel docModel)
                                throws DocumentException,
                                       ClientException
Writes the model as modified by the used in the corresponding document.

Parameters:
doc - the document where to write the changes
docModel - the model containing the changes
Throws:
DocumentException
ClientException

writeModel

protected DocumentModel writeModel(Document doc,
                                   DocumentModel docModel)
                            throws DocumentException,
                                   ClientException
Throws:
DocumentException
ClientException

writeDocumentPart

protected void writeDocumentPart(DocumentPart part)

copy

public DocumentModel copy(DocumentRef src,
                          DocumentRef dst,
                          String name)
                   throws ClientException
Description copied from interface: CoreSession<