/** * @param uuid String with the uuid of a person * @return Result containing the response from the cprBroker */ public ActionResult showPerson(String uuid) { String ipAddress = LoggingTools.GetVisitorIPAddress(); String hostName = LoggingTools.GetHostName(ipAddress); // Logging the show request cpreader.Logger.info(String.Format("At <{0}> user <{1}> requested to see uuid <{2}>. Host name: <{3}> at local IP address <{4}>.", DateTime.Now, User.Identity.Name, uuid, hostName, ipAddress )); IPerson person = null; try { person = cprBroker.read(uuid); // Logging the show request cpreader.Logger.info(String.Format("{0}'s request to CPRBroker responded, {1} - {2}.", User.Identity.Name, person.code(), person.message() )); } catch (Exception ex) { cpreader.Logger.error(ex); } SearchInput searchInput = new SearchInput(); searchInput.saveToSession(this); //searchInput.fillFromSession(this); // access level - add to person model if (person == null) { return(View("show_error", new Tuple <int, SearchInput>(503, searchInput))); } if (person.code() == 200) { List <IPerson> persons = new List <IPerson>(); persons.Add(person); String path = Request.Path; int page = 1; int accessLevel = AccessLevelManager.getCurrentAccessLevel(); return(View("list", new list_viewModel( persons, 1, page, path, searchInput, accessLevel))); } else { //TODO - A person wasn't found return(View("show_error", new Tuple <int, SearchInput>(person.code(), searchInput))); } }
public ActionResult getUuidFromCpr(string query) { //query = System.Web.HttpContext.Current.Request["query"], // Search is now by CPR, clear the saved name (if any) SearchInput searchInput = new SearchInput(); searchInput.fillFromSession(this); searchInput.setQuery(""); searchInput.saveToSession(this); String ipAddress = LoggingTools.GetVisitorIPAddress(); String hostName = LoggingTools.GetHostName(ipAddress); // Logging the search cpreader.Logger.info(String.Format("<{0}> searched for: <{1}> from host name: <{2}> at local IP address <{3}>.", User.Identity.Name, query, hostName, ipAddress )); // Check if there is errors (empty strings) // TODO: Check the ASP.NET euivalent /*if (searchForm.hasErrors()) * { * return badRequest("Form had errors"); * }*/ // Input type == cprnumber IUuid uuid = cprBroker.getUuid(query); // logging the returned resultcode cpreader.Logger.info(User.Identity.Name + "'s search request to CPRBroker responded, " + uuid.code() + " - " + uuid.message()); if (uuid.code() == 200) { String uuidStr = uuid.value(); return(Content(uuidStr)); } else { // this should never happen as person master will just assign // a new uuid if it doesn't exist cpreader.Logger.info(String.Format("CPR number <{0}> not found.", query)); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "CPR not found in local")); } }
public ActionResult searchNameAndAddress(String name, String address, bool online, int page) { List <IPerson> persons = null; try { String ipAddress = LoggingTools.GetVisitorIPAddress(); String hostName = LoggingTools.GetHostName(ipAddress); // log what page the user requested cpreader.Logger.info(String.Format("At <{0}> user <{1}> searched for name<{2}>, address<{3}>; online <{4}>, page <{5}>. Host name: <{6}> at local IP address <{7}>.", DateTime.Now, User.Identity.Name, name, address, online, page, hostName, ipAddress )); String key = String.Format("session={0};name={1};address={2}", getSessionId(), name, address); // TODO: See if there is a cahce equivalent in ASP.NET /*if (online && onlineCacheEnabled) * { * Object o = Cache.get(key); * if (o != null) * persons = (List<IPerson>)o; * }*/ if (persons == null) { persons = cprBroker.searchList( name, address, online ? ESourceUsageOrder.ExternalOnly : ESourceUsageOrder.LocalOnly, -1, -1); } // TODO: See if there is a cahce equivalent in ASP.NET /* * if (online && onlineCacheEnabled) * { * // Temporarily store the results for a while * Cache.set(key, persons, onlineCacheTimeout); * }*/ } catch (Exception ex) { cpreader.Logger.error(ex); } String path = Request.Path; path = path.Substring(0, path.IndexOf("page") + 5); SearchInput searchInput = new SearchInput(name, address, online); searchInput.saveToSession(this); int accessLevel = AccessLevelManager.getCurrentAccessLevel(); if (persons != null) { // calculate the searchIndex, which is the starting point of the search int fromIndex = ((page - 1) * 10); int toIndex = ((page) * 10); if (persons.Count < fromIndex) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (persons.Count < toIndex) { toIndex = persons.Count; } List <IPerson> subPersons = persons.Take(toIndex).Skip(fromIndex).ToList(); return(View("list", new list_viewModel(subPersons, persons.Count, page, path, searchInput, accessLevel))); } else { return(View("list", new list_viewModel(persons, 1, page, path, searchInput, accessLevel))); } }