public DeleteDataset ( System.Int64 datasetId, string username, bool rollbackCheckout ) : bool | ||
datasetId | System.Int64 | The identifier of the dataset to be checked-in. |
username | string | The username that performs the check-in, which should be the same as the check-out username. |
rollbackCheckout | bool | Determines whether latest uncommitted changes should be rolled back or checked in before marking the dataset as deleted. |
return | bool |
public bool DeleteDataset(Int64 datasetId, string username, bool rollbackCheckout)
{
Contract.Requires(datasetId >= 0);
// do not move them to editDatasetVersion function
this.DatasetRepo.Evict();
this.DatasetVersionRepo.Evict();
this.DataTupleRepo.Evict();
this.DataTupleVerionRepo.Evict();
Dataset entity = this.DatasetRepo.Get(datasetId);
if (entity.Status == DatasetStatus.Deleted)
return false;
/// the dataset must be in CheckedIn state to be deleted
/// so if it is checked out, the checkout version (working copy) is removed first
if (entity.Status == DatasetStatus.CheckedOut)
{
if (rollbackCheckout == true)
{
this.undoCheckout(entity.Id, username, false);
}
else
{
throw new Exception(string.Format("Dataset {0} is in check out state, which prevents it from being deleted. Rollback the changes or check them in and try again", entity.Id));
}
}
try
{
// Make an artificial check-out / edit/ check-in so that all the data tuples move to the history
// this movement reduces the amount of tuples in the active tuples table and also marks the dataset as archived upon delete
checkOutDataset(entity.Id, username, DateTime.UtcNow);
var workingCopy = getDatasetWorkingCopy(entity.Id);
//This fetch and insert will be problematic on bigger datasets! try implement the logic without loading the tuples
var tupleIds = getWorkingCopyTupleIds(workingCopy);
workingCopy = editDatasetVersion(workingCopy, null, null, tupleIds, null); // deletes all the tuples from the active list and moves them to the history table
checkInDataset(entity.Id, "Dataset is deleted", username, false);
using (IUnitOfWork uow = this.GetUnitOfWork())
{
IRepository<Dataset> repo = uow.GetRepository<Dataset>();
entity = repo.Get(datasetId);
entity.Status = DatasetStatus.Deleted;
repo.Put(entity);
uow.Commit();
}
// if any problem was detected during the commit, an exception will be thrown!
return (true);
}
catch (Exception ex)
{
if (entity.Status == DatasetStatus.CheckedOut)
{
checkInDataset(entity.Id, "Checked-in after failed delete try!", username, false);
}
return false;
}
}
/// <summary> /// Deletes a dataset, which means the dataset is marked as deleted, but is not physically removed from the database. /// </summary> /// <param name="id">the identifier of the dataset to be purged.</param> /// <remarks>When a dataset is deleted, it is consodered as non-exisiting, but for the sake or provenance, citation, history, etc, it is not removed froom the database. /// The function to recover a deleted dataset, will not be provided.</remarks> /// <returns></returns> public ActionResult Delete(long id) { ViewBag.Title = PresentationModel.GetViewTitleForTenant("Delete", this.Session.GetTenant()); try { DatasetManager dm = new DatasetManager(); if (dm.DeleteDataset(id, this.ControllerContext.HttpContext.User.Identity.Name, true)) { // during the delete permissions are not removed, to allow purging the dataset later on. // it is a safe operation, because deleted datasets are not returned by the DLM anyway. // Javad and Sven decided on 22.11.2016. //try //{ // PermissionManager pm = new PermissionManager(); // pm.DeleteDataPermissionsByEntity(1, id); //} //catch //{ // ViewData.ModelState.AddModelError("", string.Format("Dataset {0} was deleted, but its permissions were not altered. You need to remove them manually from the data permission management.", id)); //} try { ISearchProvider provider = IoCFactory.Container.ResolveForSession<ISearchProvider>() as ISearchProvider; provider?.UpdateSingleDatasetIndex(id, IndexingAction.DELETE); } catch { ViewData.ModelState.AddModelError("", string.Format("Dataset {0} was deleted, but it is still indexed for searching. You need to reindex the search via the managemnet console.", id)); } } else { ViewData.ModelState.AddModelError("", string.Format("Dataset {0} could not be deleted. Details: Internal system error!", id)); } } catch (Exception ex) { ViewData.ModelState.AddModelError("", string.Format("Dataset {0} could not be deleted. Details: {1}", id, ex.Message)); } return View(); //return RedirectToAction("List"); }