Exemple #1
0
        public ActionResult Delete(long datasetId, String fileName)
        {
            using (var dm = new DatasetManager())
            {
                var filePath = Path.Combine(AppConfiguration.DataPath, "Datasets", datasetId.ToString(), "Attachments", fileName);
                FileHelper.Delete(filePath);
                var dataset           = dm.GetDataset(datasetId);
                var datasetVersion    = dm.GetDatasetLatestVersion(dataset);
                var contentDescriptor = datasetVersion.ContentDescriptors.FirstOrDefault(item => item.Name == fileName);
                if (contentDescriptor == null)
                {
                    throw new Exception("There is not any content descriptor having file name '" + fileName + "'. ");
                }

                datasetVersion.ContentDescriptors.Remove(contentDescriptor);

                datasetVersion.ModificationInfo = new EntityAuditInfo()
                {
                    Performer  = GetUsernameOrDefault(),
                    Comment    = "Attachment",
                    ActionType = AuditActionType.Delete
                };

                dm.EditDatasetVersion(datasetVersion, null, null, null);
                dm.CheckInDataset(dataset.Id, fileName, GetUsernameOrDefault(), ViewCreationBehavior.None);
            }

            return(RedirectToAction("showdata", "data", new { area = "ddm", id = datasetId }));
        }
Exemple #2
0
        /// <summary>
        /// load list of variables based on the dataset id
        /// </summary>
        /// <param name="datasetId"></param>
        /// <returns></returns>
        public SelectList GetVariables(long datasetId)
        {
            if (datasetId <= 0)
            {
                throw new Exception("Id is missing.");
            }

            using (var datasetManager = new DatasetManager())
                using (var dataStructureManager = new DataStructureManager())
                {
                    // load dataset and get datasturctureid
                    var dataset = datasetManager.GetDataset(datasetId);

                    if (dataset == null)
                    {
                        throw new Exception("Dataset with id " + datasetId + " not exist");
                    }

                    var structure = dataStructureManager.StructuredDataStructureRepo.Get(dataset.DataStructure.Id);

                    // check if datastrutcure is structured
                    if (structure == null)
                    {
                        throw new Exception("Datastructure is not structured");
                    }

                    if (structure.Variables.Any())
                    {
                        // return list of vairables als selection list
                        return(new SelectList(structure.Variables.Select(v => v.Label)));
                    }
                }

            return(new SelectList(new List <string>()));
        }
Exemple #3
0
        public List <EntityStoreItem> GetVersionsById(long id)
        {
            DatasetManager         dm  = new DatasetManager();
            List <EntityStoreItem> tmp = new List <EntityStoreItem>();

            try
            {
                var datasetIds    = dm.GetDatasetLatestIds();
                var datasetHelper = new XmlDatasetHelper();
                var versions      = dm.GetDataset(id).Versions.OrderBy(v => v.Timestamp).ToList();

                foreach (var v in versions)
                {
                    tmp.Add(new EntityStoreItem()
                    {
                        Id            = v.Id,
                        Title         = v.Title,
                        Version       = versions.IndexOf(v) + 1,
                        CommitComment = "(" + v.Timestamp.ToString("dd.MM.yyyy HH:mm") + "): " + v.ChangeDescription
                    });
                }

                return(tmp);
            }
            catch (Exception ex)
            {
                return(tmp);
            }
            finally
            {
                dm.Dispose();
            }
        }
Exemple #4
0
        private List <string> getVariableNames(long datasetId)
        {
            List <string>  vars           = new List <string>();
            DatasetManager datasetManager = new DatasetManager();

            try
            {
                var dataset = datasetManager.GetDataset(datasetId);

                if (dataset != null && dataset.DataStructure != null && dataset.DataStructure.Self is StructuredDataStructure)
                {
                    StructuredDataStructure sds = (StructuredDataStructure)dataset.DataStructure.Self;
                    if (sds != null)
                    {
                        sds.Variables.ToList().ForEach(v => vars.Add(v.Label));
                    }
                }

                return(vars);
            }
            catch (Exception ex)
            {
                return(new List <string>());
            }
            finally
            {
            }
        }
Exemple #5
0
        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);
                }
        }
Exemple #6
0
        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();
            }
        }
Exemple #7
0
        /// <summary>
        /// Return a value of the attribute from the incoming metadata
        /// </summary>
        /// <param name="datasetid"></param>
        /// <param name="metadata"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetInformation(long datasetid, XmlDocument metadata, NameAttributeValues name)
        {
            using (var unitOfWork = this.GetUnitOfWork())
                using (DatasetManager dm = new DatasetManager())
                    using (MetadataStructureManager msm = new MetadataStructureManager())
                    {
                        if (datasetid <= 0)
                        {
                            return(String.Empty);
                        }

                        var dataset = dm.GetDataset(datasetid);


                        MetadataStructure metadataStructure = msm.Repo.Get(dataset.MetadataStructure.Id);

                        if ((XmlDocument)metadataStructure.Extra == null)
                        {
                            return(string.Empty);
                        }

                        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();
                        string value = metadata.SelectSingleNode(xpath).InnerText;

                        return(string.IsNullOrWhiteSpace(value) ? "not available" : value);
                    }
        }
        //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 }));
        }
Exemple #9
0
        [TestCase(2)] // primary key as double
        public void GetSplitDatatuples_AllDataTuplesEdited_SameNumberOfDatatuples(int primaryKeyIndex)
        {
            Dataset          dataset;
            DatasetVersion   latest;
            List <DataTuple> incoming            = new List <DataTuple>();
            int         count                    = 0;
            int         expectedCount            = 0;
            List <long> datatupleFromDatabaseIds = new List <long>();

            using (DatasetManager datasetManager = new DatasetManager())
            {
                //Arrange
                dataset = datasetManager.GetDataset(datasetId);
                latest  = datasetManager.GetDatasetLatestVersion(datasetId);
                datatupleFromDatabaseIds = datasetManager.GetDatasetVersionEffectiveTupleIds(latest);

                //get updated tuples as incoming datatuples
                incoming = dsHelper.GetUpdatedDatatuples(latest, dataset.DataStructure as StructuredDataStructure, datasetManager);

                //because of updateing all datatuples the incoming number is should be equal then the existing one
                expectedCount = incoming.Count;
            }

            try
            {
                List <long> primaryKeys = new List <long>();

                //get primarykey ids
                // var 1 = int = 1
                // var 2 = string = 2
                // var 3 = double = 3
                // var 4 = boolean = 4
                // var 5 = datetime = 5
                List <long> varIds = ((StructuredDataStructure)dataset.DataStructure).Variables.Select(v => v.Id).ToList();

                primaryKeys.Add(varIds.ElementAt(primaryKeyIndex));

                //Act
                Dictionary <string, List <DataTuple> > splittedDatatuples = new Dictionary <string, List <DataTuple> >();
                UploadHelper uploadhelper = new UploadHelper();
                splittedDatatuples = uploadhelper.GetSplitDatatuples(incoming, primaryKeys, null, ref datatupleFromDatabaseIds);


                //Assert
                int newCount  = splittedDatatuples["new"].Count;
                int editCount = splittedDatatuples["edit"].Count;

                Assert.That(newCount, Is.EqualTo(0));
                Assert.That(editCount, Is.EqualTo(expectedCount));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #10
0
        public void GetDatasetVersionEffectiveDataTuples_CalledOlderVersionWithPaging_ReturnListOfAbstractTuples()
        {
            //Arrange
            DatasetManager datasetManager = null;
            int            pageSize       = 4;
            int            pageNumber     = 2;

            try
            {
                datasetManager = new DatasetManager();

                var latestDatasetVersionId = datasetManager.GetDatasetLatestVersionId(datasetId);

                //get latest datatupleid before create a new dataset and data
                using (var uow = this.GetUnitOfWork())
                {
                    var latestDataTuple = uow.GetReadOnlyRepository <DataTuple>().Get().LastOrDefault();
                    var firstDataTuple  = uow.GetReadOnlyRepository <DataTuple>().Get().Where(dt => dt.DatasetVersion.Id.Equals(latestDatasetVersionId)).FirstOrDefault();
                    if (latestDataTuple != null)
                    {
                        latestDataTupleId = latestDataTuple.Id;
                    }
                    if (firstDataTuple != null)
                    {
                        firstDataTupleId = firstDataTuple.Id;
                    }
                }

                var dataset = datasetManager.GetDataset(datasetId);

                dataset = dsHelper.UpdateOneTupleForDataset(dataset, (StructuredDataStructure)dataset.DataStructure, firstDataTupleId, 1, datasetManager);
                datasetManager.CheckInDataset(dataset.Id, "for testing  datatuples with versions", username, ViewCreationBehavior.None);

                dataset = dsHelper.UpdateOneTupleForDataset(dataset, (StructuredDataStructure)dataset.DataStructure, latestDataTupleId, 2, datasetManager);
                datasetManager.CheckInDataset(dataset.Id, "for testing  datatuples with versions", username, ViewCreationBehavior.None);


                //Act
                List <DatasetVersion> datasetversions = datasetManager.GetDatasetVersions(datasetId).OrderBy(d => d.Timestamp).ToList();
                var         resultAll  = datasetManager.GetDatasetVersionEffectiveTuples(datasetversions.ElementAt(datasetversions.Count - 2));
                List <long> comapreIds = resultAll.OrderBy(dt => dt.OrderNo).Skip(pageNumber * pageSize).Take(pageSize).Select(dt => dt.Id).ToList();


                var result    = datasetManager.GetDatasetVersionEffectiveTuples(datasetversions.ElementAt(datasetversions.Count - 2), pageNumber, pageSize); // get datatuples from the one before the latest
                var resultIds = result.Select(dt => dt.Id).ToList();

                //Assert
                Assert.That(comapreIds, Is.EquivalentTo(resultIds));
            }
            finally
            {
                datasetManager.Dispose();
            }
        }
        public void EditDatasetVersion_DeleteADataTupleAfterUpdate_ReturnUpdatedVersion()
        {
            Dataset        dataset;
            DatasetVersion latest;

            using (DatasetManager datasetManager = new DatasetManager())
            {
                //Arrange
                dataset = datasetManager.GetDataset(datasetId);
                latest  = datasetManager.GetDatasetLatestVersion(datasetId);

                //update the dataset
                dataset = dsHelper.UpdateAnyTupleForDataset(dataset, dataset.DataStructure as StructuredDataStructure, datasetManager);
                datasetManager.CheckInDataset(datasetId, "for testing  update all datatuple", username, ViewCreationBehavior.None);
            }

            using (DatasetManager datasetManager = new DatasetManager())
            {
                try
                {
                    latest = datasetManager.GetDatasetLatestVersion(datasetId);

                    int before = datasetManager.GetDataTuplesCount(latest.Id);
                    var tuple  = datasetManager.GetDataTuples(latest.Id).LastOrDefault();

                    //Act
                    if (datasetManager.IsDatasetCheckedOutFor(datasetId, "David") || datasetManager.CheckOutDataset(datasetId, "David"))
                    {
                        DatasetVersion workingCopy = datasetManager.GetDatasetWorkingCopy(datasetId);


                        List <AbstractTuple> deleteTuples = new List <AbstractTuple>();
                        deleteTuples.Add(tuple);

                        workingCopy = datasetManager.EditDatasetVersion(workingCopy, null, null, deleteTuples.Select(d => d.Id).ToList());

                        datasetManager.CheckInDataset(datasetId, "delete one datatuple for testing", username, ViewCreationBehavior.None);
                    }

                    latest = datasetManager.GetDatasetLatestVersion(datasetId);

                    int after = datasetManager.GetDataTuplesCount(latest.Id);


                    //Assert
                    Assert.That(before, Is.GreaterThan(after));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
        /// <summary>
        /// return the serialized data file
        /// if the file does not exist yet, it will be created
        /// </summary>
        /// <param name="mimeType"></param>
        /// <returns></returns>
        public ActionResult DownloadFile(string mimeType)
        {
            // make sure the file was created
            if ((null == Session[SESSION_FILE]) || !((Dictionary <string, string>)Session[SESSION_FILE]).ContainsKey(mimeType))
            {
                ActionResult res = PrepareDownloadFile(mimeType);

                // check, if everything went ok
                if (200 != Response.StatusCode)
                {
                    return(res);
                }
            }

            // get file path
            string path = ((Dictionary <string, string>)Session[SESSION_FILE])[mimeType];

            //send mail

            var    es = new EmailService();
            string user;

            using (UserManager userManager = new UserManager())
            {
                user = userManager.FindByNameAsync(HttpContext.User.Identity.Name).Result.DisplayName;
            }
            LUIQueryModel model = (LUIQueryModel)Session["LUICalModel"];
            long          datasetId;

            if (model.ComponentsSet.SelectedValue.Contains("old"))
            {
                datasetId = Convert.ToInt64(Models.Settings.get("lui:datasetOldComponentsSet"));
            }
            else
            {
                datasetId = Convert.ToInt64(Models.Settings.get("lui:datasetNewComponentsSet"));
            }
            int version;

            using (DatasetManager datasetManager = new DatasetManager())
            {
                version = datasetManager.GetDataset(datasetId).VersionNo;
            }

            string text = "LUI Calculation file <b>\"" + Path.GetFileName(path) + "\"</b> with id <b>(" + datasetId + ")</b> version <b>(" + version + ")</b> was downloaded by <b>" + user + "</b>";

            es.Send("LUI data was downloaded (Id: " + datasetId + ", Version: " + version + ")", text, "*****@*****.**");


            // return file for download
            return(File(path, mimeType, Path.GetFileName(path)));
        }
Exemple #13
0
        public void GetDataTuples_CallOlderVersionAfterTwoUpdates_ReturnIQueryable()
        {
            List <long> datatupleIds;

            try
            {
                //Arrange
                using (var datasetManager = new DatasetManager())
                {
                    var dataset        = datasetManager.GetDataset(datasetId);
                    var datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId);

                    Assert.IsNotNull(dataset);
                    Assert.IsNotNull(datasetVersion);

                    //get latest datatupleid before create a new dataset and data
                    using (var uow = this.GetUnitOfWork())
                    {
                        datatupleIds = uow.GetReadOnlyRepository <DataTuple>().Get().Where(dt => dt.DatasetVersion.Id.Equals(datasetVersion.Id)).Select(dt => dt.Id).ToList();
                    }

                    dataset = dsHelper.UpdateOneTupleForDataset(dataset, (StructuredDataStructure)dataset.DataStructure, datatupleIds[0], 1000, datasetManager);
                    datasetManager.CheckInDataset(dataset.Id, "for testing  datatuples with versions", username, ViewCreationBehavior.None);

                    dataset = dsHelper.UpdateOneTupleForDataset(dataset, (StructuredDataStructure)dataset.DataStructure, datatupleIds[1], 2000, datasetManager);
                    datasetManager.CheckInDataset(dataset.Id, "for testing  datatuples with versions", username, ViewCreationBehavior.None);
                }


                //Act
                using (var datasetManager = new DatasetManager())
                {
                    List <DatasetVersion> datasetversions = datasetManager.GetDatasetVersions(datasetId).OrderBy(d => d.Timestamp).ToList();
                    Assert.That(datasetversions.Count, Is.EqualTo(3));

                    foreach (var dsv in datasetversions)
                    {
                        int c = datasetManager.GetDataTuplesCount(dsv.Id);

                        var result = datasetManager.GetDataTuples(dsv.Id); // get datatuples from the one before the latest
                        int cm     = result.Count();
                        Assert.That(c, Is.EqualTo(10));
                        Assert.That(c, Is.EqualTo(result.Count()));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #14
0
        public JsonResult DisplayPattern(long id, string variable)
        {
            //id less then 1 is not possible so return empty string
            if (id <= 0)
            {
                return(Json("", JsonRequestBehavior.AllowGet));
            }

            using (var datasetManager = new DatasetManager())
                using (var dataStructureManager = new DataStructureManager())
                    using (var dataContainerManager = new DataContainerManager())
                        using (var dataTypeManager = new DataTypeManager())
                        {
                            var dataset = datasetManager.GetDataset(id);
                            if (dataset == null)
                            {
                                return(Json("", JsonRequestBehavior.AllowGet));
                            }

                            var datastructureId = dataset.DataStructure.Id;
                            var datastructure   = dataStructureManager.StructuredDataStructureRepo.Get(datastructureId);

                            var v = datastructure.Variables.Where(var => var.Label.ToLower().Equals(variable.ToLower())).FirstOrDefault();

                            //if variable not exit return false
                            if (v == null)
                            {
                                return(Json("", JsonRequestBehavior.AllowGet));
                            }

                            if (v.DataAttribute != null)
                            {
                                var attr = dataContainerManager.DataAttributeRepo.Get(v.DataAttribute.Id);
                                if (attr.DataType.SystemType.Equals("DateTime"))
                                {
                                    var dataType = dataTypeManager.Repo.Get(attr.DataType.Id);

                                    if (dataType != null && dataType.Extra != null)
                                    {
                                        DataTypeDisplayPattern dp = DataTypeDisplayPattern.Materialize(dataType.Extra);
                                        if (dp != null)
                                        {
                                            return(Json(dp.StringPattern, JsonRequestBehavior.AllowGet));
                                        }
                                    }
                                }
                            }
                        }

            return(Json("", JsonRequestBehavior.AllowGet));
        }
        public async void uploadFiles(List <HttpContent> attachments, long datasetId, String description, string userName, DatasetManager dm)
        {
            var dataset = dm.GetDataset(datasetId);

            // var datasetVersion = dm.GetDatasetLatestVersion(dataset);
            if (dm.IsDatasetCheckedOutFor(datasetId, userName) || dm.CheckOutDataset(datasetId, userName))
            {
                DatasetVersion datasetVersion = dm.GetDatasetWorkingCopy(datasetId);
                StringBuilder  files          = new StringBuilder();
                foreach (var httpContent in attachments)
                {
                    var dataStream = await httpContent.ReadAsStreamAsync();

                    var dataPath = AppConfiguration.DataPath;
                    var fileName = httpContent.Headers.ContentDisposition.FileName;
                    fileName = Regex.Replace(fileName.Trim(), "[^A-Za-z0-9_.() ]+", "");

                    if (!Directory.Exists(Path.Combine(dataPath, "Datasets", datasetId.ToString(), "Attachments")))
                    {
                        Directory.CreateDirectory(Path.Combine(dataPath, "Datasets", datasetId.ToString(), "Attachments"));
                    }
                    var destinationPath = Path.Combine(dataPath, "Datasets", datasetId.ToString(), "Attachments", fileName);

                    using (var fileStream = File.Create(destinationPath))
                    {
                        FileHelper.CopyStream(dataStream, fileStream);
                        fileStream.Close();

                        AddFileInContentDiscriptor(datasetVersion, fileName, description);

                        if (files.Length > 0)
                        {
                            files.Append(", ");
                        }
                        files.Append(fileName);
                    }
                }

                ////set modification
                datasetVersion.ModificationInfo = new EntityAuditInfo()
                {
                    Performer  = userName,
                    Comment    = "Attachment",
                    ActionType = AuditActionType.Edit
                };

                dm.EditDatasetVersion(datasetVersion, null, null, null);
                dm.CheckInDataset(dataset.Id, "File/s :" + files.ToString() + " via api", userName, ViewCreationBehavior.None);
            }
        }
Exemple #16
0
        public void GetSplitDatatuples_CombinedPrimaryKeyOneUpdatedDataTuple_ExpectedNumberOfEditDatatuples()
        {
            Dataset          dataset;
            DatasetVersion   latest;
            List <DataTuple> incoming            = new List <DataTuple>();
            int         count                    = 0;
            int         expectedCount            = 0;
            List <long> datatupleFromDatabaseIds = new List <long>();

            //setup the primary key conbination
            List <int> primaryKeysIndex = new List <int> {
                0, 2
            };
            List <long> primaryKeyIds = new List <long>();

            using (DatasetManager datasetManager = new DatasetManager())
            {
                //Arrange
                dataset = datasetManager.GetDataset(datasetId);
                latest  = datasetManager.GetDatasetLatestVersion(datasetId);
                datatupleFromDatabaseIds = datasetManager.GetDatasetVersionEffectiveTupleIds(latest);

                foreach (var dtid in datatupleFromDatabaseIds)
                {
                    var datatuple = datasetManager.DataTupleRepo.Get(dtid);
                    datatuple.Materialize();
                    incoming.Add(datatuple);
                }

                //updated last datatuple in text
                dsHelper.GetUpdatedDatatuple(incoming.Last(), 1);

                //get varids of primary key combination
                List <long> allVarIds = ((StructuredDataStructure)dataset.DataStructure).Variables.Select(v => v.Id).ToList();

                foreach (int pkIndex in primaryKeysIndex)
                {
                    primaryKeyIds.Add(allVarIds.ElementAt(pkIndex));
                }

                //Act
                Dictionary <string, List <DataTuple> > splittedDatatuples = new Dictionary <string, List <DataTuple> >();
                UploadHelper uploadhelper = new UploadHelper();
                splittedDatatuples = uploadhelper.GetSplitDatatuples(incoming, primaryKeyIds, null, ref datatupleFromDatabaseIds);

                //Assert
                Assert.That(splittedDatatuples["new"].Count, Is.EqualTo(0));
                Assert.That(splittedDatatuples["edit"].Count, Is.EqualTo(1));
            }
        }
Exemple #17
0
        public static GFBIODataCenterFormularObject GetGFBIODataCenterFormularObject(long datasetId)
        {
            DatasetManager datasetManager = new DatasetManager();

            try
            {
                Dataset          dataset          = datasetManager.GetDataset(datasetId);
                DatasetVersion   datasetVersion   = datasetManager.GetDatasetLatestVersion(datasetId);
                XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper();

                GFBIODataCenterFormularObject gfbioDataCenterFormularObject = new GFBIODataCenterFormularObject();

                //gfbioDataCenterFormularObject.ProjectId = 1;
                //gfbioDataCenterFormularObject.ProjectTitle = "Test Poject title";
                //gfbioDataCenterFormularObject.ProjectLabel = "Test Poject label";
                //gfbioDataCenterFormularObject.ProjectAbstract = "";
                //gfbioDataCenterFormularObject.ProjectPi = "ProjectPi";

                //gfbioDataCenterFormularObject.UserId = 1;
                //gfbioDataCenterFormularObject.UserName = "******";
                //gfbioDataCenterFormularObject.UserEmail = "testEmail";
                //gfbioDataCenterFormularObject.DatasetAuthor = "TestAuthor";

                gfbioDataCenterFormularObject.DatasetId          = datasetId;
                gfbioDataCenterFormularObject.DatasetVersion     = datasetVersion.Id;
                gfbioDataCenterFormularObject.License            = "";
                gfbioDataCenterFormularObject.DatasetTitle       = xmlDatasetHelper.GetInformation(datasetId, NameAttributeValues.title);
                gfbioDataCenterFormularObject.DatasetLabel       = xmlDatasetHelper.GetInformation(datasetId, NameAttributeValues.title);
                gfbioDataCenterFormularObject.DatasetDescription = xmlDatasetHelper.GetInformation(datasetId, NameAttributeValues.description);
                //gfbioDataCenterFormularObject.DatasetAuthors = new List<string>();



                gfbioDataCenterFormularObject.DatasetCollectionTime = datasetVersion.Dataset.LastCheckIOTimestamp;

                MetadataStructureManager metadataStructureManager = new MetadataStructureManager();
                MetadataStructure        metadataStructure        = metadataStructureManager.Repo.Get(dataset.MetadataStructure.Id);

                gfbioDataCenterFormularObject.MetadataSchemaName = metadataStructure.Name;


                return(gfbioDataCenterFormularObject);
            }
            finally
            {
                datasetManager.Dispose();
            }
        }
Exemple #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datasetid"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public string GetTransmissionInformation(long datasetid, TransmissionType type)
        {
            DatasetManager dm = new DatasetManager();

            try
            {
                Dataset        dataset        = dm.GetDataset(datasetid);
                DatasetVersion datasetVersion = dm.GetDatasetLatestVersion(dataset);

                return(GetTransmissionInformation(datasetVersion.Id, type));
            }
            finally
            {
                dm.Dispose();
            }
        }
        public ActionResult AddSelectedDatasetToBus(string id)
        {
            DatasetManager datasetManager = new DatasetManager();

            try
            {
                ChooseDatasetViewModel model = new ChooseDatasetViewModel();

                long    datasetId = Convert.ToInt64(id);
                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) && TaskManager.Bus[TaskManager.DATASET_TITLE] != null)
                {
                    model.DatasetTitle = TaskManager.Bus[TaskManager.DATASET_TITLE].ToString();
                }
                model.SelectedDatasetId = Convert.ToInt32(id);
                return(PartialView("SpecifyDataset", model));
            }
            finally
            {
                datasetManager.Dispose();
            }
        }
Exemple #20
0
        public bool Exist(long id)
        {
            DatasetManager dm      = new DatasetManager();
            Dataset        dataset = null;

            try
            {
                dataset = dm.GetDataset(id);
                return(dataset != null? true:false);
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                dm.Dispose();
            }
        }
        public static GFBIOPangaeaFormularObject GetGFBIOPangaeaFormularObject(long datasetId)
        {
            using (DatasetManager datasetManager = new DatasetManager())
                using (MetadataStructureManager metadataStructureManager = new MetadataStructureManager())
                {
                    Dataset        dataset        = datasetManager.GetDataset(datasetId);
                    DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(datasetId);

                    MetadataStructure metadataStructure = metadataStructureManager.Repo.Get(dataset.MetadataStructure.Id);

                    GFBIOPangaeaFormularObject gfbioPangaeaFormularObject = new GFBIOPangaeaFormularObject();

                    XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper();

                    string title       = datasetVersion.Title;
                    string description = datasetVersion.Description;

                    return(gfbioPangaeaFormularObject);
                }
        }
Exemple #22
0
        public string GetEntityName(long datasetid)
        {
            DatasetManager           datasetManager           = new DatasetManager();
            MetadataStructureManager metadataStructureManager = new MetadataStructureManager();

            try
            {
                Dataset dataset = datasetManager.GetDataset(datasetid);

                // get MetadataStructure
                if (dataset != null)
                {
                    return(GetEntityNameFromMetadatStructure(dataset.MetadataStructure.Id));
                }
                return(string.Empty);
            }
            finally
            {
                datasetManager.Dispose();
                metadataStructureManager.Dispose();
            }
        }
        public IEnumerable <ApiSimpleDatasetModel> Get()
        {
            DatasetManager datasetManager = new DatasetManager();
            List <ApiSimpleDatasetModel> datasetModels = new List <ApiSimpleDatasetModel>();

            try
            {
                IEnumerable <long> datasetIds = datasetManager.DatasetRepo.Get().Select(d => d.Id);

                foreach (long id in datasetIds)
                {
                    Dataset tmpDataset = datasetManager.GetDataset(id);
                    ApiSimpleDatasetModel datasetModel = new ApiSimpleDatasetModel();
                    datasetModel.Id = tmpDataset.Id;

                    DatasetVersion[] tmpVersions = tmpDataset.Versions.OrderBy(ds => ds.Timestamp).ToArray();

                    for (int i = 0; i < tmpVersions.Length; i++)
                    {
                        DatasetVersion dsv = tmpVersions.ElementAt(i);
                        ApiSimpleDatasetVersionModel datasetVersionModel = new ApiSimpleDatasetVersionModel()
                        {
                            Id     = dsv.Id,
                            Number = i + 1
                        };

                        datasetModel.Versions.Add(datasetVersionModel);
                    }

                    datasetModels.Add(datasetModel);
                }

                return(datasetModels);
            }
            finally
            {
                datasetManager.Dispose();
            }
        }
Exemple #24
0
        public int CountVersions(long id)
        {
            DatasetManager dm = new DatasetManager();

            try
            {
                var datasetIds    = dm.GetDatasetLatestIds();
                var datasetHelper = new XmlDatasetHelper();

                int version = dm.GetDataset(id).Versions.Count;

                return(version);
            }
            catch (Exception ex)
            {
                return(0);
            }
            finally
            {
                dm.Dispose();
            }
        }
Exemple #25
0
        public ActionResult CountRows(long id)
        {
            int number = 0;

            using (DatasetManager dm = new DatasetManager())
            {
                try
                {
                    if (id > 0)
                    {
                        Dataset ds = dm.GetDataset(id);
                        number = ds.DataStructure.Self is StructuredDataStructure?dm.GetDatasetLatestVersionEffectiveTupleCount(ds) : 0;
                    }

                    return(Json(number, JsonRequestBehavior.AllowGet));
                }
                finally
                {
                    dm.Dispose();
                }
            }
        }
Exemple #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datasetid"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public string GetInformation(long datasetid, NameAttributeValues name)
        {
            DatasetManager dm = new DatasetManager();

            try
            {
                //DatasetVersion datasetVersion = dm.GetDatasetLatestVersion(datasetid);
                var dataset = dm.GetDataset(datasetid);

                if (!dm.IsDatasetCheckedIn(datasetid))
                {
                    return(string.Empty);
                }

                var versionId = dm.GetDatasetLatestVersionId(datasetid);

                return(GetInformationFromVersion(versionId, dataset.MetadataStructure.Id, name));
            }
            finally
            {
                dm.Dispose();
            }
        }
Exemple #27
0
        public void GetDataTuples_WhenCalledOneOlderVersion_ReturnIQueryableOfAbstractTuples()
        {
            //Arrange
            DatasetManager datasetManager = null;

            try
            {
                datasetManager = new DatasetManager();

                //get latest datatupleid before create a new dataset and data
                using (var uow = this.GetUnitOfWork())
                {
                    var latestDataTuple = uow.GetReadOnlyRepository <DataTuple>().Get().LastOrDefault();
                    if (latestDataTuple != null)
                    {
                        latestDataTupleId = latestDataTuple.Id;
                    }
                }

                var dataset = datasetManager.GetDataset(datasetId);

                dataset = dsHelper.UpdateOneTupleForDataset(dataset, (StructuredDataStructure)dataset.DataStructure, latestDataTupleId, 1, datasetManager);
                datasetManager.CheckInDataset(dataset.Id, "for testing  datatuples with versions", username, ViewCreationBehavior.None);

                //Act
                List <DatasetVersion> datasetversions = datasetManager.GetDatasetVersions(datasetId).OrderBy(d => d.Timestamp).ToList();
                var result = datasetManager.GetDataTuples(datasetversions.ElementAt(datasetversions.Count - 2).Id); // get datatuples from the one before the latest

                //Assert
                Assert.That(result.Count(), Is.EqualTo(10));
            }
            finally
            {
                datasetManager.Dispose();
            }
        }
        [TestCase(2)] // primary key as double
        public void EditDatasetVersion_UpdateAllDataTuples_SameNumberOfDatatuples(int primaryKeyIndex)
        {
            Dataset          dataset;
            DatasetVersion   latest;
            List <DataTuple> incoming            = new List <DataTuple>();
            int         count                    = 0;
            int         expectedCount            = 0;
            List <long> datatupleFromDatabaseIds = new List <long>();

            using (DatasetManager datasetManager = new DatasetManager())
            {
                //Arrange
                dataset = datasetManager.GetDataset(datasetId);
                latest  = datasetManager.GetDatasetLatestVersion(datasetId);
                datatupleFromDatabaseIds = datasetManager.GetDatasetVersionEffectiveTupleIds(latest);

                //get updated tuples as incoming datatuples
                incoming = dsHelper.GetUpdatedDatatuples(latest, dataset.DataStructure as StructuredDataStructure, datasetManager);

                //because of updateing all datatuples the incoming number is should be equal then the existing one
                expectedCount = incoming.Count;
            }

            using (DatasetManager datasetManager = new DatasetManager())
            {
                try
                {
                    if (datasetManager.IsDatasetCheckedOutFor(datasetId, "David") || datasetManager.CheckOutDataset(datasetId, "David"))
                    {
                        DatasetVersion workingCopy = datasetManager.GetDatasetWorkingCopy(datasetId);
                        List <long>    primaryKeys = new List <long>();

                        //get primarykey ids
                        // var 1 = int = 1
                        // var 2 = string = 2
                        // var 3 = double = 3
                        // var 4 = boolean = 4
                        // var 5 = datetime = 5
                        List <long> varIds = ((StructuredDataStructure)workingCopy.Dataset.DataStructure).Variables.Select(v => v.Id).ToList();

                        primaryKeys.Add(varIds.ElementAt(primaryKeyIndex));

                        //Act
                        Dictionary <string, List <DataTuple> > splittedDatatuples = new Dictionary <string, List <DataTuple> >();
                        UploadHelper uploadhelper = new UploadHelper();
                        splittedDatatuples = uploadhelper.GetSplitDatatuples(incoming, primaryKeys, workingCopy, ref datatupleFromDatabaseIds);
                        datasetManager.EditDatasetVersion(workingCopy, splittedDatatuples["new"], splittedDatatuples["edit"], null);
                        datasetManager.CheckInDataset(datasetId, count + " rows", "David");


                        //Assert
                        long c = datasetManager.GetDatasetVersionEffectiveTupleCount(workingCopy);
                        Assert.That(c, Is.EqualTo(expectedCount));
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Exemple #29
0
        public void uploadFiles(IEnumerable <HttpPostedFileBase> attachments, long datasetId, String description)
        {
            var filemNames = "";

            using (var dm = new DatasetManager())
            {
                var dataset = dm.GetDataset(datasetId);
                // var datasetVersion = dm.GetDatasetLatestVersion(dataset);

                DatasetVersion latestVersion = dm.GetDatasetLatestVersion(datasetId);
                string         status        = DatasetStateInfo.NotValid.ToString();
                if (latestVersion.StateInfo != null)
                {
                    status = latestVersion.StateInfo.State;
                }

                if (dm.IsDatasetCheckedOutFor(datasetId, GetUsernameOrDefault()) || dm.CheckOutDataset(datasetId, GetUsernameOrDefault()))
                {
                    DatasetVersion datasetVersion = dm.GetDatasetWorkingCopy(datasetId);

                    //set StateInfo of the previus version
                    if (datasetVersion.StateInfo == null)
                    {
                        datasetVersion.StateInfo = new Vaiona.Entities.Common.EntityStateInfo()
                        {
                            State = status
                        };
                    }
                    else
                    {
                        datasetVersion.StateInfo.State = status;
                    }


                    foreach (var file in attachments)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        filemNames += fileName.ToString() + ",";
                        var dataPath = AppConfiguration.DataPath;
                        if (!Directory.Exists(Path.Combine(dataPath, "Datasets", datasetId.ToString(), "Attachments")))
                        {
                            Directory.CreateDirectory(Path.Combine(dataPath, "Datasets", datasetId.ToString(), "Attachments"));
                        }
                        var destinationPath = Path.Combine(dataPath, "Datasets", datasetId.ToString(), "Attachments", fileName);
                        file.SaveAs(destinationPath);
                        AddFileInContentDiscriptor(datasetVersion, fileName, description);
                    }

                    //set modification
                    datasetVersion.ModificationInfo = new EntityAuditInfo()
                    {
                        Performer  = GetUsernameOrDefault(),
                        Comment    = "Attachment",
                        ActionType = AuditActionType.Create
                    };

                    string filenameList = string.Join(", ", attachments.Select(f => f.FileName).ToArray());

                    dm.EditDatasetVersion(datasetVersion, null, null, null);
                    dm.CheckInDataset(dataset.Id, filenameList, GetUsernameOrDefault(), ViewCreationBehavior.None);
                }
            }
        }
        private HttpResponseMessage getData(long id, int variableId, string token)
        {
            DatasetManager          datasetManager          = new DatasetManager();
            UserManager             userManager             = new UserManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
            EntityManager           entityManager           = new EntityManager();
            DataStructureManager    dataStructureManager    = null;

            bool isPublic = false;

            try
            {
                // if a dataset is public, then the api should also return data if there is no token for a user

                #region is public
                dataStructureManager = new DataStructureManager();

                long?entityTypeId = entityManager.FindByName(typeof(Dataset).Name)?.Id;
                entityTypeId = entityTypeId.HasValue ? entityTypeId.Value : -1;

                isPublic = entityPermissionManager.Exists(null, entityTypeId.Value, id);

                #endregion is public

                if (!isPublic && String.IsNullOrEmpty(token))

                {
                    var request = Request.CreateResponse();
                    request.Content = new StringContent("Bearer token not exist.");

                    return(request);
                }

                User user = userManager.Users.Where(u => u.Token.Equals(token)).FirstOrDefault();

                if (isPublic || user != null)
                {
                    if (isPublic || entityPermissionManager.HasEffectiveRight(user.Name, typeof(Dataset), id, RightType.Read))
                    {
                        XmlDatasetHelper  xmlDatasetHelper    = new XmlDatasetHelper();
                        OutputDataManager ioOutputDataManager = new OutputDataManager();

                        Dataset        dataset        = datasetManager.GetDataset(id);
                        DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(id);

                        string title = datasetVersion.Title;

                        // check the data sturcture type ...
                        if (datasetVersion.Dataset.DataStructure.Self is StructuredDataStructure)
                        {
                            object stats = new object();

                            DataTable dt = new DataTable("Varibales");

                            List <ApiDataStatisticModel> dataStatisticModels = new List <ApiDataStatisticModel>();
                            if (variableId == -1)
                            {
                                StructuredDataStructure structuredDataStructure = dataStructureManager.StructuredDataStructureRepo.Get(datasetVersion.Dataset.DataStructure.Id);
                                List <string>           varIds = new List <string>();
                                foreach (Variable vs in structuredDataStructure.Variables)
                                {
                                    varIds.Add("var" + vs.Id);
                                }
                                dt = GetDuplicates(id, varIds);
                            }
                            else
                            {
                            }
                            //dt.Strip();


                            dt.TableName = id + "_data";

                            DatasetModel model = new DatasetModel();
                            model.DataTable = dt;

                            var    response = Request.CreateResponse(HttpStatusCode.OK);
                            string resp     = JsonConvert.SerializeObject(model);

                            response.Content = new StringContent(resp, System.Text.Encoding.UTF8, "application/json");
                            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                            return(response);
                        }
                        else
                        {
                            return(Request.CreateResponse());
                        }
                    }
                    else // has rights?
                    {
                        var request = Request.CreateResponse();
                        request.Content = new StringContent("User has no read right.");

                        return(request);
                    }
                }
                else
                {
                    var request = Request.CreateResponse();
                    request.Content = new StringContent("User is not available.");

                    return(request);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                datasetManager.Dispose();
                userManager.Dispose();
                entityPermissionManager.Dispose();
                entityManager.Dispose();
                dataStructureManager.Dispose();
            }
        }