public ActionResult ImportMetadata(long metadataStructureId, bool edit = true, bool created = false, bool locked = false) { ViewBag.Title = PresentationModel.GetViewTitleForTenant("Create Dataset", this.Session.GetTenant()); TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; XmlDocument newMetadata = (XmlDocument)TaskManager.Bus[CreateTaskmanager.METADATA_XML]; List<StepModelHelper> stepInfoModelHelpers = new List<StepModelHelper>(); MetadataEditorModel Model = new MetadataEditorModel(); TaskManager.AddToBus(CreateTaskmanager.METADATA_XML, XmlUtility.ToXDocument(newMetadata)); AdvanceTaskManagerBasedOnExistingMetadata(metadataStructureId); foreach (var stepInfo in TaskManager.StepInfos) { StepModelHelper stepModelHelper = GetStepModelhelper(stepInfo.Id); if (stepModelHelper.Model == null) { if (stepModelHelper.Usage is MetadataPackageUsage) { stepModelHelper.Model = CreatePackageModel(stepInfo.Id, false); if (stepModelHelper.Model.StepInfo.IsInstanze) LoadSimpleAttributesForModelFromXml(stepModelHelper); } if (stepModelHelper.Usage is MetadataNestedAttributeUsage) { stepModelHelper.Model = CreateCompoundModel(stepInfo.Id, false); if (stepModelHelper.Model.StepInfo.IsInstanze) LoadSimpleAttributesForModelFromXml(stepModelHelper); } getChildModelsHelper(stepModelHelper); } stepInfoModelHelpers.Add(stepModelHelper); } Model.StepModelHelpers = stepInfoModelHelpers; Model.Import = IsImportAvavilable(metadataStructureId); //set addtionaly functions Model.Actions = getAddtionalActions(); Model.FromEditMode = edit; Model.Created = created; if (TaskManager.Bus.ContainsKey(CreateTaskmanager.ENTITY_ID)) { long entityId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.ENTITY_ID]); Model.EditRight = hasUserEditRights(entityId); Model.EditAccessRight = hasUserEditAccessRights(entityId); //Model.DatasetId = entityId; } else { Model.EditRight = false; Model.EditAccessRight = false; Model.DatasetId = -1; } ViewData["Locked"] = locked; return PartialView("MetadataEditor", Model); }
private void SetXml(XDocument metadataXml) { TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; // load metadatastructure with all packages and attributes if (metadataXml != null) { // locat path //string path = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "metadataTemp.Xml"); TaskManager.AddToBus(CreateTaskmanager.METADATA_XML, metadataXml); //setup loaded if (TaskManager.Bus.ContainsKey(CreateTaskmanager.SETUP_LOADED)) TaskManager.Bus[CreateTaskmanager.SETUP_LOADED] = true; else TaskManager.Bus.Add(CreateTaskmanager.SETUP_LOADED, true); } }
/// <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; }
private void CreateXml() { TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; // load metadatastructure with all packages and attributes if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATASTRUCTURE_ID)) { XmlMetadataWriter xmlMetadatWriter = new XmlMetadataWriter(XmlNodeMode.xPath); XDocument metadataXml = xmlMetadatWriter.CreateMetadataXml(Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.METADATASTRUCTURE_ID])); //local path //string path = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "metadataTemp.Xml"); TaskManager.AddToBus(CreateTaskmanager.METADATA_XML, metadataXml); //setup loaded if (TaskManager.Bus.ContainsKey(CreateTaskmanager.SETUP_LOADED)) TaskManager.Bus[CreateTaskmanager.SETUP_LOADED] = true; else TaskManager.Bus.Add(CreateTaskmanager.SETUP_LOADED, true); //save //metadataXml.Save(path); } }
// // GET: /DCM/CreateDataset/ /// <summary> /// Load the createDataset action with different parameter type options /// type eg ("DataStructureId", "DatasetId", "MetadataStructureId") /// </summary> /// <param name="id"></param> /// <param name="type"></param> /// <returns></returns> public ActionResult Index(long id = -1, string type = "") { ViewBag.Title = PresentationModel.GetViewTitleForTenant("Create Dataset", this.Session.GetTenant()); Session["CreateDatasetTaskmanager"] = null; if (TaskManager == null) TaskManager = (CreateTaskmanager)Session["CreateDatasetTaskmanager"]; if (TaskManager == null) { TaskManager = new CreateTaskmanager(); Session["CreateDatasetTaskmanager"] = TaskManager; Session["MetadataStructureViewList"] = LoadMetadataStructureViewList(); Session["DataStructureViewList"] = LoadDataStructureViewList(); Session["DatasetViewList"] = LoadDatasetViewList(); setAdditionalFunctions(); //set Entity to TaskManager TaskManager.AddToBus(CreateTaskmanager.ENTITY_CLASS_PATH,"BExIS.Dlm.Entities.Data.Dataset"); SetupModel Model = GetDefaultModel(); //if id is set and its type dataset if (id != -1 && type.ToLower().Equals("datasetid")) { ViewBag.Title = PresentationModel.GetViewTitleForTenant("Copy Dataset", this.Session.GetTenant()); DatasetManager datasetManager = new DatasetManager(); Dataset dataset = datasetManager.DatasetRepo.Get(id); Model.SelectedDatasetId = id; Model.SelectedMetadataStructureId = dataset.MetadataStructure.Id; Model.SelectedDataStructureId = dataset.DataStructure.Id; Model.BlockMetadataStructureId = true; Model.BlockDatasetId = true; } if (id != -1 && type.ToLower().Equals("metadatastructureid")) { ViewBag.Title = PresentationModel.GetViewTitleForTenant("Copy Dataset", this.Session.GetTenant()); Model.SelectedMetadataStructureId = id; } if (id != -1 && type.ToLower().Equals("datastructureid")) { ViewBag.Title = PresentationModel.GetViewTitleForTenant("Copy Dataset", this.Session.GetTenant()); Model.SelectedDataStructureId = id; if (TaskManager.Bus.ContainsKey(CreateTaskmanager.METADATASTRUCTURE_ID)) Model.SelectedMetadataStructureId = Convert.ToInt64(TaskManager.Bus[CreateTaskmanager.METADATASTRUCTURE_ID]); } return View(Model); } return View(); }