Example #1
0
        /// <summary>
        /// Purges a dataset, which means the dataset and all its versions will be physically removed from the database.
        /// </summary>
        /// <param name="id">the identifier of the dataset to be purged.</param>
        /// <remarks>This operation is not revocerable.</remarks>
        /// <returns></returns>
        public ActionResult Purge(long id)
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Purge", Session.GetTenant());

            DatasetManager dm = new DatasetManager();
            var            entityPermissionManager = new EntityPermissionManager();

            try
            {
                if (dm.PurgeDataset(id))
                {
                    entityPermissionManager.Delete(typeof(Dataset), id);

                    if (this.IsAccessibale("DDM", "SearchIndex", "ReIndexUpdateSingle"))
                    {
                        var x = this.Run("DDM", "SearchIndex", "ReIndexUpdateSingle", new RouteValueDictionary()
                        {
                            { "id", id }, { "actionType", "DELETE" }
                        });
                    }
                }
            }
            catch (Exception e)
            {
                ViewData.ModelState.AddModelError("", string.Format("Dataset {0} could not be purged.", id));
            }
            return(View());
        }
Example #2
0
        public void PurgeAllDatasets()
        {
            DatasetManager dm = new DatasetManager();

            try
            {
                dm.GetDatasetLatestIds(true).ForEach(dsId => dm.PurgeDataset(dsId));
            }
            finally
            {
                dm.Dispose();
            }
        }
Example #3
0
        public void CreateDatasetVersionTest()
        {
            long numberOfTuples = 1000;
            var  dm             = new DatasetManager();
            var  rsm            = new ResearchPlanManager();
            var  mdm            = new MetadataStructureManager();

            try
            {
                var dsHelper = new DatasetHelper();
                StructuredDataStructure dataStructure = dsHelper.CreateADataStructure();
                dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

                var rp = dsHelper.CreateResearchPlan();
                rp.Should().NotBeNull("Failed to meet a precondition: a research plan is required.");

                var mds = mdm.Repo.Query().First();
                mds.Should().NotBeNull("Failed to meet a precondition: a metadata strcuture is required.");

                Dataset dataset = dm.CreateEmptyDataset(dataStructure, rp, mds);
                dataset = dsHelper.GenerateTuplesForDataset(dataset, dataStructure, numberOfTuples, "Javad");
                dataset.Should().NotBeNull("The dataset tuple generation has failed!");

                dm.CheckInDataset(dataset.Id, "for testing purposes 2", "Javad", ViewCreationBehavior.None);
                //dm.SyncView(ds.Id, ViewCreationBehavior.Create);
                //dm.SyncView(ds.Id, ViewCreationBehavior.Refresh);
                dm.SyncView(dataset.Id, ViewCreationBehavior.Create | ViewCreationBehavior.Refresh);

                dataset.Id.Should().BeGreaterThan(0, "Dataset was not persisted.");
                dataset.LastCheckIOTimestamp.Should().NotBeAfter(DateTime.UtcNow, "The dataset's timestamp is wrong.");
                dataset.DataStructure.Should().NotBeNull("Dataset must have a data structure.");
                dataset.Status.Should().Be(DatasetStatus.CheckedIn, "Dataset must be in the CheckedIn status.");
                dm.GetDatasetLatestVersionEffectiveTupleCount(dataset.Id).Should().Be(numberOfTuples);

                dm.DatasetVersionRepo.Evict();
                dm.DataTupleRepo.Evict();
                dm.DatasetRepo.Evict();
                dm.PurgeDataset(dataset.Id, true);

                dsHelper.PurgeAllDataStructures();
            }
            finally
            {
                dm.Dispose();
                rsm.Dispose();
                mdm.Dispose();
            }
        }
Example #4
0
        public void DeleteDatasetTest()
        {
            var dm  = new DatasetManager();
            var rsm = new ResearchPlanManager();
            var mdm = new MetadataStructureManager();

            try
            {
                var dsHelper = new DatasetHelper();
                StructuredDataStructure dataStructure = dsHelper.CreateADataStructure();
                dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

                var rp = dsHelper.CreateResearchPlan();
                rp.Should().NotBeNull("Failed to meet a precondition: a research plan is required.");

                var mds = mdm.Repo.Query().First();
                mds.Should().NotBeNull("Failed to meet a precondition: a metadata strcuture is required.");

                Dataset dataset = dm.CreateEmptyDataset(dataStructure, rp, mds);
                dm.DeleteDataset(dataset.Id, "Javad", false);

                dataset.Should().NotBeNull();
                dataset.Id.Should().BeGreaterThan(0, "Dataset is not persisted.");
                dataset.LastCheckIOTimestamp.Should().NotBeAfter(DateTime.UtcNow, "The dataset's timestamp is wrong.");
                dataset.DataStructure.Should().NotBeNull("Dataset must have a data structure.");
                dataset.Status.Should().Be(DatasetStatus.Deleted, "Dataset must be in Deleted status.");

                dm.PurgeDataset(dataset.Id);
                dsHelper.PurgeAllDataStructures();
            }
            finally
            {
                dm.Dispose();
                rsm.Dispose();
                mdm.Dispose();
            }
        }
Example #5
0
        public void ProjectExpressionTest()
        {
            var dsHelper = new DatasetHelper();
            StructuredDataStructure dataStructure = dsHelper.CreateADataStructure();

            dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

            string var1Name = "var" + dataStructure.Variables.First().Id;
            string var3Name = "var" + dataStructure.Variables.Skip(2).First().Id;

            //create prjection expression
            ProjectionExpression projectionExpression = new ProjectionExpression();

            projectionExpression.Items.Add(new ProjectionItemExpression()
            {
                FieldName = var1Name
            });
            projectionExpression.Items.Add(new ProjectionItemExpression()
            {
                FieldName = var3Name
            });

            // create a dataset and test the filter, sorting, and projectgion
            long numberOfTuples = 10;
            var  dm             = new DatasetManager();
            var  rsm            = new ResearchPlanManager();
            var  mdm            = new MetadataStructureManager();

            try
            {
                dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

                var rp = dsHelper.CreateResearchPlan();
                rp.Should().NotBeNull("Failed to meet a precondition: a research plan is required.");

                var mds = mdm.Repo.Query().First();
                mds.Should().NotBeNull("Failed to meet a precondition: a metadata strcuture is required.");

                Dataset dataset = dm.CreateEmptyDataset(dataStructure, rp, mds);
                dataset = dsHelper.GenerateTuplesForDataset(dataset, dataStructure, numberOfTuples, "Javad");
                dataset.Should().NotBeNull("The dataset tuple generation has failed!");

                dm.CheckInDataset(dataset.Id, "for testing purposes 2", "Javad", ViewCreationBehavior.None);
                dm.SyncView(dataset.Id, ViewCreationBehavior.Create | ViewCreationBehavior.Refresh);

                dataset.Id.Should().BeGreaterThan(0, "Dataset was not persisted.");
                dataset.LastCheckIOTimestamp.Should().NotBeAfter(DateTime.UtcNow, "The dataset's timestamp is wrong.");
                dataset.DataStructure.Should().NotBeNull("Dataset must have a data structure.");
                dataset.Status.Should().Be(DatasetStatus.CheckedIn, "Dataset must be in the CheckedIn status.");
                dm.GetDatasetLatestVersionEffectiveTupleCount(dataset.Id).Should().Be(numberOfTuples);

                // pass this filter to get a subset of dataset X
                var dst = dm.GetLatestDatasetVersionTuples(dataset.Id, null, null, projectionExpression, 1, 3);
                dst.Should().NotBeNull();
                dst.Rows.Count.Should().BeLessOrEqualTo(3);
                dst.Columns.Count.Should().BeLessOrEqualTo(3, "Projection failed, wrong number of columns");

                dm.DatasetVersionRepo.Evict();
                dm.DataTupleRepo.Evict();
                dm.DatasetRepo.Evict();
                dm.PurgeDataset(dataset.Id, true);
                dsHelper.PurgeAllDataStructures();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dm.Dispose();
                rsm.Dispose();
                mdm.Dispose();
            }
        }
Example #6
0
        public void CreateAndExpressionForQueryingTest()
        {
            var dsHelper = new DatasetHelper();
            StructuredDataStructure dataStructure = dsHelper.CreateADataStructure();

            dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

            string var1Name = "var" + dataStructure.Variables.First().Id;
            string var2Name = "var" + dataStructure.Variables.Skip(1).First().Id;

            FilterExpression fex = BinaryFilterExpression
                                   .And(
                new FilterNumberItemExpression()
            {
                Field = new Field()
                {
                    DataType = Utils.NH.Querying.DataType.Ineteger, Name = var1Name
                }
                ,
                Operator = NumberOperator.Operation.GreaterThan
                ,
                Value = 12
            }
                ,
                new FilterStringItemExpression()
            {
                Field = new Field()
                {
                    DataType = Utils.NH.Querying.DataType.String, Name = var2Name
                }
                ,
                Operator = StringOperator.Operation.EndsWith
                ,
                Value = "Test"
            }
                );

            fex.ToSQL().Should().Be($"(({var1Name}) > (12)) AND (({var2Name}) ILIKE ('%Test'))");

            // this is to show how to apply a NOT operator on any other expression.
            // It can be applied on Numeric, String, Date, and any other type of expression
            FilterExpression notFex = UnaryFilterExpression.Not(fex);

            notFex.ToSQL().Should().Be($"NOT ((({var1Name}) > (12)) AND (({var2Name}) ILIKE ('%Test')))");
            notFex.ToSQL().Should().Be($"NOT ({fex.ToSQL()})");

            OrderByExpression orderByExpr = new OrderByExpression(
                new List <OrderItemExpression>()
            {
                new OrderItemExpression(var1Name),
                new OrderItemExpression(var2Name, SortDirection.Descending)
            });

            orderByExpr.ToSQL().Should().Be($"{var1Name} ASC, {var2Name} DESC");

            // create a dataset and test the filter, sorting, and projectgion
            long numberOfTuples = 100;
            var  dm             = new DatasetManager();
            var  rsm            = new ResearchPlanManager();
            var  mdm            = new MetadataStructureManager();

            try
            {
                dataStructure.Should().NotBeNull("Failed to meet a precondition: a data strcuture is required.");

                var rp = dsHelper.CreateResearchPlan();
                rp.Should().NotBeNull("Failed to meet a precondition: a research plan is required.");

                var mds = mdm.Repo.Query().First();
                mds.Should().NotBeNull("Failed to meet a precondition: a metadata strcuture is required.");

                Dataset dataset = dm.CreateEmptyDataset(dataStructure, rp, mds);
                dataset = dsHelper.GenerateTuplesForDataset(dataset, dataStructure, numberOfTuples, "Javad");
                dataset.Should().NotBeNull("The dataset tuple generation has failed!");

                dm.CheckInDataset(dataset.Id, "for testing purposes 2", "Javad", ViewCreationBehavior.None);
                dm.SyncView(dataset.Id, ViewCreationBehavior.Create | ViewCreationBehavior.Refresh);

                dataset.Id.Should().BeGreaterThan(0, "Dataset was not persisted.");
                dataset.LastCheckIOTimestamp.Should().NotBeAfter(DateTime.UtcNow, "The dataset's timestamp is wrong.");
                dataset.DataStructure.Should().NotBeNull("Dataset must have a data structure.");
                dataset.Status.Should().Be(DatasetStatus.CheckedIn, "Dataset must be in the CheckedIn status.");
                dm.GetDatasetLatestVersionEffectiveTupleCount(dataset.Id).Should().Be(numberOfTuples);

                // pass this filter to get a subset of dataset X
                var dst = dm.GetLatestDatasetVersionTuples(dataset.Id, fex, null, null, 1, 10);
                dst.Should().NotBeNull();
                dst.Rows.Count.Should().BeLessOrEqualTo(10);

                dm.DatasetVersionRepo.Evict();
                dm.DataTupleRepo.Evict();
                dm.DatasetRepo.Evict();
                dm.PurgeDataset(dataset.Id, true);

                dsHelper.PurgeAllDataStructures();
            }
            finally
            {
                dm.Dispose();
                rsm.Dispose();
                mdm.Dispose();
            }
        }
Example #7
0
        public ActionResult Purge(long id)
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Purge", Session.GetTenant());

            using (DatasetManager dm = new DatasetManager())
                using (var entityPermissionManager = new EntityPermissionManager())
                    using (var datasetManager = new DatasetManager())
                        using (var entityManager = new EntityManager())
                            using (var userManager = new UserManager())
                            {
                                try
                                {
                                    var userName = GetUsernameOrDefault();
                                    var user     = userManager.Users.Where(u => u.Name.Equals(userName)).FirstOrDefault();

                                    // check if a user is logged in
                                    if (user != null)
                                    {
                                        // is the user allowed to delete this dataset
                                        if (entityPermissionManager.HasEffectiveRight(user.UserName, typeof(Dataset), id, Security.Entities.Authorization.RightType.Delete))
                                        {
                                            if (dm.PurgeDataset(id))
                                            {
                                                entityPermissionManager.Delete(typeof(Dataset), id);

                                                var es = new EmailService();
                                                es.Send(MessageHelper.GetPurgeDatasetHeader(id),
                                                        MessageHelper.GetPurgeDatasetMessage(id, user.Name),
                                                        ConfigurationManager.AppSettings["SystemEmail"]
                                                        );


                                                if (this.IsAccessible("DDM", "SearchIndex", "ReIndexUpdateSingle"))
                                                {
                                                    var x = this.Run("DDM", "SearchIndex", "ReIndexUpdateSingle", new RouteValueDictionary()
                                                    {
                                                        { "id", id }, { "actionType", "DELETE" }
                                                    });
                                                }
                                            }
                                        }
                                        else // user is not allowed
                                        {
                                            ViewData.ModelState.AddModelError("", $@"You do not have the permission to purge the record.");

                                            var es = new EmailService();
                                            es.Send(MessageHelper.GetTryToPurgeDatasetHeader(id),
                                                    MessageHelper.GetTryToPurgeDatasetMessage(id, user.Name),
                                                    ConfigurationManager.AppSettings["SystemEmail"]
                                                    );
                                        }
                                    }
                                    else // no user exist
                                    {
                                        ViewData.ModelState.AddModelError("", $@"This function can only be executed with a logged-in user.");
                                        var es = new EmailService();
                                        es.Send(MessageHelper.GetTryToPurgeDatasetHeader(id),
                                                MessageHelper.GetTryToPurgeDatasetMessage(id, userName),
                                                ConfigurationManager.AppSettings["SystemEmail"]
                                                );
                                    }
                                }
                                catch (Exception e)
                                {
                                    ViewData.ModelState.AddModelError("", string.Format("Dataset {0} could not be purged.", id));
                                }
                            }
            return(View());
        }