private static int HandleOU(OrgUnitRegistrationExtended ou, OrgUnitService service, OrgUnitDao dao) { try { OrganisationRegistryProperties.SetCurrentMunicipality(ou.Cvr); if (ou.Operation.Equals(OperationType.DELETE)) { service.Delete(ou.Uuid, ou.Timestamp); } else { service.Update(ou); } dao.OnSuccess(ou.Id); dao.Delete(ou.Id); return(0); } catch (TemporaryFailureException ex) { log.Warn("Could not handle ou '" + ou.Uuid + "' at the moment, will try later", ex); return(-1); } catch (Exception ex) { log.Error("Could not handle ou '" + ou.Uuid + "'", ex); dao.OnFailure(ou.Id, ex.Message); dao.Delete(ou.Id); return(-2); } }
public void AllChildOrgs_HaveNoLeader_ShouldReturn_ChildOrgs() { var orgUnitRepoMock = NSubstitute.Substitute.For <IGenericRepository <OrgUnit> >(); orgUnitRepoMock.AsQueryable().ReturnsForAnyArgs(new List <OrgUnit>() { new OrgUnit() { Id = 1, Level = 0, }, new OrgUnit() { Id = 2, Level = 1, ParentId = 1 }, new OrgUnit() { Id = 3, Level = 1, ParentId = 1 } }.AsQueryable()); var emplRepoMock = NSubstitute.Substitute.For <IGenericRepository <Employment> >(); emplRepoMock.AsQueryable().ReturnsForAnyArgs(new List <Employment>() { new Employment() { IsLeader = false, OrgUnitId = 3, }, new Employment() { IsLeader = false, OrgUnitId = 2 } }.AsQueryable()); _uut = new OrgUnitService(emplRepoMock, orgUnitRepoMock); var res = _uut.GetChildOrgsWithoutLeader(1); Assert.AreEqual(2, res.Count()); }
/* * public static long HandleItSystems() * { * ItSystemService service = new ItSystemService(); * ItSystemDao dao = new ItSystemDao(); * long count = 0; * * ItSystemRegistrationExtended itSystem = null; * while ((itSystem = dao.GetOldestEntry()) != null) * { * try * { * if (itSystem.Operation.Equals(OperationType.DELETE)) * { * service.Delete(itSystem.Uuid, itSystem.Timestamp); * } * else * { * service.Update(itSystem); * } * * count++; * * dao.Delete(itSystem.Uuid); * } * catch (TemporaryFailureException ex) * { * log.Error("Could not handle ItSystem '" + itSystem.Uuid + "' at the moment, will try later", ex); * break; * } * catch (Exception ex) * { * log.Error("Could not handle ItSystem '" + itSystem.Uuid + "'", ex); * dao.Delete(itSystem.Uuid); * } * } * * return count; * } */ public static void HandleOUs(out long count) { OrgUnitService service = new OrgUnitService(); OrgUnitDao dao = new OrgUnitDao(); count = 0; OrgUnitRegistrationExtended ou = null; while ((ou = dao.GetOldestEntry()) != null) { try { if (ou.Operation.Equals(OperationType.DELETE)) { service.Delete(ou.Uuid, ou.Timestamp); } else { service.Update(ou); } count++; dao.Delete(ou.Id); errorCount = 0; } catch (TemporaryFailureException ex) { log.Error("Could not handle ou '" + ou.Uuid + "' at the moment, will try later"); throw ex; } catch (Exception ex) { log.Error("Could not handle ou '" + ou.Uuid + "'", ex); dao.Delete(ou.Id); } } }
private static void testReadOU(RestClient client, string uuid) { OrgUnitRegistration ou = new OrgUnitRegistration(); ou.Uuid = uuid; ou.Name = "testOU"; ou.ParentOrgUnitUuid = GetFreshUuid(); ou.Email.Value = "*****@*****.**"; // store directly, then use service to read OrgUnitService orgUnitService = new OrgUnitService(); orgUnitService.Update(ou); var request = new RestRequest("/api/v1_1/orgunit?uuid=" + uuid); request.Method = Method.GET; var response = client.Execute <OrgUnitRegistration>(request); OrgUnitRegistration responseRegistration = response.Data; if (!ou.Email.Value.Equals(responseRegistration.Email.Value)) { throw new Exception("Email mismatch"); } if (!ou.Name.Equals(responseRegistration.Name)) { throw new Exception("Name mismatch"); } if (!ou.ParentOrgUnitUuid.Equals(responseRegistration.ParentOrgUnitUuid)) { throw new Exception("Parent.UUID mismatch"); } }
public OrgUnitController() { orgUnitDao = new OrgUnitDao(); orgUnitService = new OrgUnitService(); }
public void SevenNestedOrgs_LeaderOnLevel4_ShouldReturn_3() { var orgUnitRepoMock = NSubstitute.Substitute.For <IGenericRepository <OrgUnit> >(); orgUnitRepoMock.AsQueryable().ReturnsForAnyArgs(new List <OrgUnit>() { new OrgUnit() { Id = 1, Level = 0, }, new OrgUnit() { Id = 2, Level = 1, ParentId = 1 }, new OrgUnit() { Id = 3, Level = 2, ParentId = 2 }, new OrgUnit() { Id = 4, Level = 3, ParentId = 3 }, new OrgUnit() { Id = 5, Level = 4, ParentId = 4 }, new OrgUnit() { Id = 6, Level = 5, ParentId = 5 }, new OrgUnit() { Id = 7, Level = 6, ParentId = 6 } }.AsQueryable()); var emplRepoMock = NSubstitute.Substitute.For <IGenericRepository <Employment> >(); emplRepoMock.AsQueryable().ReturnsForAnyArgs(new List <Employment>() { new Employment() { IsLeader = false, OrgUnitId = 2, }, new Employment() { IsLeader = false, OrgUnitId = 3 }, new Employment() { IsLeader = false, OrgUnitId = 4 }, new Employment() { IsLeader = true, OrgUnitId = 5 }, new Employment() { IsLeader = false, OrgUnitId = 6 }, new Employment() { IsLeader = false, OrgUnitId = 7 } }.AsQueryable()); _uut = new OrgUnitService(emplRepoMock, orgUnitRepoMock); var res = _uut.GetChildOrgsWithoutLeader(1); Assert.AreEqual(3, res.Count()); }
public static void HandleOUs(out long count) { OrgUnitService service = new OrgUnitService(); OrgUnitDao dao = new OrgUnitDao(); count = 0; var orgUnits = dao.Get4OldestEntries(); do { if (orgUnits.Count > 0) { int subCounter = 0; Parallel.ForEach(orgUnits, (orgUnit) => { using (var cancelTokenSource = new CancellationTokenSource()) { var cancelToken = cancelTokenSource.Token; var task = Task.Run(() => HandleOU(orgUnit, service, dao), cancelToken); if (task.Wait(TimeSpan.FromSeconds(300))) { int result = task.Result; switch (result) { case -1: // we are not increment subcounter here, as this is a temporary failure, and we should sleep break; case -2: // bad data, it was logged and then throw away, nothing to see here, move along lock (orgUnits) { subCounter++; } break; default: lock (orgUnits) { subCounter++; } errorCount = 0; break; } } else { log.Warn("Timeout happended while waiting for synchronization of OrgUnit: " + orgUnit.Uuid); cancelTokenSource.Cancel(); } } }); count += subCounter; if (subCounter != orgUnits.Count) { throw new TemporaryFailureException(); } orgUnits = dao.Get4OldestEntries(); } } while (orgUnits.Count > 0); }
public OrgUnitV11Controller() { messages = new ServiceMessages(); orgUnitDao = new OrgUnitDao(); orgUnitService = new OrgUnitService(); }
public void SevenNestedOrgs_OnlyLeaderOnLevel0_ShouldReturn_All() { var orgUnitRepoMock = NSubstitute.Substitute.For <IGenericRepository <OrgUnit> >(); orgUnitRepoMock.AsQueryable().ReturnsForAnyArgs(new List <OrgUnit>() { new OrgUnit() { Id = 1, Level = 0, }, new OrgUnit() { Id = 2, Level = 1, ParentId = 1 }, new OrgUnit() { Id = 3, Level = 2, ParentId = 2 }, new OrgUnit() { Id = 4, Level = 3, ParentId = 3 }, new OrgUnit() { Id = 5, Level = 4, ParentId = 4 }, new OrgUnit() { Id = 6, Level = 5, ParentId = 5 }, new OrgUnit() { Id = 7, Level = 6, ParentId = 6 } }.AsQueryable()); var emplRepoMock = NSubstitute.Substitute.For <IGenericRepository <Employment> >(); emplRepoMock.AsQueryable().ReturnsForAnyArgs(new List <Employment>() { new Employment() { IsLeader = true, OrgUnitId = 1, PersonId = 1, }, new Employment() { IsLeader = false, OrgUnitId = 2, PersonId = 20, }, new Employment() { IsLeader = false, OrgUnitId = 3, PersonId = 2, }, new Employment() { IsLeader = false, OrgUnitId = 4, PersonId = 3, }, new Employment() { IsLeader = false, OrgUnitId = 5, PersonId = 4, }, new Employment() { IsLeader = false, OrgUnitId = 6, PersonId = 5, }, new Employment() { IsLeader = false, OrgUnitId = 7, PersonId = 6, } }.AsQueryable()); _uut = new OrgUnitService(emplRepoMock, orgUnitRepoMock); var res = _uut.GetWhereUserIsResponsible(1); Assert.AreEqual(7, res.Count()); }