Ejemplo n.º 1
0
        /// <summary>
        /// Load data into the WebDyntaxaRevisionSpeciesFact instance.
        /// </summary>
        /// <param name="dyntaxaSpeciesFact">Dyntaxa revision species fact.</param>
        /// <param name='dataReader'>An open data reader.</param>
        public static void LoadData(this WebDyntaxaRevisionSpeciesFact dyntaxaSpeciesFact, DataReader dataReader)
        {
            dyntaxaSpeciesFact.Id           = dataReader.GetInt32(TaxonCommon.ID);
            dyntaxaSpeciesFact.FactorId     = dataReader.GetInt32(DyntaxaRevisionSpeciesFact.FACTOR_ID);
            dyntaxaSpeciesFact.TaxonId      = dataReader.GetInt32(TaxonCommon.TAXON_ID);
            dyntaxaSpeciesFact.RevisionId   = dataReader.GetInt32(TaxonCommon.REVISON_ID);
            dyntaxaSpeciesFact.StatusId     = dataReader.GetNullableInt32(DyntaxaRevisionSpeciesFact.STATUS_ID);
            dyntaxaSpeciesFact.QualityId    = dataReader.GetNullableInt32(DyntaxaRevisionSpeciesFact.QUALITY_ID);
            dyntaxaSpeciesFact.ReferenceId  = dataReader.GetNullableInt32(DyntaxaRevisionSpeciesFact.REFERENCE_ID);
            dyntaxaSpeciesFact.Description  = dataReader.GetString(DyntaxaRevisionSpeciesFact.DESCRIPTION);
            dyntaxaSpeciesFact.IsPublished  = dataReader.GetBoolean(TaxonCommon.IS_PUBLISHED);
            dyntaxaSpeciesFact.ModifiedBy   = dataReader.GetInt32(TaxonCommon.MODIFIED_BY);
            dyntaxaSpeciesFact.ModifiedDate = dataReader.GetDateTime(TaxonCommon.MODIFIED_DATE);
            dyntaxaSpeciesFact.CreatedBy    = dataReader.GetInt32(TaxonCommon.CREATED_BY);
            dyntaxaSpeciesFact.CreatedDate  = dataReader.GetDateTime(TaxonCommon.CREATED_DATE);
            dyntaxaSpeciesFact.IsRevisionEventIdSpecified = dataReader.IsNotDbNull(TaxonCommon.REVISON_EVENT_ID);
            if (dyntaxaSpeciesFact.IsRevisionEventIdSpecified)
            {
                dyntaxaSpeciesFact.RevisionEventId = dataReader.GetInt32(TaxonCommon.REVISON_EVENT_ID);
            }
            dyntaxaSpeciesFact.IsChangedInRevisionEventIdSpecified = dataReader.IsNotDbNull(TaxonCommon.CHANGED_IN_REVISON_EVENT_ID);
            if (dyntaxaSpeciesFact.IsChangedInRevisionEventIdSpecified)
            {
                dyntaxaSpeciesFact.ChangedInRevisionEventId = dataReader.GetInt32(TaxonCommon.CHANGED_IN_REVISON_EVENT_ID);
            }
            dyntaxaSpeciesFact.SpeciesFactExists   = dataReader.GetBoolean(DyntaxaRevisionSpeciesFact.SPECIESFACT_EXISTS);
            dyntaxaSpeciesFact.OriginalStatusId    = dataReader.GetNullableInt32(DyntaxaRevisionSpeciesFact.ORIGINAL_STATUS_ID);
            dyntaxaSpeciesFact.OriginalQualityId   = dataReader.GetNullableInt32(DyntaxaRevisionSpeciesFact.ORIGINAL_QUALITY_ID);
            dyntaxaSpeciesFact.OriginalReferenceId = dataReader.GetNullableInt32(DyntaxaRevisionSpeciesFact.ORIGINAL_REFERENCE_ID);

            dyntaxaSpeciesFact.OriginalDescription = dataReader.GetString(DyntaxaRevisionSpeciesFact.ORIGINAL_DESCRIPTION);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Check the data in current object
 /// </summary>
 /// <param name="dyntaxaSpeciesFact">Dyntaxa revision species fact.</param>
 public static void CheckData(this WebDyntaxaRevisionSpeciesFact dyntaxaSpeciesFact)
 {
     if (!dyntaxaSpeciesFact.IsDataChecked)
     {
         dyntaxaSpeciesFact.CheckStrings();
         dyntaxaSpeciesFact.IsDataChecked = true;
     }
 }
        public void CreateSpeciesFact_WithSpeciesFactStatusNullData_ThenDyntaxaRevisionSpeciesFactCreated()
        {
            Int32 revisionId = 1;

            WebDyntaxaRevisionSpeciesFact speciesFact = GetReferenceDyntaxaRevisionSpeciesFact((Int32)TaxonId.Bear);

            speciesFact.FactorId            = (Int32)FactorId.SwedishHistory;
            speciesFact.RevisionId          = revisionId;
            speciesFact.IsPublished         = false;
            speciesFact.StatusId            = null;
            speciesFact.ReferenceId         = null;
            speciesFact.QualityId           = null;
            speciesFact.SpeciesFactExists   = true;
            speciesFact.Description         = null;
            speciesFact.OriginalStatusId    = 2;
            speciesFact.OriginalQualityId   = 3;
            speciesFact.OriginalReferenceId = 4;
            speciesFact.OriginalDescription = "test test";

            WebTaxonRevisionEvent revisionEvent;

            revisionEvent = new WebTaxonRevisionEvent()
            {
                CreatedBy    = 2,
                CreatedDate  = DateTime.Now,
                TypeId       = 1,
                RevisionId   = revisionId,
                AffectedTaxa = "Bear",
                OldValue     = "StatusId=Unknown",
                NewValue     = "StatusId=400"
            };

            //using (IWebServiceTransaction transaction = new WebServiceTransaction(GetClientInformation(), WebServiceProxy.DyntaxaInternalService))
            using (IWebServiceTransaction transaction = new WebServiceTransaction(GetRevisionClientInformation(), WebServiceProxy.TaxonService))
            {
                // We now create revision event.
                WebTaxonRevisionEvent createdRevisionEvent = WebServiceProxy.DyntaxaInternalService.CreateCompleteRevisionEvent(GetClientInformation(), revisionEvent);
                speciesFact.RevisionEventId = createdRevisionEvent.Id;
                // We now create the revision species fact.
                speciesFact = WebServiceProxy.DyntaxaInternalService.CreateDyntaxaRevisionSpeciesFact(GetClientInformation(), speciesFact);
                var currentDyntaxaRevisionSpeciesFact = WebServiceProxy.DyntaxaInternalService.GetDyntaxaRevisionSpeciesFact(
                    GetClientInformation(), (Int32)FactorId.SwedishHistory, (Int32)TaxonId.Bear, revisionId);

                // Assert first Insert.
                Assert.AreEqual(createdRevisionEvent.Id, speciesFact.RevisionEventId);
                Assert.IsFalse(currentDyntaxaRevisionSpeciesFact.IsChangedInRevisionEventIdSpecified);
                Assert.IsNull(currentDyntaxaRevisionSpeciesFact.StatusId);
                Assert.IsNull(currentDyntaxaRevisionSpeciesFact.ReferenceId);
                Assert.IsNull(currentDyntaxaRevisionSpeciesFact.QualityId);
                Assert.IsNull(currentDyntaxaRevisionSpeciesFact.Description);
                Assert.AreEqual(speciesFact.StatusId, currentDyntaxaRevisionSpeciesFact.StatusId);
                Assert.IsTrue(currentDyntaxaRevisionSpeciesFact.SpeciesFactExists);
                Assert.AreEqual(2, speciesFact.OriginalStatusId);
                Assert.AreEqual(3, speciesFact.OriginalQualityId);
                Assert.AreEqual(4, speciesFact.OriginalReferenceId);
                Assert.AreEqual("test test", speciesFact.OriginalDescription);
            }
        }
 /// <summary>
 /// Creates a new Dyntaxa revision species fact.
 /// </summary>
 /// <param name="clientInformation">Client information.</param>
 /// <param name="dyntaxaRevisionSpeciesFact">Object representing the Dyntaxa revision species fact.</param>
 /// <returns>
 /// Created Dyntaxa revision species fact.
 /// </returns>
 public WebDyntaxaRevisionSpeciesFact CreateDyntaxaRevisionSpeciesFact(
     WebClientInformation clientInformation,
     WebDyntaxaRevisionSpeciesFact dyntaxaRevisionSpeciesFact)
 {
     using (WebServiceContext context = new WebServiceContext(clientInformation))
     {
         try
         {
             return(DyntaxaManager.CreateDyntaxaRevisionSpeciesFact(context, dyntaxaRevisionSpeciesFact));
         }
         catch (Exception exception)
         {
             WebServiceData.LogManager.LogError(context, exception);
             throw;
         }
     }
 }
        /// <summary>
        /// Convert a DyntaxaRevisionSpeciesFact instance to a WebDyntaxaRevisionSpeciesFact instance.
        /// </summary>
        /// <param name="speciesFact">A DyntaxaRevisionSpeciesFact object.</param>
        /// <returns>A WebDyntaxaRevisionSpeciesFact object.</returns>
        private WebDyntaxaRevisionSpeciesFact GetSpeciesFact(DyntaxaRevisionSpeciesFact speciesFact)
        {
            WebDyntaxaRevisionSpeciesFact webSpeciesFact;

            webSpeciesFact = new WebDyntaxaRevisionSpeciesFact();
            if (speciesFact.ChangedInRevisionEventId.HasValue)
            {
                webSpeciesFact.ChangedInRevisionEventId            = speciesFact.ChangedInRevisionEventId.Value;
                webSpeciesFact.IsChangedInRevisionEventIdSpecified = true;
            }
            else
            {
                webSpeciesFact.IsChangedInRevisionEventIdSpecified = false;
            }

            if (speciesFact.RevisionEventId.HasValue)
            {
                webSpeciesFact.RevisionEventId            = speciesFact.RevisionEventId.Value;
                webSpeciesFact.IsRevisionEventIdSpecified = true;
            }
            else
            {
                webSpeciesFact.IsRevisionEventIdSpecified = false;
            }

            webSpeciesFact.CreatedBy           = speciesFact.CreatedBy;
            webSpeciesFact.CreatedDate         = speciesFact.CreatedDate;
            webSpeciesFact.Description         = speciesFact.Description;
            webSpeciesFact.FactorId            = speciesFact.FactorId;
            webSpeciesFact.Id                  = speciesFact.Id;
            webSpeciesFact.IsPublished         = speciesFact.IsPublished;
            webSpeciesFact.ModifiedBy          = speciesFact.ModifiedBy;
            webSpeciesFact.ModifiedDate        = speciesFact.ModifiedDate;
            webSpeciesFact.QualityId           = speciesFact.QualityId;
            webSpeciesFact.ReferenceId         = speciesFact.ReferenceId;
            webSpeciesFact.StatusId            = speciesFact.StatusId;
            webSpeciesFact.TaxonId             = speciesFact.TaxonId;
            webSpeciesFact.RevisionId          = speciesFact.RevisionId;
            webSpeciesFact.SpeciesFactExists   = speciesFact.SpeciesFactExists;
            webSpeciesFact.OriginalStatusId    = speciesFact.OriginalStatusId;
            webSpeciesFact.OriginalQualityId   = speciesFact.OriginalQualityId;
            webSpeciesFact.OriginalReferenceId = speciesFact.OriginalReferenceId;
            webSpeciesFact.OriginalDescription = speciesFact.OriginalDescription;

            return(webSpeciesFact);
        }
        /// <summary>
        /// Get all Dyntaxa Revision Species Fact items.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="taxonRevisionId"></param>
        /// <returns></returns>
        public static List <WebDyntaxaRevisionSpeciesFact> GetAllDyntaxaRevisionSpeciesFacts(WebServiceContext context, int taxonRevisionId)
        {
            List <WebDyntaxaRevisionSpeciesFact> dyntaxaSpeciesFacts = new List <WebDyntaxaRevisionSpeciesFact>();

            // Get information from database.
            using (DataReader dataReader = context.GetTaxonDatabase().GetAllDyntaxaRevisionSpeciesFacts(taxonRevisionId))
            {
                while (dataReader.Read())
                {
                    var dyntaxaSpeciesFact = new WebDyntaxaRevisionSpeciesFact();
                    dyntaxaSpeciesFact.LoadData(dataReader);

                    dyntaxaSpeciesFacts.Add(dyntaxaSpeciesFact);
                }
            }

            return(dyntaxaSpeciesFacts);
        }
        /// <summary>
        /// Get Dyntaxa Revision Species Fact item.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <param name="factorId">Factor id.</param>
        /// <param name="taxonId">Taxon id.</param>
        /// <param name="taxonRevisionId">Revision id.</param>
        /// <returns>
        /// A WebDyntaxaRevisionSpeciesFact if any revision steps have been
        /// made for specified (factorId,taxonId,revisionId); otherwise null.
        /// </returns>
        public static WebDyntaxaRevisionSpeciesFact GetDyntaxaRevisionSpeciesFact(WebServiceContext context, Int32 factorId, Int32 taxonId, Int32 taxonRevisionId)
        {
            WebDyntaxaRevisionSpeciesFact dyntaxaSpeciesFact;

            // Get information from database.
            using (DataReader dataReader = context.GetTaxonDatabase().GetDyntaxaRevisionSpeciesFact(factorId, taxonId, taxonRevisionId))
            {
                if (dataReader.Read())
                {
                    dyntaxaSpeciesFact = new WebDyntaxaRevisionSpeciesFact();
                    dyntaxaSpeciesFact.LoadData(dataReader);
                }
                else
                {
                    return(null);
                }
            }

            return(dyntaxaSpeciesFact);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a WebDyntaxaRevisionSpeciesFact out of predefined data
        /// </summary>
        /// <returns>WebDyntaxaRevisionSpeciesFact</returns>
        public static WebDyntaxaRevisionSpeciesFact Create(int taxonId)
        {
            WebDyntaxaRevisionSpeciesFact refSpeciesFact = new WebDyntaxaRevisionSpeciesFact();

            refSpeciesFact.TaxonId     = taxonId;
            refSpeciesFact.RevisionId  = 1;
            refSpeciesFact.FactorId    = (Int32)FactorId.SwedishOccurrence;
            refSpeciesFact.StatusId    = 1;
            refSpeciesFact.QualityId   = 1;
            refSpeciesFact.Description = "Test description";
            refSpeciesFact.ReferenceId = 1;
            refSpeciesFact.CreatedBy   = Settings.Default.TestUserId;
            refSpeciesFact.CreatedDate = DateTime.Now;
            refSpeciesFact.IsRevisionEventIdSpecified          = true;
            refSpeciesFact.RevisionEventId                     = 1;
            refSpeciesFact.IsChangedInRevisionEventIdSpecified = true;
            refSpeciesFact.ChangedInRevisionEventId            = 1;
            refSpeciesFact.IsPublished = false;

            return(refSpeciesFact);
        }
        /// <summary>
        /// Creates the dyntaxa revision species fact.
        /// </summary>
        /// <param name="context">Web service request context.</param>
        /// <param name="dyntaxaRevisionSpeciesFact">The dyntaxa revision species fact.</param>
        /// <returns></returns>
        public static WebDyntaxaRevisionSpeciesFact CreateDyntaxaRevisionSpeciesFact(WebServiceContext context, WebDyntaxaRevisionSpeciesFact dyntaxaRevisionSpeciesFact)
        {
            // Check authority - AuthorityIdentifier.DyntaxaTaxonEditation
            WebServiceData.AuthorizationManager.CheckAuthorization(context, AuthorityIdentifier.DyntaxaTaxonEditation);
            if (!WebServiceData.AuthorizationManager.IsIdentiferInCurrentRole(context, Settings.Default.TaxonRevisionGuidPrefix))
            {
                throw new ApplicationException("User:"******" is not editor of revision in current role.");
            }

            // Check arguments.
            context.CheckTransaction();
            dyntaxaRevisionSpeciesFact.CheckNotNull("dyntaxaRevisionSpeciesFact");
            dyntaxaRevisionSpeciesFact.CheckData();
            //var userId = WebServiceData.UserManager.GetUser(context).Id;

            var id = context.GetTaxonDatabase().CreateDyntaxaRevisionSpeciesFact(
                dyntaxaRevisionSpeciesFact.FactorId,
                dyntaxaRevisionSpeciesFact.TaxonId,
                dyntaxaRevisionSpeciesFact.RevisionId,
                dyntaxaRevisionSpeciesFact.StatusId,
                dyntaxaRevisionSpeciesFact.QualityId,
                dyntaxaRevisionSpeciesFact.Description,
                dyntaxaRevisionSpeciesFact.ReferenceId,
                dyntaxaRevisionSpeciesFact.CreatedDate,
                dyntaxaRevisionSpeciesFact.CreatedBy,
                dyntaxaRevisionSpeciesFact.RevisionEventId,
                dyntaxaRevisionSpeciesFact.SpeciesFactExists,
                dyntaxaRevisionSpeciesFact.OriginalStatusId,
                dyntaxaRevisionSpeciesFact.OriginalQualityId,
                dyntaxaRevisionSpeciesFact.OriginalReferenceId,
                dyntaxaRevisionSpeciesFact.OriginalDescription);

            WebDyntaxaRevisionSpeciesFact newDyntaxaRevisionSpeciesFact = GetDyntaxaRevisionSpeciesFactById(context, id);

            return(newDyntaxaRevisionSpeciesFact);
        }
 /// <summary>
 /// Creates the dyntaxa revision species fact.
 /// </summary>
 /// <param name="clientInformation">The client information.</param>
 /// <param name="dyntaxaRevisionSpeciesFact">The dyntaxa revision species fact.</param>
 /// <returns></returns>
 public WebDyntaxaRevisionSpeciesFact CreateDyntaxaRevisionSpeciesFact(WebClientInformation clientInformation, WebDyntaxaRevisionSpeciesFact dyntaxaRevisionSpeciesFact)
 {
     using (ClientProxy client = new ClientProxy(this, 1))
     {
         return(client.Client.CreateDyntaxaRevisionSpeciesFact(clientInformation, dyntaxaRevisionSpeciesFact));
     }
 }
        /// <summary>
        /// Updates the dyntaxa revision species fact.
        /// </summary>
        /// <param name="userContext">The user context.</param>
        /// <param name="speciesFact">The species fact.</param>
        /// <param name="webSpeciesFact">The web species fact.</param>
        private void UpdateDyntaxaRevisionSpeciesFact(IUserContext userContext, DyntaxaRevisionSpeciesFact speciesFact, WebDyntaxaRevisionSpeciesFact webSpeciesFact)
        {
            if (webSpeciesFact.IsNull())
            {
                return;
            }

            speciesFact.CreatedBy   = webSpeciesFact.CreatedBy;
            speciesFact.CreatedDate = webSpeciesFact.CreatedDate;
            speciesFact.DataContext = GetDataContext(userContext);
            speciesFact.Description = webSpeciesFact.Description;
            speciesFact.FactorId    = webSpeciesFact.FactorId;
            speciesFact.Id          = webSpeciesFact.Id;
            if (webSpeciesFact.IsChangedInRevisionEventIdSpecified)
            {
                speciesFact.ChangedInRevisionEventId = webSpeciesFact.ChangedInRevisionEventId;
            }
            else
            {
                speciesFact.ChangedInRevisionEventId = null;
            }

            if (webSpeciesFact.IsRevisionEventIdSpecified)
            {
                speciesFact.RevisionEventId = webSpeciesFact.RevisionEventId;
            }
            else
            {
                speciesFact.RevisionEventId = null;
            }

            speciesFact.IsPublished         = webSpeciesFact.IsPublished;
            speciesFact.ModifiedBy          = webSpeciesFact.ModifiedBy;
            speciesFact.ModifiedDate        = webSpeciesFact.ModifiedDate;
            speciesFact.QualityId           = webSpeciesFact.QualityId;
            speciesFact.ReferenceId         = webSpeciesFact.ReferenceId;
            speciesFact.StatusId            = webSpeciesFact.StatusId;
            speciesFact.TaxonId             = webSpeciesFact.TaxonId;
            speciesFact.SpeciesFactExists   = webSpeciesFact.SpeciesFactExists;
            speciesFact.OriginalStatusId    = webSpeciesFact.OriginalStatusId;
            speciesFact.OriginalQualityId   = webSpeciesFact.OriginalQualityId;
            speciesFact.OriginalReferenceId = webSpeciesFact.OriginalReferenceId;
            speciesFact.OriginalDescription = webSpeciesFact.OriginalDescription;
        }
        /// <summary>
        /// Converts a WebDyntaxaRevisionSpeciesFact to a DyntaxaRevisionSpeciesFact.
        /// </summary>
        /// <param name="userContext">The user context.</param>
        /// <param name="webDyntaxaRevisionSpeciesFact">The web dyntaxa revision species fact.</param>
        /// <returns>A converted DyntaxaRevisionSpeciesFact.</returns>
        private DyntaxaRevisionSpeciesFact GetDyntaxaRevisionSpeciesFact(IUserContext userContext, WebDyntaxaRevisionSpeciesFact webDyntaxaRevisionSpeciesFact)
        {
            DyntaxaRevisionSpeciesFact speciesFact = null;

            if (webDyntaxaRevisionSpeciesFact.IsNotNull())
            {
                speciesFact = new DyntaxaRevisionSpeciesFact();
                UpdateDyntaxaRevisionSpeciesFact(userContext, speciesFact, webDyntaxaRevisionSpeciesFact);
            }

            return(speciesFact);
        }