Class ExplorerResourcesDAO
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.explorer.resources.actions.ExplorerResourcesDAO
- All Implemented Interfaces:
LogEnabled
,Component
,Contextualizable
,Serviceable
- Direct Known Subclasses:
ExplorerResourcesDAO
,WorkspaceExplorerResourceDAO
public class ExplorerResourcesDAO
extends AbstractLogEnabled
implements Serviceable, Component, Contextualizable
Explorer resources DAO
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Bean for version information -
Field Summary
Modifier and TypeFieldDescriptionprotected Context
The cocoon contextprotected Context
The avalon contextprotected CurrentUserProvider
The current user provider.protected ResourceMetadataPopulatorExtensionPoint
The metadata populator extension point.protected ObservationManager
Observer manager.protected AmetysObjectResolver
Ametys resolverprotected RightManager
The rights managerprotected ThreadDAO
The thread DAOprotected TikaProvider
The tika provider.protected UserHelper
The users managerstatic final String
Right id to add a folderstatic final String
Right id to add CMIS collectionstatic final String
Right id to delete a folderstatic final String
Right id to edit a folderstatic final String
Right id to add a resourcestatic final String
Right id to comment a resourcestatic final String
Right id to delete a resourcestatic final String
Right id to edit DC metadata of a resourcestatic final String
Right id to moderate comment a resourcestatic final String
Right id to rename a resourcestatic final String
Right id to unlock all resourcesstatic final String
Avalon Role -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
_canAddComment
(UserIdentity user, CommentableResource resource) Indicates if an user can add a comment of a given resourceprotected boolean
_canDeleteComment
(UserIdentity user, CommentableResource resource, JCRPost comment) Indicates if an user can delete a comment of a given resourceprotected boolean
_canEditComment
(UserIdentity user, CommentableResource resource, JCRPost comment) Indicates if an user can edit a comment of a given resource_comment2json
(JCRPost comment, boolean isEdition) Get JSOn representation of a commentprotected String
_getComment
(JCRPost post) Get the content of a comment as a Stringprotected String
_getCommentForEditing
(JCRPost post) Get the content of a comment to edit as a Stringprotected void
_setComment
(JCRPost comment, String content) Update the content of a comment_version2json
(JCRResource resource, ExplorerResourcesDAO.VersionInformation versionInformation) Get the JSON representation of a version of a resourceaddCMISCollection
(String parentId, String originalName, String url, String login, String password, String repoId, String mountPoint, boolean renameIfExists) Creates a new CMIS folder (seeCMISRootResourcesCollection
)addComment
(String resourceId, String comment) Add a comment to a resourceaddResourceCollection
(String parentId, String desiredName, Boolean renameIfExists) Add a resource collectionaddResourceCollection
(ModifiableResourceCollection parent, String desiredName, Boolean renameIfExists, List<String> errors) Add a resource collectionboolean
Check lock on a Ametys objectvoid
checkpoint
(ModifiableResource resource) Creates a new versionvoid
checkUserRight
(AmetysObject object, String rightId) Check the user privilege on objectvoid
contextualize
(Context context) copyResource
(List<String> ids, String target) Copy file resourcescopyResource
(List<String> ids, ModifiableResourceCollection target) Copy file resourcescreateResource
(ModifiableResourceCollection collection, String name) Creates aModifiableResource
under currentModifiableResourceCollection
.deleteComment
(String resourceId, String commentId) Delete the comment of a resourcedeleteObject
(List<String> ids) Delete an objectdeleteObject
(RemovableAmetysObject object, List<String> errors) Delete an objecteditCMISCollection
(String id, String url, String login, String password, String repoId, String mountPoint) Edits a CMIS folder (seeCMISRootResourcesCollection
)editComment
(String resourceId, String commentId, String comment) Edit the comment of a resourcevoid
extractResourceMetadata
(ModifiableResource resource, String mimeType) Extract the resource's metadata and populate the object accordingly.filterResourcesByRegExp
(String id, String value, List<String> allowedExtensions) Get the path of pages which match filter regexpGet the CMIS properties of collectiongetComment
(String commentId, boolean isEdition) Get a comment of a resourcegetComments
(String resourceId, boolean isEdition) Get the comments of a resourcegetDCMetadata
(String id) Get the DublinCore metadata of aDublinCoreAwareAmetysObject
Get the necessary default info for a root node.getDefaultInfoAsRootNode
(ExplorerNode rootNode) Get the necessary default info for a root node.Get the pattern that match an explorer node pathGet the explorer node propertiesgetNodesInfo
(List<String> ids) Get the informations on given nodes (resources or collections)Get the type of child resource collectiongetResourceProperties
(Resource resource) Get the resource propertiesGet the root nodes for resourcesgetRootNodeLabel
(ExplorerNode rootNode) Get the root node labelRetrieves the set of standard data for the explorer root nodeboolean
getUserRight
(UserIdentity user, String right, AmetysObject object) Retrieve the rights for the usergetUserRights
(ExplorerNode node) Get the user rights on the resource collectionboolean
Check current user right on given explorer nodeboolean
Determines if a object is aCMISRootResourcesCollection
moveObject
(List<String> ids, String targetId) Move objectsmoveObject
(List<String> ids, JCRTraversableAmetysObject targetNode) Move objectsrenameObject
(String id, String name) Rename a resource, or resource collectionrenameObject
(JCRAmetysObject object, String name, List<String> errors) Rename a resource, or resource collectionrenameResource
(String id, String name) Rename a resourcerenameResource
(JCRResource resource, String name, List<String> errors) Rename a resourceboolean
resourceExists
(String parentId, String name) Determines if a resource with given name already existsboolean
resourceExists
(TraversableAmetysObject parent, String name) Determines if a resource with given name already existsGet the history versions of a resourceboolean
resourcesExists
(String parentId, List<String> names) Determines if at least one resource with given names already existsvoid
restoreResource
(String id, String versionName) This action restores an old version of aResource
.void
service
(ServiceManager manager) void
setDCMetadata
(String resourceId, Map<String, Object> values) Set the Dublin Core metadata of aResource
.void
setDCMetadata
(ModifiableResource resource, Map<String, Object> values) Set the Dublin Core metadata of aResource
.void
updateResource
(ModifiableResource resource, InputStream is, String fileName) Updates resource input stream and metadataMethods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
Avalon Role -
RIGHTS_RESOURCE_UNLOCK_ALL
Right id to unlock all resources- See Also:
-
RIGHTS_RESOURCE_ADD
Right id to add a resource- See Also:
-
RIGHTS_RESOURCE_RENAME
Right id to rename a resource- See Also:
-
RIGHTS_RESOURCE_DELETE
Right id to delete a resource- See Also:
-
RIGHTS_RESOURCE_EDIT_DC
Right id to edit DC metadata of a resource- See Also:
-
RIGHTS_RESOURCE_COMMENT
Right id to comment a resource- See Also:
-
RIGHTS_RESOURCE_MODERATE_COMMENT
Right id to moderate comment a resource- See Also:
-
RIGHTS_COLLECTION_CMIS_ADD
Right id to add CMIS collection- See Also:
-
RIGHTS_COLLECTION_ADD
Right id to add a folder- See Also:
-
RIGHTS_COLLECTION_EDIT
Right id to edit a folder- See Also:
-
RIGHTS_COLLECTION_DELETE
Right id to delete a folder- See Also:
-
_resolver
Ametys resolver -
_rightManager
The rights manager -
_observationManager
Observer manager. -
_currentUserProvider
The current user provider. -
_context
The avalon context -
_cocoonContext
The cocoon context -
_tikaProvider
The tika provider. -
_metadataPopulatorEP
The metadata populator extension point. -
_userHelper
The users manager -
_threadDAO
The thread DAO
-
-
Constructor Details
-
ExplorerResourcesDAO
public ExplorerResourcesDAO()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
getResourcesRootNodes
Get the root nodes for resources- Returns:
- the root nodes
-
getRootNodesInfo
Retrieves the set of standard data for the explorer root node- Returns:
- The data structured in a map
-
getDefaultInfoAsRootNode
Get the necessary default info for a root node. Can be used to construct a root node for a tree (client side).- Parameters:
id
- The root node id- Returns:
- A map which contains a set of default info (such as id, applicationId, path, type etc...)
-
getDefaultInfoAsRootNode
Get the necessary default info for a root node. Can be used to construct a root node for a tree (client side).- Parameters:
rootNode
- The root node- Returns:
- A map which contains a set of default info (such as id, applicationId, path, type etc...)
-
getRootNodeLabel
Get the root node label- Parameters:
rootNode
- the node- Returns:
- the readable label
-
getNodesInfo
Get the informations on given nodes (resources or collections)- Parameters:
ids
- The ids of node- Returns:
- the nodes information
-
getExplorerNodeProperties
Get the explorer node properties- Parameters:
node
- The explorer node- Returns:
- The properties
-
getResourceProperties
Get the resource properties- Parameters:
resource
- The resources- Returns:
- The properties
-
getExplorerNodePathPatterns
Get the pattern that match an explorer node path- Returns:
- the patterns
-
filterResourcesByRegExp
public List<String> filterResourcesByRegExp(String id, String value, List<String> allowedExtensions) Get the path of pages which match filter regexp- Parameters:
id
- The id of explorer node to start searchvalue
- the value to matchallowedExtensions
- The allowed file extensions (lower-case). Can be null or empty to not filter on file extensions- Returns:
- the matching paths
-
getUserRights
Get the user rights on the resource collection- Parameters:
node
- The explorer node- Returns:
- The user's rights
-
hasRight
Check current user right on given explorer node- Parameters:
id
- The id of the explorer noderightId
- The if of right to check- Returns:
- true if user has right
-
checkLock
Check lock on a Ametys object- Parameters:
ao
- the Ametys object- Returns:
false
if the Ametys object is locked and can not be edited or deleted
-
checkUserRight
Check the user privilege on object- Parameters:
object
- the objectrightId
- the right id- Throws:
IllegalAccessException
- if the user has no sufficient rights
-
getUserRight
Retrieve the rights for the user- Parameters:
user
- The userright
- The rightobject
- The object- Returns:
- True if the user has the right
-
addResourceCollection
public Map<String,Object> addResourceCollection(String parentId, String desiredName, Boolean renameIfExists) Add a resource collection- Parameters:
parentId
- The identifier of the parent in which the resource collection will be addeddesiredName
- The desired name for the resource collectionrenameIfExists
- If false, in case of existing name the resource collection will not be created, if true it will be created and renamed- Returns:
- The result map with id, parentId, name and message keys
-
addResourceCollection
public ResourceCollection addResourceCollection(ModifiableResourceCollection parent, String desiredName, Boolean renameIfExists, List<String> errors) Add a resource collection- Parameters:
parent
- The parent collection in which the resource collection will be addeddesiredName
- The desired name for the resource collectionrenameIfExists
- If false, in case of existing name the resource collection will not be created, if true it will be created and renamederrors
- An optional list of possible error messages in case the creation failed. Possible values are: locked, already-exist.- Returns:
- The created resource collection or null if creation failed
-
getResourceCollectionType
Get the type of child resource collection- Returns:
- the type of child resource collection
-
renameObject
Rename a resource, or resource collection- Parameters:
id
- The id of the object to renamename
- The desired name to set to the object.- Returns:
- The result map with id, name and message keys
- Throws:
javax.jcr.RepositoryException
- If there is a repository error
-
renameObject
public JCRAmetysObject renameObject(JCRAmetysObject object, String name, List<String> errors) throws javax.jcr.RepositoryException Rename a resource, or resource collection- Parameters:
object
- The object to renamename
- The desired name to set to the object.errors
- An optional list of possible error messages in case the operation failed. Possible values are: locked, already-exist.- Returns:
- The new object
- Throws:
javax.jcr.RepositoryException
- If there is a repository error
-
deleteObject
Delete an object- Parameters:
ids
- The list of identifiers for the objects to delete- Returns:
- The result map with a message key in case of an error
-
deleteObject
Delete an object- Parameters:
object
- The object to deleteerrors
- An optional list of possible error messages in case the creation failed. Possible values are: locked.- Returns:
- the parent id of the removed object
-
renameResource
public Map<String,Object> renameResource(String id, String name) throws javax.jcr.RepositoryException Rename a resource- Parameters:
id
- The id of the resource to renamename
- The desired name to set to the resource.- Returns:
- The result map with id, name and message keys
- Throws:
javax.jcr.RepositoryException
- If there is a repository error
-
renameResource
public JCRResource renameResource(JCRResource resource, String name, List<String> errors) throws javax.jcr.RepositoryException Rename a resource- Parameters:
resource
- The resource to renamename
- The desired name to set to the resource.errors
- An optional list of possible error messages in case the operation failed. Possible values are: locked, already-exist.- Returns:
- The new resource
- Throws:
javax.jcr.RepositoryException
- If there is a repository error
-
copyResource
public Map<String,Object> copyResource(List<String> ids, String target) throws javax.jcr.RepositoryException Copy file resources- Parameters:
ids
- The list of identifiers for the resources to copytarget
- The id of target to copy into- Returns:
- The result map with a message key in case of an error or with the list of uncopied/copied resources
- Throws:
javax.jcr.RepositoryException
- If there is a repository error
-
copyResource
public Map<String,Object> copyResource(List<String> ids, ModifiableResourceCollection target) throws javax.jcr.RepositoryException Copy file resources- Parameters:
ids
- The list of identifiers for the resources to copytarget
- The target to copy into- Returns:
- The result map with a message key in case of an error or with the list of uncopied/copied resources
- Throws:
javax.jcr.RepositoryException
- If there is a repository error
-
moveObject
public Map<String,Object> moveObject(List<String> ids, String targetId) throws javax.jcr.RepositoryException Move objects- Parameters:
ids
- The list of identifiers for the objects to movetargetId
- The id of target to move into- Returns:
- The result map with a message key in case of an error or with the list of unmoved/moved objects
- Throws:
javax.jcr.RepositoryException
- If there is a repository error
-
moveObject
public Map<String,Object> moveObject(List<String> ids, JCRTraversableAmetysObject targetNode) throws javax.jcr.RepositoryException Move objects- Parameters:
ids
- The list of identifiers for the objects to movetargetNode
- The target to move into- Returns:
- The result map with a message key in case of an error or with the list of unmoved/moved objects
- Throws:
javax.jcr.RepositoryException
- If there is a repository error
-
resourceHistory
Get the history versions of a resource- Parameters:
id
- the id of resource- Returns:
- The versions
- Throws:
javax.jcr.RepositoryException
- if an error occurred
-
_version2json
protected Map<String,Object> _version2json(JCRResource resource, ExplorerResourcesDAO.VersionInformation versionInformation) throws javax.jcr.RepositoryException Get the JSON representation of a version of a resource- Parameters:
resource
- the resourceversionInformation
- the version information- Returns:
- the version as JSON object
- Throws:
javax.jcr.RepositoryException
- if failed to get revision
-
restoreResource
This action restores an old version of aResource
.- Parameters:
id
- the id of resourceversionName
- the name of version to restore
-
resourcesExists
Determines if at least one resource with given names already exists- Parameters:
parentId
- the id of parent collectionnames
- the names of the resources- Returns:
- true if a resource with same name exists
-
resourceExists
Determines if a resource with given name already exists- Parameters:
parentId
- the id of parent collectionname
- the name of resource- Returns:
- true if a resource with same name exists
-
resourceExists
Determines if a resource with given name already exists- Parameters:
parent
- the parent collectionname
- the name of resource- Returns:
- true if a resource with same name exists
-
setDCMetadata
Set the Dublin Core metadata of aResource
.- Parameters:
resourceId
- the id of resourcevalues
- the DC values- Throws:
ProcessingException
- if an error occurred
-
setDCMetadata
Set the Dublin Core metadata of aResource
.- Parameters:
resource
- the resourcevalues
- the DC values
-
getDCMetadata
Get the DublinCore metadata of aDublinCoreAwareAmetysObject
- Parameters:
id
- the id of resource- Returns:
- the DC metadata
-
addCMISCollection
public Map<String,Object> addCMISCollection(String parentId, String originalName, String url, String login, String password, String repoId, String mountPoint, boolean renameIfExists) Creates a new CMIS folder (seeCMISRootResourcesCollection
)- Parameters:
parentId
- the id of parent folderoriginalName
- the original name if CMIS folderurl
- The url of CMIS repositorylogin
- The user's login to access CMIS repositorypassword
- The user's password to access CMIS repositoryrepoId
- The id of CMIS repositorymountPoint
- The mount point in the serverrenameIfExists
- true to automatically renamed CMIS folder if requested name already exists- Returns:
- the result map with id of created node
-
editCMISCollection
public Map<String,Object> editCMISCollection(String id, String url, String login, String password, String repoId, String mountPoint) Edits a CMIS folder (seeCMISRootResourcesCollection
)- Parameters:
id
- the id of CMIS folderurl
- The url of CMIS repositorylogin
- The user's login to access CMIS repositorypassword
- The user's password to access CMIS repositoryrepoId
- The id of CMIS repositorymountPoint
- The mount point to use for the repository- Returns:
- the result map with id of edited node
-
isCMISCollection
Determines if a object is aCMISRootResourcesCollection
- Parameters:
id
- The id of object- Returns:
- true if it is a CMIS root folder
-
getCMISProperties
Get the CMIS properties of collection- Parameters:
id
- The id of CMIS collection- Returns:
- the CMIS properties to access CMIS repository
-
updateResource
Updates resource input stream and metadata- Parameters:
resource
- The resourceis
- The resource input streamfileName
- The file name
-
extractResourceMetadata
Extract the resource's metadata and populate the object accordingly.- Parameters:
resource
- the resource to populate.mimeType
- the resource MIME type.
-
checkpoint
Creates a new version- Parameters:
resource
- the resource
-
createResource
Creates aModifiableResource
under currentModifiableResourceCollection
.- Parameters:
collection
- the parentModifiableResourceCollection
name
- the name of the child resource- Returns:
- the new resource created.
- Throws:
AmetysRepositoryException
- if an error occurs.RepositoryIntegrityViolationException
- if an object with the same name already exists and same name siblings is not allowed.
-
addComment
Add a comment to a resource- Parameters:
resourceId
- The id of the resourcecomment
- The comment- Returns:
- the result
-
_canAddComment
Indicates if an user can add a comment of a given resource- Parameters:
user
- An user identityresource
- The resource to comment- Returns:
- True if the user can add a comment
-
editComment
Edit the comment of a resource- Parameters:
resourceId
- The id of the resourcecommentId
- The id of comment to editcomment
- The comment- Returns:
- the result
-
_canEditComment
Indicates if an user can edit a comment of a given resource- Parameters:
user
- An user identityresource
- The resourcecomment
- The comment to edit- Returns:
- True if the user can edit the comment
-
_setComment
Update the content of a comment- Parameters:
comment
- The comment to updatecontent
- The content as string
-
_getComment
Get the content of a comment as a String- Parameters:
post
- the post- Returns:
- The content as String
- Throws:
AmetysRepositoryException
- if failed to parse comment
-
_getCommentForEditing
Get the content of a comment to edit as a String- Parameters:
post
- the post- Returns:
- The content as String
- Throws:
AmetysRepositoryException
- if failed to parse comment
-
deleteComment
Delete the comment of a resource- Parameters:
resourceId
- The id of the resourcecommentId
- The id of comment to delete- Returns:
- the result
-
_canDeleteComment
protected boolean _canDeleteComment(UserIdentity user, CommentableResource resource, JCRPost comment) Indicates if an user can delete a comment of a given resource- Parameters:
user
- An user identityresource
- The resourcecomment
- The comment to edit- Returns:
- True if the user can edit the comment
-
getComments
Get the comments of a resource- Parameters:
resourceId
- The id of the resourceisEdition
- true to get the comments in edit mode- Returns:
- The comments
-
getComment
Get a comment of a resource- Parameters:
commentId
- The id of the commentisEdition
- true to get the comment in edit mode- Returns:
- The comments
-
_comment2json
Get JSOn representation of a comment- Parameters:
comment
- The commentisEdition
- true to get the comment in edit mode- Returns:
- the comment as JSON
-