public ActionResult Activity()
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Manage Activities", Session.GetTenant());
            List <ActivityModel> model = new List <ActivityModel>();

            using (var rManager = new ActivityManager())
                using (var permissionManager = new EntityPermissionManager())
                    using (var entityTypeManager = new EntityManager())
                    {
                        List <Activity> data = rManager.GetAllActivities().ToList();

                        // get id from loged in user
                        long userId = UserHelper.GetUserId(HttpContext.User.Identity.Name);

                        // get entity type id
                        long entityTypeId = entityTypeManager.FindByName("Activity").Id;

                        foreach (Activity a in data)
                        {
                            ActivityModel temp = new ActivityModel(a);
                            // temp.InUse = rManager.IsInEvent(a.Id);

                            // get permission from logged in user
                            temp.EditAccess = permissionManager.HasEffectiveRight(userId, new List <long> {
                                entityTypeId
                            }, a.Id, RightType.Read);
                            temp.DeleteAccess = permissionManager.HasEffectiveRight(userId, new List <long> {
                                entityTypeId
                            }, a.Id, RightType.Delete);

                            model.Add(temp);
                        }
                    }
            return(View("ActivityManager", model));
        }
        // GET: ShowMultimediaData
        public ActionResult Index(long datasetID, string entityType = "Dataset")
        {
            ViewData["id"] = datasetID;

            EntityPermissionManager entityPermissionManager = null;

            try
            {
                entityPermissionManager = new EntityPermissionManager();

                ViewData["edit"] = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Write);

                bool access = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Read);

                if (access)
                {
                    return(View(getFilesByDatasetId(datasetID, entityType)));
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
            finally
            {
                entityPermissionManager.Dispose();
            }
        }
        public List <FileInformation> getFilesByDatasetId(long datasetId, string entityType, long versionNo = 0)
        {
            EntityPermissionManager entityPermissionManager = null;
            DatasetManager          datasetManager          = null;

            try
            {
                entityPermissionManager = new EntityPermissionManager();
                datasetManager          = new DatasetManager();
                bool access = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetId, RightType.Read);
                if (access)
                {
                    Session["EntityType"] = entityType;
                    return(getFilesByDataset(datasetManager.DatasetRepo.Get(datasetId), datasetManager, entityType, versionNo));
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }
            finally
            {
                entityPermissionManager.Dispose();
                datasetManager.Dispose();
            }
        }
Beispiel #4
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var entityPermissionManager = new EntityPermissionManager();
            var userManager             = new UserManager();

            try
            {
                var userName = string.Empty;
                if (filterContext.HttpContext.User.Identity.IsAuthenticated)
                {
                    userName = filterContext.HttpContext.User.Identity.Name;
                }

                if (!entityPermissionManager.HasEffectiveRight(userName, entityType, Convert.ToInt64(filterContext.ActionParameters[keyName]), rightType))
                {
                    filterContext.Result = new RedirectToRouteResult(new
                                                                     RouteValueDictionary {
                        { "action", "AccessDenied" },
                        { "controller", "Error" },
                        { "Area", string.Empty }
                    });
                }
            }
            finally
            {
                entityPermissionManager.Dispose();
                userManager.Dispose();
            }
        }
Beispiel #5
0
        private bool hasUserRights(long entityId, RightType rightType)
        {
            #region security permissions and authorisations check

            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
            return(entityPermissionManager.HasEffectiveRight(GetUsernameOrDefault(), "Dataset", typeof(Dataset), entityId, rightType));

            #endregion security permissions and authorisations check
        }
        public FileResult getFile(string path)
        {
            path = Server.UrlDecode(path);
            if (FileHelper.FileExist(Path.Combine(AppConfiguration.DataPath, path)))
            {
                EntityPermissionManager entityPermissionManager = null;
                DatasetManager          datasetManager          = null;
                try
                {
                    entityPermissionManager = new EntityPermissionManager();
                    datasetManager          = new DatasetManager();

                    DatasetInfo datasetInfo = (DatasetInfo)Session["DatasetInfo"];
                    string      entityType  = (string)Session["EntityType"];
                    long        datasetID   = datasetInfo.DatasetId;
                    bool        access      = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Read);
                    if (access)
                    {
                        path = Path.Combine(AppConfiguration.DataPath, path);
                        FileInfo fileInfo = new FileInfo(path);
                        Session["DatasetInfo"] = datasetInfo;
                        Session["EntityType"]  = entityType;

                        // after 2.14.1 files are stored in original names
                        // by download only the files, the user need to know th edataset id and the version number
                        int    versionNr = datasetManager.GetDatasetVersionNr(datasetInfo.DatasetVersionId);
                        string filename  = datasetInfo.DatasetId + "_" + versionNr + "_" + fileInfo.Name;

                        return(File(path, MimeMapping.GetMimeMapping(fileInfo.Name), filename));
                    }
                    else
                    {
                        Session["DatasetInfo"] = datasetInfo;
                        return(null);
                    }
                }
                catch (Exception ex)
                {
                    return(null);
                }
                finally
                {
                    entityPermissionManager.Dispose();
                    datasetManager.Dispose();
                }
            }
            else
            {
                WebRequest      request  = WebRequest.Create(path);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                return(File(response.GetResponseStream(), MimeMapping.GetMimeMapping(response.ResponseUri.Segments.LastOrDefault()), response.ResponseUri.Segments.LastOrDefault()));
            }
        }
        public ActionResult ResourceStructureAttribute()
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Manage Resource Structure Attributes", this.Session.GetTenant());
            List <ResourceStructureAttributeModel> model = new List <ResourceStructureAttributeModel>();

            using (var rsManager = new ResourceStructureManager())
                using (var rsaManager = new ResourceStructureAttributeManager())
                    using (var permissionManager = new EntityPermissionManager())
                        using (var entityTypeManager = new EntityManager())
                        {
                            IQueryable <ResourceStructureAttribute> rsaList = rsaManager.GetAllResourceStructureAttributes();

                            foreach (ResourceStructureAttribute a in rsaList)
                            {
                                ResourceStructureAttributeModel rsaModel = new ResourceStructureAttributeModel(a);
                                if (rsaManager.IsAttributeInUse(a.Id))
                                {
                                    rsaModel.InUse = true;
                                }

                                //get id from loged in user
                                long userId = UserHelper.GetUserId(HttpContext.User.Identity.Name);
                                //get entity type id
                                long entityTypeId = entityTypeManager.FindByName("ResourceStructureAttribute").Id;

                                //get permission from logged in user
                                rsaModel.EditAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                                {
                                    entityTypeId
                                }, a.Id, RightType.Write);
                                rsaModel.DeleteAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                                {
                                    entityTypeId
                                }, a.Id, RightType.Delete);
                                model.Add(rsaModel);
                            }
                        }

            return(View("ResourceStructureAttributeManager", model));
        }
        public ActionResult ResourceStructure_Select()
        {
            using (var rsManager = new ResourceStructureManager())
                using (var permissionManager = new EntityPermissionManager())
                    using (var entityTypeManager = new EntityManager())
                    {
                        IQueryable <ResourceStructure> data = rsManager.GetAllResourceStructures();

                        //List<ResourceStructureModel> resourceStructures = new List<ResourceStructureModel>();
                        List <ResourceStructureManagerModel> resourceStructures = new List <ResourceStructureManagerModel>();

                        //get id from loged in user
                        long userId = UserHelper.GetUserId(HttpContext.User.Identity.Name);
                        //get entity type id
                        long entityTypeId = entityTypeManager.FindByName("ResourceStructure").Id;

                        foreach (ResourceStructure rs in data)
                        {
                            ResourceStructureManagerModel temp = new ResourceStructureManagerModel(rs);
                            temp.InUse = rsManager.IsResourceStructureInUse(rs.Id);

                            //get permission from logged in user
                            temp.EditAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                            {
                                entityTypeId
                            }, rs.Id, RightType.Write);
                            temp.DeleteAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                            {
                                entityTypeId
                            }, rs.Id, RightType.Delete);

                            resourceStructures.Add(temp);
                        }


                        return(View("ResourceStructureManager", new GridModel <ResourceStructureManagerModel> {
                            Data = resourceStructures
                        }));
                    }
        }
        public ActionResult ResourceStructureAttributesAllManager_Select()
        {
            using (var rsManager = new ResourceStructureManager())
                using (var rsaManager = new ResourceStructureAttributeManager())
                    using (var permissionManager = new EntityPermissionManager())
                        using (var entityTypeManager = new EntityManager())
                        {
                            IQueryable <ResourceStructureAttribute> rsaList = rsaManager.GetAllResourceStructureAttributes();
                            List <ResourceStructureAttributeModel>  list    = new List <ResourceStructureAttributeModel>();

                            foreach (ResourceStructureAttribute a in rsaList)
                            {
                                ResourceStructureAttributeModel rsaModel = new ResourceStructureAttributeModel(a);
                                if (rsaManager.IsAttributeInUse(a.Id))
                                {
                                    rsaModel.InUse = true;
                                }

                                //get id from loged in user
                                long userId = UserHelper.GetUserId(HttpContext.User.Identity.Name);
                                //get entity type id
                                long entityTypeId = entityTypeManager.FindByName("ResourceStructureAttribute").Id;

                                //get permission from logged in user
                                rsaModel.EditAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                                {
                                    entityTypeId
                                }, a.Id, RightType.Write);
                                rsaModel.DeleteAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                                {
                                    entityTypeId
                                }, a.Id, RightType.Delete);
                                list.Add(rsaModel);
                            }
                            return(View("ResourceStructureAttributeManager", new GridModel <ResourceStructureAttributeModel> {
                                Data = list
                            }));
                        }
        }
        public Stream getFileStream(string path)
        {
            path = Server.UrlDecode(path);
            if (FileHelper.FileExist(Path.Combine(AppConfiguration.DataPath, path)))
            {
                EntityPermissionManager entityPermissionManager = null;
                try
                {
                    entityPermissionManager = new EntityPermissionManager();

                    DatasetInfo datasetInfo = (DatasetInfo)Session["DatasetInfo"];
                    string      entityType  = (string)Session["EntityType"];
                    long        datasetID   = datasetInfo.DatasetId;
                    bool        access      = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Read);
                    if (access)
                    {
                        path = Path.Combine(AppConfiguration.DataPath, path);
                        Session["DatasetInfo"] = datasetInfo;
                        Session["EntityType"]  = entityType;
                        return(System.IO.File.OpenRead(path));
                    }
                    else
                    {
                        Session["DatasetInfo"] = datasetInfo;
                        Session["EntityType"]  = entityType;
                        return(null);
                    }
                }
                catch
                {
                    return(null);
                }
                finally
                {
                    entityPermissionManager.Dispose();
                }
            }
            else
            {
                try
                {
                    WebRequest      request  = WebRequest.Create(path);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    return(response.GetResponseStream());
                }
                catch
                {
                    return(null);
                }
            }
        }
Beispiel #11
0
        public ActionResult Notification_Select()
        {
            using (var nManager = new NotificationManager())
                using (var permissionManager = new EntityPermissionManager())
                    using (var entityTypeManager = new EntityManager())
                    {
                        List <Notification>      data          = nManager.GetAllNotifications().ToList();
                        List <NotificationModel> notifications = new List <NotificationModel>();

                        //get id from loged in user
                        long userId = UserHelper.GetUserId(HttpContext.User.Identity.Name);
                        //get entity type id
                        long entityTypeId = entityTypeManager.FindByName("Notification").Id;

                        foreach (Notification n in data)
                        {
                            NotificationModel temp = new NotificationModel(n);

                            //get permission from logged in user
                            temp.EditAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                            {
                                entityTypeId
                            }, n.Id, RightType.Write);
                            temp.DeleteAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                            {
                                entityTypeId
                            }, n.Id, RightType.Delete);

                            notifications.Add(temp);
                        }

                        //data.ToList().ForEach(r => notifications.Add(new NotificationModel(r)));

                        return(View("NotificationManager", new GridModel <NotificationModel> {
                            Data = notifications
                        }));
                    }
        }
        public ActionResult Activity_Select()
        {
            using (var rManager = new ActivityManager())
                using (var permissionManager = new EntityPermissionManager())
                    using (var entityTypeManager = new EntityManager())
                    {
                        List <Activity>      data       = rManager.GetAllActivities().ToList();
                        List <ActivityModel> activities = new List <ActivityModel>();

                        // get id from loged in user
                        long userId = UserHelper.GetUserId(HttpContext.User.Identity.Name);

                        // get entity type id
                        long entityTypeId = entityTypeManager.FindByName("Activity").Id;

                        foreach (Activity a in data)
                        {
                            ActivityModel temp = new ActivityModel(a);
                            // temp.InUse = rManager.IsInEvent(a.Id);

                            // get permission from logged in user
                            temp.EditAccess = permissionManager.HasEffectiveRight(userId, new List <long> {
                                entityTypeId
                            }, a.Id, RightType.Read);
                            temp.DeleteAccess = permissionManager.HasEffectiveRight(userId, new List <long> {
                                entityTypeId
                            }, a.Id, RightType.Delete);

                            activities.Add(temp);
                        }

                        // data.ToList().ForEach(r => activities.Add(new ActivityModel(r)));

                        return(View("ActivityManager", new GridModel <ActivityModel> {
                            Data = activities
                        }));
                    }
        }
        public ActionResult multimediaData(long datasetID, long versionId = 0, string entityType = "Dataset")
        {
            ViewData["Id"] = datasetID;

            using (EntityPermissionManager entityPermissionManager = new EntityPermissionManager())
                using (DatasetManager datasetManager = new DatasetManager())
                {
                    try
                    {
                        bool isLatestVersion = false;
                        if (versionId == datasetManager.GetDatasetLatestVersion(datasetID).Id)
                        {
                            isLatestVersion = true;
                        }

                        ViewData["edit"] = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Write);

                        bool access = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Read);
                        Session["DatasetInfo"] = new DatasetInfo(datasetID, versionId, isLatestVersion, access, entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Delete));
                        if (access)
                        {
                            return(PartialView("_multimediaData", getFilesByDatasetId(datasetID, entityType, versionId)));
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    catch
                    {
                        return(null);
                    }
                    finally
                    {
                    }
                }
        }
Beispiel #14
0
        public ActionResult Notification()
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Notification Manager", this.Session.GetTenant());
            List <NotificationModel> model = new List <NotificationModel>();

            using (var nManager = new NotificationManager())
                using (var permissionManager = new EntityPermissionManager())
                    using (var entityTypeManager = new EntityManager())
                    {
                        List <Notification> data = nManager.GetAllNotifications().ToList();

                        //get id from loged in user
                        long userId = UserHelper.GetUserId(HttpContext.User.Identity.Name);
                        //get entity type id
                        long entityTypeId = entityTypeManager.FindByName("Notification").Id;

                        foreach (Notification n in data)
                        {
                            NotificationModel temp = new NotificationModel(n);

                            //get permission from logged in user
                            temp.EditAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                            {
                                entityTypeId
                            }, n.Id, RightType.Write);
                            temp.DeleteAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                            {
                                entityTypeId
                            }, n.Id, RightType.Delete);

                            model.Add(temp);
                        }
                    }

            return(View("NotificationManager", model));
        }
        public ActionResult ResourceStructure()
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Manage Resource Structures", this.Session.GetTenant());
            List <ResourceStructureManagerModel> model = new List <ResourceStructureManagerModel>();

            using (var rsManager = new ResourceStructureManager())
                using (var permissionManager = new EntityPermissionManager())
                    using (var entityTypeManager = new EntityManager())
                    {
                        IQueryable <ResourceStructure> data = rsManager.GetAllResourceStructures();

                        //get id from loged in user
                        long userId = UserHelper.GetUserId(HttpContext.User.Identity.Name);
                        //get entity type id
                        long entityTypeId = entityTypeManager.FindByName("ResourceStructure").Id;

                        foreach (ResourceStructure rs in data)
                        {
                            ResourceStructureManagerModel temp = new ResourceStructureManagerModel(rs);
                            temp.InUse = rsManager.IsResourceStructureInUse(rs.Id);

                            //get permission from logged in user
                            temp.EditAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                            {
                                entityTypeId
                            }, rs.Id, RightType.Write);
                            temp.DeleteAccess = permissionManager.HasEffectiveRight(userId, new List <long>()
                            {
                                entityTypeId
                            }, rs.Id, RightType.Delete);

                            model.Add(temp);
                        }
                    }
            return(View("ResourceStructureManager", model));
        }
Beispiel #16
0
        public List <long> Get()
        {
            // get token from the request
            string token = this.Request.Headers.Authorization?.Parameter;

            // flag for the public dataset check
            bool isPublic = false;

            List <long> ids = new List <long>();

            using (var datasetManager = new DatasetManager())
            {
                var datasetIds = datasetManager.GetDatasetLatestIds();

                foreach (var id in datasetIds)
                {
                    using (EntityPermissionManager entityPermissionManager = new EntityPermissionManager())
                        using (EntityManager entityManager = new EntityManager())
                            using (UserManager userManager = new UserManager())
                            {
                                // load the entity id of the e.g. is it a sample or dataset or publication
                                long?entityTypeId = entityManager.FindByName(typeof(Dataset).Name)?.Id;
                                entityTypeId = entityTypeId.HasValue ? entityTypeId.Value : -1;

                                // if the subject is null and one entry exist, means this dataset is public
                                isPublic = entityPermissionManager.Exists(null, entityTypeId.Value, id);

                                // load user based on token
                                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))
                                    {
                                        var filepath = Path.Combine(AppConfiguration.DataPath, "Datasets", id.ToString(), "geoengine.json");

                                        if (File.Exists(filepath))
                                        {
                                            ids.Add(id);
                                        }
                                    }
                                }
                            }
                }
            }

            return(ids);
        }
        public FileResult getFileStreamResult(string path)
        {
            path = Server.UrlDecode(path);
            if (FileHelper.FileExist(Path.Combine(AppConfiguration.DataPath, path)))
            {
                EntityPermissionManager entityPermissionManager = null;
                try
                {
                    entityPermissionManager = new EntityPermissionManager();
                    DatasetInfo datasetInfo = (DatasetInfo)Session["DatasetInfo"];
                    string      entityType  = (string)Session["EntityType"];

                    long datasetID = datasetInfo.DatasetId;
                    bool access    = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Read);
                    if (access)
                    {
                        path = Path.Combine(AppConfiguration.DataPath, path);
                        FileInfo fileInfo = new FileInfo(path);
                        Session["DatasetInfo"] = datasetInfo;
                        Session["EntityType"]  = entityType;
                        return(new FileStreamResult(new FileStream(path, FileMode.Open), MimeMapping.GetMimeMapping(fileInfo.Name)));
                    }
                    else
                    {
                        Session["DatasetInfo"] = datasetInfo;
                        Session["EntityType"]  = entityType;
                        return(null);
                    }
                }
                catch
                {
                    return(null);
                }
                finally
                {
                    entityPermissionManager.Dispose();
                }
            }
            else
            {
                WebRequest      request  = WebRequest.Create(path);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                return(new FileStreamResult(response.GetResponseStream(), MimeMapping.GetMimeMapping(response.ResponseUri.Segments.LastOrDefault())));
            }
        }
        public List <FileInformation> getFilesByDataset(Dataset dataset, DatasetManager datasetManager, string entityType, long versionId = 0)
        {
            EntityPermissionManager entityPermissionManager = null;

            try
            {
                List <FileInformation> fileInfos = new List <FileInformation>();
                entityPermissionManager = new EntityPermissionManager();
                bool access = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), dataset.Id, RightType.Read);
                if (dataset != null && access)
                {
                    DatasetVersion datasetVersion = new DatasetVersion();
                    if (versionId > 0)
                    {
                        datasetVersion = datasetManager.GetDatasetVersion(versionId);
                    }
                    else
                    {
                        datasetVersion = datasetManager.GetDatasetLatestVersion(dataset);
                    }

                    if (datasetVersion != null)
                    {
                        List <ContentDescriptor> contentDescriptors = datasetVersion.ContentDescriptors.ToList();

                        if (contentDescriptors.Count > 0)
                        {
                            foreach (ContentDescriptor cd in contentDescriptors)
                            {
                                if (cd.Name.ToLower().Equals("unstructureddata"))
                                {
                                    fileInfos.Add(getFileInfo(cd));
                                }
                            }
                        }
                    }
                }
                return(fileInfos);
            }
            finally
            {
                entityPermissionManager.Dispose();
            }
        }
        private bool hasUserRights(long instanceId, long entityId, RightType rightType)
        {
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
            UserManager             userManager             = new UserManager();
            EntityManager           entityManager           = new EntityManager();

            try
            {
                #region security permissions and authorisations check

                var user = userManager.FindByNameAsync(GetUsernameOrDefault()).Result;
                if (user == null)
                {
                    return(false);
                }

                var entity = entityManager.FindByName("Dataset");
                if (entity == null)
                {
                    return(false);
                }
                return(entityPermissionManager.HasEffectiveRight(user.UserName, typeof(Dataset), instanceId, rightType));

                #endregion security permissions and authorisations check
            }
            catch
            {
                return(false);
            }
            finally
            {
                entityPermissionManager.Dispose();
                userManager.Dispose();
                entityManager.Dispose();
            }
        }
        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();
            }
        }
Beispiel #21
0
        // GET api/<controller>/5
        public HttpResponseMessage Get(int id)
        {
            // get token from the request
            string token = this.Request.Headers.Authorization?.Parameter;

            // flag for the public dataset check
            bool isPublic = false;

            using (EntityPermissionManager entityPermissionManager = new EntityPermissionManager())
                using (EntityManager entityManager = new EntityManager())
                    using (UserManager userManager = new UserManager())
                    {
                        // load the entity id of the e.g. is it a sample or dataset or publication
                        long?entityTypeId = entityManager.FindByName(typeof(Dataset).Name)?.Id;
                        entityTypeId = entityTypeId.HasValue ? entityTypeId.Value : -1;

                        // if the subject is null and one entry exist, means this dataset is public
                        isPublic = entityPermissionManager.Exists(null, entityTypeId.Value, id);

                        // if its not public and no token exist - fire exception
                        if (!isPublic && String.IsNullOrEmpty(token))

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

                            return(request);
                        }

                        // load user based on token
                        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))
                            {
                                var filepath = Path.Combine(AppConfiguration.DataPath, "Datasets", id.ToString(), "geoengine.json");

                                if (File.Exists(filepath))
                                {
                                    var response = Request.CreateResponse();
                                    response.Content = new StringContent(File.ReadAllText(filepath), System.Text.Encoding.UTF8, "application/json");

                                    return(response);
                                }

                                else
                                {
                                    var request = Request.CreateResponse();
                                    request.Content = new StringContent("Georeference is not available.");
                                    return(request);
                                }
                            }
                            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);
                        }
                    }
        }
Beispiel #22
0
        private HttpResponseMessage getData(long id, int version, string token, string projection = null, string selection = null)
        {
            DatasetManager          datasetManager          = new DatasetManager();
            UserManager             userManager             = new UserManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
            EntityManager           entityManager           = new EntityManager();

            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

                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);

                        // If the requested version is -1 or the last version of the dataset, then the data will be loaded in a
                        // different way than when loading the data from an older version
                        bool isLatestVersion = false;
                        if (version == -1 || dataset.Versions.Count == version)
                        {
                            isLatestVersion = true;
                        }

                        if (isLatestVersion)
                        {
                            #region get data from the latest version of a dataset

                            DatasetVersion datasetVersion = datasetManager.GetDatasetLatestVersion(id);

                            string title = datasetVersion.Title;

                            // check the data sturcture type ...
                            if (datasetVersion.Dataset.DataStructure.Self is StructuredDataStructure)
                            {
                                //FilterExpression filter = null;
                                //OrderByExpression orderBy = null;
                                //ProjectionExpression projectionExpression = GetProjectionExpression(projection);

                                // apply selection and projection
                                long count = datasetManager.RowCount(id);

                                DataTable dt = datasetManager.GetLatestDatasetVersionTuples(id, null, null, null, 0, (int)count);
                                dt.Strip();

                                if (!string.IsNullOrEmpty(selection))
                                {
                                    dt = OutputDataManager.SelectionOnDataTable(dt, selection, true);
                                }

                                if (!string.IsNullOrEmpty(projection))
                                {
                                    // make the header names upper case to make them case insensitive
                                    dt = OutputDataManager.ProjectionOnDataTable(dt, projection.ToUpper().Split(','));
                                }

                                dt.TableName = id + "_data";

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

                                var response = Request.CreateResponse();
                                response.Content = new ObjectContent(typeof(DatasetModel), model, new DatasetModelCsvFormatter(model.DataTable.TableName));
                                response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/csv");

                                //set headers on the "response"
                                return(response);

                                #endregion get data from the latest version of a dataset

                                //return model;
                            }
                            else
                            {
                                return(Request.CreateResponse());
                            }
                        }
                        else
                        {
                            #region load data of a older version of a dataset

                            int index = version - 1;
                            if (version >= dataset.Versions.Count)
                            {
                                return(Request.CreateResponse(HttpStatusCode.PreconditionFailed, String.Format("This version ({0}) is not available for the dataset", version)));
                            }

                            DatasetVersion datasetVersion = dataset.Versions.OrderBy(d => d.Timestamp).ElementAt(version - 1);

                            string title = datasetVersion.Title;

                            // check the data sturcture type ...
                            if (datasetVersion.Dataset.DataStructure.Self is StructuredDataStructure)
                            {
                                //FilterExpression filter = null;
                                //OrderByExpression orderBy = null;

                                // apply selection and projection
                                int       count = datasetManager.GetDatasetVersionEffectiveTuples(datasetVersion).Count;
                                DataTable dt    = datasetManager.GetDatasetVersionTuples(datasetVersion.Id, 0, count);

                                dt.Strip();

                                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(','));
                                }

                                dt.TableName = id + "_data";

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

                                var response = Request.CreateResponse();
                                response.Content = new ObjectContent(typeof(DatasetModel), model, new DatasetModelCsvFormatter(model.DataTable.TableName));
                                response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/csv");

                                //set headers on the "response"
                                return(response);
                            }
                            else // return files of the unstructure dataset
                            {
                                return(Request.CreateResponse());
                            }

                            #endregion load data of a older version of a dataset
                        }
                    }
                    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();
            }
        }
        //copy of BExIS.Modules.Ddm.UI.Controllers.DataController.ShowData (adapted)
        public ActionResult Index(long id, int version = 0)
        {
            DatasetManager          dm = new DatasetManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();

            try
            {
                DatasetVersion dsv;
                ShowDataModel  model = new ShowDataModel();

                string title = "";
                long   metadataStructureId = -1;
                long   dataStructureId     = -1;
                long   researchPlanId      = 1;
                long   versionId           = 0;
                string dataStructureType   = DataStructureType.Structured.ToString();
                bool   downloadAccess      = false;
                bool   requestExist        = false;
                bool   requestAble         = false;
                bool   latestVersion       = false;
                string isValid             = "no";

                XmlDocument metadata = new XmlDocument();

                if (dm.IsDatasetCheckedIn(id))
                {
                    //get latest version
                    if (version == 0)
                    {
                        versionId = dm.GetDatasetLatestVersionId(id); // check for zero value
                        //get current version number
                        version = dm.GetDatasetVersions(id).OrderBy(d => d.Timestamp).Count();

                        latestVersion = true;
                    }
                    // get specific version
                    else
                    {
                        versionId     = dm.GetDatasetVersions(id).OrderBy(d => d.Timestamp).Skip(version - 1).Take(1).Select(d => d.Id).FirstOrDefault();
                        latestVersion = versionId == dm.GetDatasetLatestVersionId(id);
                    }

                    dsv = dm.DatasetVersionRepo.Get(versionId); // this is needed to allow dsv to access to an open session that is available via the repo

                    if (dsv.StateInfo != null)
                    {
                        isValid = DatasetStateInfo.Valid.ToString().Equals(dsv.StateInfo.State) ? "yes" : "no";
                    }

                    metadataStructureId = dsv.Dataset.MetadataStructure.Id;

                    //MetadataStructureManager msm = new MetadataStructureManager();
                    //dsv.Dataset.MetadataStructure = msm.Repo.Get(dsv.Dataset.MetadataStructure.Id);

                    title           = dsv.Title;
                    dataStructureId = dsv.Dataset.DataStructure.Id;
                    researchPlanId  = dsv.Dataset.ResearchPlan.Id;
                    metadata        = dsv.Metadata;

                    // check if the user has download rights
                    downloadAccess = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), id, RightType.Read);

                    //// check if a reuqest of this dataset exist
                    //if (!downloadAccess)
                    //{
                    //    requestExist = HasOpenRequest(id);

                    //    if (UserExist() && HasRequestMapping(id)) requestAble = true;
                    //}

                    dataStructureType = DataStructureType.Unstructured.ToString();


                    ViewBag.Title = PresentationModel.GetViewTitleForTenant("Show Data : " + title, this.Session.GetTenant());
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Publication is just in processing.");
                }

                model = new ShowDataModel()
                {
                    Id                  = id,
                    Version             = version,
                    VersionSelect       = version,
                    VersionId           = versionId,
                    LatestVersion       = latestVersion,
                    Title               = title,
                    MetadataStructureId = metadataStructureId,
                    DataStructureId     = dataStructureId,
                    ResearchPlanId      = researchPlanId,
                    ViewAccess          = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), id, RightType.Read),
                    GrantAccess         = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), id, RightType.Grant),
                    DataStructureType   = dataStructureType,
                    DownloadAccess      = downloadAccess,
                    RequestExist        = requestExist,
                    RequestAble         = requestAble
                };

                //set metadata in session
                Session["ShowDataMetadata"] = metadata;
                ViewData["VersionSelect"]   = getVersionsSelectList(id, dm);
                ViewData["isValid"]         = isValid;

                return(View(model));
            }
            finally
            {
                dm.Dispose();
                entityPermissionManager.Dispose();
            }
        }
        public ActionResult ShowPrimaryData(long datasetID, int versionId)
        {
            Session["Filter"]              = null;
            Session["Columns"]             = null;
            Session["DownloadFullDataset"] = false;
            ViewData["DownloadOptions"]    = null;
            IOUtility            iOUtility = new IOUtility();
            DatasetManager       dm        = new DatasetManager();
            DataStructureManager dsm       = new DataStructureManager();
            //permission download
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();

            try
            {
                if (dm.IsDatasetCheckedIn(datasetID))
                {
                    // get latest or other datasetversion
                    DatasetVersion dsv           = dm.GetDatasetVersion(versionId);
                    bool           latestVersion = versionId == dm.GetDatasetLatestVersionId(datasetID);


                    DataStructure ds = dsm.AllTypesDataStructureRepo.Get(dsv.Dataset.DataStructure.Id);

                    // TODO: refactor Download Right not existing, so i set it to read
                    bool downloadAccess = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Read);

                    bool editRights = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Write);

                    //TITLE
                    string title = dsv.Title;

                    if (ds.Self.GetType() == typeof(UnStructuredDataStructure))
                    {
                        if (this.IsAccessible("MMM", "ShowMultimediaData", "multimediaData") && ConfigurationManager.AppSettings["useMultimediaModule"].ToLower().Equals("true"))
                        {
                            return(RedirectToAction("multimediaData", "ShowMultimediaData", new RouteValueDictionary {
                                { "area", "MMM" }, { "datasetID", datasetID }, { "versionId", versionId }, { "entityType", "Publication" }
                            }));
                        }
                        else
                        {
                            return
                                (PartialView(ShowPrimaryDataModel.Convert(datasetID,
                                                                          versionId,
                                                                          title,
                                                                          ds,
                                                                          SearchUIHelper.GetContantDescriptorFromKey(dsv, "unstructuredData"),
                                                                          downloadAccess,
                                                                          iOUtility.GetSupportedAsciiFiles(),
                                                                          latestVersion,
                                                                          editRights)));
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Dataset is just in processing.");
                }

                return(PartialView(null));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dm.Dispose();
                dsm.Dispose();
                entityPermissionManager.Dispose();
            }
        }
        public bool deleteFile(string path)
        {
            path = Server.UrlDecode(path);
            {
                using (EntityPermissionManager entityPermissionManager = new EntityPermissionManager())
                    using (DatasetManager datasetManager = new DatasetManager())
                    {
                        try
                        {
                            DatasetInfo datasetInfo = (DatasetInfo)Session["DatasetInfo"];
                            string      entityType  = (string)Session["EntityType"];

                            DatasetVersion workingCopy = new DatasetVersion();
                            string         status      = DatasetStateInfo.NotValid.ToString();
                            string[]       temp        = path.Split('\\');
                            long           datasetID   = datasetInfo.DatasetId;
                            status = datasetManager.GetDatasetLatestVersion(datasetID).StateInfo.State;
                            bool access = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, typeof(Dataset), datasetID, RightType.Delete);

                            if (access && (datasetManager.IsDatasetCheckedOutFor(datasetID, HttpContext.User.Identity.Name) || datasetManager.CheckOutDataset(datasetID, HttpContext.User.Identity.Name)))
                            {
                                try
                                {
                                    workingCopy = datasetManager.GetDatasetWorkingCopy(datasetID);

                                    using (var unitOfWork = this.GetUnitOfWork())
                                    {
                                        workingCopy = unitOfWork.GetReadOnlyRepository <DatasetVersion>().Get(workingCopy.Id);

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

                                        unitOfWork.GetReadOnlyRepository <DatasetVersion>().Load(workingCopy.ContentDescriptors);

                                        ContentDescriptor contentDescriptor = workingCopy.ContentDescriptors.Where(cd => cd.URI.Equals(path)).FirstOrDefault();
                                        datasetManager.DeleteContentDescriptor(contentDescriptor);
                                    }

                                    //set modification
                                    workingCopy.ModificationInfo = new EntityAuditInfo()
                                    {
                                        Performer  = HttpContext.User?.Identity?.Name,
                                        Comment    = "File",
                                        ActionType = AuditActionType.Delete
                                    };

                                    // set system key values
                                    int v = 1;
                                    if (workingCopy.Dataset.Versions != null && workingCopy.Dataset.Versions.Count > 1)
                                    {
                                        v = workingCopy.Dataset.Versions.Count();
                                    }
                                    workingCopy.Metadata = setSystemValuesToMetadata(v, workingCopy.Dataset.MetadataStructure.Id, workingCopy.Metadata);

                                    datasetManager.EditDatasetVersion(workingCopy, null, null, null);

                                    // ToDo: Get Comment from ui and users
                                    datasetManager.CheckInDataset(datasetID, temp.Last(), HttpContext.User.Identity.Name, ViewCreationBehavior.None);
                                    Session["DatasetInfo"] = datasetInfo;
                                    Session["EntityType"]  = entityType;
                                    return(true);
                                }
                                catch
                                {
                                    datasetManager.CheckInDataset(datasetID, "Failed to delete File " + temp.Last(), HttpContext.User.Identity.Name, ViewCreationBehavior.None);
                                    Session["DatasetInfo"] = datasetInfo;
                                    Session["EntityType"]  = entityType;
                                    return(false);
                                }
                            }
                            Session["DatasetInfo"] = datasetInfo;
                            Session["EntityType"]  = entityType;
                            return(false);
                        }
                        catch
                        {
                            return(false);
                        }
                    }
            }
        }
        public async Task <HttpResponseMessage> Put(long id)
        {
            if (Request.Content.IsMimeMultipartContent())
            {
                var    filelist = new List <Stream>();
                var    request  = Request.CreateResponse();
                User   user     = null;
                string error    = "";

                DatasetManager          datasetManager          = new DatasetManager();
                UserManager             userManager             = new UserManager();
                EntityPermissionManager entityPermissionManager = new EntityPermissionManager();

                try
                {
                    #region security

                    string token = this.Request.Headers.Authorization?.Parameter;
                    if (String.IsNullOrEmpty(token))
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Bearer token not exist."));
                    }

                    user = userManager.Users.Where(u => u.Token.Equals(token)).FirstOrDefault();
                    if (user == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Token is not valid."));
                    }

                    //check permissions

                    //entity permissions
                    if (id > 0)
                    {
                        Dataset d = datasetManager.GetDataset(id);
                        //dataset exist?
                        if (d == null)
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "the dataset with the id (" + id + ") does not exist."));
                        }
                        //user has the right to write?
                        if (!entityPermissionManager.HasEffectiveRight(user.Name, typeof(Dataset), id, RightType.Write))
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "The token is not authorized to write into the dataset."));
                        }
                    }

                    #endregion security

                    var provider = new MultipartMemoryStreamProvider();
                    await Request.Content.ReadAsMultipartAsync(provider);

                    if (provider.Contents.Count > 0)
                    {
                        uploadFiles(provider.Contents.ToList(), id, "attached via api", user.Name, datasetManager);
                    }

                    var response = Request.CreateResponse(HttpStatusCode.OK);
                    response.Content = new StringContent("Successful upload", Encoding.UTF8, "text/plain");
                    response.Content.Headers.ContentType = new MediaTypeWithQualityHeaderValue(@"text/html");
                    return(response);
                }
                catch (Exception e)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e.Message));
                }
                finally
                {
                    datasetManager.Dispose();
                    entityPermissionManager.Dispose();
                    userManager.Dispose();
                    request.Dispose();
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.UnsupportedMediaType, "The request doesn't contain valid content!"));
            }
        }
Beispiel #27
0
        // GET: DQ
        public ActionResult ShowDQ(long datasetId, long versionId)
        {
            DQModels dqModel = new DQModels();
            Dictionary <string, string> datasetInfo  = new Dictionary <string, string>();
            List <performer>            performers   = new List <performer>();
            List <varVariable>          varVariables = new List <varVariable>();
            Dictionary <string, double> datasetSize  = new Dictionary <string, double>();
            DatasetManager          dm  = new DatasetManager();
            DataStructureManager    dsm = new DataStructureManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
            PartyManager            pm          = new PartyManager();
            UserManager             um          = new UserManager();
            DatasetVersion          dsv         = new DatasetVersion();
            UserManager             userManager = new UserManager();

            // data quality files
            try
            {
                string       pathPerformerDataset   = @"C:\Data\DatasetQualities\PerformerDataset.csv";
                StreamReader readerPerformerDataset = new StreamReader(pathPerformerDataset);
            }
            catch (Exception ex)
            { }

            //////////////////////////////////////////////////////////////////////////
            DatasetVersion currentDatasetVersion = dm.GetDatasetVersion(versionId);                                                   //Current dataset version
            DataStructure  currentDataStr        = dsm.AllTypesDataStructureRepo.Get(currentDatasetVersion.Dataset.DataStructure.Id); //current data structure
            var            currentUser           = userManager.FindByNameAsync(GetUsernameOrDefault()).Result;                        //Find current user

            //Find the dataset Type
            string currentDatasetType = "file";

            if (currentDataStr.Self.GetType() == typeof(StructuredDataStructure))
            {
                currentDatasetType = "tabular";
            }
            dqModel.type = currentDatasetType;

            #region performers

            #region dataset's performers
            try
            {
                string           pathPerformerDataset   = @"C:\Data\DatasetQualities\PerformerDataset.csv";
                StreamReader     readerPerformerDataset = new StreamReader(pathPerformerDataset);
                string           pathPerformers         = @"C:\Data\DatasetQualities\Performers.csv";
                StreamReader     readerPerformers       = new StreamReader(pathPerformers);
                string           performerLine;
                List <string>    pfs = new List <string>();
                List <performer> ps  = new List <performer>();

                while ((performerLine = readerPerformerDataset.ReadLine()) != null)
                {
                    string[] s = performerLine.Split(',');
                    if (long.Parse(s[1]) == datasetId)
                    {
                        pfs.Add(s[0]);
                    }
                }
                while ((performerLine = readerPerformers.ReadLine()) != null)
                {
                    string[] s = performerLine.Split(',');
                    if (pfs.Contains(s[0]))
                    {
                        performer p = new performer();
                        p.performerName = FindPerformerNameFromUsername(um, s[0]);           //find performer name
                        p.performerRate = int.Parse(s[1]);
                        List <long> pfIds = FindDatasetsFromPerformerUsername(dm, um, s[0]); //Find all datasets in wich the username is involved.
                        p.DatasetIds = pfIds;
                        ps.Add(p);
                    }
                }
                dqModel.performers = ps;
                readerPerformerDataset.Close();
                readerPerformers.Close();
            }
            catch (Exception ex)
            {
            }
            #endregion

            #endregion //performers

            //dqModel.isPublic = entityPermissionManager.GetRights(null, 1, datasetId); //check if dataset is public
            //check the read permission for current dataset
            bool rPermission = entityPermissionManager.HasEffectiveRight(currentUser.UserName, typeof(Dataset), datasetId, Security.Entities.Authorization.RightType.Read); //find if user has read permission
            if (rPermission == true)                                                                                                                                        //has read permission or public = readable
            {
                dqModel.readable = 1;
            }
            else
            {
                dqModel.readable = 0;
            }                              //cannot read

            //Check if the current metadata is valid
            if (currentDatasetVersion.StateInfo != null)
            {
                dqModel.isValid = DatasetStateInfo.Valid.ToString().Equals(currentDatasetVersion.StateInfo.State) ? 1 : 0; //1:valid; 0:invalid.
            }
            else
            {
                dqModel.isValid = 0;
            }


            List <long> datasetIds = dm.GetDatasetLatestIds();
            dqModel.allDatasets = datasetIds.Count;
            List <int>    metadataRates      = new List <int>();
            List <int>    dsDescLength       = new List <int>();
            List <int>    dstrDescLength     = new List <int>();
            List <int>    dstrUsage          = new List <int>();
            List <int>    datasetSizeTabular = new List <int>();
            List <int>    datasetRows        = new List <int>();
            List <int>    datasetCols        = new List <int>();
            List <double> datasetSizeFiles   = new List <double>();
            double        datasetSizeFile    = new double();
            List <int>    datasetFileNumber  = new List <int>();
            List <int>    restrictions       = new List <int>();
            int           fileNumber         = 0;
            List <int>    sizeTabular        = new List <int>(); //collect size, column number, and row number for one dataset
            int           publicDatasets     = 0;
            int           restrictedDatasets = 0;
            int           fileDatasets       = 0;
            int           tabularDatasets    = 0;
            int           rpTrue             = 0;
            int           rp;
            int           validMetadata   = 0;
            int           allValidMetadas = 0;


            foreach (long Id in datasetIds) //for each dataset
            {
                if (dm.IsDatasetCheckedIn(Id))
                {
                    DatasetVersion datasetVersion = dm.GetDatasetLatestVersion(Id);          //get last dataset versions

                    //If user has read permission
                    rPermission = entityPermissionManager.HasEffectiveRight(currentUser.UserName, typeof(Dataset), Id, Security.Entities.Authorization.RightType.Read);
                    if (rPermission == true) //has read permission or public = readable
                    {
                        rp      = 1;
                        rpTrue += 1;
                    }
                    else
                    {
                        rp = 0;
                    }                //cannot read
                }
            }
            dqModel.allReadables = rpTrue;

            string       pathDatasetInfo   = @"C:\Data\DatasetQualities\datasetInfo.csv";
            StreamReader readerDatasetInfo = new StreamReader(pathDatasetInfo);
            List <datasetInformation> datasetsInformation = new List <datasetInformation>();
            try
            {
                string lineDatasetInfo;
                while ((lineDatasetInfo = readerDatasetInfo.ReadLine()) != null)
                {
                    string[]           dsInf = lineDatasetInfo.Split(';');
                    datasetInformation datasetInformation = new datasetInformation();

                    long id = long.Parse(dsInf[0]);
                    datasetInformation.datasetId = id;
                    datasetInformation.title     = dm.GetDatasetLatestVersion(id).Title;

                    rPermission = entityPermissionManager.HasEffectiveRight(currentUser.UserName, typeof(Dataset), id, Security.Entities.Authorization.RightType.Read);
                    if (rPermission == true)
                    {
                        datasetInformation.readable = 1;
                    }
                    if (rPermission == false)
                    {
                        datasetInformation.readable = 0;
                    }
                    datasetInformation.type = dsInf[1];
                    datasetInformation.metadataValidation         = int.Parse(dsInf[2]);
                    datasetInformation.metadataComplition         = int.Parse(dsInf[3]);
                    datasetInformation.descriptionLength          = int.Parse(dsInf[4]);
                    datasetInformation.structureDescriptionLength = int.Parse(dsInf[5]);
                    datasetInformation.structureUsage             = int.Parse(dsInf[6]);
                    datasetInformation.columnNumber    = int.Parse(dsInf[7]);
                    datasetInformation.rowNumber       = int.Parse(dsInf[8]);
                    datasetInformation.fileNumber      = int.Parse(dsInf[9]);
                    datasetInformation.datasetSizeFile = double.Parse(dsInf[10]);
                    string[]      pfrms          = dsInf[11].Split(',');
                    List <string> performerNames = new List <string>();
                    foreach (string p in pfrms)
                    {
                        performerNames.Add(p);
                    }
                    datasetInformation.performerNames = performerNames;

                    datasetsInformation.Add(datasetInformation);

                    if (datasetId == id)
                    {
                        dqModel.metadataComplition.requiredFields = int.Parse(dsInf[2]);
                        dqModel.metadataComplition.totalFields    = int.Parse(dsInf[3]);
                        dqModel.datasetDescriptionLength.currentDescriptionLength = int.Parse(dsInf[4]);
                        dqModel.dataStrDescriptionLength.currentDescriptionLength = int.Parse(dsInf[5]);
                        dqModel.dataStrUsage.currentDataStrUsage = int.Parse(dsInf[6]);

                        dqModel.columnNumber = datasetInformation.columnNumber;
                        dqModel.rowNumber    = datasetInformation.rowNumber;
                        dqModel.fileNumber   = datasetInformation.fileNumber;
                        dqModel.datasetTotalSize.currentTotalSize = datasetInformation.datasetSizeFile;
                    }
                }
            }
            catch
            {
            }

            dqModel.datasetsInformation = datasetsInformation;
            readerDatasetInfo.Close();

            //CURRENT DATASET VERSION
            //dqModel.metadataComplition.totalFields = GetMetadataRate(currentDatasetVersion); //current dataset version: metadata rate
            //dqModel.metadataComplition.requiredFields = 100; //Need to calculate: metadataStructureId = dsv.Dataset.MetadataStructure.Id;
            //dqModel.datasetDescriptionLength.currentDescriptionLength = currentDatasetVersion.Description.Length; // Current dataset vesion: dataset description length
            //dqModel.dataStrDescriptionLength.currentDescriptionLength = currentDatasetVersion.Dataset.DataStructure.Description.Length; // Current dataset version: data structure description length
            //dqModel.dataStrUsage.currentDataStrUsage = currentDataStr.Datasets.Count() - 1; // Current dataset version: how many times the data structure is used in other datasets

            #region comparision
            try
            {
                string       pathComparison   = @"C:\Data\DatasetQualities\Comparison.csv";
                StreamReader readerComparison = new StreamReader(pathComparison);
                string       infoline;
                List <int>   infos = new List <int>();
                while ((infoline = readerComparison.ReadLine()) != null)
                {
                    string[] s = infoline.Split(',');
                    if (s[0] == "performersActivity")
                    {
                        dqModel.performersActivity.minActivity    = int.Parse(s[1]);
                        dqModel.performersActivity.medianActivity = int.Parse(s[2]);
                        dqModel.performersActivity.maxActivity    = int.Parse(s[3]);
                    }
                    else if (s[0] == "type")
                    {
                        dqModel.allDatasets     = int.Parse(s[1]);
                        dqModel.tabularDatasets = int.Parse(s[2]);
                        dqModel.fileDatasets    = int.Parse(s[3]);
                    }
                    else if (s[0] == "metadataRates")
                    {
                        dqModel.metadataComplition.minRate    = int.Parse(s[1]);
                        dqModel.metadataComplition.medianRate = int.Parse(s[2]);
                        dqModel.metadataComplition.maxRate    = int.Parse(s[3]);
                    }
                    else if (s[0] == "allValidMetadas")
                    {
                        dqModel.allValids = int.Parse(s[1]);
                    }
                    else if (s[0] == "datasetDescriptionLength")
                    {
                        dqModel.datasetDescriptionLength.minDescriptionLength    = int.Parse(s[1]);
                        dqModel.datasetDescriptionLength.medianDescriptionLength = int.Parse(s[2]);
                        dqModel.datasetDescriptionLength.maxDescriptionLength    = int.Parse(s[3]);
                    }
                    else if (s[0] == "dataStrDescriptionLength")
                    {
                        dqModel.dataStrDescriptionLength.minDescriptionLength    = int.Parse(s[1]);
                        dqModel.dataStrDescriptionLength.medianDescriptionLength = int.Parse(s[2]);
                        dqModel.dataStrDescriptionLength.maxDescriptionLength    = int.Parse(s[3]);
                    }
                    else if (s[0] == "dataStrUsage")
                    {
                        dqModel.dataStrUsage.minDataStrUsage    = int.Parse(s[1]);
                        dqModel.dataStrUsage.medianDataStrUsage = int.Parse(s[2]);
                        dqModel.dataStrUsage.maxDataStrUsage    = int.Parse(s[3]);
                    }
                    else if (s[0] == "datasetColNumber")
                    {
                        dqModel.datasetColNumber.minColNumber    = int.Parse(s[1]);
                        dqModel.datasetColNumber.medianColNumber = int.Parse(s[2]);
                        dqModel.datasetColNumber.maxColNumber    = int.Parse(s[3]);
                    }
                    else if (s[0] == "datasetRowNumber")
                    {
                        dqModel.datasetRowNumber.minRowNumber    = int.Parse(s[1]);
                        dqModel.datasetRowNumber.medianRowNumber = int.Parse(s[2]);
                        dqModel.datasetRowNumber.maxRowNumber    = int.Parse(s[3]);
                    }
                    else if (s[0] == "datasetFileNumber")
                    {
                        dqModel.datasetFileNumber.minFileNumber    = int.Parse(s[1]);
                        dqModel.datasetFileNumber.medianFileNumber = int.Parse(s[2]);
                        dqModel.datasetFileNumber.maxFileNumber    = int.Parse(s[3]);
                    }
                    else if (s[0] == "datasetTotalSizeFiles")
                    {
                        dqModel.datasetTotalSize.minSizeFile    = double.Parse(s[1]);
                        dqModel.datasetTotalSize.medianSizeFile = double.Parse(s[2]);
                        dqModel.datasetTotalSize.maxSizeFile    = double.Parse(s[3]);
                    }
                }
                readerComparison.Close();
            }
            catch (Exception ex)
            {
            }

            #endregion

            ///////////////////////////////////////////////////////////////////////

            #region TABULAR FORMAT DATASET
            //If it is a tabular format dataset
            if (currentDatasetType == "tabular")
            {
                string       pathVariables   = @"C:\Data\DatasetQualities\Variables.csv";
                StreamReader readerVariables = new StreamReader(pathVariables);

                string varLine;
                while ((varLine = readerVariables.ReadLine()) != null)
                {
                    string[] varDetail = varLine.Split(',');
                    if (varDetail[0] == datasetId.ToString())
                    {
                        varVariable v = new varVariable();
                        v.varLabel       = varDetail[1];
                        v.varType        = varDetail[2];
                        v.varDescription = varDetail[3];
                        v.varUsage       = int.Parse(varDetail[4]);
                        v.missing        = int.Parse(varDetail[5]);

                        varVariables.Add(v);
                    }
                }
                dqModel.varVariables = varVariables;
                readerVariables.Close();
            }

            //    string serverName = "http://*****:*****@"C:\Data\DatasetQualities\Files.csv";
                try
                {
                    StreamReader readerFiles = new StreamReader(pathFiles);
                    while ((fileLine = readerFiles.ReadLine()) != null)
                    {
                        string[] fileDetail = fileLine.Split(',');
                        if (fileDetail[0] == datasetId.ToString())
                        {
                            fileInformation f = new fileInformation();
                            f.fileName   = fileDetail[1];
                            f.fileFormat = fileDetail[2];
                            double d = Convert.ToDouble(fileDetail[3]);
                            f.fileSize = d;
                            filesInformations.Add(f);
                        }
                    }
                    readerFiles.Close();
                }
                catch
                {
                }
                dqModel.filesInformation = filesInformations;
            }

            //if (currentDatasetVersion != null)
            //{
            //    List<ContentDescriptor> contentDescriptors = currentDatasetVersion.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;

            //                //get the file path
            //                try
            //                {
            //                    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)
            //                        {
            //                            //get file information
            //                            FileInformation fileInfo = new FileInformation(fs.Name.Split('\\').LastOrDefault(), MimeMapping.GetMimeMapping(fs.Name), (uint)fs.Length, uri);
            //                            fileInformation.fileName = fileInfo.Name.Split('.')[0]; //file name
            //                            fileInformation.fileFormat = fileInfo.Name.Split('.')[1].ToLower(); //file extension
            //                            fileInformation.fileSize = fileInfo.Size; //file size
            //                            totalSize += fileInfo.Size;
            //                        }
            //                    }
            //                }
            //                catch
            //                {

            //                }
            //        filesInformation.Add(fileInformation);
            //    }

            //}
            //}
            //dqModel.fileNumber = contentDescriptors.Count;
            //dqModel.datasetTotalSize.currentTotalSize = totalSize;
            //}
            //dqModel.filesInformation = filesInformation;
            //}
            #endregion


            return(PartialView(dqModel));
        }
Beispiel #28
0
        //[MeasurePerformance]
        public ActionResult ShowPrimaryData(long datasetID)
        {
            Session["Filter"]              = null;
            Session["Columns"]             = null;
            Session["DownloadFullDataset"] = false;
            ViewData["DownloadOptions"]    = null;

            DatasetManager       dm  = new DatasetManager();
            DataStructureManager dsm = new DataStructureManager();
            //permission download
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();

            try
            {
                if (dm.IsDatasetCheckedIn(datasetID))
                {
                    //long versionId = dm.GetDatasetLatestVersionId(datasetID); // check for zero value
                    //DatasetVersion dsv = dm.DatasetVersionRepo.Get(versionId);
                    DatasetVersion          dsv = dm.GetDatasetLatestVersion(datasetID);
                    StructuredDataStructure sds = dsm.StructuredDataStructureRepo.Get(dsv.Dataset.DataStructure.Id);
                    DataStructure           ds  = dsm.AllTypesDataStructureRepo.Get(dsv.Dataset.DataStructure.Id);

                    // TODO: refactor Download Right not existing, so i set it to read
                    bool downloadAccess = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name,
                                                                                    "Dataset", typeof(Dataset), datasetID, RightType.Read);

                    //TITLE
                    string title = xmlDatasetHelper.GetInformationFromVersion(dsv.Id, NameAttributeValues.title);

                    if (ds.Self.GetType() == typeof(StructuredDataStructure))
                    {
                        //ToDO Javad: 18.07.2017 -> replaced to the new API for fast retrieval of the latest version
                        //
                        //List<AbstractTuple> dataTuples = dm.GetDatasetVersionEffectiveTuples(dsv, 0, 100);
                        //DataTable table = SearchUIHelper.ConvertPrimaryDataToDatatable(dsv, dataTuples);
                        DataTable table = dm.GetLatestDatasetVersionTuples(dsv.Dataset.Id, 0, 100);

                        Session["gridTotal"] = dm.GetDatasetVersionEffectiveTupleCount(dsv);

                        return(PartialView(ShowPrimaryDataModel.Convert(datasetID, title, sds, table, downloadAccess)));

                        //return PartialView(new ShowPrimaryDataModel());
                    }

                    if (ds.Self.GetType() == typeof(UnStructuredDataStructure))
                    {
                        return
                            (PartialView(ShowPrimaryDataModel.Convert(datasetID, title, ds,
                                                                      SearchUIHelper.GetContantDescriptorFromKey(dsv, "unstructuredData"), downloadAccess)));
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Dataset is just in processing.");
                }

                return(PartialView(null));
            }
            finally
            {
                dm.Dispose();
                dsm.Dispose();
                entityPermissionManager.Dispose();
            }
        }
Beispiel #29
0
        public ActionResult ShowData(long id)
        {
            DatasetManager          dm = new DatasetManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();


            try
            {
                DatasetVersion dsv;
                ShowDataModel  model = new ShowDataModel();

                string      title = "";
                long        metadataStructureId = -1;
                long        dataStructureId     = -1;
                long        researchPlanId      = 1;
                XmlDocument metadata            = new XmlDocument();

                if (dm.IsDatasetCheckedIn(id))
                {
                    long versionId = dm.GetDatasetLatestVersionId(id); // check for zero value
                    dsv = dm.DatasetVersionRepo.Get(versionId);        // this is needed to allow dsv to access to an open session that is available via the repo

                    metadataStructureId = dsv.Dataset.MetadataStructure.Id;

                    //MetadataStructureManager msm = new MetadataStructureManager();
                    //dsv.Dataset.MetadataStructure = msm.Repo.Get(dsv.Dataset.MetadataStructure.Id);

                    title           = xmlDatasetHelper.GetInformationFromVersion(dsv.Id, NameAttributeValues.title); // this function only needs metadata and extra fields, there is no need to pass the version to it.
                    dataStructureId = dsv.Dataset.DataStructure.Id;
                    researchPlanId  = dsv.Dataset.ResearchPlan.Id;
                    metadata        = dsv.Metadata;

                    ViewBag.Title = PresentationModel.GetViewTitleForTenant("Show Data : " + title, this.Session.GetTenant());
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Dataset is just in processing.");
                }

                model = new ShowDataModel()
                {
                    Id    = id,
                    Title = title,
                    MetadataStructureId = metadataStructureId,
                    DataStructureId     = dataStructureId,
                    ResearchPlanId      = researchPlanId,
                    ViewAccess          = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, "Dataset", typeof(Dataset), id, RightType.Read),
                    GrantAccess         = entityPermissionManager.HasEffectiveRight(HttpContext.User.Identity.Name, "Dataset", typeof(Dataset), id, RightType.Grant)
                };

                //set metadata in session
                Session["ShowDataMetadata"] = metadata;

                return(View(model));
            }
            finally
            {
                dm.Dispose();
                entityPermissionManager.Dispose();
            }
        }
        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");
                            DataTable dtMissingValues = new DataTable("MissingValues");
                            dtMissingValues.Columns.Add("placeholder", typeof(String));
                            dtMissingValues.Columns.Add("displayName", typeof(String));

                            List <ApiDataStatisticModel> dataStatisticModels     = new List <ApiDataStatisticModel>();
                            StructuredDataStructure      structuredDataStructure = dataStructureManager.StructuredDataStructureRepo.Get(datasetVersion.Dataset.DataStructure.Id);
                            if (variableId == -1)
                            {
                                foreach (Variable vs in structuredDataStructure.Variables)
                                {
                                    ApiDataStatisticModel dataStatisticModel = new ApiDataStatisticModel();
                                    dt = GetUniqueValues(id, vs.Id);
                                    dataStatisticModel.VariableId   = vs.Id;
                                    dataStatisticModel.uniqueValues = dt;
                                    dataStatisticModel.minLength    = dt.Compute("Min(length)", string.Empty).ToString();
                                    dataStatisticModel.maxLength    = dt.Compute("Max(length)", string.Empty).ToString();
                                    dataStatisticModel.count        = dt.Compute("Sum(count)", string.Empty).ToString();
                                    dtMissingValues.Clear();
                                    foreach (var missingValue in vs.MissingValues)
                                    {
                                        DataRow workRow = dtMissingValues.NewRow();
                                        workRow["placeholder"] = missingValue.Placeholder;
                                        workRow["displayName"] = missingValue.DisplayName;
                                        dtMissingValues.Rows.Add(workRow);
                                    }
                                    dataStatisticModel.min           = GetMin(dtMissingValues, dt);
                                    dataStatisticModel.max           = GetMax(dtMissingValues, dt);
                                    dataStatisticModel.missingValues = dtMissingValues;
                                    dataStatisticModels.Add(dataStatisticModel);
                                }
                            }
                            else
                            {
                                Variable variable = new Variable();

                                foreach (Variable vs in structuredDataStructure.Variables)
                                {
                                    if (vs.Id == variableId)
                                    {
                                        variable = vs;
                                    }
                                }

                                ApiDataStatisticModel dataStatisticModel = new ApiDataStatisticModel();
                                dt = GetUniqueValues(id, variableId);
                                dataStatisticModel.VariableId   = variableId;
                                dataStatisticModel.uniqueValues = dt;

                                dataStatisticModel.minLength = dt.Compute("Min(length)", string.Empty).ToString();
                                dataStatisticModel.maxLength = dt.Compute("Max(length)", string.Empty).ToString();
                                dataStatisticModel.count     = dt.Compute("Sum(count)", string.Empty).ToString();
                                foreach (var missingValue in variable.MissingValues)
                                {
                                    DataRow workRow = dtMissingValues.NewRow();
                                    workRow["placeholder"] = missingValue.Placeholder;
                                    workRow["displayName"] = missingValue.DisplayName;
                                    dtMissingValues.Rows.Add(workRow);
                                }
                                dataStatisticModel.min           = GetMin(dtMissingValues, dt);
                                dataStatisticModel.max           = GetMax(dtMissingValues, dt);
                                dataStatisticModel.missingValues = dtMissingValues;
                                dataStatisticModels.Add(dataStatisticModel);
                            }
                            dt.Strip();


                            dt.TableName = id + "_data";

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

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

                            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();
            }
        }