it.sistematica.isharedoc.opencmis.indatabase.storedobj.impl
Class ObjectStoreImpl

java.lang.Object
  extended by it.sistematica.isharedoc.opencmis.indatabase.storedobj.impl.ObjectStoreImpl
All Implemented Interfaces:
ObjectStore

public class ObjectStoreImpl
extends java.lang.Object
implements ObjectStore

The object store is the central core of the in-database repository.

Certain methods in the in-memory repository must guarantee constraints. For example a folder enforces that each child has a unique name. Therefore certain operations must occur in an atomic manner. In the example it must be guaranteed that no write access occurs to the map between acquiring the iterator to find the children and finishing the add operation when no name conflicts can occur. For this purpose this class has methods to lock an unlock the state of the repository. It is very important that the caller acquiring the lock enforces an unlock under all circumstances. Typical code is:

 ObjectStoreImpl os = ... ;
 try {
     os.lock();
 } finally {
     os.unlock();
 }
 
The locking is very coarse-grained. Productive implementations would probably implement finer grained locks on a folder or document rather than the complete repository.


Field Summary
protected  DocumentManager documentManager
           
protected  it.neverworks.data.EntityManager entities
           
protected  java.lang.String fRepositoryId
           
protected  StoredObject fRootFolder
           
protected  it.neverworks.application.service.UserInfo userInfo
           
 
Constructor Summary
ObjectStoreImpl(DocumentManager documentManager, it.neverworks.data.EntityManager entities)
           
ObjectStoreImpl(DocumentManager documentManager, it.neverworks.data.EntityManager entities, java.lang.String repositoryId)
           
ObjectStoreImpl(java.lang.String repositoryId)
           
 
Method Summary
 org.apache.chemistry.opencmis.commons.data.Acl applyAcl(StoredObject so, org.apache.chemistry.opencmis.commons.data.Acl addAces, org.apache.chemistry.opencmis.commons.data.Acl removeAces, org.apache.chemistry.opencmis.commons.enums.AclPropagation aclPropagation, java.lang.String principalId)
          Apply a ACLs by relative adding and removing a list of ACEs to/from an object
 org.apache.chemistry.opencmis.commons.data.Acl applyAcl(StoredObject so, org.apache.chemistry.opencmis.commons.data.Acl acl, org.apache.chemistry.opencmis.commons.enums.AclPropagation aclPropagation, java.lang.String principalId)
          Apply a ACLs by setting a new list of ACEs to an object
 void checkAllAccess(java.lang.String principalId, StoredObject so)
           
 void checkReadAccess(java.lang.String principalId, StoredObject so)
           
 void checkWriteAccess(java.lang.String principalId, StoredObject so)
           
 void clear()
          Clear repository and remove all data.
 Document createDocument(java.lang.String name, java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap, java.lang.String user, Folder folder, java.util.List<java.lang.String> policies, org.apache.chemistry.opencmis.commons.data.Acl addACEs, org.apache.chemistry.opencmis.commons.data.Acl removeACEs)
          Create a document as initial step.
 Folder createFolder(java.lang.String name)
           
 Folder createFolder(java.lang.String name, java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap, java.lang.String user, Folder parent, java.util.List<java.lang.String> policies, org.apache.chemistry.opencmis.commons.data.Acl addACEs, org.apache.chemistry.opencmis.commons.data.Acl removeACEs)
          Create a folder as initial step.
 StoredObject createItem(java.lang.String name, java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap, java.lang.String user, Folder folder, java.util.List<java.lang.String> policies, org.apache.chemistry.opencmis.commons.data.Acl addACEs, org.apache.chemistry.opencmis.commons.data.Acl removeACEs)
          Create an item as initial step.
 StoredObject createPolicy(java.lang.String name, java.lang.String policyText, java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap, java.lang.String user)
          Create a policy.
 StoredObject createRelationship(java.lang.String name, StoredObject sourceObject, StoredObject targetObject, java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap, java.lang.String user, org.apache.chemistry.opencmis.commons.data.Acl addACEs, org.apache.chemistry.opencmis.commons.data.Acl removeACEs)
          Create a relationship.
 StoredObject createStore(java.lang.String name)
           
 DocumentVersion createVersionedDocument(java.lang.String name, java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap, java.lang.String user, Folder folder, java.util.List<java.lang.String> policies, org.apache.chemistry.opencmis.commons.data.Acl addACEs, org.apache.chemistry.opencmis.commons.data.Acl removeACEs, org.apache.chemistry.opencmis.commons.data.ContentStream contentStream, org.apache.chemistry.opencmis.commons.enums.VersioningState versioningState)
          Create a document that supports versions as initial step.
 void deleteObject(java.lang.String objectId, java.lang.Boolean allVersions, java.lang.String user)
          Deletes an object from the store.
 java.util.List<InDatabaseAcl> getAllAclsForUser(java.lang.String principalId, Permission permission)
           
 java.util.List<StoredObject> getCheckedOutDocuments(java.lang.String orderBy, java.lang.String user, org.apache.chemistry.opencmis.commons.enums.IncludeRelationships includeRelationships)
          Return a list of all documents that are checked out in the repository.
 it.neverworks.util.Configuration getConfiguration()
           
 DocumentManager getDocumentManager()
           
 it.neverworks.data.EntityManager getEntityManager()
           
 java.util.Set<java.lang.String> getIds()
           
(package private)  StoredObject getObject(java.lang.String id)
           
 StoredObject getObjectById(java.lang.String objectId)
          get an object by its id
 StoredObject getObjectByPath(java.lang.String path, java.lang.String user)
          return an object by path.
 long getObjectCount()
          For statistics: return the number of objects contained in the system
 java.util.List<StoredObject> getRelationships(java.lang.String objectId, java.util.List<java.lang.String> typeIds, org.apache.chemistry.opencmis.commons.enums.RelationshipDirection direction)
          Get relationships to and from an object
 StoredObject getRootFolder()
          Get the root folder of this object store
 boolean hasAllAccess(java.lang.String principalId, StoredObject so)
           
 boolean hasReadAccess(java.lang.String principalId, StoredObject so)
           
 boolean hasWriteAccess(java.lang.String principalId, StoredObject so)
           
 boolean isTypeInUse(java.lang.String typeId)
          Check if this store contains any object with the given type id
 void loadStore(java.lang.String repositoryId)
           
 void lock()
           
 StoredObject makeWrapper(DocumentContent dc)
           
 StoredObject makeWrapper(File file)
           
(package private)  void removeObject(java.lang.String id)
           
 void removeVersion(DocumentVersion vers)
           
 java.lang.String storeObject(StoredObject so)
           
 void unlock()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fRepositoryId

protected java.lang.String fRepositoryId

fRootFolder

protected StoredObject fRootFolder

userInfo

protected it.neverworks.application.service.UserInfo userInfo

entities

protected it.neverworks.data.EntityManager entities

documentManager

protected DocumentManager documentManager
Constructor Detail

ObjectStoreImpl

public ObjectStoreImpl(java.lang.String repositoryId)

ObjectStoreImpl

public ObjectStoreImpl(DocumentManager documentManager,
                       it.neverworks.data.EntityManager entities)

ObjectStoreImpl

public ObjectStoreImpl(DocumentManager documentManager,
                       it.neverworks.data.EntityManager entities,
                       java.lang.String repositoryId)
Method Detail

getConfiguration

public it.neverworks.util.Configuration getConfiguration()

getDocumentManager

public DocumentManager getDocumentManager()

getEntityManager

public it.neverworks.data.EntityManager getEntityManager()

loadStore

public void loadStore(java.lang.String repositoryId)

createStore

public StoredObject createStore(java.lang.String name)

lock

public void lock()

unlock

public void unlock()

getRootFolder

public StoredObject getRootFolder()
Description copied from interface: ObjectStore
Get the root folder of this object store

Specified by:
getRootFolder in interface ObjectStore
Returns:
the root folder of this store

getObjectByPath

public StoredObject getObjectByPath(java.lang.String path,
                                    java.lang.String user)
Description copied from interface: ObjectStore
return an object by path.

Specified by:
getObjectByPath in interface ObjectStore
Parameters:
path - the path to the object
Returns:
the stored object with this path

getObjectById

public StoredObject getObjectById(java.lang.String objectId)
Description copied from interface: ObjectStore
get an object by its id

Specified by:
getObjectById in interface ObjectStore
Parameters:
objectId - the id of the object
Returns:
the object identified by this id

deleteObject

public void deleteObject(java.lang.String objectId,
                         java.lang.Boolean allVersions,
                         java.lang.String user)
Description copied from interface: ObjectStore
Deletes an object from the store. For a folders the folder must be empty.

Specified by:
deleteObject in interface ObjectStore
allVersions - is TRUE all version of the document are deleted, otherwise just this one

removeVersion

public void removeVersion(DocumentVersion vers)

storeObject

public java.lang.String storeObject(StoredObject so)

getObject

StoredObject getObject(java.lang.String id)

removeObject

void removeObject(java.lang.String id)

getIds

public java.util.Set<java.lang.String> getIds()

clear

public void clear()
Clear repository and remove all data.

Specified by:
clear in interface ObjectStore

getObjectCount

public long getObjectCount()
Description copied from interface: ObjectStore
For statistics: return the number of objects contained in the system

Specified by:
getObjectCount in interface ObjectStore
Returns:
number of stored objects

makeWrapper

public StoredObject makeWrapper(DocumentContent dc)

makeWrapper

public StoredObject makeWrapper(File file)

createItem

public StoredObject createItem(java.lang.String name,
                               java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap,
                               java.lang.String user,
                               Folder folder,
                               java.util.List<java.lang.String> policies,
                               org.apache.chemistry.opencmis.commons.data.Acl addACEs,
                               org.apache.chemistry.opencmis.commons.data.Acl removeACEs)
Description copied from interface: ObjectStore
Create an item as initial step. The item is created but still temporary. It is not yet persisted and does not have an id yet. After this call additional actions can take place (like assigning properties and a type) before it is persisted.

Specified by:
createItem in interface ObjectStore
Parameters:
name - name of the document
propMap - map of properties
user - the user who creates the document
folder - the parent folder
policies - list of policies to apply
addACEs - aces that are added
removeACEs - aces that are removed
Returns:
document object

createDocument

@Transactional
public Document createDocument(java.lang.String name,
                                             java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap,
                                             java.lang.String user,
                                             Folder folder,
                                             java.util.List<java.lang.String> policies,
                                             org.apache.chemistry.opencmis.commons.data.Acl addACEs,
                                             org.apache.chemistry.opencmis.commons.data.Acl removeACEs)
Description copied from interface: ObjectStore
Create a document as initial step. The document is created but still temporary It is not yet persisted and does not have an id yet. After this call additional actions can take place (like assigning properties and a type) before it is persisted.

Specified by:
createDocument in interface ObjectStore
Parameters:
name - name of the document
propMap - map of properties
user - the user who creates the document
folder - the parent folder
policies - list of policies to apply
addACEs - aces that are added
removeACEs - aces that are removed
Returns:
document object

createVersionedDocument

@Transactional
public DocumentVersion createVersionedDocument(java.lang.String name,
                                                             java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap,
                                                             java.lang.String user,
                                                             Folder folder,
                                                             java.util.List<java.lang.String> policies,
                                                             org.apache.chemistry.opencmis.commons.data.Acl addACEs,
                                                             org.apache.chemistry.opencmis.commons.data.Acl removeACEs,
                                                             org.apache.chemistry.opencmis.commons.data.ContentStream contentStream,
                                                             org.apache.chemistry.opencmis.commons.enums.VersioningState versioningState)
Description copied from interface: ObjectStore
Create a document that supports versions as initial step. The document is created but still temporary. It is not yet persisted and does not have an id yet. After this call additional actions can take place (like assigning properties and a type) before it is persisted.

Specified by:
createVersionedDocument in interface ObjectStore
Parameters:
name - name of the document * @param propMap map of properities
user - the user who creates the document
folder - the parent folder
policies - list of policies to apply
addACEs - aces that are added
removeACEs - aces that are removed
Returns:
versioned document object

createFolder

@Transactional
public Folder createFolder(java.lang.String name,
                                         java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap,
                                         java.lang.String user,
                                         Folder parent,
                                         java.util.List<java.lang.String> policies,
                                         org.apache.chemistry.opencmis.commons.data.Acl addACEs,
                                         org.apache.chemistry.opencmis.commons.data.Acl removeACEs)
Description copied from interface: ObjectStore
Create a folder as initial step. The folder is created but still temporary. It is not yet persisted and does not have an id yet. After this call additional actions can take place (like assigning properties and a type) before it is persisted.

Specified by:
createFolder in interface ObjectStore
Parameters:
name - name of the folder
propMap - map of properties
user - the user who creates the document
parent - the parent folder
policies - list of policies to apply
addACEs - aces that are added
removeACEs - aces that are removed
Returns:
folder object

createFolder

@Transactional
public Folder createFolder(java.lang.String name)

createPolicy

@Transactional
public StoredObject createPolicy(java.lang.String name,
                                               java.lang.String policyText,
                                               java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap,
                                               java.lang.String user)
Description copied from interface: ObjectStore
Create a policy. The policy is created but still temporary. It is not yet persisted and does not have an id yet. After this call additional actions can take place (like assigning properties and a type) before it is persisted.

Specified by:
createPolicy in interface ObjectStore
Parameters:
name - name of the document
policyText - policy text to apply to this policy
propMap - map of properties
user - the user who creates the document
Returns:
policy object

getCheckedOutDocuments

public java.util.List<StoredObject> getCheckedOutDocuments(java.lang.String orderBy,
                                                           java.lang.String user,
                                                           org.apache.chemistry.opencmis.commons.enums.IncludeRelationships includeRelationships)
Description copied from interface: ObjectStore
Return a list of all documents that are checked out in the repository.

Specified by:
getCheckedOutDocuments in interface ObjectStore
Parameters:
orderBy - orderBy specification according to CMIS spec.
user - user id of user calling
includeRelationships - if true include all relationships in the response
Returns:
list of checked out documents in the repository

createRelationship

@Transactional
public StoredObject createRelationship(java.lang.String name,
                                                     StoredObject sourceObject,
                                                     StoredObject targetObject,
                                                     java.util.Map<java.lang.String,org.apache.chemistry.opencmis.commons.data.PropertyData<?>> propMap,
                                                     java.lang.String user,
                                                     org.apache.chemistry.opencmis.commons.data.Acl addACEs,
                                                     org.apache.chemistry.opencmis.commons.data.Acl removeACEs)
Description copied from interface: ObjectStore
Create a relationship. The relationship is created but still temporary. It is not yet persisted and does not have an id yet. After this call additional actions can take place (like assigning properties and a type) before it is persisted.

Specified by:
createRelationship in interface ObjectStore
sourceObject - source of the relationship
targetObject - target of the relationship
propMap - map of properities
user - the user who creates the document
addACEs - aces that are added
removeACEs - aces that are removed
Returns:
versioned document object

getRelationships

public java.util.List<StoredObject> getRelationships(java.lang.String objectId,
                                                     java.util.List<java.lang.String> typeIds,
                                                     org.apache.chemistry.opencmis.commons.enums.RelationshipDirection direction)
Description copied from interface: ObjectStore
Get relationships to and from an object

Specified by:
getRelationships in interface ObjectStore
Parameters:
objectId - id of object to get relationships with
Returns:

applyAcl

@Transactional
public org.apache.chemistry.opencmis.commons.data.Acl applyAcl(StoredObject so,
                                                                             org.apache.chemistry.opencmis.commons.data.Acl addAces,
                                                                             org.apache.chemistry.opencmis.commons.data.Acl removeAces,
                                                                             org.apache.chemistry.opencmis.commons.enums.AclPropagation aclPropagation,
                                                                             java.lang.String principalId)
Description copied from interface: ObjectStore
Apply a ACLs by relative adding and removing a list of ACEs to/from an object

Specified by:
applyAcl in interface ObjectStore
Parameters:
so - object where ACLs are applied
addAces - list of ACEs to be added
removeAces - list of ACEs to be removed
aclPropagation - enum value how to propagate ACLs to child objects
Returns:
new ACL of object

applyAcl

@Transactional
public org.apache.chemistry.opencmis.commons.data.Acl applyAcl(StoredObject so,
                                                                             org.apache.chemistry.opencmis.commons.data.Acl acl,
                                                                             org.apache.chemistry.opencmis.commons.enums.AclPropagation aclPropagation,
                                                                             java.lang.String principalId)
Description copied from interface: ObjectStore
Apply a ACLs by setting a new list of ACEs to an object

Specified by:
applyAcl in interface ObjectStore
Parameters:
so - object where ACLs are applied
acl - list of ACEs to be applied
aclPropagation - enum value how to propagate ACLs to child objects
Returns:
new ACL of object

getAllAclsForUser

public java.util.List<InDatabaseAcl> getAllAclsForUser(java.lang.String principalId,
                                                       Permission permission)

hasReadAccess

public boolean hasReadAccess(java.lang.String principalId,
                             StoredObject so)

hasWriteAccess

public boolean hasWriteAccess(java.lang.String principalId,
                              StoredObject so)

hasAllAccess

public boolean hasAllAccess(java.lang.String principalId,
                            StoredObject so)

checkReadAccess

public void checkReadAccess(java.lang.String principalId,
                            StoredObject so)

checkWriteAccess

public void checkWriteAccess(java.lang.String principalId,
                             StoredObject so)

checkAllAccess

public void checkAllAccess(java.lang.String principalId,
                           StoredObject so)

isTypeInUse

public boolean isTypeInUse(java.lang.String typeId)
Description copied from interface: ObjectStore
Check if this store contains any object with the given type id

Specified by:
isTypeInUse in interface ObjectStore
Parameters:
typeId - id of type definition to check
Returns:
true if at least one object in the store has the given type, false if no objects exist having this type