Package org.ametys.cms.trash.element
Class TrashElementDAO
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.cms.trash.element.TrashElementDAO
- All Implemented Interfaces:
TrashElementDAO
,LogEnabled
,Component
,Serviceable
- Direct Known Subclasses:
WebTrashElementDAO
public class TrashElementDAO
extends AbstractLogEnabled
implements TrashElementDAO, Serviceable, Component
TrashElementDAO
to manage TrashElement
s.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Describe the result of a restore operation. -
Field Summary
FieldsFields inherited from interface org.ametys.plugins.repository.trash.TrashElementDAO
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateTrashElement
(TrashableAmetysObject ametysObject, String title) Instantiate a new trash element where the ametys object can store data to be able to restore itself latervoid
empty
(long lifetime) Empty the trash.protected <A> A
executeInTrashSession
(Function<javax.jcr.Session, A> functionToExecute) Execute a function into the trash workspace.Find a trash element linked to a trashed ametys object.protected ModifiableTraversableAmetysObject
getOrCreateCollection
(ModifiableTraversableAmetysObject parent, String collectionName) Get or create an Ametys object collection on the given parentprotected ModifiableTraversableAmetysObject
getOrCreateRoot
(TrashableAmetysObject ametysObject) Get or create the trash rootvoid
Remove theTrashElement
and its linked objects.<A extends AmetysObject>
AResolve theAmetysObject
into the trash workspace.Restore theTrashElement
and its linked objects.void
service
(ServiceManager serviceManager) trash
(TrashableAmetysObject ametysObject) Trash theAmetysObject
.trash
(TrashableAmetysObject ametysObject, boolean hidden, String[] linkedObjects) Trash theAmetysObject
.Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
_resolver
the Ametys object resolver
-
-
Constructor Details
-
TrashElementDAO
public TrashElementDAO()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
resolve
Resolve theAmetysObject
into the trash workspace.- Type Parameters:
A
- The type of the returnedAmetysObject
.- Parameters:
ametysObjectId
- The identifier- Returns:
- the resolved Ametys object, can be null if not found
-
find
Find a trash element linked to a trashed ametys object.- Parameters:
ametysObjectId
- The ametys object id- Returns:
- the
TrashElement
, can be null if not found
-
empty
Empty the trash.- Parameters:
lifetime
- Number of days before the trash has to be emptied. 0 or less empty all elements.- Throws:
javax.jcr.RepositoryException
- if an error occurs
-
trash
Trash theAmetysObject
.- Parameters:
ametysObject
- The Ametys object- Returns:
- the
TrashElement
created while moving the object to the trash
-
trash
public TrashElement trash(TrashableAmetysObject ametysObject, boolean hidden, String[] linkedObjects) Trash theAmetysObject
.- Parameters:
ametysObject
- The Ametys objecthidden
-true
if it is an object trashed by another onelinkedObjects
- The list of linked objects to the current object to trash. Linked objects can be also trashed, but it is not mandatory.- Returns:
- the
TrashElement
created while moving the object to the trash
-
createTrashElement
Description copied from interface:TrashElementDAO
Instantiate a new trash element where the ametys object can store data to be able to restore itself later- Specified by:
createTrashElement
in interfaceTrashElementDAO
- Parameters:
ametysObject
- the ametys object to trashtitle
- the title of the element- Returns:
- the trash element
-
remove
Remove theTrashElement
and its linked objects.- Parameters:
trashElementId
- The trash element identifier to remove
-
restore
public TrashElementDAO.RestorationReport restore(String trashElementId) throws UnknownParentException Restore theTrashElement
and its linked objects.- Parameters:
trashElementId
- The trash element identifier to restore- Returns:
- a report of the operation
- Throws:
UnknownParentException
- if its not possible to obtains a parent to restore into
-
getOrCreateRoot
Get or create the trash root- Parameters:
ametysObject
- the object that need to be trashed- Returns:
- the trash where the ametys will be trashed
-
getOrCreateCollection
protected ModifiableTraversableAmetysObject getOrCreateCollection(ModifiableTraversableAmetysObject parent, String collectionName) Get or create an Ametys object collection on the given parent- Parameters:
parent
- The parentcollectionName
- The collection name- Returns:
- The
AmetysObjectCollection
-
executeInTrashSession
Execute a function into the trash workspace. This method only handles the creation of the session. The caller is responsible for logging out (either in the function itself or by using the returned value).- Type Parameters:
A
- The returned type, can be anything. If it isVoid
, the function should returnnull
- Parameters:
functionToExecute
- The function to execute, it takes aSession
as parameter- Returns:
- The result of the function
-