public Publication CreatePublication(DatasetVersion datasetVersion, Broker broker, Repository repository, string name, long researchObjectId, string filePath = "", string externalLink = "", string status = "") { Contract.Ensures(Contract.Result <Publication>() != null && Contract.Result <Publication>().Id >= 0); Publication publication = new Publication(); publication.ResearchObjectId = researchObjectId; publication.Broker = broker; publication.DatasetVersion = datasetVersion; publication.Repository = repository; publication.Timestamp = DateTime.Now; publication.Status = status; publication.FilePath = filePath; publication.ExternalLink = externalLink; using (IUnitOfWork uow = this.GetUnitOfWork()) { IRepository <Publication> repo = uow.GetRepository <Publication>(); repo.Put(publication); uow.Commit(); } return(publication); }
public void TransformDatatupleToJson() { //Arrange DatasetManager datasetManager = new DatasetManager(); try { //Act DatasetVersion datasetversion = datasetManager.GetDatasetLatestVersion(datasetId); var result = datasetManager.GetDatasetVersionEffectiveTuples(datasetversion); foreach (var dt in result) { dt.Materialize(); dt.Dematerialize(); } var newDts = result.Cast <DataTuple>(); foreach (var dt in newDts) { //dt.Materialize2(); //dt.Dematerialize2(); // convert variablevalues 1 to json } //Assert Assert.That(result.Count(), Is.EqualTo(numberOfTuples)); foreach (var dt in newDts) { for (int i = 0; i < dt.VariableValues.Count; i++) { var vv1 = dt.VariableValues.ElementAt(i); //var vv2 = dt.VariableValues2.ElementAt(i); //Assert.That(vv1.DataAttribute.Id , Is.EqualTo(vv2.DataAttribute.Id)); //Assert.That(vv1.Note, Is.EqualTo(vv2.Note)); //Assert.That(vv1.ObtainingMethod, Is.EqualTo(vv2.ObtainingMethod)); //Assert.That(vv1.ParameterValues, Is.EqualTo(vv2.ParameterValues)); //Assert.That(vv1.ResultTime, Is.EqualTo(vv2.ResultTime)); //Assert.That(vv1.SamplingTime, Is.EqualTo(vv2.SamplingTime)); //Assert.That(vv1.Tuple.Id, Is.EqualTo(vv2.Tuple.Id)); //Assert.That(vv1.Value, Is.EqualTo(vv2.Value)); //Assert.That(vv1.Variable.Id, Is.EqualTo(vv2.Variable.Id)); //Assert.That(vv1.VariableId, Is.EqualTo(vv2.VariableId)); } } } catch (Exception ex) { throw (ex); } finally { datasetManager.Dispose(); } }
private ApiDatasetAttachmentsModel GetApiDatasetAttachmentsModel(long id, DatasetManager dm) { ApiDatasetAttachmentsModel model = new ApiDatasetAttachmentsModel(); DatasetVersion datasetVersion = dm.GetDatasetLatestVersion(id); if (datasetVersion != null && datasetVersion.ContentDescriptors != null) { model.DatasetId = id; foreach (var cd in datasetVersion.ContentDescriptors) { if (cd != null && cd.URI.ToLower().Contains("attachments")) { ApiSimpleAttachmentModel attachmentModel = new ApiSimpleAttachmentModel(); attachmentModel.Id = cd.Id; attachmentModel.Name = cd.Name; attachmentModel.MimeType = cd.MimeType; model.Attachments.Add(attachmentModel); } } return(model); } return(null); }
public static GFBIOPangaeaFormularObject GetGFBIOPangaeaFormularObject(long datasetId) { DatasetManager datasetManager = new DatasetManager(); try { 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(); XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper(); string title = xmlDatasetHelper.GetInformation(datasetId, NameAttributeValues.title); string description = xmlDatasetHelper.GetInformation(datasetId, NameAttributeValues.description); return(gfbioPangaeaFormularObject); } finally { datasetManager.Dispose(); } }
public static string GetSchemaDirectoryPath(long datasetId) { using (DatasetManager datasetManager = new DatasetManager()) using (MetadataStructureManager metadataStructureManager = new MetadataStructureManager()) { try { DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId); MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(datasetVersion.Dataset.MetadataStructure.Id); string path = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DCM"), "Metadata", metadataStructure.Name); if (!String.IsNullOrEmpty(path) && Directory.Exists(path)) { return(path); } } catch (Exception ex) { throw ex; } } return(String.Empty); }
private string getStorePath(long datasetVersionId, string exportTo) { using (DatasetManager datasetManager = new DatasetManager()) using (MetadataStructureManager metadataStructureManager = new MetadataStructureManager()) { DatasetVersion datasetVersion = datasetManager.GetDatasetVersion(datasetVersionId); Dataset dataset = datasetManager.GetDataset(datasetVersionId); string md_title = metadataStructureManager.Repo.Get(datasetVersion.Dataset.MetadataStructure.Id).Name; string path; int versionNr = datasetManager.GetDatasetVersionNr(datasetVersion); if (string.IsNullOrEmpty(exportTo) || exportTo.ToLower().Equals("generic")) { path = IOHelper.GetDynamicStorePath(datasetVersion.Dataset.Id, versionNr, "metadata", ".xml"); } else { path = IOHelper.GetDynamicStorePath(datasetVersion.Dataset.Id, versionNr, "metadata_" + exportTo, ".xml"); } return(path); } }
private void addSelectedDatasetToBus(long datasetId) { using (DatasetManager datasetManager = new DatasetManager()) using (ResearchPlanManager rpm = new ResearchPlanManager()) { TaskManager = (TaskManager)Session["TaskManager"]; if (datasetManager.GetDatasetVersionEffectiveTupleCount(datasetManager.GetDatasetLatestVersion(datasetId)) > 0) { TaskManager.AddToBus("DatasetStatus", "edit"); } else { TaskManager.AddToBus("DatasetStatus", "new"); } DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId); TaskManager.AddToBus(TaskManager.DATASET_ID, datasetId); //Add Metadata to Bus //TITLE TaskManager.AddToBus(TaskManager.DATASET_TITLE, datasetVersion.Title); ResearchPlan rp = rpm.Repo.Get(datasetVersion.Dataset.ResearchPlan.Id); TaskManager.AddToBus(TaskManager.RESEARCHPLAN_ID, rp.Id); TaskManager.AddToBus(TaskManager.RESEARCHPLAN_TITLE, rp.Title); } }
public ActionResult ShowPreviewDataStructure(long datasetID) { DatasetManager dm = new DatasetManager(); DataStructureManager dsm = new DataStructureManager(); try { using (var uow = this.GetUnitOfWork()) { long dsId = dm.GetDatasetLatestVersion(datasetID).Id; DatasetVersion ds = uow.GetUnitOfWork().GetReadOnlyRepository <DatasetVersion>().Get(dsId); DataStructure dataStructure = uow.GetReadOnlyRepository <DataStructure>().Get(ds.Dataset.DataStructure.Id); long id = (long)datasetID; Tuple <DataStructure, long> m = new Tuple <DataStructure, long>( dataStructure, id ); return(PartialView("_previewDatastructure", m)); } } catch (Exception ex) { throw ex; } }
private string generatePrimaryData(long datasetVersionId) { try { DatasetManager datasetManager = new DatasetManager(); DatasetVersion datasetVersion = datasetManager.GetDatasetVersion(datasetVersionId); if (datasetVersion.Dataset.DataStructure.Self is StructuredDataStructure) { OutputDataManager outputDataManager = new OutputDataManager(); SubmissionManager submissionManager = new SubmissionManager(); long datasetId = datasetVersion.Dataset.Id; string fileName = submissionManager.GetFileNameForDataRepo(datasetId, datasetVersionId, _dataRepo.Name, "csv"); string filepath = outputDataManager.GenerateAsciiFile( datasetId, datasetVersionId, fileName, "text/txt"); return(filepath); } } catch (Exception) { throw; } return(""); }
public string GenerateAsciiFile(long id, string title, string mimeType, string[] visibleColumns) { string ext = ""; string path = ""; DatasetManager datasetManager = new DatasetManager(); try { DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(id); AsciiWriter writer = new AsciiWriter(TextSeperator.comma); // Javad: It is better to have a list of tuple IDs and pass it to the AddDataTuples method. // This method is using a special iterator to reduce the number of queries. 18.11.2016 List <long> datatuples = new List <long>(); //GetFilteredDataTuples(datasetVersion); long datastuctureId = datasetVersion.Dataset.DataStructure.Id; path = generateDownloadFile(id, datasetVersion.Id, datastuctureId, "data", ext, writer); if (visibleColumns != null) { writer.VisibleColumns = visibleColumns; } writer.AddDataTuples(datasetManager, datatuples, path, datastuctureId); return(path); } finally { datasetManager.Dispose(); } }
/// <summary> /// Information in metadata is stored as xml /// get back the vale of an attribute /// e.g. title = "dataset title" /// /// </summary> /// <param name="datasetVersion"></param> /// <param name="name"></param> /// <returns></returns> public string GetInformationFromVersion(long datasetVersionId, NameAttributeValues name) { using (var unitOfWork = this.GetUnitOfWork()) { DatasetVersion datasetVersion = unitOfWork.GetReadOnlyRepository <DatasetVersion>().Get(datasetVersionId); // get MetadataStructure if (datasetVersion != null && datasetVersion.Dataset != null && datasetVersion.Dataset.MetadataStructure != null && datasetVersion.Metadata != null) { MetadataStructure metadataStructure = datasetVersion.Dataset.MetadataStructure; if ((XmlDocument)metadataStructure.Extra != null) { XDocument xDoc = XmlUtility.ToXDocument((XmlDocument)metadataStructure.Extra); XElement temp = XmlUtility.GetXElementByAttribute(nodeNames.nodeRef.ToString(), "name", name.ToString(), xDoc); string xpath = temp.Attribute("value").Value.ToString(); XmlNode node = datasetVersion.Metadata.SelectSingleNode(xpath); string title = ""; if (node != null) { title = datasetVersion.Metadata.SelectSingleNode(xpath).InnerText; } return(title); } } return(string.Empty); } }
private void addSelectedDatasetToBus(long datasetId) { DatasetManager datasetManager = new DatasetManager(); try { TaskManager = (TaskManager)Session["TaskManager"]; if (datasetManager.GetDatasetVersionEffectiveTupleCount(datasetManager.GetDatasetLatestVersion(datasetId)) > 0) { TaskManager.AddToBus("DatasetStatus", "edit"); } else { TaskManager.AddToBus("DatasetStatus", "new"); } DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId); TaskManager.AddToBus(TaskManager.DATASET_ID, datasetId); //Add Metadata to Bus //TITLE TaskManager.AddToBus(TaskManager.DATASET_TITLE, xmlDatasetHelper.GetInformationFromVersion(datasetVersion.Id, NameAttributeValues.title)); ResearchPlanManager rpm = new ResearchPlanManager(); ResearchPlan rp = rpm.Repo.Get(datasetVersion.Dataset.ResearchPlan.Id); TaskManager.AddToBus(TaskManager.RESEARCHPLAN_ID, rp.Id); TaskManager.AddToBus(TaskManager.RESEARCHPLAN_TITLE, rp.Title); } finally { datasetManager.Dispose(); } }
public static string GenerateDataStructure(long datasetId) { string path = ""; try { DatasetManager datasetManager = null; try { datasetManager = new DatasetManager(); DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId); DataStructureDataTable dataStructureDataTable = new DataStructureDataTable(datasetId); // store in content descriptor path = storeGeneratedFilePathToContentDiscriptor(datasetId, datasetVersion, "datastructure", ".txt"); } finally { datasetManager.Dispose(); } } catch (Exception ex) { throw ex; } return(path); }
/// <summary> /// Return a metadata as html file from a datasetversion /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult GetMetadataAsHtmlFile(long id) { DatasetManager dm = new DatasetManager(); try { using (var uow = this.GetUnitOfWork()) { long dsId = dm.GetDatasetLatestVersion(id).Id; DatasetVersion ds = uow.GetUnitOfWork().GetReadOnlyRepository <DatasetVersion>().Get(dsId); XmlDocument document = OutputMetadataManager.GetConvertedMetadata(id, TransmissionType.mappingFileExport, ds.Dataset.MetadataStructure.Name); string htmlPage = PartialView("SimpleMetadata", document).RenderToString(); byte[] content = Encoding.ASCII.GetBytes(htmlPage); return(File(content, "text/html", "metadata.html")); } } catch (Exception ex) { throw ex; } finally { dm.Dispose(); } }
private void generateMetadataHtml(DatasetVersion dsv) { XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper(); long datasetId = dsv.Dataset.Id; long metadatastructureId = dsv.Dataset.MetadataStructure.Id; long datastructureId = dsv.Dataset.DataStructure.Id; long researchplanId = dsv.Dataset.ResearchPlan.Id; string title = dsv.Title; Session["ShowDataMetadata"] = dsv.Metadata; var view = this.Render("DCM", "Form", "LoadMetadataOfflineVersion", new RouteValueDictionary() { { "entityId", datasetId }, { "title", title }, { "metadatastructureId", metadatastructureId }, { "datastructureId", datastructureId }, { "researchplanId", researchplanId }, { "sessionKeyForMetadata", "ShowDataMetadata" }, { "resetTaskManager", false } }); byte[] content = Encoding.ASCII.GetBytes(view.ToString()); string dynamicPathOfMD = ""; dynamicPathOfMD = storeGeneratedFilePathToContentDiscriptor(datasetId, dsv, "metadata", ".html"); string metadataFilePath = AsciiWriter.CreateFile(dynamicPathOfMD); AsciiWriter.AllTextToFile(metadataFilePath, view.ToString()); }
/// <summary> /// returns a value of a metadata node /// </summary> /// <param name="datasetVersion"></param> /// <param name="name"></param> /// <returns></returns> public IEnumerable <string> GetAllTransmissionInformation(long datasetid, TransmissionType type, AttributeNames returnType = AttributeNames.value) { Dataset dataset = this.GetUnitOfWork().GetReadOnlyRepository <Dataset>().Get(datasetid); DatasetManager dm = new DatasetManager(); try { DatasetVersion datasetVersion = dm.GetDatasetLatestVersion(dataset); // get MetadataStructure if (datasetVersion != null && datasetVersion.Dataset != null && datasetVersion.Dataset.MetadataStructure != null && datasetVersion.Dataset.MetadataStructure.Extra != null && datasetVersion.Metadata != null) { return(GetAllTransmissionInformationFromMetadataStructure(datasetVersion.Dataset.MetadataStructure.Id, type, returnType)); } return(null); } finally { dm.Dispose(); } }
public string GetTransmissionInformation(long datasetVersionId, TransmissionType type, string name, AttributeNames returnType = AttributeNames.value) { DatasetVersion datasetVersion = this.GetUnitOfWork().GetReadOnlyRepository <DatasetVersion>().Get(datasetVersionId); Dataset dataset = this.GetUnitOfWork().GetReadOnlyRepository <Dataset>().Get(datasetVersion.Dataset.Id); MetadataStructure metadataStructure = this.GetUnitOfWork().GetReadOnlyRepository <MetadataStructure>().Get(dataset.MetadataStructure.Id); // get MetadataStructure if (datasetVersion != null && dataset != null && metadataStructure != null && datasetVersion.Metadata != null && metadataStructure.Extra != null) { XDocument xDoc = XmlUtility.ToXDocument((XmlDocument)datasetVersion.Dataset.MetadataStructure.Extra); Dictionary <string, string> queryDic = new Dictionary <string, string>(); queryDic.Add(AttributeNames.name.ToString(), name); queryDic.Add(AttributeNames.type.ToString(), type.ToString()); IEnumerable <XElement> temp = XmlUtility.GetXElementsByAttribute(nodeNames.convertRef.ToString(), queryDic, xDoc); string value = temp?.First().Attribute(returnType.ToString()).Value; return(value); } return(string.Empty); }
public JsonResult PrepareTxtData(long id) { if (hasUserRights(id, RightType.Read)) { string ext = ".txt"; DatasetManager datasetManager = new DatasetManager(); try { DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(id); AsciiWriter writer = new AsciiWriter(TextSeperator.comma); OutputDataManager ioOutputDataManager = new OutputDataManager(); string title = getTitle(writer.GetTitle(id)); string path = ""; string message = string.Format("dataset {0} version {1} was downloaded as txt.", id, datasetVersion.Id); // if filter selected if (filterInUse()) { #region generate a subset of a dataset String[] visibleColumns = null; if (Session["Columns"] != null) { visibleColumns = (String[])Session["Columns"]; } path = ioOutputDataManager.GenerateAsciiFile(id, title, "text/plain", visibleColumns); LoggerFactory.LogCustom(message); #endregion generate a subset of a dataset } else { path = ioOutputDataManager.GenerateAsciiFile(id, title, "text/plain"); LoggerFactory.LogCustom(message); } return(Json(true, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } finally { datasetManager.Dispose(); } } else { return(Json("User has no rights.", JsonRequestBehavior.AllowGet)); } }
public DataTable ConvertDatasetVersion(DatasetManager datasetManager, DatasetVersion datasetVersion, string tableName = "") { DataTable dt = new DataTable(); if (string.IsNullOrEmpty(tableName)) { dt.TableName = "Primary data table"; } else { dt.TableName = tableName; } using (DataStructureManager dsm = new DataStructureManager()) { StructuredDataStructure sds = dsm.StructuredDataStructureRepo.Get(datasetVersion.Dataset.DataStructure.Id); var tupleIds = datasetManager.GetDatasetVersionEffectiveTupleIds(datasetVersion); if (tupleIds != null && tupleIds.Count > 0 && sds != null) { buildTheHeader(sds, dt); buildTheBody(datasetManager, tupleIds, dt, sds); } } return(dt); }
//private Stream getFileStream(string uri) //{ // String path = Server.UrlDecode(uri); // path = Path.Combine(AppConfiguration.DataPath, path); // return System.IO.File.OpenRead(path); //} /// <summary> /// Get total size of a file format dataset /// </summary> /// <param name="datasetVersion"></param> /// <returns>double size</returns> private double GetFileDatasetSize(DatasetVersion datasetVersion) { List <ContentDescriptor> contentDescriptors = datasetVersion.ContentDescriptors.ToList(); double totalSize = 0; if (contentDescriptors.Count > 0) { foreach (ContentDescriptor cd in contentDescriptors) { if (cd.Name.ToLower().Equals("unstructureddata")) { fileInformation fileInformation = new fileInformation(); string uri = cd.URI; String path = Server.UrlDecode(uri); path = Path.Combine(AppConfiguration.DataPath, path); Stream fileStream = System.IO.File.OpenRead(path); if (fileStream != null) { FileStream fs = fileStream as FileStream; if (fs != null) { FileInformation fileInfo = new FileInformation(fs.Name.Split('\\').LastOrDefault(), MimeMapping.GetMimeMapping(fs.Name), (uint)fs.Length, uri); fileInformation.fileSize = fileInfo.Size; totalSize += fileInfo.Size; } } } } } return(totalSize); }
public bool HasTransmission(long datasetid, TransmissionType type) { Dataset dataset = this.GetUnitOfWork().GetReadOnlyRepository <Dataset>().Get(datasetid); DatasetManager dm = new DatasetManager(); try { DatasetVersion datasetVersion = dm.GetDatasetLatestVersion(dataset); // get MetadataStructure if (datasetVersion != null && datasetVersion.Dataset != null && datasetVersion.Dataset.MetadataStructure != null && datasetVersion.Dataset.MetadataStructure.Extra != null && datasetVersion.Metadata != null) { MetadataStructure metadataStructure = datasetVersion.Dataset.MetadataStructure; XDocument xDoc = XmlUtility.ToXDocument((XmlDocument)datasetVersion.Dataset.MetadataStructure.Extra); IEnumerable <XElement> temp = XmlUtility.GetXElementsByAttribute(nodeNames.convertRef.ToString(), AttributeNames.type.ToString(), type.ToString(), xDoc); if (temp != null && temp.Any()) { return(true); } } return(false); } finally { dm.Dispose(); } }
/// <summary> /// THE ACTIONRESULT FOR SHOW DATASET LIST VIEW /// </summary> /// <param name="datasetIds"></param> /// <param name="performerName"></param> /// <returns></returns> public ActionResult ShowDatasetList() { ExternalLink dsModel = new ExternalLink(); List <datasetInfo> datasetInfos = new List <datasetInfo>(); DatasetManager dm = new DatasetManager(); DataStructureManager dsm = new DataStructureManager(); List <long> datasetIds = dm.GetDatasetLatestIds(); foreach (long Id in datasetIds) { if (dm.IsDatasetCheckedIn(Id)) { DatasetVersion datasetVersion = dm.GetDatasetLatestVersion(Id); //get last dataset versions datasetInfo datasetInfo = new datasetInfo(); datasetInfo.title = datasetVersion.Title; DataStructure dataStr = dsm.AllTypesDataStructureRepo.Get(datasetVersion.Dataset.DataStructure.Id); string type = "file"; if (dataStr.Self.GetType() == typeof(StructuredDataStructure)) { type = "tabular"; } datasetInfo.type = type; datasetInfo.Id = Id; datasetInfos.Add(datasetInfo); } } dsModel.datasetInfos = datasetInfos; return(View(dsModel)); }
// get header public Header GetHeader(long id) { if (id <= 0) { return(null); } DatasetManager datasetManager = new DatasetManager(); try { DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(id); DateTime lastModified = datasetVersion.Timestamp; Header header = new Header(); header.OAI_Identifier = ConvertToOaiId(id); header.OAI_Set = AppConfiguration.ApplicationName; // ToDo what is a oai_set? header.Datestamp = lastModified; //Date Last Modified; header.Deleted = false; header.OAIDataProviderId = -1; return(header); } finally { datasetManager.Dispose(); } }
//copy of Dcm.UI.Helpers.DataASyncUploadHelper.FinishUpload (adapted) public ActionResult SaveFile(long entityId) { Dataset ds = null; DatasetVersion workingCopy = new DatasetVersion(); string storePath = ""; using (var dm = new DatasetManager()) { ds = dm.GetDataset(entityId); // checkout the dataset, apply the changes, and check it in. if (dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault()) || dm.CheckOutDataset(ds.Id, GetUsernameOrDefault())) { try { workingCopy = dm.GetDatasetWorkingCopy(ds.Id); using (var unitOfWork = this.GetUnitOfWork()) { workingCopy = unitOfWork.GetReadOnlyRepository <DatasetVersion>().Get(workingCopy.Id); unitOfWork.GetReadOnlyRepository <DatasetVersion>().Load(workingCopy.ContentDescriptors); storePath = SaveFileInContentDiscriptor(workingCopy); } workingCopy.StateInfo = new EntityStateInfo(); workingCopy.StateInfo.State = DatasetStateInfo.Valid.ToString(); //set modification workingCopy.ModificationInfo = new EntityAuditInfo() { Performer = GetUsernameOrDefault(), Comment = "File", ActionType = AuditActionType.Create }; dm.EditDatasetVersion(workingCopy, null, null, null); string filename = Path.GetFileName(storePath); //TaskManager TaskManager = (TaskManager)Session["TaskManager"]; //if (TaskManager.Bus.ContainsKey(TaskManager.FILENAME)) //{ // filename = TaskManager.Bus[TaskManager.FILENAME]?.ToString(); //} // ToDo: Get Comment from ui and users dm.CheckInDataset(ds.Id, filename, GetUsernameOrDefault(), ViewCreationBehavior.None); } catch (Exception ex) { throw ex; } } } return(RedirectToAction("Index", "ShowPublication", new { area = "PUB", id = entityId })); }
public JsonResult PrepareExcelData(long id) { if (hasUserRights(id, RightType.Read)) { string ext = ".xlsm"; DatasetManager datasetManager = new DatasetManager(); try { DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(id); ExcelWriter writer = new ExcelWriter(); string title = getTitle(writer.GetTitle(id)); string path = ""; string message = string.Format("dataset {0} version {1} was downloaded as excel.", id, datasetVersion.Id); // if filter selected if (filterInUse()) { #region generate a subset of a dataset //ToDo filter datatuples LoggerFactory.LogCustom(message); #endregion generate a subset of a dataset } //filter not in use else { OutputDataManager outputDataManager = new OutputDataManager(); path = outputDataManager.GenerateExcelFile(id, title); LoggerFactory.LogCustom(message); } return(Json(true, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(ex.Message, JsonRequestBehavior.AllowGet)); } finally { datasetManager.Dispose(); } } else { return(Json("User has no rights.", JsonRequestBehavior.AllowGet)); } }
public ActionResult CreateTestDatasets(int n) { DatasetManager datasetManager = new DatasetManager(); DataStructureManager dataStructureManager = new DataStructureManager(); MetadataStructureManager metadataStructureManager = new MetadataStructureManager(); ResearchPlanManager researchPlanManager = new ResearchPlanManager(); try { var structure = dataStructureManager.UnStructuredDataStructureRepo.Get(1); var metadatastructure = metadataStructureManager.Repo.Get(1); var researchplan = researchPlanManager.Repo.Get(1); var xmlDatasetHelper = new XmlDatasetHelper(); var xmlMetadatWriter = new XmlMetadataWriter(XmlNodeMode.xPath); var metadataXml = xmlMetadatWriter.CreateMetadataXml(metadatastructure.Id); for (int i = 0; i < n; i++) { var dataset = datasetManager.CreateEmptyDataset(structure, researchplan, metadatastructure); if (datasetManager.IsDatasetCheckedOutFor(dataset.Id, "test") || datasetManager.CheckOutDataset(dataset.Id, "test")) { DatasetVersion workingCopy = datasetManager.GetDatasetWorkingCopy(dataset.Id); datasetManager.EditDatasetVersion(workingCopy, null, null, null); datasetManager.CheckInDataset(dataset.Id, "", "test", ViewCreationBehavior.None); workingCopy.Metadata = Xml.Helpers.XmlWriter.ToXmlDocument(metadataXml); string xpath = xmlDatasetHelper.GetInformationPath(metadatastructure.Id, NameAttributeValues.title); workingCopy.Metadata.SelectSingleNode(xpath).InnerText = i.ToString(); workingCopy.Title = i.ToString(); datasetManager.EditDatasetVersion(workingCopy, null, null, null); datasetManager.CheckInDataset(dataset.Id, "", "test", ViewCreationBehavior.None); } } } catch (Exception ex) { throw ex; } finally { datasetManager.Dispose(); dataStructureManager.Dispose(); metadataStructureManager.Dispose(); researchPlanManager.Dispose(); } return(View("Index")); }
private string storeGeneratedFilePathToContentDiscriptor(long datasetId, DatasetVersion datasetVersion, string title, string ext) { string name = ""; string mimeType = ""; if (ext.Contains("csv")) { name = "datastructure"; mimeType = "text/comma-separated-values"; } if (ext.Contains("html")) { name = title; mimeType = "application/html"; } using (DatasetManager dm = new DatasetManager()) { int versionNr = dm.GetDatasetVersionNr(datasetVersion); // create the generated FileStream and determine its location string dynamicPath = OutputDatasetManager.GetDynamicDatasetStorePath(datasetId, versionNr, title, ext); //Register the generated data FileStream as a resource of the current dataset version //ContentDescriptor generatedDescriptor = new ContentDescriptor() //{ // OrderNo = 1, // Name = name, // MimeType = mimeType, // URI = dynamicPath, // DatasetVersion = datasetVersion, //}; if (datasetVersion.ContentDescriptors.Count(p => p.Name.Equals(name)) > 0) { // remove the one contentdesciptor foreach (ContentDescriptor cd in datasetVersion.ContentDescriptors) { if (cd.Name == name) { cd.URI = dynamicPath; dm.UpdateContentDescriptor(cd); } } } else { // add current contentdesciptor to list //datasetVersion.ContentDescriptors.Add(generatedDescriptor); dm.CreateContentDescriptor(name, mimeType, dynamicPath, 1, datasetVersion); } //dm.EditDatasetVersion(datasetVersion, null, null, null); return(dynamicPath); } }
// GET: api/data/5 /// <summary> /// In addition to the id, it is possible to have projection and selection criteria passed to the action via query string parameters /// </summary> /// <param name="id">Dataset Id</param> /// <returns></returns> /// <remarks> The action accepts the following additional parameters via the query string /// 1: projection: is a comman separated list of ids that determines which variables of the dataset version tuples should take part in the result set /// 2: selection: is a logical expression that filters the tuples of the chosen dataset. The expression should have been written against the variables of the dataset only. /// logical operators, nesting, precedence, and SOME functions should be supported. /// /api/data/6?header=TimeUTC,D8CO1_1&filter=TimeUTC<5706000 /// </remarks> public HttpResponseMessage Get(int id) { string projection = this.Request.GetQueryNameValuePairs().FirstOrDefault(p => "header".Equals(p.Key, StringComparison.InvariantCultureIgnoreCase)).Value; string selection = this.Request.GetQueryNameValuePairs().FirstOrDefault(p => "filter".Equals(p.Key, StringComparison.InvariantCultureIgnoreCase)).Value; DatasetManager datasetManager = new DatasetManager(); try { OutputDataManager ioOutputDataManager = new OutputDataManager(); DatasetVersion version = datasetManager.GetDatasetLatestVersion(id); string title = xmlDatasetHelper.GetInformationFromVersion(version.Id, NameAttributeValues.title); // check the data sturcture type ... if (version.Dataset.DataStructure.Self is StructuredDataStructure) { // apply selection and projection //var tuples = dm.GetDatasetVersionEffectiveTuples(version); DataTable dt = OutputDataManager.ConvertPrimaryDataToDatatable(datasetManager, version, title, true); if (!string.IsNullOrEmpty(selection)) { dt = OutputDataManager.SelectionOnDataTable(dt, selection); } if (!string.IsNullOrEmpty(projection)) { // make the header names upper case to make them case insensitive dt = OutputDataManager.ProjectionOnDataTable(dt, projection.ToUpper().Split(',')); } DatasetModel model = new DatasetModel(); model.DataTable = dt; var response = Request.CreateResponse(); response.Content = new ObjectContent(typeof(DatasetModel), model, new DatasetModelCsvFormatter(model.DataTable.TableName)); //set headers on the "response" return(response); //return model; } else { return(Request.CreateResponse()); } } finally { datasetManager.Dispose(); } }
public static string CreateConvertedMetadata(long datasetId, TransmissionType type) { XmlDocument newXml; DatasetManager datasetManager = new DatasetManager(); MetadataStructureManager metadataMetadataStructureManager = new MetadataStructureManager(); try { DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId); MetadataStructure metadataStructure = metadataMetadataStructureManager.Repo.Get(datasetVersion.Dataset.MetadataStructure.Id); XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper(); int versionNr = datasetManager.GetDatasetVersionNr(datasetVersion); string mappingName = metadataStructure.Name; string mappingFileName = xmlDatasetHelper.GetTransmissionInformation(datasetVersion.Id, type, mappingName); //if mapping file not exist if (string.IsNullOrEmpty(mappingFileName)) { return(""); } string pathMappingFile = Path.Combine(AppConfiguration.GetModuleWorkspacePath("DIM"), mappingFileName); XmlMapperManager xmlMapperManager = new XmlMapperManager(TransactionDirection.InternToExtern); xmlMapperManager.Load(pathMappingFile, "exporttest"); newXml = xmlMapperManager.Export(datasetVersion.Metadata, datasetVersion.Id, mappingName, true); string title = datasetVersion.Title; // store in content descriptor string filename = "metadata"; if (String.IsNullOrEmpty(mappingName) || mappingName.ToLower() == "generic") { storeGeneratedFilePathToContentDiscriptor(datasetId, datasetVersion, filename, ".xml"); } else { filename = "metadata_" + mappingName; storeGeneratedFilePathToContentDiscriptor(datasetId, datasetVersion, filename, ".xml"); } return(OutputDatasetManager.GetDynamicDatasetStorePath(datasetId, versionNr, filename, ".xml")); } catch (Exception ex) { throw ex; } finally { datasetManager.Dispose(); metadataMetadataStructureManager.Dispose(); } }
/// <summary> /// This function calculates the percentage of a metadata completeness. /// </summary> /// <param name="dsv">dataset version</param> /// <returns>rate: percentage of the metadata completeness</returns> private int GetMetadataRate(DatasetVersion dsv) { XmlDocument metadata = dsv.Metadata; string xmlFrag = metadata.OuterXml; List <int> metaInfo = GetMetaInfoArray(xmlFrag); // [0] number of all metadata attributes, [1] number of filled metadata atributes // [2] number of all required metadata attributes, [3] number of filled required metadata attributes int rate = (metaInfo[1] * 100) / metaInfo[0]; //percentage of all metadata fields contains information return(rate); }