public GetDataset ( System.Int64 datasetId ) : Dataset | ||
datasetId | System.Int64 | The identifier of the dataset. |
return | Dataset |
public ActionResult AddSelectedDatasetToBus(string id) { ChooseDatasetViewModel model = new ChooseDatasetViewModel(); long datasetId = Convert.ToInt64(id); DatasetManager datasetManager = new DatasetManager(); Dataset dataset = datasetManager.GetDataset(datasetId); DatasetVersion datasetVersion; if(datasetManager.IsDatasetCheckedIn(datasetId)) { addSelectedDatasetToBus(datasetId); } else { model.ErrorList.Add(new Error(ErrorType.Dataset, "Dataset is not checked in.")); } Session["TaskManager"] = TaskManager; //create Model model.StepInfo = TaskManager.Current(); if ((List<ListViewItem>)Session["DatasetVersionViewList"] != null) model.DatasetsViewList = (List<ListViewItem>)Session["DatasetVersionViewList"]; if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_TITLE)) model.DatasetTitle = TaskManager.Bus[TaskManager.DATASET_TITLE].ToString(); model.SelectedDatasetId = Convert.ToInt32(id); return PartialView("SpecifyDataset", model); }
public ActionResult Reset() { TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; if (TaskManager != null) { DatasetManager dm = new DatasetManager(); long datasetid = -1; long metadataStructureid = -1; bool resetTaskManager = true; XmlDocument metadata = null; bool edit = true; bool created = false; if (TaskManager.Bus.ContainsKey(CreateTaskmanager.ENTITY_ID)) { datasetid = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.ENTITY_ID]); } if (datasetid > -1 && dm.IsDatasetCheckedIn(datasetid)) { Dataset dataset = dm.GetDataset(datasetid); metadataStructureid = dataset.MetadataStructure.Id; metadata = dm.GetDatasetLatestMetadataVersion(datasetid); TaskManager.UpdateBus(CreateTaskmanager.METADATA_XML, metadata); } return RedirectToAction("ImportMetadata", "Form", new { area = "DCM", metadataStructureId = metadataStructureid, edit, created }); } return RedirectToAction("StartMetadataEditor", "Form"); }
public ActionResult SpecifyDataset(object[] data) { TaskManager = (TaskManager)Session["TaskManager"]; ChooseDatasetViewModel model = new ChooseDatasetViewModel(); model.StepInfo = TaskManager.Current(); if (TaskManager != null) { TaskManager.Current().SetValid(false); if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_ID)) { DatasetManager dm = new DatasetManager(); Dataset ds = new Dataset(); try { dm = new DatasetManager(); ds = dm.GetDataset((long)Convert.ToInt32(TaskManager.Bus[TaskManager.DATASET_ID])); TaskManager.AddToBus(TaskManager.DATASTRUCTURE_ID, ((DataStructure)(ds.DataStructure.Self)).Id); TaskManager.AddToBus(TaskManager.DATASTRUCTURE_TITLE, ((DataStructure)(ds.DataStructure.Self)).Name); TaskManager.Current().SetValid(true); } catch { model.ErrorList.Add(new Error(ErrorType.Other, "Dataset not exist.")); } } else { model.ErrorList.Add(new Error(ErrorType.Other, "Dataset not exist.")); } if (TaskManager.Current().valid == true) { TaskManager.AddExecutedStep(TaskManager.Current()); TaskManager.GoToNext(); Session["TaskManager"] = TaskManager; ActionInfo actionInfo = TaskManager.Current().GetActionInfo; return RedirectToAction(actionInfo.ActionName, actionInfo.ControllerName, new RouteValueDictionary { { "area", actionInfo.AreaName }, { "index", TaskManager.GetCurrentStepInfoIndex() } }); } else { TaskManager.Current().SetStatus(StepStatus.error); //reload model model.StepInfo = TaskManager.Current(); if ((List<ListViewItem>)Session["DatasetVersionViewList"] != null) model.DatasetsViewList = (List<ListViewItem>)Session["DatasetVersionViewList"]; } } return PartialView(model); }
public List<Error> FinishUpload2(TaskManager taskManager) { List<Error> temp = new List<Error>(); if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_ID) && TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_ID)) { long id = Convert.ToInt32(TaskManager.Bus[TaskManager.DATASET_ID]); DataStructureManager dsm = new DataStructureManager(); long iddsd = Convert.ToInt32(TaskManager.Bus[TaskManager.DATASTRUCTURE_ID]); //datatuple list List<DataTuple> rows; DatasetManager dm = new DatasetManager(); Dataset ds = dm.GetDataset(id); DatasetVersion workingCopy = new DatasetVersion(); #region Progress Informations if (TaskManager.Bus.ContainsKey(TaskManager.CURRENTPACKAGESIZE)) { TaskManager.Bus[TaskManager.CURRENTPACKAGESIZE] = 0; } else { TaskManager.Bus.Add(TaskManager.CURRENTPACKAGESIZE, 0); } if (TaskManager.Bus.ContainsKey(TaskManager.CURRENTPACKAGE)) { TaskManager.Bus[TaskManager.CURRENTPACKAGE] = 0; } else { TaskManager.Bus.Add(TaskManager.CURRENTPACKAGE, 0); } #endregion #region structured data if (TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_TYPE) && TaskManager.Bus[TaskManager.DATASTRUCTURE_TYPE].Equals(DataStructureType.Structured)) { try { //Stopwatch fullTime = Stopwatch.StartNew(); //Stopwatch loadDT = Stopwatch.StartNew(); List<AbstractTuple> datatupleFromDatabase = dm.GetDatasetVersionEffectiveTuples(dm.GetDatasetLatestVersion(ds.Id)); //loadDT.Stop(); //Debug.WriteLine("Load DT From Db Time " + loadDT.Elapsed.TotalSeconds.ToString()); StructuredDataStructure sds = dsm.StructuredDataStructureRepo.Get(iddsd); dsm.StructuredDataStructureRepo.LoadIfNot(sds.Variables); #region excel reader if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".xlsm")) { int packageSize = 10000; TaskManager.Bus[TaskManager.CURRENTPACKAGESIZE] = packageSize; int counter = 0; ExcelReader reader = new ExcelReader(); //schleife dm.CheckOutDatasetIfNot(ds.Id, GetUsernameOrDefault()); // there are cases, the dataset does not get checked out!! if (!dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault())) throw new Exception(string.Format("Not able to checkout dataset '{0}' for user '{1}'!", ds.Id, GetUsernameOrDefault())); workingCopy = dm.GetDatasetWorkingCopy(ds.Id); do { //Stopwatch packageTime = Stopwatch.StartNew(); counter++; TaskManager.Bus[TaskManager.CURRENTPACKAGE] = counter; // open file Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString()); rows = reader.ReadFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), sds, (int)id, packageSize); if (reader.ErrorMessages.Count > 0) { //model.ErrorList = reader.errorMessages; } else { //XXX Add packagesize to excel read function if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_STATUS)) { if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("new")) { //Stopwatch upload = Stopwatch.StartNew(); dm.EditDatasetVersion(workingCopy, rows, null, null); //Debug.WriteLine("Upload : " + counter + " Time " + upload.Elapsed.TotalSeconds.ToString()); //Debug.WriteLine("----"); } if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("edit")) { if (rows.Count() > 0) { //Stopwatch split = Stopwatch.StartNew(); Dictionary<string, List<DataTuple>> splittedDatatuples = new Dictionary<string, List<DataTuple>>(); splittedDatatuples = UploadWizardHelper.GetSplitDatatuples2(rows, (List<long>)TaskManager.Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabase); //split.Stop(); //Debug.WriteLine("Split : " + counter + " Time " + split.Elapsed.TotalSeconds.ToString()); //Stopwatch upload = Stopwatch.StartNew(); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); // upload.Stop(); // Debug.WriteLine("Upload : " + counter + " Time " + upload.Elapsed.TotalSeconds.ToString()); // Debug.WriteLine("----"); } } } else { } } Stream.Close(); //packageTime.Stop(); //Debug.WriteLine("Package : " + counter + " packageTime Time " + packageTime.Elapsed.TotalSeconds.ToString()); } while (rows.Count() > 0); //fullTime.Stop(); //Debug.WriteLine("FullTime " + fullTime.Elapsed.TotalSeconds.ToString()); } #endregion #region ascii reader if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".csv") || TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".txt")) { // open file AsciiReader reader = new AsciiReader(); //Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString()); //DatasetManager dm = new DatasetManager(); //Dataset ds = dm.GetDataset(id); Stopwatch totalTime = Stopwatch.StartNew(); if (dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault()) || dm.CheckOutDataset(ds.Id, GetUsernameOrDefault())) { workingCopy = dm.GetDatasetWorkingCopy(ds.Id); int packageSize = 100000; TaskManager.Bus[TaskManager.CURRENTPACKAGESIZE] = packageSize; //schleife int counter = 0; do { counter++; TaskManager.Bus[TaskManager.CURRENTPACKAGE] = counter; Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString()); rows = reader.ReadFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), (AsciiFileReaderInfo)TaskManager.Bus[TaskManager.FILE_READER_INFO], sds, id, packageSize); Stream.Close(); if (reader.ErrorMessages.Count > 0) { //model.ErrorList = reader.errorMessages; } else { //model.Validated = true; Stopwatch dbTimer = Stopwatch.StartNew(); if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_STATUS)) { if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("new")) { dm.EditDatasetVersion(workingCopy, rows, null, null); } if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("edit")) { if (rows.Count() > 0) { Dictionary<string, List<DataTuple>> splittedDatatuples = new Dictionary<string, List<DataTuple>>(); splittedDatatuples = UploadWizardHelper.GetSplitDatatuples2(rows, (List<long>)TaskManager.Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabase); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); } } } else { if (rows.Count() > 0) { Dictionary<string, List<DataTuple>> splittedDatatuples = new Dictionary<string, List<DataTuple>>(); splittedDatatuples = UploadWizardHelper.GetSplitDatatuples2(rows, (List<long>)TaskManager.Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabase); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); } } dbTimer.Stop(); Debug.WriteLine(" db time" + dbTimer.Elapsed.TotalSeconds.ToString()); } } while (rows.Count() > 0); totalTime.Stop(); Debug.WriteLine(" Total Time " + totalTime.Elapsed.TotalSeconds.ToString()); } //Stream.Close(); } #endregion // start download generator // filepath //string path = ""; //if (workingCopy != null) //{ // path = GenerateDownloadFile(workingCopy); // dm.EditDatasetVersion(workingCopy, null, null, null); //} // ToDo: Get Comment from ui and users dm.CheckInDataset(ds.Id, "upload data from upload wizard", GetUsernameOrDefault()); LoggerFactory.LogData(id.ToString(), typeof(Dataset).Name, Vaiona.Entities.Logging.CrudState.Updated); } catch (Exception e) { temp.Add(new Error(ErrorType.Other, "Can not upload. : " + e.Message)); dm.CheckInDataset(ds.Id, "checked in but no update on data tuples", GetUsernameOrDefault()); } finally { } } #endregion #region unstructured data if (TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_TYPE) && TaskManager.Bus[TaskManager.DATASTRUCTURE_TYPE].Equals(DataStructureType.Unstructured)) { workingCopy = dm.GetDatasetLatestVersion(ds.Id); SaveFileInContentDiscriptor(workingCopy); dm.EditDatasetVersion(workingCopy, null, null, null); // ToDo: Get Comment from ui and users dm.CheckInDataset(ds.Id, "upload unstructured data", GetUsernameOrDefault()); } #endregion } else { temp.Add(new Error(ErrorType.Dataset, "Dataset is not selected.")); } return temp; }
public List<Error> FinishUpload(TaskManager taskManager) { List<Error> temp = new List<Error>(); DatasetManager dm = new DatasetManager(); DatasetVersion workingCopy = new DatasetVersion(); //datatuple list List<DataTuple> rows = new List<DataTuple>(); Dataset ds = null; bool inputWasAltered = false; if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_ID) && TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_ID)) { long id = Convert.ToInt32(TaskManager.Bus[TaskManager.DATASET_ID]); DataStructureManager dsm = new DataStructureManager(); long iddsd = Convert.ToInt32(TaskManager.Bus[TaskManager.DATASTRUCTURE_ID]); ds = dm.GetDataset(id); // Javad: Please check if the dataset does exists!! #region Progress Informations if (TaskManager.Bus.ContainsKey(TaskManager.CURRENTPACKAGESIZE)) { TaskManager.Bus[TaskManager.CURRENTPACKAGESIZE] = 0; } else { TaskManager.Bus.Add(TaskManager.CURRENTPACKAGESIZE, 0); } if (TaskManager.Bus.ContainsKey(TaskManager.CURRENTPACKAGE)) { TaskManager.Bus[TaskManager.CURRENTPACKAGE] = 0; } else { TaskManager.Bus.Add(TaskManager.CURRENTPACKAGE, 0); } #endregion #region structured data if (TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_TYPE) && TaskManager.Bus[TaskManager.DATASTRUCTURE_TYPE].Equals(DataStructureType.Structured)) { try { //Stopwatch fullTime = Stopwatch.StartNew(); //Stopwatch loadDT = Stopwatch.StartNew(); List<long> datatupleFromDatabaseIds = dm.GetDatasetVersionEffectiveTupleIds(dm.GetDatasetLatestVersion(ds.Id)); //loadDT.Stop(); //Debug.WriteLine("Load DT From Db Time " + loadDT.Elapsed.TotalSeconds.ToString()); StructuredDataStructure sds = dsm.StructuredDataStructureRepo.Get(iddsd); dsm.StructuredDataStructureRepo.LoadIfNot(sds.Variables); #region excel reader if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".xlsm")) { int packageSize = 10000; TaskManager.Bus[TaskManager.CURRENTPACKAGESIZE] = packageSize; int counter = 0; ExcelReader reader = new ExcelReader(); //schleife dm.CheckOutDatasetIfNot(ds.Id, GetUsernameOrDefault()); // there are cases, the dataset does not get checked out!! if (!dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault())) throw new Exception(string.Format("Not able to checkout dataset '{0}' for user '{1}'!", ds.Id, GetUsernameOrDefault())); workingCopy = dm.GetDatasetWorkingCopy(ds.Id); //workingCopy.ContentDescriptors = new List<ContentDescriptor>(); do { //Stopwatch packageTime = Stopwatch.StartNew(); counter++; TaskManager.Bus[TaskManager.CURRENTPACKAGE] = counter; // open file Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString()); Stopwatch upload = Stopwatch.StartNew(); rows = reader.ReadFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), sds, (int)id, packageSize); upload.Stop(); Debug.WriteLine("ReadFile: " + counter + " Time " + upload.Elapsed.TotalSeconds.ToString()); if (reader.ErrorMessages.Count > 0) { //model.ErrorList = reader.errorMessages; } else { //XXX Add packagesize to excel read function if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_STATUS)) { if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("new")) { upload = Stopwatch.StartNew(); dm.EditDatasetVersion(workingCopy, rows, null, null); upload.Stop(); Debug.WriteLine("EditDatasetVersion: " + counter + " Time " + upload.Elapsed.TotalSeconds.ToString()); //Debug.WriteLine("----"); } if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("edit")) { if (rows.Count() > 0) { //Stopwatch split = Stopwatch.StartNew(); Dictionary<string, List<DataTuple>> splittedDatatuples = new Dictionary<string, List<DataTuple>>(); splittedDatatuples = UploadWizardHelper.GetSplitDatatuples(rows, (List<long>)TaskManager.Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabaseIds); //split.Stop(); //Debug.WriteLine("Split : " + counter + " Time " + split.Elapsed.TotalSeconds.ToString()); //Stopwatch upload = Stopwatch.StartNew(); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); // upload.Stop(); // Debug.WriteLine("Upload : " + counter + " Time " + upload.Elapsed.TotalSeconds.ToString()); // Debug.WriteLine("----"); } } } else { } } Stream.Close(); //packageTime.Stop(); //Debug.WriteLine("Package : " + counter + " packageTime Time " + packageTime.Elapsed.TotalSeconds.ToString()); } while (rows.Count() > 0); //fullTime.Stop(); //Debug.WriteLine("FullTime " + fullTime.Elapsed.TotalSeconds.ToString()); } #endregion #region ascii reader if (TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".csv") || TaskManager.Bus[TaskManager.EXTENTION].ToString().Equals(".txt")) { // open file AsciiReader reader = new AsciiReader(); //Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString()); //DatasetManager dm = new DatasetManager(); //Dataset ds = dm.GetDataset(id); Stopwatch totalTime = Stopwatch.StartNew(); if (dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault()) || dm.CheckOutDataset(ds.Id, GetUsernameOrDefault())) { workingCopy = dm.GetDatasetWorkingCopy(ds.Id); int packageSize = 100000; TaskManager.Bus[TaskManager.CURRENTPACKAGESIZE] = packageSize; //schleife int counter = 0; do { counter++; inputWasAltered = false; TaskManager.Bus[TaskManager.CURRENTPACKAGE] = counter; Stream = reader.Open(TaskManager.Bus[TaskManager.FILEPATH].ToString()); rows = reader.ReadFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), (AsciiFileReaderInfo)TaskManager.Bus[TaskManager.FILE_READER_INFO], sds, id, packageSize); Stream.Close(); if (reader.ErrorMessages.Count > 0) { foreach (var err in reader.ErrorMessages) { temp.Add(new Error(ErrorType.Dataset, err.GetMessage())); } //return temp; } //model.Validated = true; Stopwatch dbTimer = Stopwatch.StartNew(); if (TaskManager.Bus.ContainsKey(TaskManager.DATASET_STATUS)) { if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("new")) { dm.EditDatasetVersion(workingCopy, rows, null, null); } if (TaskManager.Bus[TaskManager.DATASET_STATUS].ToString().Equals("edit")) { if (rows.Count() > 0) { //Dictionary<string, List<DataTuple>> splittedDatatuples = new Dictionary<string, List<AbstractTuple>>(); var splittedDatatuples = UploadWizardHelper.GetSplitDatatuples(rows, (List<long>)TaskManager.Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabaseIds); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); inputWasAltered = true; } } } else { if (rows.Count() > 0) { Dictionary<string, List<DataTuple>> splittedDatatuples = new Dictionary<string, List<DataTuple>>(); splittedDatatuples = UploadWizardHelper.GetSplitDatatuples(rows, (List<long>)TaskManager.Bus[TaskManager.PRIMARY_KEYS], workingCopy, ref datatupleFromDatabaseIds); dm.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null); inputWasAltered = true; } } dbTimer.Stop(); Debug.WriteLine(" db time" + dbTimer.Elapsed.TotalSeconds.ToString()); } while (rows.Count() > 0 || inputWasAltered == true); totalTime.Stop(); Debug.WriteLine(" Total Time " + totalTime.Elapsed.TotalSeconds.ToString()); } //Stream.Close(); } #endregion #region contentdescriptors //remove all contentdescriptors from the old version //generatedTXT if (workingCopy.ContentDescriptors.Any(c => c.Name.Equals("generatedTXT"))) { ContentDescriptor tmp = workingCopy.ContentDescriptors.Where(c => c.Name.Equals("generatedTXT")) .FirstOrDefault(); dm.DeleteContentDescriptor(tmp); } //generatedCSV if (workingCopy.ContentDescriptors.Any(c => c.Name.Equals("generatedCSV"))) { ContentDescriptor tmp = workingCopy.ContentDescriptors.Where(c => c.Name.Equals("generatedCSV")) .FirstOrDefault(); dm.DeleteContentDescriptor(tmp); } //generated if (workingCopy.ContentDescriptors.Any(c => c.Name.Equals("generated"))) { ContentDescriptor tmp = workingCopy.ContentDescriptors.Where(c => c.Name.Equals("generated")) .FirstOrDefault(); dm.DeleteContentDescriptor(tmp); } #endregion // ToDo: Get Comment from ui and users MoveAndSaveOriginalFileInContentDiscriptor(workingCopy); dm.CheckInDataset(ds.Id, "upload data from upload wizard", GetUsernameOrDefault()); } catch (Exception e) { temp.Add(new Error(ErrorType.Other, "Can not upload. : " + e.Message)); } finally { } } #endregion #region unstructured data if (TaskManager.Bus.ContainsKey(TaskManager.DATASTRUCTURE_TYPE) && TaskManager.Bus[TaskManager.DATASTRUCTURE_TYPE].Equals(DataStructureType.Unstructured)) { // checkout the dataset, apply the changes, and check it in. if (dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault()) || dm.CheckOutDataset(ds.Id, GetUsernameOrDefault())) { workingCopy = dm.GetDatasetWorkingCopy(ds.Id); SaveFileInContentDiscriptor(workingCopy); dm.EditDatasetVersion(workingCopy, null, null, null); // ToDo: Get Comment from ui and users dm.CheckInDataset(ds.Id, "upload unstructured data", GetUsernameOrDefault()); } } #endregion } else { temp.Add(new Error(ErrorType.Dataset, "Dataset is not selected.")); } if (temp.Count <= 0) { dm.CheckInDataset(ds.Id, "checked in but no update on data tuples", GetUsernameOrDefault()); } else { dm.UndoCheckoutDataset(ds.Id, GetUsernameOrDefault()); } return temp; }
public static GFBIODataCenterFormularObject GetGFBIODataCenterFormularObject(long datasetId) { DatasetManager datasetManager = new DatasetManager(); datasetManager.GetDataset(datasetId); Dataset dataset = datasetManager.GetDataset(datasetId); DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId); GFBIODataCenterFormularObject gfbioDataCenterFormularObject = new GFBIODataCenterFormularObject(); gfbioDataCenterFormularObject.ProjectId = 1; gfbioDataCenterFormularObject.ProjectTitle = "Test Poject title"; gfbioDataCenterFormularObject.ProjectLabel = "Test Poject label"; gfbioDataCenterFormularObject.ProjectAbstract = ""; gfbioDataCenterFormularObject.UserId = 1; gfbioDataCenterFormularObject.UserName = "******"; gfbioDataCenterFormularObject.UserEmail = "testEmail"; gfbioDataCenterFormularObject.DatasetAuthor = "TestAuthor"; gfbioDataCenterFormularObject.DatasetId = datasetId; gfbioDataCenterFormularObject.DatasetVersion = datasetVersion.Id; gfbioDataCenterFormularObject.DatasetTitle = XmlDatasetHelper.GetInformation(datasetId,NameAttributeValues.title); gfbioDataCenterFormularObject.DatasetLabel = XmlDatasetHelper.GetInformation(datasetId,NameAttributeValues.title); gfbioDataCenterFormularObject.DatasetDescription = XmlDatasetHelper.GetInformation(datasetId,NameAttributeValues.description); gfbioDataCenterFormularObject.DatasetCollectionDate = datasetVersion.Dataset.LastCheckIOTimestamp; MetadataStructureManager metadataStructureManager = new MetadataStructureManager(); MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(dataset.MetadataStructure.Id); gfbioDataCenterFormularObject.MetadataSchemaName = metadataStructure.Name; return gfbioDataCenterFormularObject; }
public static GFBIOPangaeaFormularObject GetGFBIOPangaeaFormularObject(long datasetId) { DatasetManager datasetManager = new DatasetManager(); datasetManager.GetDataset(datasetId); Dataset dataset = datasetManager.GetDataset(datasetId); DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId); MetadataStructureManager metadataStructureManager = new MetadataStructureManager(); MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(dataset.MetadataStructure.Id); GFBIOPangaeaFormularObject gfbioPangaeaFormularObject = new GFBIOPangaeaFormularObject(); string title = XmlDatasetHelper.GetInformation(datasetId, NameAttributeValues.title); string description = XmlDatasetHelper.GetInformation(datasetId, NameAttributeValues.description); return gfbioPangaeaFormularObject; }
private void removeContentDescriptor() { DatasetManager dm = new DatasetManager(); Dataset dataset = dm.GetDataset(1); // check if the dataset is in the checked-in status DatasetVersion dsVersion = dm.GetDatasetLatestVersion(dataset); if(dsVersion.ContentDescriptors.Count(p => p.Name.Equals("generated")) > 0) { dm.CheckOutDataset(1, "admin"); dsVersion = dm.GetDatasetWorkingCopy(1); //dm.EditDatasetVersion(dsVersion, null, null, null, null); // The descriptor to be deleted must be object equal to the one in the list. The following command does the job. // The condition can be different, but the item should be taken from the list, and any other instance must be released, by setting them to NULL. var cd = dsVersion.ContentDescriptors.FirstOrDefault(p => p.Name.Equals("generated")); dm.DeleteContentDescriptor(cd); dm.CheckInDataset(1, "removed content descriptor:" + cd.Name, "admin"); } }
// private void createADataStructure() // { // DataStructureGenerator sdGen = new DataStructureGenerator(); // StructuredDataStructure sds = sdGen.GenerateStructuredDataStructure(); // DataContainerManager dcm = new DataContainerManager(); // List<Parameter> pps = (from vari in sds.VariableUsages // from pari in vari.DataAttribute.ParameterUsages // select pari.Parameter).ToList(); // if(sds.Indexer != null) // pps.Add(sds.Indexer); // pps = pps.Distinct().ToList(); // foreach (var item in pps) //{ // dcm.CreateParameter(item.Name, //} // DataStructureManager dsm = new DataStructureManager(); // dsm.CreateStructuredDataStructure( // } private void testExtendedProperty() { DatasetManager dm = new DatasetManager(); DataContainerManager dcManager = new DataContainerManager(); Dataset ds = dm.GetDataset(24L); StructuredDataStructure sds = (ds.DataStructure.Self as StructuredDataStructure); ExtendedProperty exp = null; try { exp = dcManager.ExtendedPropertyRepo.Get(1); } catch { } //if(exp == null) // exp = dcManager.CreateExtendedProperty("Source", "the data provider", sds.VariableUsages.First().DataAttribute, null); // issue with session management //ds.ExtendedPropertyValues = new List<ExtendedPropertyValue>() //{ // new ExtendedPropertyValue() {Dataset = ds, ExtendedPropertyId = exp.Id, Value="Jena Experiment"}, // new ExtendedPropertyValue() {Dataset = ds, ExtendedPropertyId = exp.Id, Value="MPI"}, //}; ds.Dematerialize(); //dm.UpdateDataset(ds); }
public ActionResult StoreSelectedDataset(long id) { if (TaskManager == null) TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; DatasetManager dm = new DatasetManager(); Dataset dataset = dm.GetDataset(id); SetupModel Model = GetDefaultModel(); if (id == -1) { if (TaskManager.Bus.ContainsKey(CreateTaskmanager.DATASTRUCTURE_ID)) Model.SelectedDataStructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.DATASTRUCTURE_ID]); if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATASTRUCTURE_ID)) Model.SelectedMetadataStructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.METADATASTRUCTURE_ID]); } else { Model.SelectedDatasetId = id; Model.SelectedDataStructureId = dataset.DataStructure.Id; Model.SelectedMetadataStructureId = dataset.MetadataStructure.Id; Model.BlockMetadataStructureId = true; //add to Bus TaskManager.AddToBus(CreateTaskmanager.DATASTRUCTURE_ID, dataset.DataStructure.Id); TaskManager.AddToBus(CreateTaskmanager.METADATASTRUCTURE_ID, dataset.MetadataStructure.Id); TaskManager.AddToBus(CreateTaskmanager.COPY_OF_ENTITY_ID, dataset.Id); } return PartialView("Index", Model); }
public string TransferDataPermission() { SubjectManager subjectManager = new SubjectManager(); var securityMigration = new SecurityMigration(); Dictionary<int, int> DataSetIDs = new Dictionary<int, int>(); var groups = subjectManager.GetAllGroups(); string DatasetMappingPath = Path.Combine(AppConfiguration.DataPath, "DatasetMapping.txt"); //Key is last datasetId and value is the new one Dictionary<int, int> DatasetsMapping = File.ReadAllLines(DatasetMappingPath).AsEnumerable().Select(item => new { oldId = int.Parse(item.Split('\t')[0]), newId = int.Parse(item.Split('\t')[1]) }).ToDictionary(c => c.oldId, c => c.newId); DatasetManager dm = new DatasetManager(); PermissionManager permissionManager = new PermissionManager(); List<SecurityMigration.Right> rights = securityMigration.GetBexisRights(DataBase, DatasetsMapping); foreach (var group in groups) { var groupRights = rights.Where(item => item.RoleName == group.Name || item.RoleName == "_" + group.Name); foreach (var right in groupRights) { int newDataSetId = DatasetsMapping.FirstOrDefault(item => item.Key == right.DataSetId).Value; //each entity wich exists in this list has view and download feature permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.View); permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.Download); if (right.CanEdit) permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.Update); } } foreach (var DatasetMapping in DatasetsMapping) { //extract grant user from the last version and add it to new ver if (dm.GetDataset(DatasetMapping.Value) == null) continue; DatasetVersion dsv = dm.GetDatasetLatestVersion(DatasetMapping.Value); string grantUserEmailAddress = dsv.Metadata.SelectSingleNode("Metadata/general/general/designatedDatasetManager/contactType/email/email").InnerText; if (!string.IsNullOrEmpty(grantUserEmailAddress)) { var grantUser = subjectManager.GetUserByEmail(grantUserEmailAddress); permissionManager.CreateDataPermission(grantUser.Id, 1, DatasetMapping.Value, RightType.Grant); } } return "All of permissions transfered successfully."; }
private string getStorePath(long datasetVersionId,string exportTo) { DatasetManager datasetManager = new DatasetManager(); DatasetVersion datasetVersion = datasetManager.GetDatasetVersion(datasetVersionId); Dataset dataset = datasetManager.GetDataset(datasetVersionId); MetadataStructureManager metadataStructureManager = new MetadataStructureManager(); string md_title = metadataStructureManager.Repo.Get(datasetVersion.Dataset.MetadataStructure.Id).Name; string path; if (string.IsNullOrEmpty(exportTo) || exportTo.ToLower().Equals("generic")) path = IOHelper.GetDynamicStorePath(datasetVersion.Dataset.Id, datasetVersionId,"metadata", ".xml"); else path = IOHelper.GetDynamicStorePath(datasetVersion.Dataset.Id, datasetVersionId, "metadata_"+ exportTo, ".xml"); return path; }
/// <summary> /// test unique of primary keys on a dataset /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="datasetId"></param> /// <param name="primaryKeys"></param> /// <returns></returns> ////[MeasurePerformance] public static Boolean IsUnique2(long datasetId, List<long> primaryKeys) { Hashtable hashtable = new Hashtable(); // load data DatasetManager datasetManager = new DatasetManager(); Dataset dataset = datasetManager.GetDataset(datasetId); DatasetVersion datasetVersion; List<long> dataTupleIds = new List<long>(); if (datasetManager.IsDatasetCheckedIn(datasetId)) { datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId); #region load all datatuples first int size = 10000; int counter = 0; IEnumerable<long> dataTuplesIds; dataTuplesIds = datasetManager.GetDatasetVersionEffectiveTupleIds(datasetVersion); IEnumerable<long> currentIds; DataTuple dt; do { currentIds = dataTupleIds.Skip(counter * size).Take(size); //byte[] pKey; string pKey; foreach (long dtId in currentIds) { dt = datasetManager.DataTupleRepo.Query(d=>d.Id.Equals(dtId)).FirstOrDefault(); //pKey = getPrimaryKeysAsByteArray(dt, primaryKeys); pKey = pKey = getPrimaryKeysAsStringFromXml(dt, primaryKeys); if (pKey.Count() > 0) { try { //Debug.WriteLine(pKey +" : " +Utility.ComputeKey(pKey)); hashtable.Add(pKey, ""); //hashtable.Add(pKey, 0); } catch { return false; } } } counter++; } while (currentIds.Count() >= (size * counter)); #endregion } else { throw new Exception("Dataset is not checked in."); } return true; }
/// <summary> /// test unique of primary keys on a dataset /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="datasetId"></param> /// <param name="primaryKeys"></param> /// <returns></returns> ////[MeasurePerformance] public static Boolean IsUnique(long datasetId, List<long> primaryKeys) { Hashtable hashtable = new Hashtable(); // load data DatasetManager datasetManager = new DatasetManager(); Dataset dataset = datasetManager.GetDataset(datasetId); DatasetVersion datasetVersion; List<long> dataTupleIds = new List<long>(); if (datasetManager.IsDatasetCheckedIn(datasetId)) { datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId); #region load all datatuples first int size = 10000; int counter = 0; IEnumerable<AbstractTuple> dataTuples; do { dataTuples = datasetManager.GetDatasetVersionEffectiveTuples(datasetVersion,counter,size); //byte[] pKey; string pKey; foreach (DataTuple dt in dataTuples) { //pKey = getPrimaryKeysAsByteArray(dt, primaryKeys); pKey = getPrimaryKeysAsString(dt, primaryKeys); if (pKey.Count() > 0) { try { //Debug.WriteLine(pKey +" : " +Utility.ComputeKey(pKey)); hashtable.Add(pKey, ""); //hashtable.Add(pKey, 0); } catch { return false; } } } counter++; } while (dataTuples.Count() >= (size * counter)); #endregion } else { throw new Exception("Dataset is not checked in."); } return true; }