예제 #1
0
 public void UpdateUserToken(Dictionary <string, object> items, BO.ORCID.Person person, string loggedInInternalUsername)
 {
     try
     {
         BO.ORCID.PersonToken accessToken = PersonToken.GetAPIUserAccessToken(items, person);
         if (!Save(accessToken))
         {
             throw new Exception("An unexpected error occurred while saving the token");
         }
         if (accessToken.PermissionID == (int)BO.ORCID.REFPermission.REFPermissions.orcid_profile_read_limited)
         {
             BLL.ORCID.PersonMessage       personMessageBLL = new PersonMessage();
             List <BO.ORCID.PersonMessage> personMessages   = personMessageBLL.GetByPersonIDAndRecordStatusIDAndPermissionID(person.PersonID,
                                                                                                                             (int)BO.ORCID.REFRecordStatus.REFRecordStatuss.Waiting_for_ORCID_User_for_approval,
                                                                                                                             (int)accessToken.PermissionID, false);
             foreach (BO.ORCID.PersonMessage personMessage in personMessages)
             {
                 personMessage.RecordStatusID = (int)BO.ORCID.REFRecordStatus.REFRecordStatuss.Success;
                 if (!personMessageBLL.Save(personMessage))
                 {
                     throw new Exception("Token was saved but an unexpected error occurred while updating the related messages.");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw BLL.ORCID.ErrorLog.LogError(ex, loggedInInternalUsername, "Error saving token information to table: ProfileToken in databae: BUMC_ORCID.");
     }
 }
 public void UpdateUserToken(Dictionary<string, object> items, BO.ORCID.Person person, string loggedInInternalUsername)
 {
     try
     {
         BO.ORCID.PersonToken accessToken = PersonToken.GetAPIUserAccessToken(items, person);
         if (!Save(accessToken))
         {
             throw new Exception("An unexpected error occurred while saving the token");
         }
         if (accessToken.PermissionID == (int)BO.ORCID.REFPermission.REFPermissions.orcid_profile_read_limited)
         {
             BLL.ORCID.PersonMessage personMessageBLL = new PersonMessage();
             List<BO.ORCID.PersonMessage> personMessages = personMessageBLL.GetByPersonIDAndRecordStatusIDAndPermissionID(person.PersonID,
                 (int)BO.ORCID.REFRecordStatus.REFRecordStatuss.Waiting_for_ORCID_User_for_approval,
                 (int)accessToken.PermissionID, false);
             foreach (BO.ORCID.PersonMessage personMessage in personMessages)
             {
                 personMessage.RecordStatusID = (int)BO.ORCID.REFRecordStatus.REFRecordStatuss.Success;
                 if (!personMessageBLL.Save(personMessage))
                 {
                     throw new Exception("Token was saved but an unexpected error occurred while updating the related messages.");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         throw BLL.ORCID.ErrorLog.LogError(ex, loggedInInternalUsername, "Error saving token information to table: ProfileToken in databae: BUMC_ORCID.");
     }
 }
예제 #3
0
        private void GetWebResponseMethodGet(BO.ORCID.PersonMessage personMessage, BO.ORCID.REFPermission refPermission, NameValueCollection parameters)
        {
            BLL.ORCID.PersonMessage personMessageBLL = new PersonMessage();
            InitializePersonMessageRequestInfo(personMessage, personMessageBLL);
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(personMessage.RequestURL);

            try
            {
                httpWebRequest.ContentType = "application/orcid+xml";
                httpWebRequest.Method      = "GET";

                foreach (var key in parameters.AllKeys)
                {
                    httpWebRequest.Headers.Add(key, parameters[key]);
                }

                WebResponse wr = httpWebRequest.GetResponse();
                personMessage.XML_Response       = new StreamReader(wr.GetResponseStream()).ReadToEnd();
                personMessage.MessagePostSuccess = true;
            }
            catch (WebException en)
            {
                ProcessWebException(personMessage, en, httpWebRequest);
            }
            SavePersonMessage(personMessage, refPermission, personMessageBLL);
        }
        public void SendORCIDXMLMessage(BO.ORCID.Person person, string accessToken, BO.ORCID.PersonMessage personMessage, BO.ORCID.REFPermission refPermission)
        {
            List<string> responseMessage = new List<string>();
            BLL.ORCID.PersonMessage personMessageBLL = new PersonMessage();
            personMessage.RequestURL = ProfilesRNSDLL.BO.ORCID.Config.ORCID_API_URL_WITH_VERSION + "/" + person.ORCID + "/" + refPermission.MethodAndRequest;
            InitializePersonMessageRequestInfo(personMessage, personMessageBLL);

            string method = System.Net.WebRequestMethods.Http.Post.ToString();
            if (personMessage.PermissionID == (int)BO.ORCID.REFPermission.REFPermissions.orcid_bio_update)
            {
                method = System.Net.WebRequestMethods.Http.Put.ToString();
            }

            string msg = string.Empty;

            WebRequest httpWebRequest = WebRequest.Create(personMessage.RequestURL);
            httpWebRequest.ContentType = "application/orcid+xml";
            httpWebRequest.Method = method;

            NameValueCollection param2 = new NameValueCollection();
            string AuthBearer = "Authorization: Bearer " + accessToken;
            responseMessage.Add(AuthBearer);

            param2.Add("Authorization", " Bearer " + accessToken);

            foreach (var key in param2.AllKeys)
            {
                httpWebRequest.Headers.Add(key, param2[key]);
            }

            string profile = personMessage.XML_Sent;

            byte[] xmlBytes = Encoding.UTF8.GetBytes(profile);
            using (var requestStream = httpWebRequest.GetRequestStream())
            {
                requestStream.Write(xmlBytes, 0, xmlBytes.Length);
                requestStream.Close();
            }
            try
            {
                using (WebResponse response = httpWebRequest.GetResponse())
                {
                    HttpWebResponse httpResponse = (HttpWebResponse)response;
                    using (Stream data = response.GetResponseStream())
                    {
                        string text = new StreamReader(data).ReadToEnd();
                        personMessage.HttpResponseCode = httpResponse.StatusCode.ToString();
                        responseMessage.Add(text);
                        personMessage.MessagePostSuccess = true;
                    }
                }
            }
            catch (WebException en)
            {
                ProcessWebException(personMessage, en, httpWebRequest);
            }
            SavePersonMessage(personMessage, refPermission, personMessageBLL);
        }
예제 #5
0
        private bool PostNewORCIDRequestToORCIDAPI(BO.ORCID.Person person, string loggedInInternalUsername)
        {
            BO.ORCID.REFPermission refPermission = new ProfilesRNSDLL.BLL.ORCID.REFPermission().Get((int)BO.ORCID.REFPermission.REFPermissions.orcid_profile_create);
            string ORCIDCreateProfileURL         = ProfilesRNSDLL.BO.ORCID.Config.ORCID_API_URL_WITH_VERSION + "/" + "orcid-profile";

            var httpWebRequest = WebRequest.Create(ORCIDCreateProfileURL);

            httpWebRequest.ContentType = "application/orcid+xml";
            httpWebRequest.Method      = System.Net.WebRequestMethods.Http.Post.ToString();

            string authToken = BLL.ORCID.OAuth.GetClientToken(refPermission.PermissionScope, loggedInInternalUsername);

            httpWebRequest.Headers.Add("Authorization", " Bearer " + authToken);

            byte[] xmlBytes = Encoding.UTF8.GetBytes(PersonMessage.CreateNewBasicORCIDMessage(person));
            using (var requestStream = httpWebRequest.GetRequestStream())
            {
                requestStream.Write(xmlBytes, 0, xmlBytes.Length);
                requestStream.Close();
            }
            try
            {
                using (WebResponse response = httpWebRequest.GetResponse())
                {
                    // Example of response.Headers["Location"] is 'http://api.orcid.org/0000-0002-4523-3823/orcid-profile'
                    person.ORCID = System.Text.RegularExpressions.Regex.Split(response.Headers["Location"].ToString(), "/")[3];
                }
            }
            catch (WebException en)
            {
                using (WebResponse response = en.Response)
                {
                    HttpWebResponse httpResponse = (HttpWebResponse)response;

                    person.Error += string.Format("Error code: {0}", httpResponse.StatusCode);
                    using (Stream data = response.GetResponseStream())
                    {
                        string text = new StreamReader(data).ReadToEnd();
                        person.Error += text;
                    }
                }
            }
            if (string.IsNullOrEmpty(person.Error))
            {
                if (!person.HasValidORCID)
                {
                    person.Error = "Error! Invalid ORCID value";
                }
            }
            if (person.Error.Contains("Cannot create ORCID"))
            {
                person.Error = "An error occured creating your ORCID. This email address has already been registed with ORCID.";
            }
            person.HasError = !person.Error.Equals(string.Empty);
            return(!person.HasError);
        }
        private void GetWebResponseMethodGet(BO.ORCID.PersonMessage personMessage, BO.ORCID.REFPermission refPermission, NameValueCollection parameters)
        {
            BLL.ORCID.PersonMessage personMessageBLL = new PersonMessage();
            InitializePersonMessageRequestInfo(personMessage, personMessageBLL);
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(personMessage.RequestURL);
            try
            {

                httpWebRequest.ContentType = "application/orcid+xml";
                httpWebRequest.Method = "GET";

                foreach (var key in parameters.AllKeys)
                {
                    httpWebRequest.Headers.Add(key, parameters[key]);
                }

                WebResponse wr = httpWebRequest.GetResponse();
                personMessage.XML_Response = new StreamReader(wr.GetResponseStream()).ReadToEnd();
                personMessage.MessagePostSuccess = true;
            }
            catch (WebException en)
            {
                ProcessWebException(personMessage, en, httpWebRequest);
            }
            SavePersonMessage(personMessage, refPermission, personMessageBLL);
        }
예제 #7
0
        public void SendORCIDXMLMessage(BO.ORCID.Person person, string accessToken, BO.ORCID.PersonMessage personMessage, BO.ORCID.REFPermission refPermission)
        {
            List <string> responseMessage = new List <string>();

            BLL.ORCID.PersonMessage personMessageBLL = new PersonMessage();
            personMessage.RequestURL = ProfilesRNSDLL.BO.ORCID.Config.ORCID_API_URL_WITH_VERSION + "/" + person.ORCID + "/" + refPermission.MethodAndRequest;
            InitializePersonMessageRequestInfo(personMessage, personMessageBLL);

            string method = System.Net.WebRequestMethods.Http.Post.ToString();

            if (personMessage.PermissionID == (int)BO.ORCID.REFPermission.REFPermissions.orcid_bio_update)
            {
                method = System.Net.WebRequestMethods.Http.Put.ToString();
            }

            string msg = string.Empty;

            WebRequest httpWebRequest = WebRequest.Create(personMessage.RequestURL);

            httpWebRequest.ContentType = "application/orcid+xml";
            httpWebRequest.Method      = method;

            NameValueCollection param2 = new NameValueCollection();
            string AuthBearer          = "Authorization: Bearer " + accessToken;

            responseMessage.Add(AuthBearer);

            param2.Add("Authorization", " Bearer " + accessToken);

            foreach (var key in param2.AllKeys)
            {
                httpWebRequest.Headers.Add(key, param2[key]);
            }

            string profile = personMessage.XML_Sent;

            byte[] xmlBytes = Encoding.UTF8.GetBytes(profile);
            using (var requestStream = httpWebRequest.GetRequestStream())
            {
                requestStream.Write(xmlBytes, 0, xmlBytes.Length);
                requestStream.Close();
            }
            try
            {
                using (WebResponse response = httpWebRequest.GetResponse())
                {
                    HttpWebResponse httpResponse = (HttpWebResponse)response;
                    using (Stream data = response.GetResponseStream())
                    {
                        string text = new StreamReader(data).ReadToEnd();
                        personMessage.HttpResponseCode = httpResponse.StatusCode.ToString();
                        responseMessage.Add(text);
                        personMessage.MessagePostSuccess = true;
                    }
                }
            }
            catch (WebException en)
            {
                ProcessWebException(personMessage, en, httpWebRequest);
            }
            SavePersonMessage(personMessage, refPermission, personMessageBLL);
        }
        public bool CreateNewORCID(BO.ORCID.Person person, string loggedInInternalUsername, ProfilesRNSDLL.BO.ORCID.REFPersonStatusType.REFPersonStatusTypes failedStatus)
        {
            // Make sure an institution email has been provided.
            // Ensure that the new ORCID information can be saved in the database as it doesn't violate any business rules, e.g. missing internal username.
            if (!BizRulesForCreation(person))
            {
                try
                {
                    person.HasError = false;
                    person.PersonStatusTypeID = (int)failedStatus;
                    Edit(person, false);
                }
                catch
                {

                }
                return false;
            }
            try
            {
                ProfilesRNSDLL.BLL.ORCID.PersonMessage personMessageBLL = new PersonMessage();
                ProfilesRNSDLL.BLL.ORCID.PersonOthername personOthernameBLL = new PersonOthername();
                ProfilesRNSDLL.BLL.ORCID.PersonAlternateEmail personAlternateEmailBLL = new PersonAlternateEmail();
                ProfilesRNSDLL.BLL.ORCID.PersonURL personURLBLL = new PersonURL();
                ProfilesRNSDLL.BLL.ORCID.PersonWork personWorkBLL = new PersonWork();
                ProfilesRNSDLL.BLL.ORCID.PersonAffiliation personAffiliationBLL = new PersonAffiliation();

                if (PostNewORCIDRequestToORCIDAPI(person, loggedInInternalUsername))
                {
                    // Save the person record (includes the narrative, aka biography, if one was provided).
                    person.PersonStatusTypeID = (int)ProfilesRNSDLL.BO.ORCID.REFPersonStatusType.REFPersonStatusTypes.ORCID_Created;
                    person.ORCIDRecorded = DateTime.Now;
                    if (!Save(person))
                    {
                        person.Error += "The ORCID was created but a problem (person save failed) occurred while saving the data in the BU database. ";
                        return false;
                    }
                    // Create a message to save what was sent to ORCID.
                    // Also mark the person with the person message ID
                    if (!personMessageBLL.CreatePersonMessage(person))
                    {
                        person.Error += "The ORCID was created but a problem (person message save failed) occurred while saving the data in the BU database. ";
                        return false;
                    }
                    BLL.ORCID.PersonMessage.SetPersonMessageID(person);
                    // Save the other names
                    if (!personOthernameBLL.AddIfAny(person))
                    {
                        person.Error += "The ORCID was created but a problem (saving of other names failed) occurred while saving the data in the BU database. ";
                        return false;
                    }
                    // Save the alternate email addresses
                    if (!personAlternateEmailBLL.AddIfAny(person))
                    {
                        person.Error += "The ORCID was created but a problem (saving of alternate emails failed) occurred while saving the data in the BU database. ";
                        return false;
                    }
                    // Save the urls
                    if (!personURLBLL.AddIfAny(person))
                    {
                        person.Error += "The ORCID was created but a problem (saving of urls failed) occurred while saving the data in the BU database. ";
                        return false;
                    }
                    // Save the works
                    if (!personWorkBLL.AddIfAny(person))
                    {
                        person.Error += "The ORCID was created but a problem (saving of works failed) occurred while saving the data in the BU database. ";
                        return false;
                    }
                    // Save the works
                    if (!personAffiliationBLL.AddIfAny(person))
                    {
                        person.Error += "The ORCID was created but a problem (saving of affiliations failed) occurred while saving the data in the BU database. ";
                        return false;
                    }
                    return true;
                }
                else
                {
                    person.HasError = false;
                    person.PersonStatusTypeID = (int)failedStatus;
                    try
                    {
                        Save(person, false);
                    }
                    catch (Exception ex)
                    {
                        throw BLL.ORCID.ErrorLog.LogError(ex, loggedInInternalUsername, "An error occurred while saving the fact that the batch push failed.");
                    }
                    return false;
                }
            }
            catch (Exception ex)
            {
                throw ErrorLog.LogError(ex, loggedInInternalUsername, "An error occurred while generating the messages to send to ORCID.");
            }
        }
예제 #9
0
        public bool CreateNewORCID(BO.ORCID.Person person, string loggedInInternalUsername, ProfilesRNSDLL.BO.ORCID.REFPersonStatusType.REFPersonStatusTypes failedStatus)
        {
            // Make sure an institution email has been provided.
            // Ensure that the new ORCID information can be saved in the database as it doesn't violate any business rules, e.g. missing internal username.
            if (!BizRulesForCreation(person))
            {
                try
                {
                    person.HasError           = false;
                    person.PersonStatusTypeID = (int)failedStatus;
                    Edit(person, false);
                }
                catch
                {
                }
                return(false);
            }
            try
            {
                ProfilesRNSDLL.BLL.ORCID.PersonMessage        personMessageBLL        = new PersonMessage();
                ProfilesRNSDLL.BLL.ORCID.PersonOthername      personOthernameBLL      = new PersonOthername();
                ProfilesRNSDLL.BLL.ORCID.PersonAlternateEmail personAlternateEmailBLL = new PersonAlternateEmail();
                ProfilesRNSDLL.BLL.ORCID.PersonURL            personURLBLL            = new PersonURL();
                ProfilesRNSDLL.BLL.ORCID.PersonWork           personWorkBLL           = new PersonWork();
                ProfilesRNSDLL.BLL.ORCID.PersonAffiliation    personAffiliationBLL    = new PersonAffiliation();

                if (PostNewORCIDRequestToORCIDAPI(person, loggedInInternalUsername))
                {
                    // Save the person record (includes the narrative, aka biography, if one was provided).
                    person.PersonStatusTypeID = (int)ProfilesRNSDLL.BO.ORCID.REFPersonStatusType.REFPersonStatusTypes.ORCID_Created;
                    person.ORCIDRecorded      = DateTime.Now;
                    if (!Save(person))
                    {
                        person.Error += "The ORCID was created but a problem (person save failed) occurred while saving the data in the BU database. ";
                        return(false);
                    }
                    // Create a message to save what was sent to ORCID.
                    // Also mark the person with the person message ID
                    if (!personMessageBLL.CreatePersonMessage(person))
                    {
                        person.Error += "The ORCID was created but a problem (person message save failed) occurred while saving the data in the BU database. ";
                        return(false);
                    }
                    BLL.ORCID.PersonMessage.SetPersonMessageID(person);
                    // Save the other names
                    if (!personOthernameBLL.AddIfAny(person))
                    {
                        person.Error += "The ORCID was created but a problem (saving of other names failed) occurred while saving the data in the BU database. ";
                        return(false);
                    }
                    // Save the alternate email addresses
                    if (!personAlternateEmailBLL.AddIfAny(person))
                    {
                        person.Error += "The ORCID was created but a problem (saving of alternate emails failed) occurred while saving the data in the BU database. ";
                        return(false);
                    }
                    // Save the urls
                    if (!personURLBLL.AddIfAny(person))
                    {
                        person.Error += "The ORCID was created but a problem (saving of urls failed) occurred while saving the data in the BU database. ";
                        return(false);
                    }
                    // Save the works
                    if (!personWorkBLL.AddIfAny(person))
                    {
                        person.Error += "The ORCID was created but a problem (saving of works failed) occurred while saving the data in the BU database. ";
                        return(false);
                    }
                    // Save the works
                    if (!personAffiliationBLL.AddIfAny(person))
                    {
                        person.Error += "The ORCID was created but a problem (saving of affiliations failed) occurred while saving the data in the BU database. ";
                        return(false);
                    }
                    return(true);
                }
                else
                {
                    person.HasError           = false;
                    person.PersonStatusTypeID = (int)failedStatus;
                    try
                    {
                        Save(person, false);
                    }
                    catch (Exception ex)
                    {
                        throw BLL.ORCID.ErrorLog.LogError(ex, loggedInInternalUsername, "An error occurred while saving the fact that the batch push failed.");
                    }
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ErrorLog.LogError(ex, loggedInInternalUsername, "An error occurred while generating the messages to send to ORCID.");
            }
        }