Ejemplo n.º 1
0
        public void AddParentGetTest()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                LoginApplicationUserAndSetSessionVariables();
                TaxonController controller     = new TaxonController();
                string          controllerName = "Taxon";
                string          actionName     = "AddParent";
                controller.ControllerContext = GetShimControllerContext(actionName, controllerName);

                ITaxonRevision refTaxonRevision = TaxonDataSourceTestRepositoryData.GetReferenceRevision(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId, TaxonRevisionStateId.Ongoing.ToString());
                ITaxon         refTaxon         = TaxonDataSourceTestRepositoryData.GetReferenceTaxon(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId);
                TaxonIdTuple   taxonIdentifier  = TaxonIdTuple.Create(refTaxon.ScientificName, refTaxon.Id);

                SessionRevision   = refTaxonRevision;
                SessionRevisionId = DyntaxaTestSettings.Default.TestRevisionOngoingId;
                SessionTaxonId    = taxonIdentifier;
                // Mock Controller
                //           builder.InitializeController(controller);

                // Test 1:
                // Act
                var addParentResult    = controller.AddParent(DyntaxaTestSettings.Default.TestTaxonId.ToString()) as ViewResult;
                var addParentViewModel = addParentResult.ViewData.Model as TaxonAddParentViewModel;


                // Assert
                Assert.IsNotNull(addParentResult);
                Assert.IsNotNull(addParentViewModel);

                // Test that correct view is returned
                Assert.AreEqual("AddParent", addParentResult.ViewName);

                // Test model values
                // TODO test more model values....

                Assert.IsNull(addParentViewModel.SelectedTaxonList);
                Assert.AreEqual(1, addParentViewModel.AvailableParents.Count);
                Assert.AreEqual(refTaxon.Id.ToString(), addParentViewModel.TaxonId);
                Assert.AreEqual(refTaxonRevision.Id.ToString(), addParentViewModel.RevisionId);

                foreach (TaxonParentViewModelHelper helper in addParentViewModel.TaxonList)
                {
                    Assert.IsNotNull(helper.Category);
                    Assert.IsNotNull(helper.CommonName);
                    Assert.IsNotNull(helper.SortOrder);
                    Assert.IsNotNull(helper.TaxonId);
                    Assert.IsNotNull(helper.ScientificName);
                }
            }
        }
 public static bool SetCurrentUserRoleToTaxonRevisionEditor(this IUserContext user, int revisionId)
 {
     try
     {
         ITaxonRevision taxonRevision = CoreData.TaxonManager.GetTaxonRevision(user, revisionId);
         return(AuthorizationManager.SetUserRoleToTaxonRevisionEditor(user, taxonRevision.Guid));
     }
     catch (Exception ex)
     {
         DyntaxaLogger.WriteException(ex);
         return(false);
     }
 }
Ejemplo n.º 3
0
 public void SaveTaxonRevision(IUserContext userContext, ITaxonRevision taxonRevision)
 {
     if (taxonRevision.State.Id == (int)TaxonRevisionStateId.Created || taxonRevision.State.Id == 0)
     {
         taxonRevision.Id = DyntaxaTestSettings.Default.TestRevisionId;
     }
     else if (taxonRevision.State.Id == (int)TaxonRevisionStateId.Ongoing)
     {
         taxonRevision.Id = DyntaxaTestSettings.Default.TestRevisionOngoingId;
     }
     else
     {
         taxonRevision.Id = DyntaxaTestSettings.Default.TestRevisionPublishedId;
     }
     return;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Get dyntaxa reference relation
        /// </summary>
        /// <param name="taxonRevision"></param>
        /// <returns></returns>
        public static List <IReferenceRelation> GetDyntaxaRevisionReferenceRelation(ITaxonRevision taxonRevision)
        {
            var referencesToAdd = new List <IReferenceRelation>();

            IUserContext      userContext          = CoreData.UserManager.GetCurrentUser();
            ReferenceRelation newReferenceRelation = new ReferenceRelation()
            {
                RelatedObjectGuid = taxonRevision.Guid,
                Type        = CoreData.ReferenceManager.GetReferenceRelationType(userContext, ReferenceRelationTypeId.Source),
                Reference   = null,
                ReferenceId = DyntaxaReference
            };

            referencesToAdd.Add(newReferenceRelation);
            return(referencesToAdd);
        }
Ejemplo n.º 5
0
        //public int RevisionId { get { return _revisionId; } }

        /// <summary>
        /// Constructor
        /// </summary>
        public ListTaxonNameViewModel(ITaxon taxon, ITaxonRevision taxonRevision)
        {
            this._taxonRevision = taxonRevision;
            this._taxon         = taxon;

            Dictionary <ITaxonNameCategory, List <ITaxonName> > dicNames = GetTaxonNamesByCategory(taxon.GetTaxonNames(CoreData.UserManager.GetCurrentUser()));

            var nameCategories = new List <TaxonNameCategoryViewModel>();

            foreach (ITaxonNameCategory nameCategory in dicNames.Keys)
            {
                nameCategories.Add(new TaxonNameCategoryViewModel(taxon, nameCategory, dicNames[nameCategory]));
            }

            NameCategories = nameCategories;
        }
        public void ReInitializeTaxonMoveViewModel(TaxonMoveViewModel model, ITaxonRevision taxonRevision, bool isOkToMove = true) //, ITaxon taxon, bool isOkToMove = true)
        {
            ITaxon taxon = CoreData.TaxonManager.GetTaxon(_user, model.OldParentTaxonId);

            model.HasChildren = true;
            model.IsOkToMove  = isOkToMove;

            // Child taxa
            model.ChildTaxa = new List <RelatedTaxonViewModel>();
            if (taxon.GetNearestChildTaxonRelations(_user).IsNotEmpty())
            {
                foreach (ITaxonRelation taxonRelation in taxon.GetNearestChildTaxonRelations(_user))
                {
                    model.ChildTaxa.Add(new RelatedTaxonViewModel(taxonRelation.ChildTaxon, taxonRelation.ChildTaxon.Category, null));
                }
            }
            if (model.ChildTaxa.Count == 0)
            {
                // TODO cant throw exception
                //throw new Exception("Taxon has no children");
                model.HasChildren = false;
            }

            // Available parents
            model.AvailableParents = new List <RelatedTaxonViewModel>();
            if (model.ChildTaxa.Count != 0)
            {
                ITaxon    revisionTaxon = CoreData.TaxonManager.GetTaxon(_user, model.ChildTaxa[0].TaxonId);
                TaxonList list          = revisionTaxon.GetTaxaPossibleParents(_user, taxonRevision);
                foreach (ITaxon possibleParentTaxon in list)
                {
                    model.AvailableParents.Add(new RelatedTaxonViewModel(possibleParentTaxon, possibleParentTaxon.Category, null));
                }
            }

            // Taxon categories
            model.TaxonCategories = new List <TaxonCategoryViewModel>();
            // var categories = GetTaxonCategories(taxon);
            // Get all categories within this revision
            var categories = GetTaxonCategories(taxonRevision.RootTaxon);

            foreach (ITaxonCategory taxonCategory in categories)
            {
                model.TaxonCategories.Add(new TaxonCategoryViewModel(taxonCategory.Id, taxonCategory.Name));
            }
        }
        // Called "LIVE"
        public TaxonInfoViewModel(ITaxon taxon, IUserContext user, ITaxonRevision taxonRevision, int?revisionTaxonCategorySortOrder)
        {
            this._user          = user;
            this._taxon         = taxon;
            this._taxonRevision = taxonRevision;
            this._revisionTaxonCategorySortOrder = revisionTaxonCategorySortOrder;
            _taxonCategory = taxon.Category;
            bool isInRevision      = IsInRevision;
            bool isUserTaxonEditor = user.IsTaxonEditor();

            //AcceptedNames = GetAcceptedNames(isInRevision, isUserTaxonEditor);
            Synonyms = _taxon.GetSynonymsViewModel(isInRevision, isUserTaxonEditor, false);
            //NewSynonyms = GetNewSynonyms(isInRevision, isUserTaxonEditor);
            ProParteSynonyms = _taxon.GetProParteSynonymsViewModel(isInRevision, isUserTaxonEditor);
            MisappliedNames  = _taxon.GetMisappliedNamesViewModel(isInRevision, isUserTaxonEditor);
            Identifiers      = _taxon.GetIdentfiersViewModel(isInRevision, isUserTaxonEditor);
        }
        public static bool IsInRevision(IUserContext user, int?revisionId)
        {
            ITaxonRevision rev = GetRevisionFromSession();

            if (rev != null)
            {
                return(IsInRevision(user, rev));
            }

            if (!revisionId.HasValue)
            {
                return(false);
            }

            ITaxonRevision taxonRevision = CoreData.TaxonManager.GetTaxonRevision(user, revisionId.Value);

            return(user.IsTaxonRevisionEditor(taxonRevision));
        }
        public static bool IsInRevision()
        {
            ITaxonRevision taxonRevision = GetRevisionFromSession();
            IUserContext   userContext   = CoreData.UserManager.GetCurrentUser();

            if (taxonRevision != null)
            {
                return(IsInRevision(userContext, taxonRevision));
            }

            if (HttpContext.Current == null || HttpContext.Current.Session == null)
            {
                return(false);
            }

            var revisionId = HttpContext.Current.Session["RevisionId"] as int?;

            return(IsInRevision(userContext, revisionId));
        }
Ejemplo n.º 10
0
        private static string GetRevisionDescription(ITaxonRevision taxonRevision)
        {
            if (taxonRevision == null)
            {
                return("");
            }
            else
            {
                string taxonName;
                if (taxonRevision.RootTaxon.ScientificName.IsNotEmpty())
                {
                    taxonName = taxonRevision.RootTaxon.ScientificName;
                }
                else
                {
                    taxonName = string.Format("TaxonId: {0}", taxonRevision.RootTaxon.Id);
                }

                return(string.Format("{0}: {1}", Resources.DyntaxaResource.ReferenceGuidObjectInfoRevisionText, taxonName));
            }
        }
        // **************************************
        // URL: /Account/AutoLogIn
        // **************************************
        // TODO: inactivate this action when publish
        public ActionResult AutoLogIn(string returnUrl, int? revisionId)
        {
            IUserContext userContext = CoreData.UserManager.Login("testuser", "Qwertyasdfg123", Resources.DyntaxaSettings.Default.DyntaxaApplicationIdentifier);
           
            if (userContext.IsNotNull())
            {
                Session["userContext"] = userContext;

                // Must clear the service cash so that roles can be reloded.
                // CoreData.TaxonManager.ClearCacheForUserRoles(userContext);

                /* globalization with cookie */
                HttpCookie cookie = new HttpCookie("CultureInfo");
                cookie.Value = userContext.Locale.ISOCode;
                cookie.Expires = DateTime.Now.AddYears(1);
                Response.Cookies.Add(cookie);

                FormsService.SignIn("testuser");
                if (revisionId.HasValue)
                {
                    this.RevisionId = revisionId.Value;                    
                    ITaxonRevision taxonRevision = CoreData.TaxonManager.GetTaxonRevision(GetCurrentUser(), revisionId.Value);
                    this.TaxonRevision = taxonRevision;
                    this.RevisionTaxonId = taxonRevision.RootTaxon.Id;
                    this.RevisionTaxonCategorySortOrder = taxonRevision.RootTaxon.Category.SortOrder;
                }
                this.RedrawTree();
            }
            else
            {
                ModelState.AddModelError("", Resources.DyntaxaResource.AccountControllerIncorrectLoginError);
            }

            if (string.IsNullOrEmpty(returnUrl))
            {
                return RedirectToAction("SearchResult", "Taxon");
            }

            return Redirect(returnUrl);            
        }
        public ActionResult Add(TaxonNameDetailsViewModel model)
        {
            ITaxon         taxon         = CoreData.TaxonManager.GetTaxon(GetCurrentUser(), model.TaxonId);
            ITaxonName     taxonName     = new TaxonName();
            ITaxonRevision taxonRevision = this.TaxonRevision;

            _taxonNameViewManager.InitTaxonNameDetails(model, taxon);

            // Only Nomenclature: Correct, Provisional, PreliminarySuggestion or Informal names may have usage: Accepted.
            if (model.SelectedTaxonNameUsageId == (int)TaxonNameUsageId.Accepted &&
                !(model.SelectedTaxonNameStatusId == (int)TaxonNameStatusId.ApprovedNaming ||
                  model.SelectedTaxonNameStatusId == (int)TaxonNameStatusId.Provisional ||
                  model.SelectedTaxonNameStatusId == (int)TaxonNameStatusId.PreliminarySuggestion ||
                  model.SelectedTaxonNameStatusId == (int)TaxonNameStatusId.Informal))
            {
                ModelState.AddModelError("", Resources.DyntaxaResource.TaxonNameAddEditIncorrectNomencalture);
            }

            if (!ModelState.IsValid)
            {
                return(View("Add", model));
            }
            IUserContext loggedInUser = GetLoggedInUser();

            // Creation of taxon name
            using (ITransaction transaction = loggedInUser.StartTransaction())
            {
                taxonName = _taxonNameViewManager.AddTaxonName(model, TaxonIdentifier.Id.Value, this.TaxonRevision);
                // Must set default reference, set from Revision..
                ReferenceRelationList referencesToAdd = ReferenceHelper.GetDefaultReferences(GetCurrentUser(), taxonName, taxonRevision, null);
                var referencesToRemove = new ReferenceRelationList();
                CoreData.ReferenceManager.CreateDeleteReferenceRelations(GetCurrentUser(), referencesToAdd, referencesToRemove);
                transaction.Commit();
            }
            return(RedirectToAction("Edit", new { @taxonId = model.TaxonId, @nameId = taxonName.Version }));
        }
        /// <summary>
        /// Split taxa
        /// </summary>
        /// <param name="loggedInUser"></param>
        /// <param name="splitTaxonId"></param>
        /// <param name="taxonRevision"></param>
        /// <param name="ctrReplaceTaxonIdList"></param>
        public void SplitTaxon(IUserContext loggedInUser, int?splitTaxonId, ITaxonRevision taxonRevision, List <int?> ctrReplaceTaxonIdList)
        {
            ITaxon splitTaxon = null;

            if (splitTaxonId.IsNotNull())
            {
                splitTaxon = CoreData.TaxonManager.GetTaxon(loggedInUser, (int)splitTaxonId);
            }
            TaxonList replacingTaxa = new TaxonList();

            foreach (var taxonId in ctrReplaceTaxonIdList)
            {
                if (taxonId.IsNotNull())
                {
                    replacingTaxa.Add(CoreData.TaxonManager.GetTaxon(loggedInUser, (int)taxonId));
                }
            }

            using (ITransaction transaction = loggedInUser.StartTransaction())
            {
                CoreData.TaxonManager.SplitTaxon(loggedInUser, splitTaxon, replacingTaxa, taxonRevision);
                transaction.Commit();
            }
        }
Ejemplo n.º 14
0
        public ITaxonName AddTaxonName(TaxonNameDetailsViewModel model, int taxonId, ITaxonRevision taxonRevision)
        {
            ITaxon taxon = CoreData.TaxonManager.GetTaxon(_user, taxonId);

            var taxonName = new ArtDatabanken.Data.TaxonName();

            taxonName.DataContext = new DataContext(_user);
            taxonName.Name        = model.Name;
            taxonName.Author      = model.Author;
            taxonName.Category    = CoreData.TaxonManager.GetTaxonNameCategory(_user, model.SelectedCategoryId);
            taxonName.Status      = CoreData.TaxonManager.GetTaxonNameStatus(CoreData.UserManager.GetCurrentUser(), model.SelectedTaxonNameStatusId);
            taxonName.NameUsage   = CoreData.TaxonManager.GetTaxonNameUsage(CoreData.UserManager.GetCurrentUser(), model.SelectedTaxonNameUsageId);
            // Todo Not set in GUI only Changed in list
            taxonName.IsRecommended = model.IsRecommended;
            taxonName.Description   = model.Comment;
            // taxonName.Taxon = CoreData.TaxonManager.GetTaxon(_user, model.TaxonId);
            taxonName.IsOkForSpeciesObservation = !model.IsNotOkForObsSystem;
            taxonName.IsOriginalName            = model.IsOriginal;
            taxonName.Taxon = taxon;

            CoreData.TaxonManager.CreateTaxonName(_user, taxonRevision, taxonName);
            //CoreData.TaxonManager.AddTaxonName(_user, taxon, revision, taxonName);
            return(taxonName);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="loggedInUser"></param>
        /// <param name="dyntaxaApplicationUserContext"></param>
        /// <param name="taxonRevision"></param>
        /// <param name="isTaxonInRevision"></param>
        /// <param name="revisionUsers"></param>
        /// <param name="allUsers"></param>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public RevisionEditViewModel GetRevisionEditViewModel(
            IUserContext loggedInUser,
            IUserContext dyntaxaApplicationUserContext,
            ITaxonRevision taxonRevision,
            ITaxon taxon,
            bool isTaxonInRevision,
            IList <RevisionUserItemModelHelper> revisionUsers,
            IList <RevisionUserItemModelHelper> allUsers,
            int roleId)
        {
            RevisionEditViewModel model = new RevisionEditViewModel();

            if (loggedInUser.IsNotNull() && dyntaxaApplicationUserContext.IsNotNull())
            {
                // Set locale to logged in user.
                dyntaxaApplicationUserContext.Locale = loggedInUser.Locale;

                if (taxonRevision.IsNotNull())
                {
                    if (taxon.IsNotNull())
                    {
                        model.ExpectedStartDate             = taxonRevision.ExpectedStartDate;
                        model.ExpectedPublishingDate        = taxonRevision.ExpectedEndDate;
                        model.IsSpeciesFactPublished        = taxonRevision.IsSpeciesFactPublished;
                        model.IsReferenceRelationsPublished = taxonRevision.IsReferenceRelationsPublished;
                        model.GUID = taxonRevision.Guid;
                        model.RevisionReferencesList = new List <int>();
                        model.NoOfRevisionReferences = 0;
                        foreach (ReferenceRelation referenceRelation in taxonRevision.GetReferences(loggedInUser))
                        {
                            model.RevisionReferencesList.Add(referenceRelation.Id);
                            model.NoOfRevisionReferences++;
                        }

                        model.SelectedUserList = new List <RevisionUserItemModelHelper>();
                        model.UserList         = new List <RevisionUserItemModelHelper>();
                        foreach (RevisionUserItemModelHelper user in allUsers)
                        {
                            bool userAssigedToRevision = false;
                            foreach (RevisionUserItemModelHelper revisionUser in revisionUsers)
                            {
                                if (user.Id == revisionUser.Id)
                                {
                                    //We found a alreday assigned user
                                    userAssigedToRevision = true;
                                    break;
                                }
                            }

                            if (userAssigedToRevision)
                            {
                                model.SelectedUserList.Add(user);
                            }
                            else
                            {
                                model.UserList.Add(user);
                            }
                        }
                        string url = Resources.DyntaxaResource.SharedRevisionUserAdminLinkText;
                        model.RoleId        = roleId.ToString();
                        model.UserAdminLink = new LinkItem(LinkType.Url, LinkQuality.Automatic, url, userAdminRoleLink);

                        model.RevisionDescription = taxonRevision.Description;

                        // Get specices fact information
                        try
                        {
                            SpeciesFactModelManager speciesModel = new SpeciesFactModelManager(taxon, loggedInUser);
                            try
                            {
                                if (speciesModel.QualityStatus.IsNotNull())
                                {
                                    model.RevisionQualityId = speciesModel.QualityStatus.Id;
                                }
                                else if (speciesModel.QualityStatusList.IsNotNull() && speciesModel.QualityStatusList.Count > 1)
                                {
                                    model.RevisionQualityId = speciesModel.QualityStatusList.ElementAt(0).Id;
                                }
                                else
                                {
                                    model.RevisionQualityId = 0;
                                }

                                model.RevisionQualityList = new List <TaxonDropDownModelHelper>();
                                foreach (var status in speciesModel.QualityStatusList)
                                {
                                    model.RevisionQualityList.Add(new TaxonDropDownModelHelper(status.Id, status.Label));
                                }
                                model.RevisionQualityDescription = speciesModel.QualityDescription;
                            }
                            catch (Exception)
                            {
                                model.ErrorMessage = Resources.DyntaxaResource.SharedNotPossibleToReadSpeciesFactError;
                            }
                        }
                        catch (Exception)
                        {
                            model.ErrorMessage = Resources.DyntaxaResource.SharedNotPossibleToReadSpeciesFactError;
                        }

                        model.RevisionTaxonInfoViewModel = new RevisionTaxonInfoViewModel();

                        model.RevisionTaxonInfoViewModel.Id                = taxonRevision.Id.ToString();
                        model.RevisionTaxonInfoViewModel.CommonName        = taxon.CommonName.IsNotEmpty() ? taxon.CommonName : string.Empty;
                        model.RevisionTaxonInfoViewModel.ScientificName    = taxon.ScientificName;
                        model.RevisionTaxonInfoViewModel.Category          = taxon.Category.Name;
                        model.RevisionTaxonInfoViewModel.CategorySortOrder = taxon.Category.SortOrder;

                        model.RevisionTaxonInfoViewModel.RevisionText   = Resources.DyntaxaResource.SharedRevisionIdLabelText;
                        model.RevisionTaxonInfoViewModel.MainHeaderText = Resources.DyntaxaResource.RevisionEditMainHeaderFullText;

                        model.RevisionId          = taxonRevision.Id.ToString();
                        model.ShowFinalizeButton  = false;
                        model.ShowInitalizeButton = false;
                        model.ShowDeleteButton    = false;
                        ITaxon revisionTaxon = taxonRevision.RootTaxon;
                        int    state         = taxonRevision.State.Id;
                        if (state == (int)TaxonRevisionStateId.Created)
                        {
                            model.RevisionStatus      = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusCreatedText;
                            model.ShowInitalizeButton = true;
                            model.IsTaxonInRevision   = revisionTaxon.IsInRevision;
                            model.ShowDeleteButton    = true;
                        }
                        else if (state == (int)TaxonRevisionStateId.Ongoing)
                        {
                            model.RevisionStatus     = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusOngoingText;
                            model.ShowFinalizeButton = true;
                        }
                        else if (state == (int)TaxonRevisionStateId.Closed)
                        {
                            model.RevisionStatus = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusClosedText;
                            model.ShowUpdateSpeciesFactButton        = !taxonRevision.IsSpeciesFactPublished;
                            model.ShowUpdateReferenceRelationsButton = !taxonRevision.IsReferenceRelationsPublished;
                        }
                        model.RevisionTaxonId = revisionTaxon.Id.ToString();

                        return(model);
                    }
                    else
                    {
                        model.ErrorMessage = Resources.DyntaxaResource.RevisonAddInvalidTaxonErrorText;
                    }
                }
                else
                {
                    model.ErrorMessage = Resources.DyntaxaResource.RevisionSharedNoValidRevisionIdErrorText + taxonRevision.Id + ".";
                }
            }
            else
            {
                model.ErrorMessage = Resources.DyntaxaResource.SharedInvalidUserContext + " " + Resources.DyntaxaResource.SharedInvalidApplicationUserContext;
            }
            return(model);
        }
        public RevisionEditViewModel ReloadRevisionEditViewModel(
            IUserContext userContext,
            IUserContext dyntaxaApplicationUserContext,
            ITaxon taxon,
            ITaxonRevision taxonRevision,
            RevisionEditViewModel model,
            IList <RevisionUserItemModelHelper> revisionUsers,
            IList <RevisionUserItemModelHelper> allUsers)
        {
            IUserContext loggedInUser = userContext;

            model.RevisionQualityList        = new List <TaxonDropDownModelHelper>();
            model.SelectedUserList           = new List <RevisionUserItemModelHelper>();
            model.UserList                   = new List <RevisionUserItemModelHelper>();
            model.RevisionReferencesList     = new List <int>();
            model.RevisionTaxonInfoViewModel = new RevisionTaxonInfoViewModel();
            if (loggedInUser.IsNotNull() && dyntaxaApplicationUserContext.IsNotNull())
            {
                if (taxonRevision.IsNotNull())
                {
                    foreach (ReferenceRelation referenceRelation in taxonRevision.GetReferences(userContext))
                    {
                        model.RevisionReferencesList.Add(referenceRelation.Id);
                    }
                }

                foreach (RevisionUserItemModelHelper user in allUsers)
                {
                    bool userAssigedToRevision = false;
                    if (revisionUsers.IsNotNull())
                    {
                        foreach (RevisionUserItemModelHelper revisionUser in revisionUsers)
                        {
                            if (user.Id == revisionUser.Id)
                            {
                                //We found a alreday assigned user
                                userAssigedToRevision = true;
                                break;
                            }
                        }
                    }
                    if (userAssigedToRevision)
                    {
                        model.SelectedUserList.Add(user);
                    }
                    else
                    {
                        model.UserList.Add(user);
                    }
                }

                if (taxon.IsNotNull())
                {
                    SpeciesFactModelManager speciesModel = new SpeciesFactModelManager(taxon, loggedInUser);
                    foreach (var status in speciesModel.QualityStatusList)
                    {
                        model.RevisionQualityList.Add(new TaxonDropDownModelHelper(status.Id, status.Label));
                    }
                }
                if (taxon.IsNotNull() && taxonRevision.IsNotNull())
                {
                    model.RevisionTaxonInfoViewModel = new RevisionTaxonInfoViewModel();

                    model.RevisionTaxonInfoViewModel.Id                = taxonRevision.Id.ToString();
                    model.RevisionTaxonInfoViewModel.CommonName        = taxon.CommonName.IsNotEmpty() ? taxon.CommonName : string.Empty;
                    model.RevisionTaxonInfoViewModel.ScientificName    = taxon.ScientificName;
                    model.RevisionTaxonInfoViewModel.Category          = taxon.Category.Name;
                    model.RevisionTaxonInfoViewModel.CategorySortOrder = taxon.Category.SortOrder;

                    model.RevisionTaxonInfoViewModel.RevisionText   = Resources.DyntaxaResource.SharedRevisionIdLabelText;
                    model.RevisionTaxonInfoViewModel.MainHeaderText = Resources.DyntaxaResource.RevisionEditMainHeaderFullText;
                }

                string url = Resources.DyntaxaResource.SharedRevisionUserAdminLinkText;
                model.UserAdminLink = new LinkItem(LinkType.Url, LinkQuality.Automatic, url, userAdminRoleLink);
            }
            else
            {
                model.ErrorMessage = Resources.DyntaxaResource.SharedInvalidUserContext + " " + Resources.DyntaxaResource.SharedInvalidApplicationUserContext;
            }
            return(model);
        }
        public RevisionTaxonInfoViewModel GetRevisionInfoViewModel(ITaxon revisionTaxon, ITaxonRevision taxonRevision)
        {
            RevisionTaxonInfoViewModel revisionTaxonInfoViewModel = new RevisionTaxonInfoViewModel();

            if (revisionTaxon.IsNotNull())
            {
                revisionTaxonInfoViewModel.CommonName = revisionTaxon.CommonName.IsNotEmpty()
                                                              ? revisionTaxon.CommonName
                                                              : string.Empty;
                revisionTaxonInfoViewModel.ScientificName    = revisionTaxon.ScientificName;
                revisionTaxonInfoViewModel.Category          = revisionTaxon.Category.Name;
                revisionTaxonInfoViewModel.CategorySortOrder = revisionTaxon.Category.SortOrder;
            }
            else
            {
                revisionTaxonInfoViewModel.CommonName        = string.Empty;
                revisionTaxonInfoViewModel.ScientificName    = string.Empty;
                revisionTaxonInfoViewModel.Category          = string.Empty;
                revisionTaxonInfoViewModel.CategorySortOrder = 0;
            }
            if (taxonRevision.IsNotNull())
            {
                revisionTaxonInfoViewModel.Id = taxonRevision.Id.ToString();
            }
            else
            {
                revisionTaxonInfoViewModel.Id = "0";
            }

            revisionTaxonInfoViewModel.RevisionText   = Resources.DyntaxaResource.SharedRevisionIdLabelText;
            revisionTaxonInfoViewModel.MainHeaderText = Resources.DyntaxaResource.RevisionListEventMainHeaderlText;

            return(revisionTaxonInfoViewModel);
        }
 /// <summary>
 /// Checks if the user is TaxonRevisionEditor
 /// </summary>
 /// <param name="user">the user</param>
 /// <param name="taxonRevision">the revision</param>
 /// <returns></returns>
 public static bool IsTaxonRevisionEditor(this IUserContext user, ITaxonRevision taxonRevision)
 {
     return(IsAuthenticated(user) && AuthorizationManager.IsTaxonRevisionEditor(user, taxonRevision));
 }
        /// <summary>
        /// Returns information extracted from revision
        /// </summary>
        /// <param name="loggedInUser"></param>
        /// <param name="revisionTaxon"></param>
        /// <param name="taxonRevision"></param>
        /// <param name="infoItem"></param>
        /// <returns></returns>
        public RevisionInfoItemModelHelper GetRevisionInformation(IUserContext loggedInUser, ITaxon revisionTaxon, ITaxonRevision taxonRevision, RevisionInfoItemModelHelper infoItem)
        {
            infoItem.ExpectedStartDate      = taxonRevision.ExpectedStartDate.ToShortDateString();
            infoItem.ExpectedPublishingDate = taxonRevision.ExpectedEndDate.ToShortDateString();
            infoItem.RevisionDescription    = taxonRevision.Description;
            infoItem.RevisionId             = taxonRevision.Id.ToString();
            infoItem.TaxonId = revisionTaxon.Id.ToString();
            int state = taxonRevision.State.Id;

            if (state == (int)TaxonRevisionStateId.Created)
            {
                infoItem.RevisionStatus = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusCreatedText;
            }
            else if (state == (int)TaxonRevisionStateId.Ongoing)
            {
                infoItem.RevisionStatus = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusOngoingText;
            }
            else if (state == (int)TaxonRevisionStateId.Closed)
            {
                infoItem.RevisionStatus = Resources.DyntaxaResource.RevisionListSelectedRevisionStatusClosedText;
            }
            if (revisionTaxon.ScientificName.IsNotEmpty())
            {
                infoItem.ScientificName = revisionTaxon.ScientificName;
            }
            if (revisionTaxon.CommonName.IsNotEmpty())
            {
                infoItem.CommonName = revisionTaxon.CommonName;
            }
            infoItem.TaxonCategory = revisionTaxon.Category.Name;
            return(infoItem);
        }
Ejemplo n.º 20
0
        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            bool authorized = false;

            AuthorizationManager authorizationManager = new AuthorizationManager(httpContext.Session);
            int roleIndex = -1;

            if (authorizationManager.UserContext.IsNotNull())
            {
                switch (this.Order)
                {
                case RequiredAuthorization.Authenticated:
                    authorized = authorizationManager.UserContext.IsNotNull();
                    break;

                case RequiredAuthorization.TaxonRevisionAdministrator:

                    authorized = authorizationManager.IsTaxonRevisionAdministrator(out roleIndex);
                    break;

                case RequiredAuthorization.TaxonEditor:
                    authorized = authorizationManager.IsTaxonEditor(out roleIndex);
                    break;

                case RequiredAuthorization.TaxonRevisionEditor:
                    int?revId = httpContext.Session["RevisionId"] as int?;
                    if (revId.HasValue)
                    {
                        ITaxonRevision taxonRevision = CoreData.TaxonManager.GetTaxonRevision(authorizationManager.UserContext, revId.Value);
                        authorized = authorizationManager.IsTaxonRevisionEditor(taxonRevision, out roleIndex);
                    }

                    //var strRevisionId = httpContext.Request.RequestContext.RouteData.Values["revisionId"] ??
                    //                    httpContext.Request.QueryString["revisionId"] ??
                    //                    httpContext.Request.Form["revisionId"];

                    //if (strRevisionId != null)
                    //{
                    //    int revisionId;
                    //    if (int.TryParse(strRevisionId.ToString(), out revisionId))
                    //    {
                    //        authorized = authorizationManager.IsTaxonRevisionEditor(revisionId, out roleIndex);
                    //    }
                    //}
                    break;

                case RequiredAuthorization.SpeciesFactEditor:
                    authorized        = authorizationManager.HasSpeciesFactAuthority();
                    ChangeCurrentRole = false;
                    break;

                case RequiredAuthorization.SpeciesFactEVAEditor:
                    authorized        = authorizationManager.HasEVASpeciesFactAuthority();
                    ChangeCurrentRole = false;
                    break;

                case RequiredAuthorization.EditReference:
                    authorized        = authorizationManager.HasEditReferenceAuthority();
                    ChangeCurrentRole = false;
                    break;
                }
            }

            if (ChangeCurrentRole && authorized && Order != RequiredAuthorization.Authenticated)
            {
                authorizationManager.SetUserRole(roleIndex);
            }

            return(authorized);
        }
 public SwedishOccurrenceSummaryManager(IUserContext userContext, ITaxonRevision taxonRevision)
 {
     _userContext   = userContext;
     _taxonRevision = taxonRevision;
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Remove old source reference for taxon.
        /// </summary>
        /// <param name="taxonRevision"></param>
        /// <param name="replacingTaxon"></param>
        /// <returns></returns>
        public static ReferenceRelationList RemoveTaxonSourceReferences(IUserContext userContext, ITaxonRevision taxonRevision, ITaxon replacingTaxon)
        {
            // Must remove old source reference though
            ReferenceRelationList referencesToRemove = new ReferenceRelationList();

            foreach (IReferenceRelation oldReferenceRelation in replacingTaxon.GetReferenceRelations(userContext))
            {
                if (oldReferenceRelation.Type.Id == (int)ReferenceRelationTypeId.Source)
                {
                    referencesToRemove.Add(oldReferenceRelation);
                }
            }

            return(referencesToRemove);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Get default reference from revision
        /// </summary>
        /// <param name="userContext"></param>
        /// <param name="newObject"></param>
        /// <param name="taxonRevision"></param>
        /// <param name="referencesToAdd"> </param>
        /// <returns></returns>
        public static ReferenceRelationList GetDefaultReferences(IUserContext userContext, object newObject, ITaxonRevision taxonRevision, ReferenceRelationList referencesToAdd)
        {
            // Check if list is null the create a new one
            var referencesToAddTemp = new ReferenceRelationList();

            if (referencesToAdd.IsNotNull())
            {
                referencesToAddTemp = referencesToAdd;
            }

            if (taxonRevision.GetReferences(userContext).IsNotEmpty())
            {
                // Set all revision references of type Source as references
                foreach (var referenceRelation in taxonRevision.GetReferences(userContext))
                {
                    if (referenceRelation.Type.Id == (int)ReferenceRelationTypeId.Source)
                    {
                        IReference newReference = new ArtDatabanken.Data.Reference();
                        newReference.Id = referenceRelation.ReferenceId;
                        IReferenceRelation newReferenceRelation = GetReferenceRelation(newObject, newReference);
                        if (newReferenceRelation.IsNotNull())
                        {
                            referencesToAddTemp.Add(newReferenceRelation);
                        }
                    }
                }

                // Get first reference of type Used in and set as Source reference.
                if (referencesToAddTemp.Count == 0)
                {
                    IReference newReference = new ArtDatabanken.Data.Reference();
                    newReference.Id = taxonRevision.GetReferences(userContext).First().ReferenceId;
                    IReferenceRelation newReferenceRelation = GetReferenceRelation(newObject, newReference);
                    if (newReferenceRelation.IsNotNull())
                    {
                        referencesToAddTemp.Add(newReferenceRelation);
                    }
                }
            }

            // If no references found set dyntaxa as reference
            else
            {
                IReference newReference = new ArtDatabanken.Data.Reference();
                newReference.Id = DyntaxaReference;
                IReferenceRelation newReferenceRelation = GetReferenceRelation(newObject, newReference);
                if (newReferenceRelation.IsNotNull())
                {
                    referencesToAddTemp.Add(newReferenceRelation);
                }
            }

            return(referencesToAddTemp);
        }
        /// <summary>
        /// Saves the move to db
        /// </summary>
        /// <param name="selectedTaxa"></param>
        /// <param name="oldParentId"></param>
        /// <param name="newParentId"></param>
        /// <param name="taxonRevision"></param>
        public void MoveTaxa(List <int> selectedTaxa, int oldParentId, int newParentId, ITaxonRevision taxonRevision)
        {
            ITaxon oldParent = CoreData.TaxonManager.GetTaxon(_user, oldParentId);
            ITaxon newParent = CoreData.TaxonManager.GetTaxon(_user, newParentId);

            TaxonList taxa = new TaxonList();

            foreach (int taxonId in selectedTaxa)
            {
                ITaxon taxon = CoreData.TaxonManager.GetTaxon(_user, taxonId);
                taxa.Add(taxon);
            }

            using (ITransaction transaction = _user.StartTransaction())
            {
                CoreData.TaxonManager.MoveTaxa(_user, taxa, oldParent, newParent, taxonRevision);
                transaction.Commit();
            }
        }
Ejemplo n.º 25
0
        public void AddPostTest()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                LoginApplicationUserAndSetSessionVariables();

                // TODO this does not work; how do we set transactions to a user and shim them in code?
                Transaction = new ShimTransaction()
                {
                    Commit = () => { return; },
                };

                TaxonController controller     = new TaxonController();
                string          controllerName = "Taxon";
                string          actionName     = "Add";
                controller.ControllerContext = GetShimControllerContext(actionName, controllerName);

                ITaxonRevision refTaxonRevision = TaxonDataSourceTestRepositoryData.GetReferenceRevision(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId, TaxonRevisionStateId.Ongoing.ToString());
                ITaxon         refTaxon         = TaxonDataSourceTestRepositoryData.GetReferenceTaxon(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId);
                TaxonIdTuple   taxonIdentifier  = TaxonIdTuple.Create(refTaxon.ScientificName, refTaxon.Id);

                SessionRevision   = refTaxonRevision;
                SessionRevisionId = DyntaxaTestSettings.Default.TestRevisionOngoingId;
                SessionTaxonId    = taxonIdentifier;

                // Create model....
                TaxonAddViewModel model = new TaxonAddViewModel();
                model.ParentTaxonId   = DyntaxaTestSettings.Default.TestParentTaxonId.ToString();
                model.TaxonCategoryId = 14;
                model.ScientificName  = "New Parent";

                // Test 1: Model state is valid
                // Act
                var result = controller.Add(model) as RedirectToRouteResult;

                // Test that correct view is returned
                Assert.IsNotNull(result);

                Assert.AreEqual(DyntaxaTestSettings.Default.TestTaxonId.ToString(), result.RouteValues["taxonId"]);
                Assert.AreEqual("Edit", result.RouteValues["action"]);

                // Test 2: Model state is invalid
                // Act
                // Set model state to be invalid
                controller.ModelState.AddModelError("", "dummy error message");
                var addResult    = controller.Add(model) as ViewResult;
                var addViewModel = addResult.ViewData.Model as TaxonAddViewModel;


                // Assert
                Assert.IsNotNull(addResult);

                // Test that correct view is returned ie th add view is reloaded...
                Assert.AreEqual("Add", addResult.ViewName);

                Assert.IsNotNull(addViewModel);

                // Test that Imodel values.
                Assert.AreEqual(DyntaxaTestSettings.Default.TestParentTaxonId.ToString(), addViewModel.ParentTaxonId);
            }
        }
Ejemplo n.º 26
0
 public bool IsTaxonRevisionEditor(ITaxonRevision taxonRevision, out int index)
 {
     return(IsTaxonRevisionEditor(this.UserContext, taxonRevision, out index));
 }
Ejemplo n.º 27
0
        public ITaxonName SaveTaxonNameDetailsChanges(TaxonNameDetailsViewModel model, int taxonId, ITaxonRevision taxonRevision)
        {
            ITaxon     taxon     = CoreData.TaxonManager.GetTaxon(_user, taxonId);
            ITaxonName taxonName = taxon.GetTaxonNameByVersion(_user, Int32.Parse(model.Version));

            taxonName.Name      = model.Name;
            taxonName.Author    = model.Author;
            taxonName.Category  = CoreData.TaxonManager.GetTaxonNameCategory(_user, model.SelectedCategoryId);
            taxonName.Status    = CoreData.TaxonManager.GetTaxonNameStatus(_user, model.SelectedTaxonNameStatusId);
            taxonName.NameUsage = CoreData.TaxonManager.GetTaxonNameUsage(_user, model.SelectedTaxonNameUsageId);
            //taxonName.IsRecommended = model.IsRecommended;
            taxonName.Description = model.Comment;
            taxonName.Taxon       = CoreData.TaxonManager.GetTaxon(_user, model.TaxonId);
            taxonName.IsOkForSpeciesObservation = !model.IsNotOkForObsSystem;
            taxonName.IsOriginalName            = model.IsOriginal;

            // at least one scientific name must be recommended
            if (taxonName.Category.Id == (Int32)TaxonNameCategoryId.ScientificName && taxonName.IsRecommended == false)
            {
                var  scientificNames  = taxon.GetTaxonNames(_user).Where(name => name.Category.Id == (Int32)TaxonNameCategoryId.ScientificName).ToList();
                bool isAnyRecommended = scientificNames.Any(scientificName => scientificName.IsRecommended);
                if (!isAnyRecommended)
                {
                    taxonName.IsRecommended = true;
                }
            }

            using (ITransaction transaction = _user.StartTransaction())
            {
                CoreData.TaxonManager.UpdateTaxonName(_user, taxonRevision, taxonName);

                transaction.Commit();
            }
            return(taxonName);
        }
        public void AddScientificRecommendedTaxonName(string name, string author, ITaxon taxon, ITaxonRevision taxonRevision)
        {
            var taxonName = new ArtDatabanken.Data.TaxonName();

            taxonName.DataContext               = new DataContext(_user);
            taxonName.Name                      = name;
            taxonName.Author                    = author;
            taxonName.Category                  = CoreData.TaxonManager.GetTaxonNameCategory(_user, (Int32)TaxonNameCategoryId.ScientificName);
            taxonName.Status                    = CoreData.TaxonManager.GetTaxonNameStatus(_user, TaxonNameStatusId.ApprovedNaming);
            taxonName.NameUsage                 = CoreData.TaxonManager.GetTaxonNameUsage(_user, TaxonNameUsageId.Accepted);
            taxonName.IsRecommended             = true;
            taxonName.Description               = "";
            taxonName.Taxon                     = taxon;
            taxonName.IsOkForSpeciesObservation = true;
            taxonName.IsOriginalName            = false;
            using (ITransaction transaction = _user.StartTransaction())
            {
                CoreData.TaxonManager.CreateTaxonName(_user, taxonRevision, taxonName);
                // Set default reference, set from Revision..
                ReferenceRelationList referencesToAdd = ReferenceHelper.GetDefaultReferences(
                    _user,
                    taxonName,
                    taxonRevision,
                    null);
                var referencesToRemove = new ReferenceRelationList();
                CoreData.ReferenceManager.CreateDeleteReferenceRelations(_user, referencesToAdd, referencesToRemove);
                transaction.Commit();
            }
        }
Ejemplo n.º 29
0
        public void DropParentPostTest()
        {
            using (ShimsContext.Create())
            {
                // Arrange
                LoginApplicationUserAndSetSessionVariables();

                // TODO this does not work; how do we set transactions to a user and shim them in code?
                Transaction = new ShimTransaction()
                {
                    Commit = () => { return; },
                };
                TaxonController controller     = new TaxonController();
                string          controllerName = "Taxon";
                string          actionName     = "DropParent";
                controller.ControllerContext = GetShimControllerContext(actionName, controllerName);

                ITaxonRevision refTaxonRevision = TaxonDataSourceTestRepositoryData.GetReferenceRevision(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId, TaxonRevisionStateId.Ongoing.ToString());
                ITaxon         refTaxon         = TaxonDataSourceTestRepositoryData.GetReferenceTaxon(ApplicationUserContext, DyntaxaTestSettings.Default.TestTaxonId);
                TaxonIdTuple   taxonIdentifier  = TaxonIdTuple.Create(refTaxon.ScientificName, refTaxon.Id);

                SessionRevision   = refTaxonRevision;
                SessionRevisionId = DyntaxaTestSettings.Default.TestRevisionOngoingId;
                SessionTaxonId    = taxonIdentifier;
                refTaxon.GetNearestParentTaxonRelations(UserContextData).Add(new TaxonRelation()
                {
                    ReplacedInTaxonRevisionEventId = null,
                    CreatedBy      = 1,
                    CreatedDate    = new DateTime(2011),
                    ValidToDate    = new DateTime(2022),
                    IsMainRelation = false,
                    Id             = 55555
                });


                // Mock Controller
                //        builder.InitializeController(controller);
                // Create model....
                TaxonDropParentViewModel model = new TaxonDropParentViewModel();
                model.TaxonId           = DyntaxaTestSettings.Default.TestTaxonId.ToString();
                model.RevisionId        = DyntaxaTestSettings.Default.TestRevisionOngoingId.ToString();
                model.SelectedTaxonList = new List <string>()
                {
                    "55555"
                };


                var addParentResult = controller.DropParent(model) as RedirectToRouteResult;

                // Test 1: Test Save button pressed

                // Assert
                Assert.IsNotNull(addParentResult);

                // Test that AddParent action is returned.
                Assert.AreEqual(refTaxon.Id.ToString(), addParentResult.RouteValues["TaxonId"]);
                Assert.AreEqual("DropParent", addParentResult.RouteValues["action"]);

                // Test 2: No new parent seleceted reload view
                // Act
                model.SelectedTaxonList = null;
                var addParentResult2 = controller.DropParent(model) as RedirectToRouteResult;

                // Assert
                Assert.IsNotNull(addParentResult2);

                // Test that AddParent action is returned.
                Assert.AreEqual(refTaxon.Id.ToString(), addParentResult2.RouteValues["taxonId"]);
                Assert.AreEqual("DropParent", addParentResult.RouteValues["action"]);
            }
        }
Ejemplo n.º 30
0
 public bool IsTaxonRevisionEditor(ITaxonRevision taxonRevision)
 {
     return(IsTaxonRevisionEditor(this.UserContext, taxonRevision));
 }