TrashService

public interface TrashService

The TrashService provides methods related with the module trash mode (by default the mode is active and it can be turned off by the user).

Methods

countTrashRecords

long countTrashRecords(String className)

Gets a number of instances moved to trash, for entity with given class name. This will only consider the instances, that have been moved to trash on the current entity schema version.

Parameters:
  • className – fully qualified entity class name
Returns:

trash instances count

emptyTrash

void emptyTrash()

Cleans the module trash. All instances in trash should be removed permanently and if they contain any historical data they should also be removed permanently.

This method should only be executed by the job created in the scheduleEmptyTrashJob() method.

findTrashById

Object findTrashById(Object instanceId, Object entityId)

Return instance with given id from trash.

Parameters:
  • instanceId – id of instance
  • entityId – id of instance entity

getInstancesFromTrash

Collection getInstancesFromTrash(String entityName, QueryParams queryParams)

Returns the collection of instances from trash of a certain entity. Returned collection contains only instances that are on the current schema version.

Parameters:
  • entityName – Instances of what entity should be looked for
  • queryParams – Query parameters such as page number, size of page and sort direction. If null method will return all records in trash.
Returns:

Collection of instances on the current schema version in trash

isTrashMode

boolean isTrashMode()

Checks if trash mode is active. This method should be used before executing the moveToTrash(Object,Long,boolean) method to resolve whether the given instance should be moved to trash or removed permanently.

Returns:true if delete mode is equal to org.motechproject.mds.config.DeleteMode.TRASH; false otherwise.

moveFromTrash

void moveFromTrash(Object newInstance, Object trash, boolean recordHistory)

Sets history for given trashed instance to match the new one and deletes trashed one from trash.

Parameters:
  • newInstance – instance to be returned from trash
  • trash – trashed instance to be removed
  • recordHistory – true if entity has active history recording ; otherwise false

moveToTrash

void moveToTrash(Object instance, Long schemaVersion, boolean recordHistory)

Moves the given instance to the trash. This method should only be executed, when the module trash mode is active.

Parameters:
  • instance – an instance created from the given entity definition.
  • recordHistory – true if entity has active history recording ; otherwise false

See also: .isTrashMode()

scheduleEmptyTrashJob

void scheduleEmptyTrashJob()

Sets the repeating schedule job that will be executed from time to time. Execution time depends on the value of time value and time unit (defined in org.motechproject.mds.util.Constants.Config.MODULE_FILE).

Before scheduling new job, the old one should be unscheduled to prevent the errors.