/// <summary>
        /// Check if taxon is correct
        /// </summary>
        /// <param name="inputTaxonId"></param>
        /// <param name="taxon"></param>
        /// <returns></returns>
        protected bool CheckTaxonVaildity(string inputTaxonId, ITaxon taxon)
        {
            string errorMsg;
            bool   valid = true;

            if (taxon.IsNull())
            {
                errorMsg = Resources.DyntaxaResource.RevisonAddInvalidTaxonErrorText;
                ModelState.AddModelError("", errorMsg);
                valid = false;
            }
            if (taxon.IsNotNull() && !taxon.Id.ToString().Equals(inputTaxonId))
            {
                errorMsg = Resources.DyntaxaResource.RevisionSharedNoValidTaxonIdErrorText;
                string propName  = string.Empty;
                string propValue = string.Empty;
                if (taxon.IsNotNull())
                {
                    propName = ReflectionUtility.GetPropertyName(() => taxon.Id);
                    PropertyInfo pi = taxon.GetType().GetProperty(propName);
                    propValue = pi.GetValue(taxon, null).ToString();
                    ModelState.AddModelError("", errorMsg + " " + propValue);
                }
                else
                {
                    ModelState.AddModelError("", errorMsg);
                }
                valid = false;
            }
            return(valid);
        }
        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>
        ///
        /// </summary>
        /// <param name="loggedInUser"></param>
        /// <param name="applicationUserContext"></param>
        /// <param name="taxonId"></param>
        /// <param name="taxon"></param>
        /// <param name="userList"></param>
        /// <returns></returns>
        public RevisionAddViewModel GetRevisionAddViewModel(IUserContext loggedInUser, IUserContext applicationUserContext, string taxonId, ITaxon taxon, List <RevisionUserItemModelHelper> userList)
        {
            // Create model
            RevisionAddViewModel model = new RevisionAddViewModel();

            // Set initaial values
            model.TaxonId                = taxonId;
            model.ExpectedStartDate      = DateTime.Now;
            model.ExpectedPublishingDate = DateTime.Now.AddYears(1);
            model.RevisionDescription    = string.Empty;
            model.ShowInitalizeButton    = true;
            string url = Resources.DyntaxaResource.SharedRevisionUserAdminLinkText;

            model.UserAdminLink = new LinkItem(LinkType.Url, LinkQuality.Automatic, url, userAdminRoleLink);

            // Check that all logged in user and dyntaxa application user is valid.
            if (loggedInUser.IsNotNull())
            {
                if (applicationUserContext.IsNotNull())
                {
                    // Set locale to logged in user, used so that correct language for created roles  and authorities will be set.
                    applicationUserContext.Locale = loggedInUser.Locale;

                    // Get all users that are allowed to to edit taxon
                    model.UserList   = userList; //GetAllTaxonEditors(applicationUserContext, out roleId);
                    model.RevisionId = "0";
                    // Set taxon values
                    if (taxon.IsNotNull() && taxon.Id.IsNotNull())
                    {
                        model.TaxonId = taxon.Id.ToString();
                    }
                    else
                    {
                        model.ErrorMessage = Resources.DyntaxaResource.RevisonAddInvalidTaxonErrorText;
                        model.TaxonId      = taxonId;
                    }
                }
                else
                {
                    model.ErrorMessage = Resources.DyntaxaResource.SharedInvalidApplicationUserContext;
                }
            }
            else
            {
                model.ErrorMessage = Resources.DyntaxaResource.SharedInvalidUserContext;
            }
            return(model);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method that generates an unique identifier for a species fact.
        /// </summary>
        /// <param name="taxon">Taxon that is related to the species fact.</param>
        /// <param name="individualCategory">Individual category that is related to the species fact.</param>
        /// <param name="factor">Factor that is related to the species fact.</param>
        /// <param name="host">Host taxon that is related to the species fact.</param>
        /// <param name="period">Period that is related to the species fact.</param>
        /// <returns>Identifier for a species fact.</returns>
        public virtual String GetSpeciesFactIdentifier(ITaxon taxon,
                                                       IIndividualCategory individualCategory,
                                                       IFactor factor,
                                                       ITaxon host,
                                                       IPeriod period)
        {
            Int32 hostId = 0, periodId = 0;

            if ((host.IsNotNull()) && (factor.IsTaxonomic))
            {
                hostId = host.Id;
            }

            if ((period.IsNotNull()) && (factor.IsPeriodic))
            {
                periodId = period.Id;
            }

            return(GetSpeciesFactIdentifier(taxon.Id,
                                            individualCategory.Id,
                                            factor.Id,
                                            hostId,
                                            periodId));
        }
        /// <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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a species fact instance with data from data source.
        /// </summary>
        /// <param name="id">Id of the species fact.</param>
        /// <param name="taxon">Taxon of the species fact.</param>
        /// <param name="individualCategory">Individual Category of the species fact.</param>
        /// <param name="factor">Factor of the species fact.</param>
        /// <param name="host">Host taxon associated with the species fact.</param>
        /// <param name="period">Period of the species fact.</param>
        /// <param name="fieldValue1">Field value of field 1 for the species fact.</param>
        /// <param name="hasFieldValue1">Indicates if field 1 has a value.</param>
        /// <param name="fieldValue2">Field value of field 2 for the species fact.</param>
        /// <param name="hasFieldValue2">Indicates if field 2 has a value.</param>
        /// <param name="fieldValue3">Field value of field 3 for the species fact.</param>
        /// <param name="hasFieldValue3">Indicates if field 3 has a value.</param>
        /// <param name="fieldValue4">Field value of field 4 for the species fact.</param>
        /// <param name="hasFieldValue4">Indicates if field 4 has a value.</param>
        /// <param name="fieldValue5">Field value of field 5 for the species fact.</param>
        /// <param name="hasFieldValue5">Indicates if field 5 has a value.</param>
        /// <param name="quality">Quality of the species fact.</param>
        /// <param name="reference">Reference of the species fact.</param>
        /// <param name="modifiedBy">Full name of the update user of the species fact.</param>
        /// <param name="modifiedDate">Update date of the species fact.</param>
        public SpeciesFact(Int32 id,
                           ITaxon taxon,
                           IIndividualCategory individualCategory,
                           IFactor factor,
                           ITaxon host,
                           IPeriod period,
                           Double fieldValue1,
                           Boolean hasFieldValue1,
                           Double fieldValue2,
                           Boolean hasFieldValue2,
                           Double fieldValue3,
                           Boolean hasFieldValue3,
                           String fieldValue4,
                           Boolean hasFieldValue4,
                           String fieldValue5,
                           Boolean hasFieldValue5,
                           ISpeciesFactQuality quality,
                           IReference reference,
                           String modifiedBy,
                           DateTime modifiedDate)
        {
            Int32 fieldIndex;

            Id                 = id;
            _fields            = null;
            _substantialFields = null;
            _mainField         = null;
            _hasId             = true;
            _identifier        = CoreData.SpeciesFactManager.GetSpeciesFactIdentifier(taxon,
                                                                                      individualCategory,
                                                                                      factor,
                                                                                      host,
                                                                                      period);

            _taxon = taxon;
            _individualCategory = individualCategory;
            _factor             = factor;
            _host            = host;
            _hasHost         = host.IsNotNull();
            _period          = period;
            _hasPeriod       = period.IsNotNull();
            _quality         = quality;
            _oldQuality      = quality;
            _reference       = reference;
            _oldReference    = reference;
            _modifiedBy      = modifiedBy;
            _modifiedDate    = modifiedDate;
            _hasModifiedDate = true;

            if (!_factor.UpdateMode.IsHeader)
            {
                _fields            = new SpeciesFactFieldList();
                _substantialFields = new SpeciesFactFieldList();
                _fieldArray        = new ISpeciesFactField[CoreData.FactorManager.GetFactorFieldMaxCount()];
                for (fieldIndex = 0; fieldIndex < CoreData.FactorManager.GetFactorFieldMaxCount(); fieldIndex++)
                {
                    _fieldArray[fieldIndex] = null;
                }

                foreach (FactorField factorField in _factor.DataType.Fields)
                {
                    Boolean          hasFieldValue;
                    SpeciesFactField field;
                    Object           fieldValue;

                    switch (factorField.Index)
                    {
                    case 0:
                        fieldValue    = fieldValue1;
                        hasFieldValue = hasFieldValue1;
                        break;

                    case 1:
                        fieldValue    = fieldValue2;
                        hasFieldValue = hasFieldValue2;
                        break;

                    case 2:
                        fieldValue    = fieldValue3;
                        hasFieldValue = hasFieldValue3;
                        break;

                    case 3:
                        fieldValue    = fieldValue4;
                        hasFieldValue = hasFieldValue4;
                        break;

                    case 4:
                        fieldValue    = fieldValue5;
                        hasFieldValue = hasFieldValue5;
                        break;

                    default:
                        throw new Exception("Unknown data field!");
                    }

                    field = new SpeciesFactField(this, factorField, hasFieldValue, fieldValue);
                    _fields.Add(field);
                    _fieldArray[field.Index] = field;

                    if (factorField.IsSubstantial)
                    {
                        _substantialFields.Add(field);
                    }

                    if (factorField.IsMain)
                    {
                        _mainField = field;
                    }
                }
            }

            Fields.Sort();
            _shouldBeSaved = AllowUpdate;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a species fact instance with no data from web service.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="taxon">Taxon object of the species fact.</param>
        /// <param name="individualCategory">Individual category object of the species fact.</param>
        /// <param name="factor">Factor object of the species fact.</param>
        /// <param name="host">Host taxon object of the species fact.</param>
        /// <param name="period">Period object of the species fact.</param>
        public SpeciesFact(IUserContext userContext,
                           ITaxon taxon,
                           IIndividualCategory individualCategory,
                           IFactor factor,
                           ITaxon host,
                           IPeriod period)
        {
            Int32 fieldIndex;

            Id                 = -1;
            _fields            = null;
            _substantialFields = null;
            _mainField         = null;
            _hasId             = false;

            _identifier = CoreData.SpeciesFactManager.GetSpeciesFactIdentifier(taxon,
                                                                               individualCategory,
                                                                               factor,
                                                                               host,
                                                                               period);
            _taxon = taxon;
            _individualCategory = individualCategory;
            _factor             = factor;
            _host            = host;
            _hasHost         = _host.IsNotNull();
            _period          = period;
            _hasPeriod       = _period.IsNotNull();
            _quality         = CoreData.SpeciesFactManager.GetDefaultSpeciesFactQuality(userContext);
            _oldQuality      = _quality;
            _reference       = null;
            _oldReference    = null;
            _modifiedBy      = null;
            _modifiedDate    = DateTime.MinValue;
            _hasModifiedDate = false;

            if (!_factor.UpdateMode.IsHeader)
            {
                _fields            = new SpeciesFactFieldList();
                _substantialFields = new SpeciesFactFieldList();
                _fieldArray        = new ISpeciesFactField[CoreData.FactorManager.GetFactorFieldMaxCount()];
                for (fieldIndex = 0; fieldIndex < CoreData.FactorManager.GetFactorFieldMaxCount(); fieldIndex++)
                {
                    _fieldArray[fieldIndex] = null;
                }

                foreach (FactorField factorField in _factor.DataType.Fields)
                {
                    ISpeciesFactField field;

                    field = new SpeciesFactField(this, factorField, false, null);
                    _fields.Add(field);
                    _fieldArray[field.Index] = field;

                    if (factorField.IsSubstantial)
                    {
                        _substantialFields.Add(field);
                    }

                    if (factorField.IsMain)
                    {
                        _mainField = field;
                    }
                }
            }

            Fields.Sort();
            _shouldBeSaved = AllowUpdate;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates a species fact instance with data from web service.
        /// </summary>
        /// <param name="userContext">
        /// Information about the user that makes this method call.
        /// </param>
        /// <param name="id">Id of the species fact.</param>
        /// <param name="taxonId">Taxon Id of the species fact.</param>
        /// <param name="individualCategoryId">Individual Category Id of the species fact.</param>
        /// <param name="factorId">Factor Id of the species fact.</param>
        /// <param name="hostId">Taxon Id of the host taxon associated with the species fact.</param>
        /// <param name="hasHost">Indicates if this species fact has a host.</param>
        /// <param name="periodId">Period Id of the species fact.</param>
        /// <param name="hasPeriod">Indicates if this species fact has a period.</param>
        /// <param name="fieldValue1">Field value of field 1 for the species fact.</param>
        /// <param name="hasFieldValue1">Indicates if field 1 has a value.</param>
        /// <param name="fieldValue2">Field value of field 2 for the species fact.</param>
        /// <param name="hasFieldValue2">Indicates if field 2 has a value.</param>
        /// <param name="fieldValue3">Field value of field 3 for the species fact.</param>
        /// <param name="hasFieldValue3">Indicates if field 3 has a value.</param>
        /// <param name="fieldValue4">Field value of field 4 for the species fact.</param>
        /// <param name="hasFieldValue4">Indicates if field 4 has a value.</param>
        /// <param name="fieldValue5">Field value of field 5 for the species fact.</param>
        /// <param name="hasFieldValue5">Indicates if field 5 has a value.</param>
        /// <param name="qualityId">Quality Id of the species fact.</param>
        /// <param name="referenceId">Reference id of the species fact.</param>
        /// <param name="modifiedBy">Full Name of the update user of the species fact.</param>
        /// <param name="modifiedDate">Update date of the species fact.</param>
        public SpeciesFact(IUserContext userContext,
                           Int32 id,
                           Int32 taxonId,
                           Int32 individualCategoryId,
                           Int32 factorId,
                           Int32 hostId,
                           Boolean hasHost,
                           Int32 periodId,
                           Boolean hasPeriod,
                           Double fieldValue1,
                           Boolean hasFieldValue1,
                           Double fieldValue2,
                           Boolean hasFieldValue2,
                           Double fieldValue3,
                           Boolean hasFieldValue3,
                           String fieldValue4,
                           Boolean hasFieldValue4,
                           String fieldValue5,
                           Boolean hasFieldValue5,
                           Int32 qualityId,
                           Int32 referenceId,
                           String modifiedBy,
                           DateTime modifiedDate)
        {
            Int32 fieldIndex;

            Id                 = id;
            _fields            = null;
            _substantialFields = null;
            _mainField         = null;
            _hasId             = true;
            _identifier        = CoreData.SpeciesFactManager.GetSpeciesFactIdentifier(taxonId,
                                                                                      individualCategoryId,
                                                                                      factorId,
                                                                                      hasHost,
                                                                                      hostId,
                                                                                      hasPeriod,
                                                                                      periodId);

            _taxon = CoreData.TaxonManager.GetTaxon(userContext, taxonId);
            _individualCategory = CoreData.FactorManager.GetIndividualCategory(userContext, individualCategoryId);
            _factor             = CoreData.FactorManager.GetFactor(userContext, factorId);

            if (hasHost)
            {
                _host    = CoreData.TaxonManager.GetTaxon(userContext, hostId);
                _hasHost = true;
            }
            else
            {
                if (_factor.IsTaxonomic)
                {
                    _host = CoreData.TaxonManager.GetTaxon(userContext, 0);
                }
                else
                {
                    _host = null;
                }

                _hasHost = _host.IsNotNull();
            }

            if (hasPeriod)
            {
                _period = CoreData.FactorManager.GetPeriod(userContext, periodId);
            }
            else
            {
                _period = null;
            }

            _hasPeriod = hasPeriod;

            _quality         = CoreData.SpeciesFactManager.GetSpeciesFactQuality(userContext, qualityId);
            _oldQuality      = _quality;
            _reference       = CoreData.ReferenceManager.GetReference(userContext, referenceId);
            _oldReference    = _reference;
            _modifiedBy      = modifiedBy;
            _modifiedDate    = modifiedDate;
            _hasModifiedDate = true;

            if (!_factor.UpdateMode.IsHeader)
            {
                _fields            = new SpeciesFactFieldList();
                _substantialFields = new SpeciesFactFieldList();
                _fieldArray        = new ISpeciesFactField[CoreData.FactorManager.GetFactorFieldMaxCount()];
                for (fieldIndex = 0; fieldIndex < CoreData.FactorManager.GetFactorFieldMaxCount(); fieldIndex++)
                {
                    _fieldArray[fieldIndex] = null;
                }

                foreach (FactorField factorField in _factor.DataType.Fields)
                {
                    Boolean          hasFieldValue;
                    SpeciesFactField field;
                    Object           fieldValue;

                    switch (factorField.Index)
                    {
                    case 0:
                        fieldValue    = fieldValue1;
                        hasFieldValue = hasFieldValue1;
                        break;

                    case 1:
                        fieldValue    = fieldValue2;
                        hasFieldValue = hasFieldValue2;
                        break;

                    case 2:
                        fieldValue    = fieldValue3;
                        hasFieldValue = hasFieldValue3;
                        break;

                    case 3:
                        fieldValue    = fieldValue4;
                        hasFieldValue = hasFieldValue4;
                        break;

                    case 4:
                        fieldValue    = fieldValue5;
                        hasFieldValue = hasFieldValue5;
                        break;

                    default:
                        throw new Exception("Unknown data field!");
                    }

                    field = new SpeciesFactField(this, factorField, hasFieldValue, fieldValue);
                    _fields.Add(field);
                    _fieldArray[field.Index] = field;

                    if (factorField.IsSubstantial)
                    {
                        _substantialFields.Add(field);
                    }

                    if (factorField.IsMain)
                    {
                        _mainField = field;
                    }
                }
            }

            Fields.Sort();
            _shouldBeSaved = AllowUpdate;
        }
        /// <summary>
        /// Creates the model for lumping
        /// </summary>
        /// <param name="userContext"></param>
        /// <param name="taxon"></param>
        /// <param name="revisionId"></param>
        /// <param name="replacingTaxonId"></param>
        /// <param name="lumpTaxonIdList"></param>
        /// <returns></returns>
        public TaxonLumpViewModel GetTaxonLumpViewModel(IUserContext userContext, ITaxon taxon, int revisionId, int?replacingTaxonId, List <int?> lumpTaxonIdList, bool isOkToLump, bool isReloaded)
        {
            TaxonLumpViewModel model        = new TaxonLumpViewModel();
            IUserContext       loggedInUser = userContext;

            if (loggedInUser.IsNotNull())
            {
                if (taxon.IsNotNull() && taxon.Id.IsNotNull())
                {
                    model.TaxonErrorId = taxon.Id.ToString();
                    if (revisionId.IsNotNull())
                    {
                        model.RevisionErrorId = revisionId.ToString();
                        model.RevisionId      = revisionId.ToString();
                        model.TaxonId         = taxon.Id.ToString();
                        model.IsSelectedTaxonSetAsReplacingTaxon = false;
                        model.IsSelectedTaxonAlreadyInLumpList   = false;
                        model.IsReplacingTaxonSet      = false;
                        model.IsSelectedTaxonChildless = true;
                        model.IsAnyLumpTaxonSet        = false;
                        model.IsOkToLump               = isOkToLump;
                        model.IsReloaded               = isReloaded;
                        model.IsReplacingTaxonValid    = true;
                        model.IsLumpTaxonValid         = true;
                        model.IsLumpTaxonCategoryValid = true;

                        // 1. first we check selected taxon if it has any children
                        if (taxon.GetNearestChildTaxonRelations(userContext).IsNotEmpty())
                        {
                            model.IsSelectedTaxonChildless = false;
                        }
                        //model.SelectedTaxon = new List<TaxonParentViewModelHelper>();
                        //// Get selected taxon ie taxon selected in GUI
                        //TaxonParentViewModelHelper selectedTaxon = new TaxonParentViewModelHelper();
                        //selectedTaxon.Category = CoreData.TaxonManager.GetTaxonCategoryById(loggedInUser, taxon.Category).Name;
                        //selectedTaxon.CommonName = taxon.RecommendedCommonName.IsNotNull() ? taxon.RecommendedCommonName.Name : string.Empty;
                        //selectedTaxon.ScientificName = taxon.RecommendedScentificName.IsNotNull() ? taxon.RecommendedScentificName.Name : string.Empty;
                        //selectedTaxon.TaxonId = taxon.Id.ToString();
                        //model.SelectedTaxon.Add(selectedTaxon);
                        // we now check if selected taxon exist in list to lump
                        if (lumpTaxonIdList.IsNotNull() && !lumpTaxonIdList.Contains(null) && lumpTaxonIdList.Contains(taxon.Id))
                        {
                            model.IsSelectedTaxonAlreadyInLumpList = true;
                        }

                        //2. Check if replacing taxon is set, if so show it.
                        if (replacingTaxonId.IsNotNull())
                        {
                            model.IsReplacingTaxonSet = true;
                            ITaxon repTaxon = CoreData.TaxonManager.GetTaxon(loggedInUser, (int)replacingTaxonId);
                            model.ReplacingTaxon = new List <TaxonParentViewModelHelper>();
                            TaxonParentViewModelHelper replacingTaxon = new TaxonParentViewModelHelper();
                            replacingTaxon.Category       = repTaxon.Category.Name;
                            replacingTaxon.CommonName     = repTaxon.CommonName.IsNotEmpty() ? repTaxon.CommonName : string.Empty;
                            replacingTaxon.ScientificName = repTaxon.ScientificName.IsNotEmpty() ? repTaxon.ScientificName : string.Empty;
                            replacingTaxon.TaxonId        = repTaxon.Id.ToString();
                            model.ReplacingTaxon.Add(replacingTaxon);

                            model.ReplacingTaxonId = repTaxon.Id.ToString();
                            // Now we must check if selected taxon equals replacing taxon
                            if (repTaxon.Id == taxon.Id)
                            {
                                model.IsSelectedTaxonSetAsReplacingTaxon = true;
                            }
                            if (!model.IsOkToLump)
                            {
                                if (repTaxon.GetCheckedOutChangesTaxonProperties(userContext).IsValid == false)
                                {
                                    model.IsReplacingTaxonValid = false;
                                    model.TaxonErrorName        = repTaxon.ScientificName;
                                    //  model.IsOkToLump = true;
                                }
                            }
                        }

                        // 3. Check and populate list of taxon to lump
                        model.LumpTaxonList = new List <TaxonParentViewModelHelper>();
                        if (taxon.IsNotNull())
                        {
                            if (lumpTaxonIdList.IsNotNull() && !lumpTaxonIdList.Contains(null))
                            {
                                var       lumpIdList = lumpTaxonIdList.Cast <int>().ToList();
                                TaxonList taxa       = CoreData.TaxonManager.GetTaxa(loggedInUser, lumpIdList);
                                if (taxa.IsNotNull() && taxa.Count > 0)
                                {
                                    var category = taxa[0].GetCheckedOutChangesTaxonProperties(userContext).TaxonCategory;
                                    foreach (ITaxon lumpTaxon in taxa)
                                    {
                                        var lumpTaxonModel = new TaxonParentViewModelHelper();
                                        lumpTaxonModel.Category       = lumpTaxon.Category.Name;
                                        lumpTaxonModel.SortOrder      = lumpTaxon.Category.SortOrder;
                                        lumpTaxonModel.CommonName     = lumpTaxon.CommonName.IsNotEmpty() ? lumpTaxon.CommonName : string.Empty;
                                        lumpTaxonModel.ScientificName = lumpTaxon.ScientificName.IsNotEmpty() ? lumpTaxon.ScientificName : string.Empty;
                                        lumpTaxonModel.TaxonId        = lumpTaxon.Id.ToString();
                                        model.LumpTaxonList.Add(lumpTaxonModel);
                                        // Check why it is not ok to lump
                                        if (!model.IsOkToLump)
                                        {
                                            if (lumpTaxon.GetCheckedOutChangesTaxonProperties(userContext).TaxonCategory.Id != category.Id)
                                            {
                                                model.IsLumpTaxonCategoryValid = false;
                                                model.TaxonErrorName           = lumpTaxon.ScientificName;
                                                // model.IsOkToLump = true;
                                            }

                                            if (lumpTaxon.GetCheckedOutChangesTaxonProperties(userContext).IsValid == false)
                                            {
                                                model.IsLumpTaxonValid = false;
                                                model.TaxonErrorName   = lumpTaxon.ScientificName;
                                                // model.IsOkToLump = true;
                                            }
                                        }
                                    }
                                }

                                model.IsAnyLumpTaxonSet = true;
                            }
                        }
                    }
                    else
                    {
                        model.ErrorMessage = Resources.DyntaxaResource.TaxonSharedInvalidRevision;
                    }
                }
                else
                {
                    model.ErrorMessage = Resources.DyntaxaResource.TaxonSharedInvalidTaxon;
                }
            }
            else
            {
                model.ErrorMessage = Resources.DyntaxaResource.SharedInvalidUserContext;
            }
            return(model);
        }
        /// <summary>
        /// Create view model for split
        /// </summary>
        /// <param name="userContext"></param>
        /// <param name="taxon"></param>
        /// <param name="revisionId"></param>
        /// <param name="replaceTaxonIdList"></param>
        /// <param name="splitTaxonId"></param>
        /// <returns></returns>
        public TaxonSplitViewModel GetTaxonSplitViewModel(IUserContext userContext, ITaxon taxon, int revisionId, List <int?> replaceTaxonIdList, int?splitTaxonId, bool isOkToSplit, bool isReloaded)
        {
            TaxonSplitViewModel model        = new TaxonSplitViewModel();
            IUserContext        loggedInUser = userContext;

            if (loggedInUser.IsNotNull())
            {
                if (taxon.IsNotNull() && taxon.Id.IsNotNull())
                {
                    model.TaxonErrorId = taxon.Id.ToString();
                    if (revisionId.IsNotNull())
                    {
                        model.RevisionErrorId = revisionId.ToString();
                        model.RevisionId      = revisionId.ToString();
                        model.TaxonId         = taxon.Id.ToString();
                        model.IsSelectedTaxonSetAsSplitTaxon        = false;
                        model.IsSelectedTaxonAlreadyInReplacingList = false;
                        model.IsSelectedTaxonChildless = true;
                        model.IsAnyReplacingTaxonSet   = false;
                        model.IsSplitTaxonSet          = false;
                        model.IsOkToSplit                   = isOkToSplit;
                        model.IsReloaded                    = isReloaded;
                        model.IsSplitTaxonValid             = true;
                        model.IsReplacingTaxonValid         = true;
                        model.IsReplacingTaxonCategoryValid = true;

                        // 1. first we check selected taxon if it has any children
                        if (taxon.GetNearestChildTaxonRelations(userContext).IsNotEmpty())
                        {
                            model.IsSelectedTaxonChildless = false;
                        }
                        model.SelectedTaxon = new List <TaxonParentViewModelHelper>();
                        // Set selected taxon
                        TaxonParentViewModelHelper selectedTaxon = new TaxonParentViewModelHelper();
                        selectedTaxon.Category       = taxon.Category.Name;
                        selectedTaxon.CommonName     = taxon.CommonName.IsNotEmpty() ? taxon.CommonName : string.Empty;
                        selectedTaxon.ScientificName = taxon.ScientificName.IsNotEmpty() ? taxon.ScientificName : string.Empty;
                        selectedTaxon.TaxonId        = taxon.Id.ToString();
                        model.SelectedTaxon.Add(selectedTaxon);
                        // We now check if selected taxon exist in list of replacing taxa
                        if (replaceTaxonIdList.IsNotNull() && !replaceTaxonIdList.Contains(null) && replaceTaxonIdList.Contains(taxon.Id))
                        {
                            model.IsSelectedTaxonAlreadyInReplacingList = true;
                        }

                        // 2. Check and populate list of replacing taxa
                        model.ReplacingTaxonList = new List <TaxonParentViewModelHelper>();
                        if (taxon.IsNotNull())
                        {
                            if (replaceTaxonIdList.IsNotNull() && !replaceTaxonIdList.Contains(null))
                            {
                                var       replaceIdList = replaceTaxonIdList.Cast <int>().ToList();
                                TaxonList taxa          = CoreData.TaxonManager.GetTaxa(loggedInUser, replaceIdList);
                                var       category      = taxa[0].GetCheckedOutChangesTaxonProperties(userContext).TaxonCategory;

                                if (taxa.IsNotNull() && taxa.Count > 0)
                                {
                                    foreach (ITaxon replaceTaxon in taxa)
                                    {
                                        var splitTaxonModel = new TaxonParentViewModelHelper();
                                        splitTaxonModel.Category       = replaceTaxon.Category.Name;
                                        splitTaxonModel.SortOrder      = replaceTaxon.Category.SortOrder;
                                        splitTaxonModel.CommonName     = replaceTaxon.CommonName.IsNotEmpty() ? replaceTaxon.CommonName : string.Empty;
                                        splitTaxonModel.ScientificName = replaceTaxon.ScientificName.IsNotEmpty() ? replaceTaxon.ScientificName : string.Empty;
                                        splitTaxonModel.TaxonId        = replaceTaxon.Id.ToString();
                                        model.ReplacingTaxonList.Add(splitTaxonModel);

                                        // Check why it is not ok to split
                                        if (!model.IsOkToSplit)
                                        {
                                            if (replaceTaxon.GetCheckedOutChangesTaxonProperties(userContext).TaxonCategory.Id != category.Id)
                                            {
                                                model.IsReplacingTaxonCategoryValid = false;
                                                model.TaxonErrorName = replaceTaxon.ScientificName;
                                                // model.IsOkToSplit = true;
                                            }

                                            if (replaceTaxon.GetCheckedOutChangesTaxonProperties(userContext).IsValid == false)
                                            {
                                                model.IsReplacingTaxonValid = false;
                                                model.TaxonErrorName        = replaceTaxon.ScientificName;
                                                // model.IsOkToSplit = true;
                                            }
                                        }
                                    }
                                }
                                model.IsAnyReplacingTaxonSet = true;
                            }
                        }

                        //3. Check if split taxon is set, if so show it.
                        if (splitTaxonId.IsNotNull())
                        {
                            ITaxon repTaxon = CoreData.TaxonManager.GetTaxon(loggedInUser, (int)splitTaxonId);
                            model.SplitTaxon = new List <TaxonParentViewModelHelper>();
                            TaxonParentViewModelHelper replacingTaxon = new TaxonParentViewModelHelper();
                            replacingTaxon.Category       = repTaxon.Category.Name;
                            replacingTaxon.CommonName     = repTaxon.CommonName.IsNotEmpty() ? repTaxon.CommonName : string.Empty;
                            replacingTaxon.ScientificName = repTaxon.ScientificName.IsNotEmpty() ? repTaxon.ScientificName : string.Empty;
                            replacingTaxon.TaxonId        = repTaxon.Id.ToString();
                            model.SplitTaxon.Add(replacingTaxon);
                            model.IsSplitTaxonSet  = true;
                            model.ReplacingTaxonId = repTaxon.Id.ToString();
                            // Now we must check if selected taxon equals replacing taxon
                            if (repTaxon.Id == taxon.Id)
                            {
                                model.IsSelectedTaxonSetAsSplitTaxon = true;
                            }
                            if (!model.IsOkToSplit)
                            {
                                if (repTaxon.GetCheckedOutChangesTaxonProperties(userContext).IsValid == false)
                                {
                                    model.IsSplitTaxonValid = false;
                                    model.TaxonErrorName    = repTaxon.ScientificName;
                                    // model.IsOkToSplit = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        model.ErrorMessage = Resources.DyntaxaResource.TaxonSharedInvalidRevision;
                    }
                }
                else
                {
                    model.ErrorMessage = Resources.DyntaxaResource.TaxonSharedInvalidTaxon;
                }
            }
            else
            {
                model.ErrorMessage = Resources.DyntaxaResource.SharedInvalidUserContext;
            }
            return(model);
        }
        /// <summary>
        /// Get taxon information about specified taxon.
        /// Returned taxon has the same order id as the input taxon id.
        /// </summary>
        /// <param name="taxonId">Taxon to get chached information on.</param>
        /// <returns>Taxon list information about specified taxa.</returns>
        public TaxonListInformation GetTaxonInformationFromCache(int taxonId)
        {
            if (!mIsInitialized)
            {
                throw new Exception("TaxonListInformation cache is not initialized");
            }

            ITaxon taxon = CoreData.TaxonManager.GetTaxon(mContext, taxonId);
            TaxonListInformation tempTaxon = null;

            if (TaxonInformationCache.TaxonInformation.IsNotNull() && TaxonInformationCache.TaxonInformation.ContainsKey(taxonId) && taxon.IsNotNull())
            {
                var taxa = new TaxonList {
                    taxon
                };

                // Check is performed on list therefore a temporary list is created with one item.
                CheckCachedInformation(taxa);
                tempTaxon = TaxonInformationCache.TaxonInformation[taxon.Id];
            }

            return(tempTaxon);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Get string with taxonomic information.
        /// </summary>
        /// <returns>String with taxonomic information.</returns>
        private String GetAutomaticTaxonomicString()
        {
            StringBuilder text;

            if (_taxonomicParagraphSpeciesFact.IsNotNull() &&
                (_taxonomicParagraphSpeciesFact.Quality.Id == (Int32)SpeciesFactQualityId.VeryGood) &&
                _taxonomicParagraphSpeciesFact.Field5.HasValue)
            {
                return(_taxonomicParagraphSpeciesFact.Field5.StringValue);
            }

            text = new StringBuilder();
            if (_taxon.IsNotNull())
            {
                _italicStringsInAutomaticTaxonomicParagraph.Clear();


                Int32 startFromIndex = ParentTaxa.Count - 3;
                if (startFromIndex < 0)
                {
                    startFromIndex = 0;
                }
                for (Int32 index = startFromIndex; index < ParentTaxa.Count; index++)
                {
                    if (text.ToString() != String.Empty)
                    {
                        text.Append(", ");
                    }
                    text.Append(ParentTaxa[index].Category.Name + " ");
                    text.Append(ParentTaxa[index].ScientificName);

                    //Eventuellt ska denna kodrad tas bort (förslag från Tomas Hallingbäck): Överordnade taxa bör ej vara kursiverade
                    //Enligt artexperternas diskussion 2010-03-04 ska överordnade vetenskapliga taxonnamn ej kursiveras!
                    //_italicStringsInAutomaticTaxonomicParagraph.Add(suitableParents[index].ScientificName);

                    if (ParentTaxa[index].CommonName.IsNotEmpty())
                    {
                        text.Append(" (" + ParentTaxa[index].CommonName + ")");
                    }
                }

                if (text.ToString() != String.Empty)
                {
                    text.Append(", ");
                }

                text.Append(_taxon.GetScientificNameAndAuthor());
                _italicStringsInAutomaticTaxonomicParagraph.Add(_taxon.ScientificName);



                if (Synonyms.Count > 0)
                {
                    text.Append(". Syn. ");
                    for (Int32 itemIndex = 0; itemIndex < Synonyms.Count; itemIndex++)
                    {
                        if (itemIndex > 0)
                        {
                            if (itemIndex == Synonyms.Count - 1)
                            {
                                text.Append(" och ");
                            }
                            else
                            {
                                text.Append(", ");
                            }
                        }

                        text.Append(Synonyms[itemIndex].Name);
                        if (Synonyms[itemIndex].Author.IsNotEmpty())
                        {
                            text.Append(" " + Synonyms[itemIndex].Author);
                        }
                    }
                }
                if (text.ToString() != String.Empty)
                {
                    text.Append(". ");
                }
            }
            String cleanText = text.ToString().Replace("..", ".");

            return(cleanText);
        }