public IsDatasetCheckedOutFor ( System.Int64 datasetId, string username ) : bool | ||
datasetId | System.Int64 | The identifier of the dataset. |
username | string | the username of the user that may have checked the dataset out. |
리턴 | bool |
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; }
// // GET: /DIM/Import/ public ActionResult Index() { //xml metadata for import string metadataForImportPath = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DIM"), "MetadataIDIV_EXAMPLE.xml"); XmlDocument metadataForImport = new XmlDocument(); metadataForImport.Load(metadataForImportPath); // metadataStructure DI long metadataStructureId = 3; MetadataStructureManager metadataStructureManager = new MetadataStructureManager(); string metadataStructrueName = metadataStructureManager.Repo.Get(metadataStructureId).Name; // loadMapping file string path_mappingFile = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DIM"), XmlMetadataImportHelper.GetMappingFileName(metadataStructureId, TransmissionType.mappingFileImport, metadataStructrueName)); // XML mapper + mapping file XmlMapperManager xmlMapperManager = new XmlMapperManager(TransactionDirection.InternToExtern); xmlMapperManager.Load(path_mappingFile, "IDIV"); // generate intern metadata XmlDocument metadataResult = xmlMapperManager.Generate(metadataForImport,1); // generate intern template XmlMetadataWriter xmlMetadatWriter = new XmlMetadataWriter(BExIS.Xml.Helpers.XmlNodeMode.xPath); XDocument metadataXml = xmlMetadatWriter.CreateMetadataXml(metadataStructureId); XmlDocument metadataXmlTemplate = XmlMetadataWriter.ToXmlDocument(metadataXml); XmlDocument completeMetadata = XmlMetadataImportHelper.FillInXmlAttributes(metadataResult, metadataXmlTemplate); // create Dataset //load datastructure DataStructureManager dsm = new DataStructureManager(); ResearchPlanManager rpm = new ResearchPlanManager(); MetadataStructureManager msm = new MetadataStructureManager(); DatasetManager dm = new DatasetManager(); Dataset dataset = dm.CreateEmptyDataset(dsm.UnStructuredDataStructureRepo.Get(1), rpm.Repo.Get(1), msm.Repo.Get(3)); if (dm.IsDatasetCheckedOutFor(dataset.Id, GetUsernameOrDefault()) || dm.CheckOutDataset(dataset.Id, GetUsernameOrDefault())) { DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(dataset.Id); workingCopy.Metadata = completeMetadata; string title = XmlDatasetHelper.GetInformation(workingCopy, NameAttributeValues.title); if (String.IsNullOrEmpty(title)) title = "No Title available."; dm.EditDatasetVersion(workingCopy, null, null, null); dm.CheckInDataset(dataset.Id, "Metadata was submited.", GetUsernameOrDefault()); // add security if (GetUsernameOrDefault() != "DEFAULT") { PermissionManager pm = new PermissionManager(); SubjectManager sm = new SubjectManager(); BExIS.Security.Entities.Subjects.User user = sm.GetUserByName(GetUsernameOrDefault()); foreach (RightType rightType in Enum.GetValues(typeof(RightType)).Cast<RightType>()) { pm.CreateDataPermission(user.Id, 1, dataset.Id, rightType); } } } return View(); }
public long createDataset(string dataSetID, XmlDocument metadataXml, long metadataStructureId, DataStructure dataStructure, string researchPlanName) { Dataset dataset = new Dataset(); DatasetManager datasetManager = new DatasetManager(); DataStructureManager dataStructureManager = new DataStructureManager(); ResearchPlanManager researchPlanManager = new ResearchPlanManager(); MetadataStructureManager metadataStructureManager = new MetadataStructureManager(); PermissionManager permissionManager = new PermissionManager(); SubjectManager subjectManager = new SubjectManager(); // get existing researchPlan ResearchPlan researchPlan = researchPlanManager.Repo.Get(r => researchPlanName.Equals(r.Title)).FirstOrDefault(); // get existing metadataStructure (created manualy by using edited Bexis1_XSD) MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(metadataStructureId); // update verwendet, da bei unstructured structures im dataset constructor dataset(dataStructure) nullexception dataset = datasetManager.CreateEmptyDataset(dataStructure, researchPlan, metadataStructure); long datasetId = dataset.Id; // dataPermission List<string> usersWithDataPerm = new List<string>(); // create dataPermission for originalDatasetManager string originalDatasetManager = metadataXml.SelectSingleNode("Metadata/general/general/originalDatasetManager/originalDatasetManager").InnerText; User userODM = subjectManager.UsersRepo.Get(u => originalDatasetManager.Equals(u.FullName)).FirstOrDefault(); permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.Create); permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.View); permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.Update); permissionManager.CreateDataPermission(userODM.Id, 1, dataset.Id, RightType.Download); usersWithDataPerm.Add(originalDatasetManager); // create dataPermissions for metadataAuthor string metadataAuthor = metadataXml.SelectSingleNode("Metadata/general/general/metadataCreator/metadataCreator").InnerText; if (!usersWithDataPerm.Contains(metadataAuthor)) { User userMA = subjectManager.UsersRepo.Get(u => metadataAuthor.Equals(u.FullName)).FirstOrDefault(); permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.Create); permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.View); permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.Update); permissionManager.CreateDataPermission(userMA.Id, 1, dataset.Id, RightType.Download); usersWithDataPerm.Add(metadataAuthor); } // create dataPermissions for designatedDatasetManager string designatedDatasetManager = metadataXml.SelectSingleNode("Metadata/general/general/designatedDatasetManager/contactType/designatedDatasetManagerName/designatedDatasetManagerName").InnerText; if (!usersWithDataPerm.Contains(designatedDatasetManager)) { User userDDM = subjectManager.UsersRepo.Get(u => designatedDatasetManager.Equals(u.FullName)).FirstOrDefault(); permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.Create); permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.View); permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.Update); permissionManager.CreateDataPermission(userDDM.Id, 1, dataset.Id, RightType.Download); usersWithDataPerm.Add(designatedDatasetManager); } // create dataPermissions for owners XmlNodeList ownerNodes = metadataXml.SelectNodes("Metadata/general/general/owners/ownerType/owner/owner"); foreach (XmlNode ownerNode in ownerNodes) { string owner = ownerNode.InnerText; if (!usersWithDataPerm.Contains(owner)) { User userO = subjectManager.UsersRepo.Get(u => owner.Equals(u.FullName)).FirstOrDefault(); if (userO != null) { permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.Create); permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.View); permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.Update); permissionManager.CreateDataPermission(userO.Id, 1, dataset.Id, RightType.Download); usersWithDataPerm.Add(owner); } } } // integrate metadataXml to dataset // checkOut if (datasetManager.IsDatasetCheckedOutFor(datasetId, userODM.Name) || datasetManager.CheckOutDataset(datasetId, userODM.Name)) { DatasetVersion workingCopy = datasetManager.GetDatasetWorkingCopy(datasetId); // get dataset workingCopy.Metadata = metadataXml; // set metadata to dataset datasetManager.EditDatasetVersion(workingCopy, null, null, null); // edit dataset datasetManager.CheckInDataset(datasetId, "Metadata was submited.", userODM.Name); // check in } return dataset.Id; }
/// <summary> /// create a new dataset, check it out to create the first version, add a tuple to it. /// </summary> /// <returns></returns> private Int64 createDatasetVersion() { DataStructureManager dsManager = new DataStructureManager(); ResearchPlanManager rpManager = new ResearchPlanManager(); DatasetManager dm = new DatasetManager(); MetadataStructureManager mdsManager = new MetadataStructureManager(); MDS.MetadataStructure mds = mdsManager.Repo.Query().First(); Dataset ds = dm.CreateEmptyDataset(dsManager.StructuredDataStructureRepo.Get(1), rpManager.Repo.Get(1), mds); if (dm.IsDatasetCheckedOutFor(ds.Id, "Javad") || dm.CheckOutDataset(ds.Id, "Javad")) { DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(ds.Id); //DataTuple changed = dm.GetDatasetVersionEffectiveTuples(workingCopy).First(); //changed.VariableValues.First().Value = (new Random()).Next().ToString(); DataTuple dt = dm.DataTupleRepo.Get(1); // its sample data List<DataTuple> tuples = new List<DataTuple>(); for (int i = 0; i < 10000; i++) { DataTuple newDt = new DataTuple(); newDt.XmlAmendments = dt.XmlAmendments; newDt.XmlVariableValues = dt.XmlVariableValues; // in normal cases, the VariableValues are set and then Dematerialize is called newDt.Materialize(); newDt.OrderNo = i; //newDt.TupleAction = TupleAction.Created;//not required //newDt.Timestamp = DateTime.UtcNow; //required? no, its set in the Edit //newDt.DatasetVersion = workingCopy;//required? no, its set in the Edit tuples.Add(newDt); } dm.EditDatasetVersion(workingCopy, tuples, null, null); dm.CheckInDataset(ds.Id, "for testing purposes", "Javad"); dm.DatasetVersionRepo.Evict(); dm.DataTupleRepo.Evict(); dm.DatasetRepo.Evict(); workingCopy.PriliminaryTuples.Clear(); workingCopy = null; } var dsId = ds.Id; ds = null; return (dsId); }
/// <summary> /// CAUTION !!!!!!!!!!!!!!!!! /// upload bezieht sich derzeit nur auf daten mit einem block (einer tabelle) /// umsetzung von mehreren blöckes noch nicht geklärt. /// (für einen wert gibt es eine weitere tabelle) /// </summary> /// <param name="dataSetID"></param> /// <param name="DataBase"></param> public void uploadData(string dataSetID, string DataBase) { DatasetManager datasetManager = new DatasetManager(); DataStructureManager dataStructureManager = new DataStructureManager(); XmlDataReader xmlDataReader = new XmlDataReader(); User user = new User(); string variableNames = ""; // query metadataAuthor and variable names from explorer.datasets queryAuthorAndVariables(ref user, ref variableNames, dataSetID, DataBase); List<string> varNames = variableNames.Split(',').ToList(); // get all dataStructures with equal variables count List<StructuredDataStructure> dataStructures = dataStructureManager.StructuredDataStructureRepo.Get(s => varNames.Count().Equals(s.Variables.Count)).ToList(); // get all Ids of dataStructures with equal variables List<long> dataStructureIds = new List<long>(); foreach (StructuredDataStructure dataStructure in dataStructures) { bool isSimilarStructure = true; foreach (Variable variable in dataStructure.Variables) { if (!varNames.Contains(variable.Label)) { isSimilarStructure &= false; break; } } if (isSimilarStructure) dataStructureIds.Add(dataStructure.Id); } // get the wanted dataset by comparing the old B1 datasetId out of the datasets with similar dataStructure Dataset dataset = null; List<Dataset> datasets = datasetManager.DatasetRepo.Get(d => dataStructureIds.Contains(d.DataStructure.Id)).ToList(); foreach (Dataset ds in datasets) { string oldDatasetId = ""; try { XmlNode extraID = ds.Versions.FirstOrDefault().Metadata.SelectSingleNode("Metadata/general/general/id/id"); oldDatasetId = extraID.InnerText; } catch { } if (oldDatasetId == dataSetID) { dataset = ds; break; } } if (dataset != null) { // get distinct and ascending ordered insertdates from DB List<DB2TimeStamp> distInsertDates = queryDistInsertDates(dataSetID, DataBase); bool checkObsIds = false; foreach (DB2TimeStamp insertDate in distInsertDates) { List<DataTuple> createdDataTuples = new List<DataTuple>(); List<DataTuple> editedDataTuples = new List<DataTuple>(); List<DataTuple> deletedDataTuples = new List<DataTuple>(); DatasetVersion workingCopy = datasetManager.GetDatasetLatestVersion(dataset.Id); // get dataset // get obsid, data, deleted and newest for each observation from DB List<Observation> observations = queryObservation(dataSetID, DataBase, insertDate.ToString()); Dictionary<long, long> obsIdMapsToTupleId = new Dictionary<long, long>(); if (checkObsIds) { // get all EffectiveTupleIds List<long> datasetTupleIds = datasetManager.GetDatasetVersionEffectiveTupleIds(workingCopy).ToList(); // id-mapping-list key=obsId, value=TupleId foreach EffectiveTupleId and obsId from Tuple.Extra obsIdMapsToTupleId = idMapping(datasetTupleIds, ref datasetManager); } // observation counter int observationIndex = 0; bool isNewest = true; foreach (Observation observation in observations) //////////////parallel { isNewest = (isNewest && observation.newest != 'Y') ? false : isNewest; // create dataTuple with xmlDataReader // split xml to string list and use DataReader.ReadRow DataTuple dataRow = xmlDataReader.XmlRowReader(observation.data, dataset.DataStructure.Id, observationIndex); // check if observation.obsid is in id-mapping-list long TupleId; if (checkObsIds && obsIdMapsToTupleId.TryGetValue(observation.obsid, out TupleId)) { DataTuple dataTuple = datasetManager.DataTupleRepo.Get(TupleId); if (observation.deleted != 'Y') { dataTuple.VariableValues = dataRow.VariableValues; // edit tuple if observation exists as tuple in EffectiveTuple and observation is not deleted editedDataTuples.Add(dataTuple); } else { // delete tuple if observation exists as tuple in EffectiveTuple and observ. is deleted deletedDataTuples.Add(dataTuple); } } else { // write the obsId and oldBExISdatasetId in Extra: <extra><obsid>[obsid]</obsid><oldBExISdatasetId>[dataSetID]</oldBExISdatasetId></extra> dataRow.Extra = oldIdsIntoExtra(observation.obsid, dataSetID, dataRow.Extra); // create tuple if observation exists not in EffectiveTuple createdDataTuples.Add(dataRow); } observationIndex++; // observation counter } checkObsIds = (!checkObsIds && !isNewest) ? true : checkObsIds; // checkOut if (datasetManager.IsDatasetCheckedOutFor(dataset.Id, user.Name) || datasetManager.CheckOutDataset(dataset.Id, user.Name)) { workingCopy = datasetManager.GetDatasetWorkingCopy(dataset.Id); // get dataset datasetManager.EditDatasetVersion(workingCopy, createdDataTuples, editedDataTuples, deletedDataTuples); // edit dataset datasetManager.CheckInDataset(dataset.Id, "Primary data row was submited.", user.Name); // checkIn } } } }
/// <summary> /// Submit a Dataset based on the imformations /// in the CreateTaskManager /// </summary> public long SubmitDataset() { #region create dataset TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; if (TaskManager.Bus.ContainsKey(CreateTaskmanager.DATASTRUCTURE_ID) && TaskManager.Bus.ContainsKey(CreateTaskmanager.RESEARCHPLAN_ID) && TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATASTRUCTURE_ID)) { DatasetManager dm = new DatasetManager(); long datasetId = 0; // for e new dataset if (!TaskManager.Bus.ContainsKey(CreateTaskmanager.ENTITY_ID)) { long datastructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.DATASTRUCTURE_ID]); long researchPlanId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.RESEARCHPLAN_ID]); long metadataStructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.METADATASTRUCTURE_ID]); DataStructureManager dsm = new DataStructureManager(); DataStructure dataStructure = dsm.StructuredDataStructureRepo.Get(datastructureId); //if datastructure is not a structured one if (dataStructure == null) dataStructure = dsm.UnStructuredDataStructureRepo.Get(datastructureId); ResearchPlanManager rpm = new ResearchPlanManager(); ResearchPlan rp = rpm.Repo.Get(researchPlanId); MetadataStructureManager msm = new MetadataStructureManager(); MetadataStructure metadataStructure = msm.Repo.Get(metadataStructureId); var ds = dm.CreateEmptyDataset(dataStructure, rp, metadataStructure); datasetId = ds.Id; // add security if (GetUsernameOrDefault() != "DEFAULT") { PermissionManager pm = new PermissionManager(); SubjectManager sm = new SubjectManager(); BExIS.Security.Entities.Subjects.User user = sm.GetUserByName(GetUsernameOrDefault()); foreach (RightType rightType in Enum.GetValues(typeof(RightType)).Cast<RightType>()) { pm.CreateDataPermission(user.Id, 1, ds.Id, rightType); } } } else { datasetId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.ENTITY_ID]); } TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; if (dm.IsDatasetCheckedOutFor(datasetId, GetUsernameOrDefault()) || dm.CheckOutDataset(datasetId, GetUsernameOrDefault())) { DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(datasetId); if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATA_XML)) { XDocument xMetadata = (XDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML]; workingCopy.Metadata = XmlMetadataWriter.ToXmlDocument(xMetadata); } string title = XmlDatasetHelper.GetInformation(workingCopy, NameAttributeValues.title); if(String.IsNullOrEmpty(title)) title = "No Title available."; TaskManager.AddToBus(CreateTaskmanager.ENTITY_TITLE, title );//workingCopy.Metadata.SelectNodes("Metadata/Description/Description/Title/Title")[0].InnerText); TaskManager.AddToBus(CreateTaskmanager.ENTITY_ID, datasetId); dm.EditDatasetVersion(workingCopy, null, null, null); dm.CheckInDataset(datasetId, "Metadata was submited.", GetUsernameOrDefault()); //add to index // ToDo check which SearchProvider it is, default luceneprovider ISearchProvider provider = IoCFactory.Container.ResolveForSession<ISearchProvider>() as ISearchProvider; provider?.UpdateSingleDatasetIndex(datasetId, IndexingAction.CREATE); LoggerFactory.LogData(datasetId.ToString(), typeof(Dataset).Name, Vaiona.Entities.Logging.CrudState.Created); } return datasetId; } #endregion return -1; }