Esempio n. 1
0
        /// <summary>
        /// Loads children
        /// </summary>
        /// <param name="parent">the parent</param>
        /// <param name="allDescendants">true if we should load all descendants. If false only the closest children is loaded</param>
        /// <returns></returns>
        public List <TaxonTreeViewItem> LoadChildren(TaxonTreeViewItem parent, bool allDescendants)
        {
            IUserContext userContext  = CoreData.UserManager.GetCurrentUser();
            bool         isInRevision = DyntaxaHelper.IsInRevision(userContext, this._revisionId);
            var          children     = new List <TaxonTreeViewItem>();
            var          parentChilds = parent.Taxon.GetChildTaxonRelations(userContext, isInRevision, false);

            foreach (ITaxonRelation taxonRelation in parentChilds)
            {
                if (!ShowSecondaryRelations.GetValueOrDefault(true))
                {
                    if (!taxonRelation.IsMainRelation)
                    {
                        continue;
                    }
                }

                TaxonTreeViewItem item = new TaxonTreeViewItem(taxonRelation.ChildTaxon, parent, parent.Level + 1, GetUniqueNumber(), taxonRelation.IsMainRelation);
                children.Add(item);
                //TODO might be a problem if we are in a revision (should then use CheckedOutChangerChildTaxa)
                if (isInRevision)
                {
                    if (allDescendants && item.Taxon.GetNearestChildTaxonRelations(userContext).IsNotEmpty())
                    {
                        item.Children = LoadChildren(item, true);
                    }
                }
                else
                {
                    if (allDescendants && item.Taxon.GetNearestChildTaxonRelations(userContext).IsNotEmpty())
                    {
                        item.Children = LoadChildren(item, true);
                    }
                }
            }
            return(children);
        }
Esempio n. 2
0
        /// <summary>
        /// Builds a list with all parents.
        /// The current taxon is also added last.
        /// </summary>
        /// <param name="rootTaxon"></param>
        public void BuildParentTaxaList(TaxonTreeViewItem rootTaxon)
        {
            IUserContext userContext  = CoreData.UserManager.GetCurrentUser();
            bool         isInRevision = DyntaxaHelper.IsInRevision(userContext, this._revisionId);
            var          allParents   = (List <ITaxonRelation>)rootTaxon.Taxon.GetAllParentTaxonRelations(userContext, null, isInRevision, false);
            var          parents      = allParents.GroupBy(x => x.ParentTaxon.Id).Select(x => x.First().ParentTaxon).ToList();

            this.ParentTaxa = new List <TaxonTreeViewTaxon>();
            string categoryName = null;

            foreach (ITaxon parentTaxon in parents)
            {
                if (_revisionTaxonCategorySortOrder.HasValue)
                {
                    if (parentTaxon.Category.SortOrder < _revisionTaxonCategorySortOrder.Value)
                    {
                        continue;
                    }
                }
                //var parentTaxon = taxonRelation.RelatedTaxon;
                categoryName = parentTaxon.Category.Name;
                this.ParentTaxa.Add(new TaxonTreeViewTaxon(parentTaxon.Id, parentTaxon.ScientificName.IsNotEmpty() ? parentTaxon.ScientificName : "-", categoryName));
            }
            categoryName = rootTaxon.Taxon.Category.Name;
            this.ParentTaxa.Add(new TaxonTreeViewTaxon(rootTaxon.Taxon.Id, rootTaxon.Taxon.ScientificName.IsNotEmpty() ? rootTaxon.Taxon.ScientificName : "-", categoryName));

            // decide which is current root
            foreach (var item in this.ParentTaxa)
            {
                if (item.TaxonId == _rootNode.TaxonId)
                {
                    item.IsCurrentRoot = true;
                    break;
                }
            }
        }
        /// <summary>
        /// Creates a swedish occurrence summary view model.
        /// </summary>
        /// <param name="taxon">The taxon.</param>
        /// <returns></returns>
        public SwedishOccurrenceSummaryViewModel CreateSwedishOccurrenceSummaryViewModel(ITaxon taxon)
        {
            var model        = new SwedishOccurrenceSummaryViewModel();
            int?redListValue = null;

            // Species fact
            try
            {
                Dictionary <ArtDatabanken.Data.FactorId, ArtDatabanken.Data.SpeciesFact> dicSpeciesFacts = SpeciesFactHelper.GetCommonDyntaxaSpeciesFacts(this._userContext, taxon);
                if (dicSpeciesFacts.ContainsKey(FactorId.SwedishHistory))
                {
                    model.SwedishHistory     = SpeciesFactHelper.GetFactorValue(dicSpeciesFacts, ArtDatabanken.Data.FactorId.SwedishHistory);
                    model.SwedishHistoryFact = dicSpeciesFacts[FactorId.SwedishHistory];
                }

                if (dicSpeciesFacts.ContainsKey(FactorId.SwedishOccurrence))
                {
                    //CoreData.SpeciesFactManager.GetSpeciesFact()
                    model.SwedishOccurrence     = SpeciesFactHelper.GetFactorValue(dicSpeciesFacts, ArtDatabanken.Data.FactorId.SwedishOccurrence);
                    model.SwedishOccurrenceFact = dicSpeciesFacts[FactorId.SwedishOccurrence];
                }

                if (dicSpeciesFacts.ContainsKey(FactorId.RedlistCategory))
                {
                    model.RedListInfo = GetRedListCategory(dicSpeciesFacts[ArtDatabanken.Data.FactorId.RedlistCategory]);
                    redListValue      = GetRedListCategoryValue(dicSpeciesFacts[ArtDatabanken.Data.FactorId.RedlistCategory]);
                }

                // If swedish occurrence or swedish history is changed in the current revision, then show those values instead.
                if (DyntaxaHelper.IsInRevision(_userContext, _taxonRevision))
                {
                    DyntaxaInternalTaxonServiceManager internalTaxonServiceManager =
                        new DyntaxaInternalTaxonServiceManager();

                    // Check if Swedish occurrence is stored in Taxon database in this revision.
                    DyntaxaRevisionSpeciesFact swedishOccurrenceRevisionSpeciesFact =
                        internalTaxonServiceManager.GetDyntaxaRevisionSpeciesFact(
                            _userContext,
                            (Int32)FactorId.SwedishOccurrence,
                            taxon.Id,
                            _taxonRevision.Id);
                    if (swedishOccurrenceRevisionSpeciesFact != null)
                    {
                        SpeciesFactModelManager speciesFactModel = new SpeciesFactModelManager(taxon, _userContext);
                        TaxonModelManager.UpdateOldSpeciesFactModelWithDyntaxaRevisionSpeciesFactValues(_userContext, speciesFactModel.SwedishOccurrenceSpeciesFact, swedishOccurrenceRevisionSpeciesFact);
                        model.SwedishOccurrence     = speciesFactModel.SwedishOccurrenceSpeciesFact.GetStatusOriginalLabel();
                        model.SwedishOccurrenceFact = speciesFactModel.SwedishOccurrenceSpeciesFact;
                    }

                    // Check if Swedish history is stored in Taxon database in this revision.
                    DyntaxaRevisionSpeciesFact swedishHistoryRevisionSpeciesFact =
                        internalTaxonServiceManager.GetDyntaxaRevisionSpeciesFact(
                            _userContext,
                            (Int32)FactorId.SwedishHistory,
                            taxon.Id,
                            _taxonRevision.Id);
                    if (swedishHistoryRevisionSpeciesFact != null)
                    {
                        if (swedishHistoryRevisionSpeciesFact.StatusId.HasValue)
                        {
                            SpeciesFactModelManager speciesFactModel = new SpeciesFactModelManager(taxon, _userContext);
                            TaxonModelManager.UpdateOldSpeciesFactModelWithDyntaxaRevisionSpeciesFactValues(_userContext, speciesFactModel.SwedishHistorySpeciesFact, swedishHistoryRevisionSpeciesFact);
                            model.SwedishHistory     = speciesFactModel.SwedishHistorySpeciesFact.GetStatusOriginalLabel();
                            model.SwedishHistoryFact = speciesFactModel.SwedishHistorySpeciesFact;
                        }
                        else // swedish history is deleted in this revision
                        {
                            model.SwedishHistory     = null;
                            model.SwedishHistoryFact = null;
                        }
                    }
                }
            }
            catch (Exception)
            {
                // the taxon did not exist in Artfakta
            }

            const int noRedListValue = 6;

            if (!string.IsNullOrEmpty(model.RedListInfo) && redListValue.GetValueOrDefault(0) < noRedListValue)
            {
                var    linkManager = new LinkManager();
                string url         = linkManager.GetUrlToRedlist(taxon.Id.ToString());
                if (url != "")
                {
                    var item = new LinkItem(
                        LinkType.Url,
                        LinkQuality.ApprovedByExpert,
                        Resources.DyntaxaResource.LinkToSwedishRedlistLabel,
                        url);
                    model.RedListLink = item;
                }
            }

            return(model);
        }