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 CreateUploadMessages(BO.ORCID.Person person, string loggedInInternalUsername) { // Before opening the transaction get the 'read limited' token if it exists. // if it does not exist or is expired we will create a message to update it. BO.ORCID.PersonToken personToken = new BLL.ORCID.PersonToken().GetByPersonIDAndPermissionID(person.PersonID, (int)BO.ORCID.REFPermission.REFPermissions.orcid_profile_read_limited); using (System.Data.Common.DbTransaction trans = base.GetEditTransaction()) { try { new ProfilesRNSDLL.BLL.ORCID.Person().Edit(person, trans); if (!personToken.Exists || personToken.IsExpired) { CreateMessageToReadLimited(person, trans); } if (person.PushBiographyToORCID || (person.HasURLsToPush)) { CreateBioUpdateMessage(person, trans, loggedInInternalUsername); } WorksUpdate(person, trans); AffiliationsUpdate(person, trans); trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw ErrorLog.LogError(ex, loggedInInternalUsername, "An error occurred while generating the messages to send to ORCID."); } } }
internal bool AddIfAny(BO.ORCID.Person person) { if (person.Works != null) { BLL.ORCID.PersonWorkIdentifier personWorkIdentifierBLL = new PersonWorkIdentifier(); for (int i = 0; i < person.Works.Count; i++) { person.Works[i].PersonID = person.PersonID; if (this.Add(person.Works[i])) { foreach (BO.ORCID.PersonWorkIdentifier personWorkIdentifier in person.Works[i].Identifiers) { personWorkIdentifier.PersonWorkID = person.Works[i].PersonWorkID; if (!personWorkIdentifierBLL.Save(personWorkIdentifier)) { throw new DevelopmentBase.BO.ExceptionSafeToDisplay("Unable to save the work identifier info while creating a work message to ORCID"); } } } else { return(false); } } } return(true); }
internal static void SetPersonMessageID(BO.ORCID.Person person) { BLL.ORCID.PersonURL.SetPersonMessageID(person); BLL.ORCID.PersonAlternateEmail.SetPersonMessageID(person); BLL.ORCID.PersonWork.SetPersonMessageID(person); BLL.ORCID.PersonOthername.SetPersonMessageID(person); BLL.ORCID.PersonAffiliation.SetPersonMessageID(person); }
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); }
public BO.ORCID.PersonMessage Create(BO.ORCID.Person person, BO.ORCID.REFPermission refPermission) { ProfilesRNSDLL.BO.ORCID.PersonMessage personMessage = new ProfilesRNSDLL.BO.ORCID.PersonMessage(); personMessage.PermissionID = refPermission.PermissionID; personMessage.RecordStatusID = (int)ProfilesRNSDLL.BO.ORCID.REFRecordStatus.REFRecordStatuss.Waiting_for_ORCID_User_for_approval; personMessage.PersonID = person.PersonID; personMessage.RequestURL = ProfilesRNSDLL.BO.ORCID.Config.ORCID_API_URL_WITH_VERSION + "/" + person.ORCID + "/" + refPermission.MethodAndRequest; new BLL.ORCID.PersonMessage().Save(personMessage); return(personMessage); }
internal static void SetPersonMessageID(BO.ORCID.Person person) { if (person.Works != null && person.Works.Count > 0) { foreach (BO.ORCID.PersonWork personWork in person.Works) { personWork.PersonMessageID = person.PersonMessage.PersonMessageID; } } }
internal static void SetPersonMessageID(BO.ORCID.Person person) { if (person.Affiliations != null && person.Affiliations.Count > 0) { foreach (BO.ORCID.PersonAffiliation personAffiliation in person.Affiliations) { personAffiliation.PersonMessageID = person.PersonMessage.PersonMessageID; } } }
internal static void SetPersonMessageID(BO.ORCID.Person person) { if (person.Othernames != null && person.Othernames.Count > 0) { foreach (BO.ORCID.PersonOthername personOthername in person.Othernames) { personOthername.PersonMessageID = person.PersonMessage.PersonMessageID; } } }
public void ReadORCIDProfile(BO.ORCID.Person person, BO.ORCID.PersonMessage personMessage, BO.ORCID.REFPermission refPermission, string loggedInInternalUsername) { personMessage.RequestURL = ProfilesRNSDLL.BO.ORCID.Config.ORCID_API_URL_WITH_VERSION + "/" + person.ORCID + "/" + refPermission.MethodAndRequest; NameValueCollection param2 = new NameValueCollection(); string token = BLL.ORCID.OAuth.GetClientToken(refPermission.PermissionScope, loggedInInternalUsername); param2.Add("Authorization", " Bearer " + token); param2.Add("Scope", refPermission.PermissionScope); GetWebResponseMethodGet(personMessage, refPermission, param2); }
internal static void SetPersonMessageID(BO.ORCID.Person person) { if (person.AlternateEmails != null && person.AlternateEmails.Count > 0) { foreach (BO.ORCID.PersonAlternateEmail personAlternateEmail in person.AlternateEmails) { personAlternateEmail.PersonMessageID = person.PersonMessage.PersonMessageID; } } }
internal static void SetPersonMessageID(BO.ORCID.Person person) { if (person.URLs != null && person.URLs.Count > 0) { foreach (BO.ORCID.PersonURL personURL in person.URLs) { personURL.PersonMessageID = person.PersonMessage.PersonMessageID; } } }
public bool Save(BO.ORCID.Person bo) { if (bo.Exists) { return(base.Edit(bo)); } else { return(base.Add(bo)); } }
public bool Save(BO.ORCID.Person bo, bool checkBizRules) { if (bo.Exists) { return(base.Edit(bo, checkBizRules)); } else { return(base.Add(bo, checkBizRules)); } }
public void UpdateUserToken(string oAuthCode, BO.ORCID.Person person, string returnPage, string loggedInInternalUsername) { try { Dictionary <string, object> items = ProfilesRNSDLL.BLL.ORCID.OAuth.GetUserAccessTokenItems(oAuthCode, returnPage, loggedInInternalUsername); UpdateUserToken(items, person, loggedInInternalUsername); } catch (Exception ex) { throw BLL.ORCID.ErrorLog.LogError(ex, loggedInInternalUsername, "Error saving token information to table: ProfileToken in databae: BUMC_ORCID."); } }
public ProfilesRNSDLL.BO.ORCID.PersonToken Get(BO.ORCID.Person person, BO.ORCID.REFPermission refPermission) { ProfilesRNSDLL.BO.ORCID.PersonToken personToken = new BLL.ORCID.PersonToken().GetByPersonIDAndPermissionID(person.PersonID, refPermission.PermissionID); if (personToken.Exists && !personToken.IsExpired) { return(personToken); } else { BO.ORCID.PersonToken bo = new BO.ORCID.PersonToken(); bo.PersonID = person.PersonID; bo.PermissionID = refPermission.PermissionID; return(bo); } }
internal bool AddIfAny(BO.ORCID.Person person) { if (person.Othernames != null) { foreach (BO.ORCID.PersonOthername otherName in person.Othernames) { otherName.PersonID = person.PersonID; if (!this.Add(otherName)) { return(false); } } } return(true); }
public void CheckAlternateEmails(BO.ORCID.Person bo) { if (bo.AlternateEmails != null && bo.AlternateEmails.Count > 0) { foreach (BO.ORCID.PersonAlternateEmail email in bo.AlternateEmails) { if (!DevelopmentBase.RegEx.GeneralValidation.isValidEmail(email.EmailAddress)) { bo.HasError = true; bo.AlternateEmailDecisionIDErrors += "Please check the email address as at least one is not valid. " + Environment.NewLine; break; } } } }
internal bool AddIfAny(BO.ORCID.Person person) { if (person.AlternateEmails != null) { foreach (BO.ORCID.PersonAlternateEmail altEmail in person.AlternateEmails) { altEmail.PersonID = person.PersonID; if (!this.Add(altEmail)) { return(false); } } } return(true); }
public System.Xml.XmlDocument GetORCIDRecordPublic(BO.ORCID.Person orcidPerson, string loggedInInternalUsername) { BO.ORCID.REFPermission refPermission = new BLL.ORCID.REFPermission().Get((int)BO.ORCID.REFPermission.REFPermissions.read_public); // Make sure we have either created the ORCID or the user has provided the ORCID. if (orcidPerson.ORCIDIsNull) { throw new ProfilesRNSDLL.DevelopmentBase.BO.ExceptionSafeToDisplay("Cannot return the ORCID record, the ORCID identifier has not been recorded."); } try { string ORCIDCreateProfileURL = ProfilesRNSDLL.BO.ORCID.Config.ORCID_API_URL + "/" + orcidPerson.ORCID + "/"; var httpWebRequest = WebRequest.Create(ORCIDCreateProfileURL); httpWebRequest.ContentType = "application/vdn.orcid+xml"; httpWebRequest.Method = System.Net.WebRequestMethods.Http.Get; //string authToken = BLL.ORCID.OAuth.SetToken(refPermission.PermissionScope, loggedInInternalUsername); //httpWebRequest.Headers.Add("client_id", ProfilesRNSDLL.BO.ORCID.Config.ClientID); //httpWebRequest.Headers.Add("client_secret", ProfilesRNSDLL.BO.ORCID.Config.ClientSecret); //httpWebRequest.Headers.Add("scope", SCOPE_READ_PUBLIC); //httpWebRequest.Headers.Add("grant_type", "client_credentials"); string token = BLL.ORCID.OAuth.GetClientToken(refPermission.PermissionScope, loggedInInternalUsername); httpWebRequest.Headers.Add("Authorization", " Bearer " + token); httpWebRequest.Headers.Add("Scope", refPermission.PermissionScope); using (WebResponse response = httpWebRequest.GetResponse()) { using (var reader = new StreamReader(response.GetResponseStream())) { string result = reader.ReadToEnd(); System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); xml.LoadXml(result); return(xml); } } // curl -H 'Content-Type: application/vdn.orcid+xml' -H 'Authorization: Bearer f6d49570-c048-45a9-951f-a81ebb1fa543' -X GET 'http://api.sandbox-1.orcid.org/v1.0.23/0000-0003-1495-7122/orcid-profile' -L -i } catch (Exception ex) { throw BLL.ORCID.ErrorLog.LogError(ex, loggedInInternalUsername, "An error occurred while connecting to ORCID. Unable to retrieve token information to save."); } }
public System.Xml.XmlDocument GetORCIDRecordLimited(BO.ORCID.Person orcidPerson, string loggedInInternalUsername) { BO.ORCID.REFPermission refPermission = new BLL.ORCID.REFPermission().Get((int)BO.ORCID.REFPermission.REFPermissions.orcid_profile_read_limited); // Make sure we have either created the ORCID or the user has provided the ORCID. if (orcidPerson.ORCIDIsNull) { throw new ProfilesRNSDLL.DevelopmentBase.BO.ExceptionSafeToDisplay("Cannot return the ORCID record, the ORCID identifier has not been recorded."); } // Make sure the users has granted the permission to read the profile. BO.ORCID.PersonToken personToken = new BLL.ORCID.PersonToken().GetByPersonIDAndPermissionID(orcidPerson.PersonID, (int)BO.ORCID.REFPermission.REFPermissions.orcid_profile_read_limited); if (personToken.Exists && !personToken.IsExpired) { try { string ORCIDCreateProfileURL = ProfilesRNSDLL.BO.ORCID.Config.ORCID_API_URL_WITH_VERSION + "/" + orcidPerson.ORCID + "/" + refPermission.MethodAndRequest; var httpWebRequest = WebRequest.Create(ORCIDCreateProfileURL); httpWebRequest.ContentType = "application/vdn.orcid+xml"; httpWebRequest.Method = System.Net.WebRequestMethods.Http.Get; httpWebRequest.Headers.Add("Authorization", " Bearer " + personToken.AccessToken); using (WebResponse response = httpWebRequest.GetResponse()) { using (var reader = new StreamReader(response.GetResponseStream())) { string result = reader.ReadToEnd(); System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); xml.LoadXml(result); return(xml); } } // curl -H 'Content-Type: application/vdn.orcid+xml' -H 'Authorization: Bearer f6d49570-c048-45a9-951f-a81ebb1fa543' -X GET 'http://api.sandbox-1.orcid.org/v1.0.23/0000-0003-1495-7122/orcid-profile' -L -i } catch (Exception ex) { throw BLL.ORCID.ErrorLog.LogError(ex, loggedInInternalUsername, "An error occurred while connecting to ORCID. Unable to retrieve token information to save."); } } else { throw new ProfilesRNSDLL.DevelopmentBase.BO.ExceptionSafeToDisplay("Cannot return the ORCID record, permission has not been granted to read the record."); } }
public override void BizRules(BO.ORCID.Person bo, BO.ORCID.Person boBefore) { if (!string.IsNullOrEmpty(bo.Biography)) { if (bo.Biography.Length > ORCID_MAX_BIOGRAPHY_LENGTH) { bo.BiographyErrors = "ORCID can only accept Biography's that have 5000 or fewer characters."; bo.HasError = true; } } if (string.IsNullOrEmpty(bo.InternalUsername) || bo.InternalUsername.Trim().Equals(string.Empty)) { bo.HasError = true; bo.Error += "Missing internal username identifier." + Environment.NewLine; } CheckAlternateEmails(bo); }
private bool OneEmailIsOrgEmail(BO.ORCID.Person bo) { if (!bo.EmailAddressIsNull && !bo.EmailAddress.Trim().Equals(string.Empty)) { if (EmailIsOrgEmail(bo.EmailAddress)) { return(true); } } foreach (BO.ORCID.PersonAlternateEmail email in bo.AlternateEmails) { if (EmailIsOrgEmail(email.EmailAddress)) { return(true); } } return(false); }
public System.Xml.XmlDocument GetORCIDRecord(BO.ORCID.Person orcidPerson, string loggedInInternalUsername) { try { return(GetORCIDRecordLimited(orcidPerson, loggedInInternalUsername)); } catch { } try { return(GetORCIDRecordPublic(orcidPerson, loggedInInternalUsername)); } catch { return(null); } }
//public List<BO.ORCID.PersonURL> GetByPersonID(int personID) //{ // return base.GetByPersonID(personID, false); //} internal bool AddIfAny(BO.ORCID.Person person, System.Data.Common.DbTransaction trans) { if (person.AlternateEmails != null) { foreach (BO.ORCID.PersonURL personURL in person.URLs) { // get id if it already exists personURL.PersonID = person.PersonID; GetPersonURLID(personURL); // Add the new person message id if (!Save(personURL, trans)) { return(false); } } } return(true); }
internal bool AddIfAny(BO.ORCID.Person person) { if (person.AlternateEmails != null) { foreach (BO.ORCID.PersonAffiliation personAffiliation in person.Affiliations) { // get id if it already exists personAffiliation.PersonID = person.PersonID; GetPersonAffiliationID(personAffiliation); // Add the new person message id if (!Save(personAffiliation)) { return(false); } } } return(true); }
internal static string CreateNewBasicORCIDMessage(BO.ORCID.Person person) { string msg = XML_MESSAGE_HEADER; msg += ORCID_MESSAGE_BEGIN; { msg += "<message-version>" + BO.ORCID.Config.MessageVersion + "</message-version>"; msg += "<!-- <error-desc>No researcher found.</error-desc> --> "; # region orcid-profile msg += "<orcid-profile>"; { # region orcid-bio msg += "<orcid-bio>"; { AddPersonDetails(ref msg, person); AddBioFieldNewORCID(ref msg, person); AddContactDetails(ref msg, person); } msg += "</orcid-bio>"; # endregion orcid-bio
public new List <BO.ORCID.PersonURL> GetForORCIDUpdate(BO.ORCID.Person orcidPerson, long subjectID) { List <ProfilesRNSDLL.BO.ORCID.PersonURL> webSites = new List <ProfilesRNSDLL.BO.ORCID.PersonURL>(); try { ProfilesRNSDLL.BO.ORNG.AppData appData = new ProfilesRNSDLL.BLL.ORNG.AppData().GetWebsites(subjectID); //value = [{"link_name":"Clinical and Translational Science Institute Leadership","link_url":"http://ctsi.bu.edu/index.php/about-us/leadership/"}, {"link_name":"My Google","link_url":"www.google.com"}] string webSitesJSON = appData.value; while (webSitesJSON.ToLower().Contains("\"link_name\"")) { BO.ORCID.PersonURL website = new BO.ORCID.PersonURL(); if (webSitesJSON.ToLower().IndexOf("\"link_name\"") < webSitesJSON.ToLower().IndexOf("\"link_url\"")) { website.URLName = GetFieldValueFromJsonString(ref webSitesJSON, "link_name"); website.URL = GetFieldValueFromJsonString(ref webSitesJSON, "link_url"); } else { website.URL = GetFieldValueFromJsonString(ref webSitesJSON, "link_url"); website.URLName = GetFieldValueFromJsonString(ref webSitesJSON, "link_name"); } // Default to Public website.DecisionID = (int)BO.ORCID.REFDecision.REFDecisions.Public; webSites.Add(website); } } catch //(Exception ex) { // unable to get links from the Open Social. return(new List <ProfilesRNSDLL.BO.ORCID.PersonURL>()); } // Get the list of processed affiliations List <ProfilesRNSDLL.BO.ORCID.PersonURL> processedWebsites = GetSuccessfullyProcessedURLs(orcidPerson.PersonID); // Get the affiliations that have not been processed return((from w in webSites where !processedWebsites.Any(pw => pw.URL == w.URL) select w).ToList()); }
private bool BizRulesForCreation(BO.ORCID.Person person) { int checkForOrgEmail = DevelopmentBase.Common.GetConfigInt("ORCID.CheckOrganizationNameEmailSuffix"); if (checkForOrgEmail.Equals(1) && !OneEmailIsOrgEmail(person)) { person.EmailAddressErrors += BLL.ORCID.Person.EmailRequiredMessage; person.HasError = true; } if (person.FirstNameIsNull || person.FirstName.Trim().Equals(string.Empty)) { person.HasError = true; person.FirstNameErrors += "Required." + Environment.NewLine; } if (person.LastNameIsNull || person.LastName.Trim().Equals(string.Empty)) { person.HasError = true; person.LastNameErrors += "Required." + Environment.NewLine; } BizRules(person, new BO.ORCID.Person()); DBRulesCG(person); return(!person.HasError); }
internal new bool Edit(BO.ORCID.Person person, System.Data.Common.DbTransaction trans) { return(base.Edit(person, trans)); }