コード例 #1
0
        // 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();
            }
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        public ActionResult Subjects_Select(long entityId, long instanceId)
        {
            var subjectManager          = new SubjectManager();
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var subjects = new List <EntityPermissionGridRowModel>();
                foreach (var subject in subjectManager.Subjects)
                {
                    var rights          = entityPermissionManager.GetRights(subject.Id, entityId, instanceId);
                    var effectiveRights = entityPermissionManager.GetEffectiveRights(subject.Id, entityId, instanceId);

                    subjects.Add(EntityPermissionGridRowModel.Convert(subject, rights, effectiveRights));
                }

                return(View(new GridModel <EntityPermissionGridRowModel> {
                    Data = subjects
                }));
            }
            finally
            {
                subjectManager.Dispose();
                entityPermissionManager.Dispose();
            }
        }
コード例 #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();
            }
        }
コード例 #5
0
        public void AddRightToEntityPermission(long subjectId, long entityId, long instanceId, int rightType)
        {
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var entityPermission = entityPermissionManager.Find(subjectId, entityId, instanceId);

                if (entityPermission == null)
                {
                    entityPermissionManager.Create(subjectId, entityId, instanceId, rightType);
                }
                else
                {
                    if ((entityPermission.Rights & rightType) != 0)
                    {
                        return;
                    }
                    entityPermission.Rights += rightType;
                    entityPermissionManager.Update(entityPermission);
                }
            }
            finally
            {
                entityPermissionManager.Dispose();
            }
        }
コード例 #6
0
        public void RemoveInstanceFromPublic(long entityId, long instanceId)
        {
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var entityPermission = entityPermissionManager.Find(null, entityId, instanceId);

                if (entityPermission == null)
                {
                    return;
                }
                entityPermissionManager.Delete(entityPermission);

                if (this.IsAccessible("DDM", "SearchIndex", "ReIndexSingle"))
                {
                    var x = this.Run("DDM", "SearchIndex", "ReIndexSingle", new RouteValueDictionary()
                    {
                        { "id", instanceId }
                    });
                }
            }
            finally
            {
                entityPermissionManager.Dispose();
            }
        }
コード例 #7
0
        public void AddInstanceToPublic(long entityId, long instanceId)
        {
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var entityPermission = entityPermissionManager.Find(null, entityId, instanceId);

                if (entityPermission == null)
                {
                    entityPermissionManager.Create(null, entityId, instanceId, (int)RightType.Read);

                    if (this.IsAccessible("DDM", "SearchIndex", "ReIndexSingle"))
                    {
                        var x = this.Run("DDM", "SearchIndex", "ReIndexSingle", new RouteValueDictionary()
                        {
                            { "id", instanceId }
                        });
                    }
                }
            }
            finally
            {
                entityPermissionManager.Dispose();
            }
        }
コード例 #8
0
        public void RemoveRightFromEntityPermission(long subjectId, long entityId, long instanceId, int rightType)
        {
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var entityPermission = entityPermissionManager.Find(subjectId, entityId, instanceId);

                if (entityPermission == null)
                {
                    return;
                }

                if (entityPermission.Rights == rightType)
                {
                    entityPermissionManager.Delete(entityPermission);
                }
                else
                {
                    if ((entityPermission.Rights & rightType) == 0)
                    {
                        return;
                    }
                    entityPermission.Rights -= rightType;
                    entityPermissionManager.Update(entityPermission);
                }
            }
            finally
            {
                entityPermissionManager.Dispose();
            }
        }
コード例 #9
0
        public ActionResult Subjects_Select(GridCommand command, long entityId, long instanceId)
        {
            var subjectManager          = new SubjectManager();
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var subjectsDb = new List <Subject>();
                var count      = 0;
                if (command != null)// filter subjects based on grid filter settings
                {
                    FilterExpression  filter  = TelerikGridHelper.Convert(command.FilterDescriptors.ToList());
                    OrderByExpression orderBy = TelerikGridHelper.Convert(command.SortDescriptors.ToList());

                    subjectsDb = subjectManager.GetSubjects(filter, orderBy, command.Page, command.PageSize, out count);
                }
                else
                {
                    subjectsDb = subjectManager.Subjects.ToList();
                    count      = subjectsDb.Count();
                }

                var subjects = new List <EntityPermissionGridRowModel>();
                //using (PartyManager partyManager = new PartyManager())

                //foreach (var subject in subjectsDb)
                //{
                //    var rights = entityPermissionManager.GetRights(subject.Id, entityId, instanceId);
                //    var effectiveRights = entityPermissionManager.GetEffectiveRights(subject.Id, entityId, instanceId);

                //    subjects.Add(EntityPermissionGridRowModel.Convert(subject, rights, effectiveRights));
                //}

                var rightsDic          = entityPermissionManager.GetRights(subjectsDb, entityId, instanceId);
                var effectiveRightsDic = entityPermissionManager.GetEffectiveRights(subjectsDb, entityId, instanceId);

                foreach (var item in rightsDic)
                {
                    var subject         = subjectsDb.Where(s => s.Id.Equals(item.Key)).FirstOrDefault();
                    var rights          = item.Value;
                    var effectiveRights = effectiveRightsDic[item.Key];

                    subjects.Add(EntityPermissionGridRowModel.Convert(subject, rights, effectiveRights));
                }

                return(View(new GridModel <EntityPermissionGridRowModel> {
                    Data = subjects, Total = count
                }));
            }
            finally
            {
                subjectManager.Dispose();
                entityPermissionManager.Dispose();
            }
        }
コード例 #10
0
        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()));
            }
        }
コード例 #11
0
        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);
                }
            }
        }
コード例 #12
0
        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())));
            }
        }
コード例 #13
0
        public void AddInstanceToPublic(long entityId, long instanceId)
        {
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var entityPermission = entityPermissionManager.Find(null, entityId, instanceId);

                if (entityPermission == null)
                {
                    entityPermissionManager.Create(null, entityId, instanceId, (int)RightType.Read);
                }
            }
            finally
            {
                entityPermissionManager.Dispose();
            }
        }
コード例 #14
0
        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();
            }
        }
コード例 #15
0
ファイル: MappingUtils.cs プロジェクト: navabpourn/Core
        private static List <MappingEntityResultElement> getAllValuesFromEntites(IEnumerable <Entities.Mapping.Mapping> mappings, string value)
        {
            List <MappingEntityResultElement> tmp           = new List <MappingEntityResultElement>();
            EntityManager           entityManager           = new EntityManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();

            try
            {
                foreach (var mapping in mappings)
                {
                    //load the entiy for each source element id wich is the entity id
                    var entity = entityManager.EntityRepository.Get(mapping.Source.ElementId);
                    // load all existing entity objects iwith the defined manager

                    var instanceStore = (IEntityStore)Activator.CreateInstance(entityManager.FindById(entity.Id).EntityStoreType);
                    var instances     = instanceStore.GetEntities().Where(e => e.Title.ToLower().Contains(value.ToLower())).Select(i => new MappingEntityResultElement()
                    {
                        EntityId     = i.Id,
                        EntityTypeId = entity.Id,
                        Value        = i.Title,
                        Url          = "url to " + i.Id
                    }).ToList();

                    //check if allready exist in list
                    if (instances.Any())
                    {
                        foreach (var instance in instances)
                        {
                            if (!tmp.Any(i => i.EntityId.Equals(instance.EntityId) && i.EntityTypeId.Equals(instance.EntityTypeId)))
                            {
                                tmp.Add(instance);
                            }
                        }
                    }
                }
            }
            finally
            {
                entityManager.Dispose();
                entityPermissionManager.Dispose();
            }

            return(tmp.OrderBy(i => i.Value).ToList());
        }
コード例 #16
0
        public void RemoveInstanceFromPublic(long entityId, long instanceId)
        {
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var entityPermission = entityPermissionManager.Find(null, entityId, instanceId);

                if (entityPermission == null)
                {
                    return;
                }
                entityPermissionManager.Delete(entityPermission);
            }
            finally
            {
                entityPermissionManager.Dispose();
            }
        }
コード例 #17
0
ファイル: SubmitController.cs プロジェクト: navabpourn/Core
        public List <ListViewItem> LoadDatasetVersionViewList(DataStructureType dataStructureType)
        {
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
            DataStructureManager    dataStructureManager    = new DataStructureManager();
            DatasetManager          dm = new DatasetManager();

            try
            {
                List <long> datasetIds = entityPermissionManager.GetKeys(GetUsernameOrDefault(), "Dataset", typeof(Dataset), RightType.Write).ToList();

                List <ListViewItem> tempStructured   = new List <ListViewItem>();
                List <ListViewItem> tempUnStructured = new List <ListViewItem>();

                var DatasetVersions = dm.GetDatasetLatestVersions(datasetIds, false);

                foreach (var dsv in DatasetVersions)
                {
                    if (dsv.Dataset.DataStructure.Self.GetType().Equals(typeof(StructuredDataStructure)))
                    {
                        tempStructured.Add(new ListViewItem(dsv.Dataset.Id, dsv.Title));
                    }
                    else
                    {
                        tempUnStructured.Add(new ListViewItem(dsv.Dataset.Id, dsv.Title));
                    }
                }

                if (dataStructureType.Equals(DataStructureType.Structured))
                {
                    return(tempStructured.OrderBy(p => p.Title).ToList());
                }
                else
                {
                    return(tempUnStructured.OrderBy(p => p.Title).ToList());
                }
            }
            finally
            {
                entityPermissionManager.Dispose();
                dataStructureManager.Dispose();
                dm.Dispose();
            }
        }
コード例 #18
0
        public ActionResult Instances_Select(long entityId)
        {
            var entityManager           = new EntityManager();
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var instanceStore = (IEntityStore)Activator.CreateInstance(entityManager.FindById(entityId).EntityStoreType);
                var instances     = instanceStore.GetEntities().Select(i => EntityInstanceGridRowModel.Convert(i, entityPermissionManager.Exists(null, entityId, i.Id))).ToList();

                return(View(new GridModel <EntityInstanceGridRowModel> {
                    Data = instances
                }));
            }
            finally
            {
                entityManager.Dispose();
                entityPermissionManager.Dispose();
            }
        }
コード例 #19
0
        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();
            }
        }
コード例 #20
0
        public ActionResult Instances_Select(long entityId)
        {
            var entityManager           = new EntityManager();
            var entityPermissionManager = new EntityPermissionManager();

            //var userManager = new UserManager();

            try
            {
                var instanceStore = (IEntityStore)Activator.CreateInstance(entityManager.FindById(entityId).EntityStoreType);
                //var user = userManager.FindByNameAsync(HttpContext.User.Identity.Name).Result;
                //var keys = entityPermissionManager.GetKeys(user?.Id, entityId, RightType.Grant);
                //var instances = instanceStore.GetEntities().Where(i => keys.Contains(i.Id)).Select(i => EntityInstanceGridRowModel.Convert(i, entityPermissionManager.Exists(null, entityId, i.Id))).ToList();
                var instances = instanceStore.GetEntities().Select(i => EntityInstanceGridRowModel.Convert(i, entityPermissionManager.Exists(null, entityId, i.Id))).ToList();
                return(View(new GridModel <EntityInstanceGridRowModel> {
                    Data = instances
                }));
            }
            finally
            {
                entityManager.Dispose();
                entityPermissionManager.Dispose();
            }
        }
コード例 #21
0
        public List <ListViewItem> LoadDatasetViewList()
        {
            List <ListViewItem> temp = new List <ListViewItem>();

            DatasetManager          datasetManager          = new DatasetManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();
            //get all datasetsid where the current userer has access to
            UserManager      userManager      = new UserManager();
            XmlDatasetHelper xmlDatasetHelper = new XmlDatasetHelper();

            try
            {
                List <long> datasetIds = entityPermissionManager.GetKeys(GetUsernameOrDefault(), "Dataset",
                                                                         typeof(Dataset), RightType.Write);

                foreach (long id in datasetIds)
                {
                    if (datasetManager.IsDatasetCheckedIn(id))
                    {
                        string title       = xmlDatasetHelper.GetInformation(id, NameAttributeValues.title);
                        string description = xmlDatasetHelper.GetInformation(id, NameAttributeValues.description);

                        temp.Add(new ListViewItem(id, title, description));
                    }
                }


                return(temp.OrderBy(p => p.Title).ToList());
            }
            finally
            {
                datasetManager.Dispose();
                entityPermissionManager.Dispose();
                userManager.Dispose();
            }
        }
コード例 #22
0
        //[MeasurePerformance]
        //temporary solution: norman
        //For original solution, look into Aquadiva Code
        public List <Error> FinishUpload(EasyUploadTaskManager taskManager)
        {
            DataStructureManager dsm = new DataStructureManager();
            DatasetManager       dm  = new DatasetManager();
            DataContainerManager dam = new DataContainerManager();
            //SubjectManager sm = new SubjectManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();

            List <Error> temp = new List <Error>();

            try
            {
                using (IUnitOfWork unitOfWork = this.GetUnitOfWork())
                {
                    // initialize all necessary manager

                    DataTuple[] rows = null;

                    //First, try to validate - if there are errors, return immediately
                    string       JsonArray        = TaskManager.Bus[EasyUploadTaskManager.SHEET_JSON_DATA].ToString();
                    List <Error> ValidationErrors = ValidateRows(JsonArray);
                    if (ValidationErrors.Count != 0)
                    {
                        temp.AddRange(ValidationErrors);
                        return(temp);
                    }

                    string timestamp = DateTime.UtcNow.ToString("r");
                    string title     = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]);

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE))
                    {
                        string tmp = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                        if (!String.IsNullOrWhiteSpace(tmp))
                        {
                            title = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                        }
                    }

                    StructuredDataStructure   sds         = null;
                    List <VariableIdentifier> identifiers = new List <VariableIdentifier>(); //Used in Excel reader
                    //Try to find an exact matching datastructure
                    Boolean foundReusableDataStructure = false;

                    List <RowModel> headers = (List <RowModel>)TaskManager.Bus[EasyUploadTaskManager.ROWS];

                    //For some reason, MappedHeaders might be in a different order in this list than what's indicated by its IDs - to prevent mismatching, sort the headers
                    headers.Sort((m1, m2) => m1.Index.CompareTo(m2.Index));

                    List <StructuredDataStructure> allDatastructures = dsm.StructuredDataStructureRepo.Get().ToList();
                    foreach (StructuredDataStructure existingStructure in allDatastructures)
                    {
                        if (!foundReusableDataStructure)
                        {
                            //For now a datastructure is considered an exact match if it contains variables with
                            //the same names (labels), datatypes and units in the correct order
                            List <Variable> variablesOfExistingStructure = existingStructure.Variables.ToList();
                            foundReusableDataStructure = true;
                            if (variablesOfExistingStructure.Count != headers.Count)
                            {
                                foundReusableDataStructure = false;
                            }
                            else
                            {
                                for (int i = 0; i < variablesOfExistingStructure.Count; i++)
                                {
                                    Variable exVar         = variablesOfExistingStructure.ElementAt(i);
                                    RowModel currentHeader = headers.ElementAt(i);
                                    if (exVar.Label != currentHeader.Name ||
                                        exVar.Unit.Id != currentHeader.SelectedUnit.UnitId ||
                                        exVar.DataAttribute.DataType.Id != currentHeader.SelectedDataType.DataTypeId)
                                    {
                                        foundReusableDataStructure = false;
                                    }
                                }
                            }
                            if (foundReusableDataStructure)
                            {
                                sds = existingStructure;
                                foreach (Variable exVar in variablesOfExistingStructure)
                                {
                                    VariableIdentifier vi = new VariableIdentifier
                                    {
                                        name = exVar.Label,
                                        id   = exVar.Id
                                    };
                                    identifiers.Add(vi);
                                }
                            }
                        }
                    }

                    if (!foundReusableDataStructure)
                    {
                        sds = dsm.CreateStructuredDataStructure(title, title + " " + timestamp, "", "", DataStructureCategory.Generic);
                    }

                    TaskManager.AddToBus(EasyUploadTaskManager.DATASTRUCTURE_ID, sds.Id);
                    TaskManager.AddToBus(EasyUploadTaskManager.DATASTRUCTURE_TITLE, title + " " + timestamp);

                    if (!TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DATASET_TITLE))
                    {
                        TaskManager.AddToBus(EasyUploadTaskManager.DATASET_TITLE, title);
                        TaskManager.AddToBus(EasyUploadTaskManager.TITLE, title);
                    }

                    MetadataStructure metadataStructure = null;
                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA))
                    {
                        long metadataStructureId = Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]);
                        metadataStructure = unitOfWork.GetReadOnlyRepository <MetadataStructure>()
                                            .Get(m => m.Id == metadataStructureId).FirstOrDefault();
                    }
                    else
                    {
                        //Default option but shouldn't happen because previous steps can't be finished without selecting the metadata-structure
                        metadataStructure = unitOfWork.GetReadOnlyRepository <MetadataStructure>()
                                            .Get(m => m.Name.ToLower().Contains("eml")).FirstOrDefault();
                    }
                    ResearchPlan rp = unitOfWork.GetReadOnlyRepository <ResearchPlan>().Get().FirstOrDefault();
                    TaskManager.AddToBus(EasyUploadTaskManager.RESEARCHPLAN_ID, rp.Id);
                    TaskManager.AddToBus(EasyUploadTaskManager.RESEARCHPLAN_TITLE, rp.Title);

                    #region Progress Information

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.CURRENTPACKAGESIZE))
                    {
                        TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGESIZE] = 0;
                    }
                    else
                    {
                        TaskManager.Bus.Add(EasyUploadTaskManager.CURRENTPACKAGESIZE, 0);
                    }

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.CURRENTPACKAGE))
                    {
                        TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGE] = 0;
                    }
                    else
                    {
                        TaskManager.Bus.Add(EasyUploadTaskManager.CURRENTPACKAGE, 0);
                    }

                    #endregion Progress Information

                    if (!foundReusableDataStructure)
                    {
                        #region Set Variables and information for new DataStructure

                        XmlDocument xmldoc       = new XmlDocument();
                        XmlElement  extraElement = xmldoc.CreateElement("extra");
                        XmlElement  orderElement = xmldoc.CreateElement("order");

                        //Sorting necessary to prevent problems when inserting the tuples
                        headers.OrderBy(r => r.Index);

                        var dataTypeRepo      = unitOfWork.GetReadOnlyRepository <DataType>();
                        var unitRepo          = unitOfWork.GetReadOnlyRepository <Unit>();
                        var dataAttributeRepo = unitOfWork.GetReadOnlyRepository <DataAttribute>();

                        List <DataAttribute> allDataAttributes = dataAttributeRepo.Get().ToList();

                        foreach (RowModel header in headers)
                        {
                            int i = headers.IndexOf(header);

                            DataType dataType            = dataTypeRepo.Get(header.SelectedDataType.DataTypeId);
                            Unit     CurrentSelectedUnit = unitRepo.Get(header.SelectedUnit.UnitId);

                            DataAttribute CurrentDataAttribute = new DataAttribute();
                            //If possible, map the chosen variable name, unit and datatype to an existing DataAttribute (Exact match)
                            DataAttribute existingDataAttribute = allDataAttributes.Where(da => da.Name.ToLower().Equals(TrimAndLimitString(header.SelectedDataAttribute.Name).ToLower()) &&
                                                                                          da.Unit.Dimension == CurrentSelectedUnit.Dimension).FirstOrDefault();
                            if (existingDataAttribute != null)
                            {
                                CurrentDataAttribute = existingDataAttribute;
                            }
                            else
                            {
                                //No matching DataAttribute => Create a new one
                                CurrentDataAttribute = dam.CreateDataAttribute(TrimAndLimitString(header.Name), header.Name, header.SelectedDataAttribute.Description, false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, CurrentSelectedUnit, null, null, null, null, null, null);
                            }

                            Variable           newVariable = dsm.AddVariableUsage(sds, CurrentDataAttribute, true, header.Name, "", "", "", CurrentSelectedUnit);
                            VariableIdentifier vi          = new VariableIdentifier
                            {
                                name = newVariable.Label,
                                id   = newVariable.Id
                            };
                            identifiers.Add(vi);

                            XmlElement newVariableXml = xmldoc.CreateElement("variable");
                            newVariableXml.InnerText = Convert.ToString(newVariable.Id);

                            orderElement.AppendChild(newVariableXml);
                        }
                        extraElement.AppendChild(orderElement);
                        xmldoc.AppendChild(extraElement);

                        sds.Extra       = xmldoc;
                        sds.Name        = "generated import structure " + timestamp;
                        sds.Description = "automatically generated structured data structure by user " + GetUsernameOrDefault() + " for file " + title + " on " + timestamp;

                        #endregion Set Variables and information for new DataStructure
                    }

                    Dataset ds = null;
                    ds = dm.CreateEmptyDataset(sds, rp, metadataStructure);

                    long datasetId = ds.Id;
                    long sdsId     = sds.Id;

                    if (dm.IsDatasetCheckedOutFor(datasetId, GetUsernameOrDefault()) || dm.CheckOutDataset(datasetId, GetUsernameOrDefault()))
                    {
                        DatasetVersion    dsv = dm.GetDatasetWorkingCopy(datasetId);
                        long              METADATASTRUCTURE_ID = metadataStructure.Id;
                        XmlMetadataWriter xmlMetadatWriter     = new XmlMetadataWriter(XmlNodeMode.xPath);
                        XDocument         metadataX            = xmlMetadatWriter.CreateMetadataXml(METADATASTRUCTURE_ID);
                        XmlDocument       metadataXml          = XmlMetadataWriter.ToXmlDocument(metadataX);
                        dsv.Metadata = metadataXml;
                        try
                        {
                            dsv.Metadata = xmlDatasetHelper.SetInformation(dsv, metadataXml, NameAttributeValues.title, title);
                            dsv.Title    = title;
                        }
                        catch (NullReferenceException ex)
                        {
                            //Reference of the title node is missing
                            throw new NullReferenceException("The extra-field of this metadata-structure is missing the title-node-reference!");
                        }
                        dm.EditDatasetVersion(dsv, null, null, null);
                    }

                    #region security

                    // add security
                    if (GetUsernameOrDefault() != "DEFAULT")
                    {
                        foreach (RightType rightType in Enum.GetValues(typeof(RightType)).Cast <RightType>())
                        {
                            //The user gets full permissions
                            // add security
                            if (GetUsernameOrDefault() != "DEFAULT")
                            {
                                entityPermissionManager.Create <User>(GetUsernameOrDefault(), "Dataset", typeof(Dataset), ds.Id, Enum.GetValues(typeof(RightType)).Cast <RightType>().ToList());
                            }
                        }
                    }

                    #endregion security

                    #region excel reader

                    int packageSize  = 100000;
                    int numberOfRows = 0;
                    //HACK ?
                    TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGESIZE] = packageSize;

                    int counter = 0;

                    dm.CheckOutDatasetIfNot(ds.Id, GetUsernameOrDefault()); // there are cases, the dataset does not get checked out!!
                    if (!dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault()))
                    {
                        throw new Exception(string.Format("Not able to checkout dataset '{0}' for  user '{1}'!", ds.Id, GetUsernameOrDefault()));
                    }

                    DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(ds.Id);

                    counter++;
                    TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGE] = counter;

                    //rows = reader.ReadFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), oldSds, (int)id, packageSize).ToArray();

                    List <string> selectedDataAreaJsonArray   = (List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA];
                    string        selectedHeaderAreaJsonArray = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString();
                    List <int[]>  areaDataValuesList          = new List <int[]>();
                    foreach (string area in selectedDataAreaJsonArray)
                    {
                        areaDataValuesList.Add(JsonConvert.DeserializeObject <int[]>(area));
                    }
                    int[] areaHeaderValues = JsonConvert.DeserializeObject <int[]>(selectedHeaderAreaJsonArray);

                    Orientation orientation = 0;

                    switch (TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT].ToString())
                    {
                    case "LeftRight":
                        orientation = Orientation.rowwise;
                        break;

                    case "Matrix":
                        //orientation = Orientation.matrix;
                        break;

                    default:
                        orientation = Orientation.columnwise;
                        break;
                    }

                    String worksheetUri = null;
                    //Get the Uri to identify the correct worksheet
                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.ACTIVE_WOKSHEET_URI))
                    {
                        worksheetUri = TaskManager.Bus[EasyUploadTaskManager.ACTIVE_WOKSHEET_URI].ToString();
                    }

                    int batchSize = (new Object()).GetUnitOfWork().PersistenceManager.PreferredPushSize;
                    int batchnr   = 1;
                    foreach (int[] areaDataValues in areaDataValuesList)
                    {
                        //First batch starts at the start of the current data area
                        int currentBatchStartRow = areaDataValues[0] + 1;
                        while (currentBatchStartRow <= areaDataValues[2] + 1) //While the end of the current data area has not yet been reached
                        {
                            //End row is start row plus batch size
                            int currentBatchEndRow = currentBatchStartRow + batchSize;

                            //Set the indices for the reader
                            EasyUploadFileReaderInfo fri = new EasyUploadFileReaderInfo
                            {
                                DataStartRow = currentBatchStartRow,
                                //End row is either at the end of the batch or the end of the marked area
                                //DataEndRow = (currentBatchEndRow > areaDataValues[2] + 1) ? areaDataValues[2] + 1 : currentBatchEndRow,
                                DataEndRow = Math.Min(currentBatchEndRow, areaDataValues[2] + 1),
                                //Column indices as marked in a previous step
                                DataStartColumn = areaDataValues[1] + 1,
                                DataEndColumn   = areaDataValues[3] + 1,

                                //Header area as marked in a previous step
                                VariablesStartRow    = areaHeaderValues[0] + 1,
                                VariablesStartColumn = areaHeaderValues[1] + 1,
                                VariablesEndRow      = areaHeaderValues[2] + 1,
                                VariablesEndColumn   = areaHeaderValues[3] + 1,

                                Offset      = areaDataValues[1],
                                Orientation = orientation
                            };
                            //Create a new reader each time because the reader saves ALL tuples it read and therefore the batch processing wouldn't work
                            EasyUploadExcelReader reader = new EasyUploadExcelReader(sds, fri);
                            // open file
                            Stream = reader.Open(TaskManager.Bus[EasyUploadTaskManager.FILEPATH].ToString());

                            //Set variable identifiers because they might differ from the variable names in the file
                            reader.setSubmittedVariableIdentifiers(identifiers);

                            //Read the rows and convert them to DataTuples
                            rows = reader.ReadFile(Stream, TaskManager.Bus[EasyUploadTaskManager.FILENAME].ToString(), fri, (int)datasetId, worksheetUri);

                            //After reading the rows, add them to the dataset
                            if (rows != null)
                            {
                                dm.EditDatasetVersion(workingCopy, rows.ToList(), null, null);
                                numberOfRows += rows.Count();
                            }

                            //Close the Stream so the next ExcelReader can open it again
                            Stream.Close();

                            //Debug information
                            int lines   = (areaDataValues[2] + 1) - (areaDataValues[0] + 1);
                            int batches = lines / batchSize;
                            batchnr++;

                            //Next batch starts after the current one
                            currentBatchStartRow = currentBatchEndRow + 1;
                        }
                    }

                    #endregion excel reader

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

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

                    dm.CheckInDataset(ds.Id, "Import " + numberOfRows + " rows", GetUsernameOrDefault());

                    //Reindex search
                    if (this.IsAccessible("DDM", "SearchIndex", "ReIndexSingle"))
                    {
                        this.Run("DDM", "SearchIndex", "ReIndexSingle", new RouteValueDictionary()
                        {
                            { "id", datasetId }
                        });
                    }

                    TaskManager.AddToBus(EasyUploadTaskManager.DATASET_ID, ds.Id);

                    return(temp);
                }
            }
            catch (Exception ex)
            {
                temp.Add(new Error(ErrorType.Other, "An error occured during the upload. " +
                                   "Please try again later. If this problem keeps occuring, please contact your administrator."));
                return(temp);
            }
            finally
            {
                dsm.Dispose();
                dm.Dispose();
                dam.Dispose();
                //sm.Dispose();
                entityPermissionManager.Dispose();
            }
        }
コード例 #23
0
        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();
            }
        }
コード例 #24
0
        /// <summary>
        /// create a model to fill the table of My Dataset
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref="ShowMyDatasets"/>
        /// <param>NA</param>
        /// <returns>model</returns>
        public ActionResult _CustomMyDatasetBinding()
        {
            DataTable model = new DataTable();

            ViewData["PageSize"]    = 10;
            ViewData["CurrentPage"] = 1;

            #region header

            List <HeaderItem> headerItems = CreateHeaderItems();
            ViewData["DefaultHeaderList"] = headerItems;

            #endregion header

            model = CreateDataTable(headerItems);

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

            try
            {
                var entity = entityManager.FindByName("Dataset");
                var user   = userManager.FindByNameAsync(GetUsernameOrDefault()).Result;

                List <long> gridCommands = datasetManager.GetDatasetLatestIds();
                gridCommands.Skip(Convert.ToInt16(ViewData["CurrentPage"])).Take(Convert.ToInt16(ViewData["PageSize"]));

                List <DatasetVersion> datasetVersions = datasetManager.GetDatasetLatestVersions(gridCommands, false);
                foreach (var dsv in datasetVersions)
                {
                    var datasetId = dsv.Dataset.Id;

                    //get permissions
                    int rights = entityPermissionManager.GetEffectiveRights(user?.Id, entity.Id, datasetId);

                    if (rights > 0)
                    {
                        DataRow  dataRow  = model.NewRow();
                        Object[] rowArray = new Object[8];
                        string   isValid  = "no";

                        if (datasetManager.IsDatasetCheckedIn(datasetId))
                        {
                            string title       = dsv.Title;
                            string description = dsv.Description;

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

                            rowArray[0] = Convert.ToInt64(datasetId);
                            rowArray[1] = title;
                            rowArray[2] = description;
                        }
                        else
                        {
                            rowArray[0] = Convert.ToInt64(datasetId);
                            rowArray[1] = "";
                            rowArray[2] = "Dataset is just in processing.";
                        }

                        rowArray[3] = (rights & (int)RightType.Read) > 0 ? "✔" : "✘";
                        rowArray[4] = (rights & (int)RightType.Write) > 0 ? "✔" : "✘";
                        rowArray[5] = (rights & (int)RightType.Delete) > 0 ? "✔" : "✘";
                        //rowArray[6] = (rights & (int)RightType.Download) > 0 ? "✔" : "✘";
                        rowArray[6] = (rights & (int)RightType.Grant) > 0 ? "✔" : "✘";
                        rowArray[7] = isValid;

                        dataRow           = model.NewRow();
                        dataRow.ItemArray = rowArray;
                        model.Rows.Add(dataRow);
                    }
                }

                return(View(new GridModel(model)));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                datasetManager.Dispose();
                entityPermissionManager.Dispose();
                entityManager.Dispose();
                userManager.Dispose();
            }
        }
コード例 #25
0
        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!"));
            }
        }
コード例 #26
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();
            }
        }
コード例 #27
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();
            }
        }
コード例 #28
0
        /// <summary>
        /// create a model to fill the table of My Dataset
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref="ShowMyDatasets"/>
        /// <param>NA</param>
        /// <returns>model</returns>
        public ActionResult _CustomMyDatasetBinding()
        {
            DataTable model = new DataTable();

            ViewData["PageSize"]    = 10;
            ViewData["CurrentPage"] = 1;

            #region header
            List <HeaderItem> headerItems = CreateHeaderItems();
            ViewData["DefaultHeaderList"] = headerItems;

            #endregion

            model = CreateDataTable(headerItems);


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


            try
            {
                var entity = entityManager.FindByName("Dataset");
                var user   = userManager.FindByNameAsync(GetUsernameOrDefault()).Result;

                List <long> gridCommands = datasetManager.GetDatasetLatestIds();
                gridCommands.Skip(Convert.ToInt16(ViewData["CurrentPage"])).Take(Convert.ToInt16(ViewData["PageSize"]));

                foreach (long datasetId in gridCommands)
                {
                    //get permissions
                    int rights = entityPermissionManager.GetEffectiveRights(user?.Id, entity.Id, datasetId);

                    if (rights > 0)
                    {
                        DataRow  dataRow  = model.NewRow();
                        Object[] rowArray = new Object[8];

                        if (datasetManager.IsDatasetCheckedIn(datasetId))
                        {
                            //long versionId = datasetManager.GetDatasetLatestVersionId (datasetId); // check for zero value
                            //DatasetVersion dsv = datasetManager.DatasetVersionRepo.Get(versionId);

                            DatasetVersion dsv = datasetManager.GetDatasetLatestVersion(datasetId);

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

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

                            rowArray[0] = Convert.ToInt64(datasetId);
                            rowArray[1] = title;
                            rowArray[2] = description;
                        }
                        else
                        {
                            rowArray[0] = Convert.ToInt64(datasetId);
                            rowArray[1] = "";
                            rowArray[2] = "Dataset is just in processing.";
                        }

                        rowArray[3] = (rights & (int)RightType.Read) > 0 ? "✔" : "✘";
                        rowArray[4] = (rights & (int)RightType.Write) > 0 ? "✔" : "✘";
                        rowArray[5] = (rights & (int)RightType.Delete) > 0 ? "✔" : "✘";
                        rowArray[6] = (rights & (int)RightType.Download) > 0 ? "✔" : "✘";
                        rowArray[7] = (rights & (int)RightType.Grant) > 0 ? "✔" : "✘";

                        dataRow           = model.NewRow();
                        dataRow.ItemArray = rowArray;
                        model.Rows.Add(dataRow);
                    }
                }

                return(View(new GridModel(model)));
            }
            finally
            {
                datasetManager.Dispose();
                entityPermissionManager.Dispose();
                entityManager.Dispose();
                userManager.Dispose();
            }
        }
コード例 #29
0
        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();
            }
        }
コード例 #30
0
        //[MeasurePerformance]
        //temporary solution: norman
        //For original solution, look into Aquadiva Code
        public List <Error> FinishUpload(EasyUploadTaskManager taskManager)
        {
            DataStructureManager dsm = new DataStructureManager();
            DatasetManager       dm  = new DatasetManager();
            DataContainerManager dam = new DataContainerManager();
            //SubjectManager sm = new SubjectManager();
            EntityPermissionManager entityPermissionManager = new EntityPermissionManager();

            List <Error> temp = new List <Error>();

            try
            {
                using (IUnitOfWork unitOfWork = this.GetUnitOfWork())
                {
                    // initialize all necessary manager

                    DataTuple[] rows = null;

                    //First, try to validate - if there are errors, return immediately
                    string       JsonArray        = TaskManager.Bus[EasyUploadTaskManager.SHEET_JSON_DATA].ToString();
                    List <Error> ValidationErrors = ValidateRows(JsonArray);
                    if (ValidationErrors.Count != 0)
                    {
                        temp.AddRange(ValidationErrors);
                        return(temp);
                    }

                    string timestamp = DateTime.UtcNow.ToString("r");
                    string title     = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.FILENAME]);

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DESCRIPTIONTITLE))
                    {
                        string tmp = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                        if (!String.IsNullOrWhiteSpace(tmp))
                        {
                            title = Convert.ToString(TaskManager.Bus[EasyUploadTaskManager.DESCRIPTIONTITLE]);
                        }
                    }

                    StructuredDataStructure sds = dsm.CreateStructuredDataStructure(title, title + " " + timestamp, "", "", DataStructureCategory.Generic);

                    TaskManager.AddToBus(EasyUploadTaskManager.DATASTRUCTURE_ID, sds.Id);
                    TaskManager.AddToBus(EasyUploadTaskManager.DATASTRUCTURE_TITLE, title + " " + timestamp);

                    if (!TaskManager.Bus.ContainsKey(EasyUploadTaskManager.DATASET_TITLE))
                    {
                        TaskManager.AddToBus(EasyUploadTaskManager.DATASET_TITLE, title);
                        TaskManager.AddToBus(EasyUploadTaskManager.TITLE, title);
                    }

                    MetadataStructure metadataStructure = null;
                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.SCHEMA))
                    {
                        long metadataStructureId = Convert.ToInt64(TaskManager.Bus[EasyUploadTaskManager.SCHEMA]);
                        metadataStructure = unitOfWork.GetReadOnlyRepository <MetadataStructure>()
                                            .Get(m => m.Id == metadataStructureId).FirstOrDefault();
                    }
                    else
                    {
                        //Default option but shouldn't happen because previous steps can't be finished without selecting the metadata-structure
                        metadataStructure = unitOfWork.GetReadOnlyRepository <MetadataStructure>()
                                            .Get(m => m.Name.ToLower().Contains("eml")).FirstOrDefault();
                    }
                    ResearchPlan rp = unitOfWork.GetReadOnlyRepository <ResearchPlan>().Get().FirstOrDefault();
                    TaskManager.AddToBus(EasyUploadTaskManager.RESEARCHPLAN_ID, rp.Id);
                    TaskManager.AddToBus(EasyUploadTaskManager.RESEARCHPLAN_TITLE, rp.Title);

                    #region Progress Information

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.CURRENTPACKAGESIZE))
                    {
                        TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGESIZE] = 0;
                    }
                    else
                    {
                        TaskManager.Bus.Add(EasyUploadTaskManager.CURRENTPACKAGESIZE, 0);
                    }

                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.CURRENTPACKAGE))
                    {
                        TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGE] = 0;
                    }
                    else
                    {
                        TaskManager.Bus.Add(EasyUploadTaskManager.CURRENTPACKAGE, 0);
                    }

                    #endregion

                    #region DataStructure
                    XmlDocument xmldoc       = new XmlDocument();
                    XmlElement  extraElement = xmldoc.CreateElement("extra");
                    XmlElement  orderElement = xmldoc.CreateElement("order");


                    List <Tuple <int, string, UnitInfo> > MappedHeaders = (List <Tuple <int, string, UnitInfo> >)TaskManager.Bus[EasyUploadTaskManager.VERIFICATION_MAPPEDHEADERUNITS];
                    //Sorting necessary to prevent problems when inserting the tuples
                    MappedHeaders.Sort((head1, head2) => head1.Item1.CompareTo(head2.Item1));
                    List <VariableIdentifier> identifiers = new List <VariableIdentifier>();

                    var dataTypeRepo      = unitOfWork.GetReadOnlyRepository <DataType>();
                    var unitRepo          = unitOfWork.GetReadOnlyRepository <Unit>();
                    var dataAttributeRepo = unitOfWork.GetReadOnlyRepository <DataAttribute>();

                    List <DataAttribute> allDataAttributes = dataAttributeRepo.Get().ToList();

                    foreach (Tuple <int, string, UnitInfo> Entry in MappedHeaders)
                    {
                        int i = MappedHeaders.IndexOf(Entry);

                        DataType dataType            = dataTypeRepo.Get(Entry.Item3.SelectedDataTypeId);
                        Unit     CurrentSelectedUnit = unitRepo.Get(Entry.Item3.UnitId);

                        DataAttribute CurrentDataAttribute = new DataAttribute();
                        //If possible, map the chosen variable name, unit and datatype to an existing DataAttribute (Exact match)
                        DataAttribute existingDataAttribute = allDataAttributes.Where(da => da.Name.ToLower().Equals(TrimAndLimitString(Entry.Item2).ToLower()) &&
                                                                                      da.DataType.Id == dataType.Id &&
                                                                                      da.Unit.Id == CurrentSelectedUnit.Id).FirstOrDefault();
                        if (existingDataAttribute != null)
                        {
                            CurrentDataAttribute = existingDataAttribute;
                        }
                        else
                        {
                            //No matching DataAttribute => Create a new one
                            CurrentDataAttribute = dam.CreateDataAttribute(TrimAndLimitString(Entry.Item2), Entry.Item2, "", false, false, "", MeasurementScale.Categorial, DataContainerType.ReferenceType, "", dataType, CurrentSelectedUnit, null, null, null, null, null, null);
                        }

                        Variable           newVariable = dsm.AddVariableUsage(sds, CurrentDataAttribute, true, Entry.Item2, "", "", "");
                        VariableIdentifier vi          = new VariableIdentifier
                        {
                            name = newVariable.Label,
                            id   = newVariable.Id
                        };
                        identifiers.Add(vi);

                        XmlElement newVariableXml = xmldoc.CreateElement("variable");
                        newVariableXml.InnerText = Convert.ToString(newVariable.Id);

                        orderElement.AppendChild(newVariableXml);
                    }
                    extraElement.AppendChild(orderElement);
                    xmldoc.AppendChild(extraElement);

                    sds.Extra       = xmldoc;
                    sds.Name        = "generated import structure " + timestamp;
                    sds.Description = "automatically generated structured data structure by user " + GetUsernameOrDefault() + " for file " + title + " on " + timestamp;

                    #endregion

                    Dataset ds = null;
                    ds = dm.CreateEmptyDataset(sds, rp, metadataStructure);

                    //TODO Should a template be created?

                    /*ExcelTemplateProvider etp = new ExcelTemplateProvider();
                     * etp.CreateTemplate(sds);*/

                    long datasetId = ds.Id;
                    long sdsId     = sds.Id;


                    if (dm.IsDatasetCheckedOutFor(datasetId, GetUsernameOrDefault()) || dm.CheckOutDataset(datasetId, GetUsernameOrDefault()))
                    {
                        DatasetVersion    dsv = dm.GetDatasetWorkingCopy(datasetId);
                        long              METADATASTRUCTURE_ID = metadataStructure.Id;
                        XmlMetadataWriter xmlMetadatWriter     = new XmlMetadataWriter(XmlNodeMode.xPath);
                        XDocument         metadataX            = xmlMetadatWriter.CreateMetadataXml(METADATASTRUCTURE_ID);
                        XmlDocument       metadataXml          = XmlMetadataWriter.ToXmlDocument(metadataX);
                        dsv.Metadata = metadataXml;
                        try
                        {
                            dsv.Metadata = xmlDatasetHelper.SetInformation(dsv, metadataXml, NameAttributeValues.title, title);
                        }
                        catch (NullReferenceException ex)
                        {
                            //Reference of the title node is missing
                            throw new NullReferenceException("The extra-field of this metadata-structure is missing the title-node-reference!");
                        }
                        dm.EditDatasetVersion(dsv, null, null, null);
                    }


                    #region security
                    // add security
                    if (GetUsernameOrDefault() != "DEFAULT")
                    {
                        //PermissionManager pm = new PermissionManager();

                        //User user = sm.GetUserByName(GetUsernameOrDefault());

                        //Rights-Management

                        /*
                         * TODO: Use the BExIS Party API for that
                         *
                         * */
                        /*
                         * UserPiManager upm = new UserPiManager();
                         * List<long> piList = (new UserSelectListModel(GetUsernameOrDefault())).UserList.Select(x => x.Id).ToList();
                         */


                        foreach (RightType rightType in Enum.GetValues(typeof(RightType)).Cast <RightType>())
                        {
                            //The user gets full permissions
                            // add security
                            if (GetUsernameOrDefault() != "DEFAULT")
                            {
                                entityPermissionManager.Create <User>(GetUsernameOrDefault(), "Dataset", typeof(Dataset), ds.Id, Enum.GetValues(typeof(RightType)).Cast <RightType>().ToList());
                            }

                            // adding the rights for the pis

                            /*foreach (long piId in piList)
                             * {
                             *  //Each pi gets full permissions
                             *  pm.CreateDataPermission(piId, 1, ds.Id, rightType);
                             *
                             *  // get all pi members
                             *  List<UserPi> currentMembers = upm.GetAllPiMember(piId).ToList();
                             *
                             *  foreach (UserPi currentMapping in currentMembers)
                             *  {
                             *      switch (rightType)
                             *      {
                             *          //Each member of each of the pis gets view-rights
                             *          case RightType.View:
                             *              pm.CreateDataPermission(currentMapping.UserId, 1, ds.Id, rightType);
                             *              break;
                             *          //Each member of each of the pis gets download-rights
                             *          case RightType.Download:
                             *              pm.CreateDataPermission(currentMapping.UserId, 1, ds.Id, rightType);
                             *              break;
                             *          default:
                             *              //No other permissions - is this call necessary?
                             *              pm.CreateDataPermission(currentMapping.UserId, 0, ds.Id, rightType);
                             *              break;
                             *      }
                             *  }
                             * }*/
                        }
                    }
                    #endregion security


                    #region excel reader

                    int packageSize = 10000;
                    //HACK ?
                    TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGESIZE] = packageSize;

                    int counter = 0;

                    dm.CheckOutDatasetIfNot(ds.Id, GetUsernameOrDefault()); // there are cases, the dataset does not get checked out!!
                    if (!dm.IsDatasetCheckedOutFor(ds.Id, GetUsernameOrDefault()))
                    {
                        throw new Exception(string.Format("Not able to checkout dataset '{0}' for  user '{1}'!", ds.Id, GetUsernameOrDefault()));
                    }

                    DatasetVersion workingCopy = dm.GetDatasetWorkingCopy(ds.Id);

                    counter++;
                    TaskManager.Bus[EasyUploadTaskManager.CURRENTPACKAGE] = counter;

                    //rows = reader.ReadFile(Stream, TaskManager.Bus[TaskManager.FILENAME].ToString(), oldSds, (int)id, packageSize).ToArray();

                    List <string> selectedDataAreaJsonArray   = (List <string>)TaskManager.Bus[EasyUploadTaskManager.SHEET_DATA_AREA];
                    string        selectedHeaderAreaJsonArray = TaskManager.Bus[EasyUploadTaskManager.SHEET_HEADER_AREA].ToString();
                    List <int[]>  areaDataValuesList          = new List <int[]>();
                    foreach (string area in selectedDataAreaJsonArray)
                    {
                        areaDataValuesList.Add(JsonConvert.DeserializeObject <int[]>(area));
                    }
                    int[] areaHeaderValues = JsonConvert.DeserializeObject <int[]>(selectedHeaderAreaJsonArray);

                    Orientation orientation = 0;

                    switch (TaskManager.Bus[EasyUploadTaskManager.SHEET_FORMAT].ToString())
                    {
                    case "LeftRight":
                        orientation = Orientation.rowwise;
                        break;

                    case "Matrix":
                        //orientation = Orientation.matrix;
                        break;

                    default:
                        orientation = Orientation.columnwise;
                        break;
                    }

                    String worksheetUri = null;
                    //Get the Uri to identify the correct worksheet
                    if (TaskManager.Bus.ContainsKey(EasyUploadTaskManager.ACTIVE_WOKSHEET_URI))
                    {
                        worksheetUri = TaskManager.Bus[EasyUploadTaskManager.ACTIVE_WOKSHEET_URI].ToString();
                    }

                    int batchSize = (new Object()).GetUnitOfWork().PersistenceManager.PreferredPushSize;
                    int batchnr   = 1;
                    foreach (int[] areaDataValues in areaDataValuesList)
                    {
                        //First batch starts at the start of the current data area
                        int currentBatchStartRow = areaDataValues[0] + 1;
                        while (currentBatchStartRow <= areaDataValues[2] + 1) //While the end of the current data area has not yet been reached
                        {
                            //Create a new reader each time because the reader saves ALL tuples it read and therefore the batch processing wouldn't work
                            EasyUploadExcelReader reader = new EasyUploadExcelReader();
                            // open file
                            Stream = reader.Open(TaskManager.Bus[EasyUploadTaskManager.FILEPATH].ToString());

                            //End row is start row plus batch size
                            int currentBatchEndRow = currentBatchStartRow + batchSize;

                            //Set the indices for the reader
                            EasyUploadFileReaderInfo fri = new EasyUploadFileReaderInfo
                            {
                                DataStartRow = currentBatchStartRow,
                                //End row is either at the end of the batch or the end of the marked area
                                //DataEndRow = (currentBatchEndRow > areaDataValues[2] + 1) ? areaDataValues[2] + 1 : currentBatchEndRow,
                                DataEndRow = Math.Min(currentBatchEndRow, areaDataValues[2] + 1),
                                //Column indices as marked in a previous step
                                DataStartColumn = areaDataValues[1] + 1,
                                DataEndColumn   = areaDataValues[3] + 1,

                                //Header area as marked in a previous step
                                VariablesStartRow    = areaHeaderValues[0] + 1,
                                VariablesStartColumn = areaHeaderValues[1] + 1,
                                VariablesEndRow      = areaHeaderValues[2] + 1,
                                VariablesEndColumn   = areaHeaderValues[3] + 1,

                                Offset      = areaDataValues[1],
                                Orientation = orientation
                            };

                            //Set variable identifiers because they might differ from the variable names in the file
                            reader.setSubmittedVariableIdentifiers(identifiers);

                            //Read the rows and convert them to DataTuples
                            rows = reader.ReadFile(Stream, TaskManager.Bus[EasyUploadTaskManager.FILENAME].ToString(), fri, sds, (int)datasetId, worksheetUri);

                            //After reading the rows, add them to the dataset
                            if (rows != null)
                            {
                                dm.EditDatasetVersion(workingCopy, rows.ToList(), null, null);
                            }

                            //Close the Stream so the next ExcelReader can open it again
                            Stream.Close();

                            //Debug information
                            int lines   = (areaDataValues[2] + 1) - (areaDataValues[0] + 1);
                            int batches = lines / batchSize;
                            batchnr++;

                            //Next batch starts after the current one
                            currentBatchStartRow = currentBatchEndRow + 1;
                        }
                    }

                    #endregion


                    dm.CheckInDataset(ds.Id, "upload data from upload wizard", GetUsernameOrDefault());

                    //Reindex search
                    if (this.IsAccessibale("DDM", "SearchIndex", "ReIndexSingle"))
                    {
                        this.Run("DDM", "SearchIndex", "ReIndexSingle", new RouteValueDictionary()
                        {
                            { "id", datasetId }
                        });
                    }

                    TaskManager.AddToBus(EasyUploadTaskManager.DATASET_ID, ds.Id);

                    return(temp);
                }
            }
            catch (Exception ex)
            {
                temp.Add(new Error(ErrorType.Other, "An error occured during the upload. " +
                                   "Please try again later. If this problem keeps occuring, please contact your administrator."));
                return(temp);
            }
            finally
            {
                dsm.Dispose();
                dm.Dispose();
                dam.Dispose();
                //sm.Dispose();
                entityPermissionManager.Dispose();
            }
        }