private void PopulatePatronAddressInfoUsingExistingModel(SierraModel model) { if (_connection.State != ConnectionState.Open) { throw new SierraConnectionException("Status på koppling mot Sierra är inte \"open\", det är: \"" + _connection.State.ToString() + "\"."); } using (NpgsqlCommand newcommand = new NpgsqlCommand("SELECT patron_record_address_type_id, addr1, addr2, addr3, village, city, region, postal_code, country from sierra_view.patron_record_address where patron_record_id=:record_id order by patron_record_address_type_id", _connection)) { newcommand.Parameters.Add(new NpgsqlParameter("record_id", NpgsqlTypes.NpgsqlDbType.Bigint)); newcommand.Parameters[0].Value = model.id; model.adress = new List <SierraAddressModel>(); using (NpgsqlDataReader adr = newcommand.ExecuteReader()) { while (adr.Read()) { model.adress.Add(new SierraAddressModel() { addresscount = adr["patron_record_address_type_id"].ToString(), addr1 = adr["addr1"].ToString(), addr2 = adr["addr2"].ToString(), addr3 = adr["addr3"].ToString(), village = adr["village"].ToString(), city = adr["city"].ToString(), region = adr["region"].ToString(), postal_code = adr["postal_code"].ToString(), country = adr["country"].ToString() }); } } } }
public SierraModel GetPatronInfoFromLibraryCardNumber(string barcode) { SierraModel model = new SierraModel(); var runCount = 0; var success = false; while (runCount < 2 && !success) { runCount++; try { PopulateBasicPatronInfoFromLibraryCardNumber(barcode, model); PopulatePatronAddressInfoUsingExistingModel(model); success = true; } catch (Exception e) { _umbraco.LogError <Sierra>("Failed to get patron info from library card number " + barcode + " from Sierra.", e); // If we fail the first time we reconnect and try to fetch the information one more time. if (runCount < 2) { Disconnect(); Connect(); } } } return(model); }
public SierraModel GetPatronInfoFromSierraId(string sierraId) { SierraModel model = new SierraModel(); var runCount = 0; var success = false; while (runCount < 2 && !success) { runCount++; try { PopulateBasicPatronInfoFromSierraId(sierraId, model); success = true; } catch (Exception e) { _umbraco.LogError <Sierra>("Failed to get patron info using sierra identifier " + sierraId + " from Sierra.", e); // If we fail the first time we reconnect and try to fetch the information one more time. if (runCount < 2) { Disconnect(); Connect(); } } } return(model); }
private void PopulateBasicPatronInfoFromPersonnummer(string pnr, SierraModel model) { if (_connection.State != ConnectionState.Open) { throw new SierraConnectionException("Status på koppling mot Sierra är inte \"open\", det är: \"" + _connection.State.ToString() + "\"."); } using (NpgsqlCommand command = new NpgsqlCommand("SELECT pv.id, pv.barcode, pv.ptype_code, pv.record_num, vv.field_content as email, first_name, last_name, home_library_code, mblock_code from sierra_view.patron_record_fullname fn, sierra_view.patron_view pv, sierra_view.varfield_view vv where pv.id=fn.patron_record_id and pv.id=vv.record_id and vv.varfield_type_code='z' and pv.id=(select record_id from sierra_view.varfield_view vs where lower(vs.field_content)=:barcode)", _connection)) { command.Parameters.Add(new NpgsqlParameter("barcode", NpgsqlTypes.NpgsqlDbType.Text)); command.Parameters[0].Value = pnr.ToLower(); using (NpgsqlDataReader dr = command.ExecuteReader()) { while (dr.Read()) { model.id = dr["id"].ToString(); model.barcode = dr["barcode"].ToString(); model.ptype = Convert.ToInt32(dr["ptype_code"]); model.email = dr["email"].ToString(); model.first_name = dr["first_name"].ToString(); model.last_name = dr["last_name"].ToString(); model.home_library = dr["home_library_code"].ToString(); model.home_library_pretty_name = _templateService.GetPrettyLibraryNameFromLibraryAbbreviation(model.home_library); model.mblock = dr["mblock_code"].ToString(); model.record_id = Convert.ToInt32(dr["record_num"].ToString()); } } } }
public void AddSierraDataToLog(int orderItemNodeId, SierraModel sm, string eventId, bool doReindex = true, bool doSignal = true) { if (!string.IsNullOrEmpty(sm.id)) { string logtext = "Firstname: " + sm.first_name + " Lastname: " + sm.last_name + "\n" + "Barcode: " + sm.barcode + " Email: " + sm.email + " Ptyp: " + sm.ptype + "\n"; AddLogItem(orderItemNodeId, "SIERRA", logtext, eventId, doReindex, doSignal); } else { AddLogItem(orderItemNodeId, "SIERRA", "Låntagaren hittades inte.", eventId, doReindex, doSignal); } }
public SierraModel GetPatronInfoFromSierraId(string sierraId) { SierraModel res = new SierraModel(); var json = GetDataFromFolioWithRetries("/users?limit=1&query=" + Uri.EscapeDataString("id=" + sierraId)); if (json != null && json.users != null && json.users.Count == 1) { var mblockJson = GetDataFromFolioWithRetries("/manualblocks?query=userId=" + json.users[0].id); FillInSierraModelFromFolioData(json.users[0], mblockJson, res); } return(res); }
public SierraModel GetPatronInfoFromLibraryCardNumberOrPersonnummer(string barcode, string pnr) { SierraModel res = new SierraModel(); var json = GetDataFromFolioWithRetries("/users?limit=1&query=" + Uri.EscapeDataString("username="******" or barcode=" + barcode)); if (json != null && json.users != null && json.users.Count == 1) { var mblockJson = GetDataFromFolioWithRetries("/manualblocks?query=userId=" + json.users[0].id); FillInSierraModelFromFolioData(json.users[0], mblockJson, res); } return(res); }
public SierraModel GetPatronInfoFromLibraryCardNumberOrPersonnummer(string barcode, string pnr) { SierraModel model = new SierraModel(); var runCount = 0; var success = false; while (runCount < 2 && !success) { runCount++; try { PopulateBasicPatronInfoFromPersonnummer(barcode, model); if (String.IsNullOrEmpty(model.id)) { if (barcode.Contains("-")) { PopulateBasicPatronInfoFromPersonnummer(barcode.Replace("-", ""), model); } else { string pnrdash = barcode.Substring(0, 6) + "-" + barcode.Substring(6, 4); // Check if we have got a "personnummer" instead of a library card number? PopulateBasicPatronInfoFromPersonnummer(pnrdash, model); } } if (!String.IsNullOrEmpty(model.id)) { PopulatePatronAddressInfoUsingExistingModel(model); } success = true; } catch (Exception e) { _umbraco.LogError <Sierra>("Failed to get patron info from library card number or personnummer " + barcode + " from Sierra.", e); // If we fail the first time we reconnect and try to fetch the information one more time. if (runCount < 2) { Disconnect(); Connect(); } } } return(model); }
private void UpdateDeliveryLibraryIfNeeded(int nodeId, SierraModel sierraModel, string eventId) { var orderItem = _orderItemManager.GetOrderItem(nodeId); if (sierraModel.home_library != null && sierraModel.home_library.Contains("hbib")) { _orderItemManager.SetDeliveryLibrary(nodeId, "Huvudbiblioteket", eventId, false, false); } else if (sierraModel.home_library != null && sierraModel.home_library.Contains("abib")) { _orderItemManager.SetDeliveryLibrary(nodeId, "Arkitekturbiblioteket", eventId, false, false); } else if (sierraModel.home_library != null && sierraModel.home_library.Contains("lbib")) { _orderItemManager.SetDeliveryLibrary(nodeId, "Lindholmenbiblioteket", eventId, false, false); } }
private void FillInSierraModelFromSolrData(dynamic recordData, /* out */ SierraModel result) { var address1 = BuildSierraAddressModel(((string)recordData.address)); var address2 = BuildSierraAddressModel(((string)recordData.address2)); var address3 = BuildSierraAddressModel(((string)recordData.address3)); string patronName = recordData.pname; var patronNameParts = patronName.Split(','); string recordId = recordData.recordnum; if (address1 != null) { result.adress.Add(address1); } if (address2 != null) { result.adress.Add(address2); } if (address3 != null) { result.adress.Add(address3); } result.barcode = recordData.barcode; result.home_library = ((string)recordData.homelib).Trim(); result.home_library_pretty_name = _templateService.GetPrettyLibraryNameFromLibraryAbbreviation(result.home_library); result.id = "0"; result.email = recordData.email; if (patronNameParts.Length == 2) { result.first_name = patronNameParts[1].Trim(); result.last_name = patronNameParts[0].Trim(); } else { result.first_name = patronName; } result.mblock = recordData.mblock; result.ptype = recordData.ptype; result.record_id = Convert.ToInt32(recordId.Remove(recordId.Length - 1).Remove(0, 1)); result.aff = _affiliationDataProvider.GetAffiliationFromPersonNumber(recordData.pnum.ToString()); }
public IList <SierraModel> GetPatrons(string query) { var res = new List <SierraModel>(); query = "(personal.email=\"" + query + "*\" or barcode=\"" + query + "*\" or username=\"" + query + "*\" or personal.firstName=\"" + query + "*\" or personal.lastName=\"" + query + "*\")"; var json = GetDataFromFolioWithRetries("/users?query=" + Uri.EscapeDataString(query)); if (json != null && json.users != null) { foreach (var user in json.users) { var sierraModelForUser = new SierraModel(); FillInSierraModelFromFolioData(user, null, sierraModelForUser); res.Add(sierraModelForUser); } } return(res); }
public ActionResult FetchPatronDataUsingSierraId(int orderItemNodeId, string sierraId, bool cache = true) { var json = new ResultResponse(); try { var content = _orderItemManager.GetOrderItem(orderItemNodeId); var eventId = _orderItemManager.GenerateEventId(EVENT_TYPE); SierraModel sm = null; if (cache) { // Cache expects sierra identifier with starting 'p' and ending control number. sm = _patronDataProviderSierraCache.GetPatronInfoFromSierraId(sierraId); } else { // Non cache expects sierra identifier without starting 'p' and ending control number. sm = _patronDataProviderSierra.GetPatronInfoFromSierraId(sierraId); } if (!String.IsNullOrEmpty(sm.id)) { _orderItemManager.SetPatronData(content.NodeId, JsonConvert.SerializeObject(sm), sm.record_id, sm.ptype, sm.home_library, sm.aff); _orderItemManager.SaveWithoutEventsAndWithSynchronousReindexing(content.NodeId, false, false); } _orderItemManager.AddSierraDataToLog(orderItemNodeId, sm, eventId); json.Success = true; json.Message = "Succcessfully loaded Sierra data using sierra identifier."; } catch (Exception e) { json.Success = false; json.Message = "Failed to load Sierra data using sierra identifier: " + e.Message; } return(Json(json, JsonRequestBehavior.AllowGet)); }
public ActionResult FetchPatronDataUsingLcnOrPnr(int orderItemNodeId, string lcn, string pnr, bool cache = true) { var json = new ResultResponse(); try { var content = _orderItemManager.GetOrderItem(orderItemNodeId); var eventId = _orderItemManager.GenerateEventId(EVENT_TYPE); SierraModel sm = null; if (cache) { sm = _patronDataProviderSierraCache.GetPatronInfoFromLibraryCardNumberOrPersonnummer(lcn, pnr); } else { sm = _patronDataProviderSierra.GetPatronInfoFromLibraryCardNumberOrPersonnummer(lcn, pnr); } if (!String.IsNullOrEmpty(sm.id)) { _orderItemManager.SetPatronData(content.NodeId, JsonConvert.SerializeObject(sm), sm.record_id, sm.ptype, sm.home_library, sm.aff); _orderItemManager.SaveWithoutEventsAndWithSynchronousReindexing(content.NodeId, false, false); } _orderItemManager.AddSierraDataToLog(orderItemNodeId, sm, eventId); json.Success = true; json.Message = "Succcessfully loaded Sierra data from \"personnummer\" or library card number."; } catch (Exception e) { json.Success = false; json.Message = "Failed to load Sierra data from \"personnummer\" or library card number: " + e.Message; } return(Json(json, JsonRequestBehavior.AllowGet)); }
private void FillInSierraModelFromFolioData(dynamic recordData, dynamic mblockData, /* out */ SierraModel result) { result.barcode = recordData.barcode; result.id = recordData.id; if (recordData.personal != null) { result.email = recordData.personal.email; result.first_name = recordData.personal.firstName; result.last_name = recordData.personal.lastName; } result.mblock = mblockData != null?CalculateMblock(mblockData, recordData.id.ToString()) : ""; result.ptype = ConvertToSierraPtype(recordData.patronGroup.ToString()); result.expdate = recordData.expirationDate; result.pnum = recordData.username; result.aff = _affiliationDataProvider.GetAffiliationFromPersonNumber(Convert.ToString(recordData.username)); }