Search in sources :

Example 1 with TrashInstanceNotFoundException

use of org.motechproject.mds.exception.audit.TrashInstanceNotFoundException in project motech by motech.

the class DefaultMotechDataService method revertFromTrash.

@Override
@Transactional
public T revertFromTrash(Long trashId) {
    validateCredentials();
    Object trashRecord = trashService.findTrashById(trashId, getClassType().getName());
    if (trashRecord == null) {
        throw new TrashInstanceNotFoundException(getClassType().getName(), trashId);
    }
    verifySchemaVersion(trashRecord, trashId, true);
    try {
        T newInstance = getClassType().newInstance();
        copyValuesFromRecord(newInstance, trashRecord);
        newInstance = create(newInstance);
        trashService.removeFromTrash(trashRecord);
        return newInstance;
    } catch (InstantiationException | IllegalAccessException e) {
        throw new ObjectUpdateException(trashRecord.getClass().getName(), trashId, e);
    }
}
Also used : TrashInstanceNotFoundException(org.motechproject.mds.exception.audit.TrashInstanceNotFoundException) ObjectUpdateException(org.motechproject.mds.exception.object.ObjectUpdateException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

TrashInstanceNotFoundException (org.motechproject.mds.exception.audit.TrashInstanceNotFoundException)1 ObjectUpdateException (org.motechproject.mds.exception.object.ObjectUpdateException)1 Transactional (org.springframework.transaction.annotation.Transactional)1