public static Result SaveParentOrganisations(OrganisationList OrganisationList) { Result results = new Result(); OrganisationRelationshipList organisationRelationships = OrganisationRelationshipList.GetOrganisationRelationshipList(); OrganisationList OrganisationToSaveList = OrganisationList.NewOrganisationList(); StringBuilder linkedOrganisations = new StringBuilder(); try { //only deal with organisations that have changes foreach (var organisation in OrganisationList.Where(c => c.IsDirty)) { //check if the organisation has been linked if (organisation.ParentInd == false && organisationRelationships.Any(c => c.OrganisationId_Parent == organisation.OrganisationID)) { //make a list of those organisations so that we may inform the user linkedOrganisations.AppendLine(organisation.OrganisationName + ";<br>"); } else { OrganisationToSaveList.Add(organisation); } } //only save the list when none of the modified organisations if (OrganisationToSaveList.IsValid) { OrganisationToSaveList.Save(); results.Success = true; if (linkedOrganisations.Length > 0) { results.Data = "The following organisations were not saved: " + linkedOrganisations + " as they are parents to other organisations."; } else { results.Data = "Parent Organisations setup was successful."; } } else { results.Success = false; results.ErrorText = OrganisationToSaveList.GetErrorsAsHTMLString(); return(results); } } catch (Exception ex) { results.Success = false; results.ErrorText = ex.Message; } return(results); }
public OrganisationListItemResponse( OrganisationList organisationList) { OvoNumber = organisationList.OvoNumber; Links = new List <Link> { new Link($"/organisations/{organisationList.OvoNumber}", Link.Relations.Organisation, WebRequestMethods.Http.Get), new Link($"/organisations/{organisationList.OvoNumber}/bankaccountnumbers", Link.Relations.BankAccountNumbers, WebRequestMethods.Http.Get) }; }
public void ReturnEmptyListIfNotExists() { OrganisationList list = new OrganisationList { new Organisation { Id = "1" } }; Assert.AreEqual(0, list.GetOrganisationAndDescendants("Foo").Count); }
static void Main(string[] args) { var directory = Directory.GetCurrentDirectory(); var model = new OrganisationList(); ImportFile(Path.Combine(directory, "ons"), DataSource.Ons, model); ImportFile(Path.Combine(directory, "nhs"), DataSource.Nhs, model); ImportFile(Path.Combine(directory, "police"), DataSource.Police, model); ExportFile(Path.Combine(directory, "output.json"), model); }
private static void ExportFile(string filename, OrganisationList model) { try { using (var fs = File.Open(filename, FileMode.Create)) using (var sw = new StreamWriter(fs)) using (JsonWriter jw = new JsonTextWriter(sw)) { jw.Formatting = Formatting.Indented; var serializer = new JsonSerializer(); serializer.Serialize(jw, model); } } catch (Exception ex) { Console.WriteLine($"An error occurred exporting data to {filename}: {ex.Message}"); return; } Console.WriteLine($"Exported {model.Organisations.Count} records"); }
public void TestGetHierarchyWithMultipleOrgsFromLower() { OrganisationList list = new OrganisationList { new Organisation { Id = "1", BaseOrganisation = true }, new Organisation { Id = "2", ParentOrganisationId = "1" }, new Organisation { Id = "3", ParentOrganisationId = "2" } }; Assert.AreEqual(2, list.GetOrganisationAndDescendants("2").Count); }
public void TestGetComplexHierarchy() { OrganisationList list = new OrganisationList { new Organisation { Id = "1", BaseOrganisation = true }, new Organisation { Id = "2", ParentOrganisationId = "1" }, new Organisation { Id = "3", ParentOrganisationId = "2" }, new Organisation { Id = "4", ParentOrganisationId = "1" }, new Organisation { Id = "5", ParentOrganisationId = "4" } }; Assert.AreEqual(5, list.GetOrganisationAndDescendants("1").Count); Assert.AreEqual(2, list.GetOrganisationAndDescendants("2").Count); Assert.AreEqual(1, list.GetOrganisationAndDescendants("3").Count); Assert.AreEqual(2, list.GetOrganisationAndDescendants("4").Count); Assert.AreEqual(1, list.GetOrganisationAndDescendants("5").Count); }
private static void ImportFile(string filename, DataSource source, OrganisationList model) { if (!File.Exists(filename)) { Console.WriteLine($"Unable to find {source} file at {filename}"); return; } string[] lines; try { lines = File.ReadAllLines(filename); } catch (Exception ex) { Console.WriteLine($"An error occurred importing {source} file at {filename}: {ex.Message}"); return; } foreach (var line in lines) { var splitLine = line.Split('|'); var organisation = new Organisation { Name = splitLine[0], Sector = splitLine.Length > 1 ? splitLine[1] : "", Source = source }; model.Organisations.Add(organisation); } Console.WriteLine($"Imported {lines.Length} {source} records from {filename}"); }
protected override void Setup() { base.Setup(); OrganisationList = OrganisationList.GetOrganisationList(); }
public void TestGetHierarchyWithSingleOrg() { OrganisationList list = new OrganisationList { new Organisation { Id = "1" } }; Assert.AreEqual(1, list.GetOrganisationAndDescendants("1").Count); }
public void TestGetHierarchyWithMultipleOrgsNoDescendents() { OrganisationList list = new OrganisationList { new Organisation { Id = "1" }, new Organisation { Id = "2" } }; Assert.AreEqual(1, list.GetOrganisationAndDescendants("1").Count); }
/// <summary> /// Imports the users. /// </summary> /// <param name="sessionData">The session data.</param> /// <param name="users">The list of users to import.</param> /// <param name="allRoles">A list of all roles in the system.</param> /// <param name="allOrganisations">A list of all organisations in the system.</param> /// <param name="systemRoleMap">A map of role ids, where the old id is the key and the new id is the value.</param> /// <param name="organisationMap">A map of organisation ids, where the old id is the key and the new id is the value.</param> /// <param name="validationResults">A list of validation results.</param> /// <param name="migrationResults">A list to which import results will be appended.</param> private void ImportUsers(SessionData sessionData, UserList users, RoleList allRoles, OrganisationList allOrganisations, Dictionary<string, string> systemRoleMap, Dictionary<string, string> organisationMap, MigrationDataResults validationResults, MigrationDataResults migrationResults) { foreach (User user in users) { if (!validationResults.GetNotificationsFor(user).CanImport) { migrationResults.AddNotification(user, MessageType.Information, string.Format(Messages.Import_UserSkipped, user.DisplayName)); continue; } foreach (KeyValuePair<string, string> kvp in systemRoleMap) { if (user.Roles.ContainsKey(kvp.Key)) { user.Roles.Remove(kvp.Key); user.Roles.Add(kvp.Value, allRoles[kvp.Value].RoleName); } } foreach (KeyValuePair<string, string> kvp in organisationMap) { if (user.Organisations.ContainsKey(kvp.Key)) { user.Organisations.Remove(kvp.Key); user.Organisations.Add(kvp.Value, allOrganisations[kvp.Value].Name); } } user.Id = null; User savedUser = this.securityGateway.SaveUser(sessionData, user); if (string.IsNullOrEmpty(user.ExternalId)) { migrationResults.AddNotification(savedUser, MessageType.Information, string.Format(Messages.Import_UserSuccess, savedUser.DisplayName)); } else { migrationResults.AddNotification(savedUser, MessageType.Information, string.Format(Messages.Import_UserSuccessNoPasswordChange, savedUser.DisplayName)); } } }
/// <summary> /// Imports the organisations. /// </summary> /// <param name="userId">The user making the request.</param> /// <param name="allOrganisations">All organisations.</param> /// <param name="organisations">The list of organisations to import.</param> /// <param name="validationResults">A list of validation results.</param> /// <param name="migrationResults">A list to which import results will be appended.</param> /// <returns> /// A map of organisation ids, where the old id is the key and the new id is the value. /// </returns> private Dictionary<string, string> ImportOrganisations(string userId, OrganisationList allOrganisations, List<MigrationOrganisation> organisations, MigrationDataResults validationResults, MigrationDataResults migrationResults) { Dictionary<string, string> organisationMap = new Dictionary<string, string>(); Organisation baseOrg = this.manager.GetBaseOrganisation(); foreach (MigrationOrganisation org in organisations) { if (!validationResults.GetNotificationsFor(org).CanImport) { migrationResults.AddNotification(org, MessageType.Information, string.Format(Messages.Import_OrganisationSkipped, org.Name)); continue; } string oldId = org.Id; org.Id = null; if (string.IsNullOrWhiteSpace(org.ParentOrganisationId) || org.BaseOrganisation) { organisationMap.Add(oldId, baseOrg.Id); migrationResults.AddNotification(org, MessageType.Information, string.Format(Messages.Import_BaseOrganisation, org.Name)); } else { Organisation parent = allOrganisations.FirstOrDefault(o => o.Name == org.ParentOrganisationName); Organisation thisOrg = allOrganisations.FirstOrDefault(o => o.Name == org.Name); if (parent != null) { org.ParentOrganisationId = parent.Id; } if (thisOrg != null) { organisationMap.Add(oldId, thisOrg.Id); migrationResults.AddNotification(org, MessageType.Information, string.Format(Messages.Import_OrganisationSkipped, org.Name)); } else { Organisation newOrg = this.manager.SaveOrganisation(org, userId); organisationMap.Add(oldId, newOrg.Id); allOrganisations.Add(newOrg); migrationResults.AddNotification(org, MessageType.Information, string.Format(Messages.Import_OrganisationSuccess, org.Name)); } } } return organisationMap; }