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);
}
}
Aggregations