Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        /*
         * 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);
                }
            }
        }
Ejemplo n.º 3
0
        private static void TestListAndReadOUs()
        {
            // small hack to ensure this test passes (the search parameters will find all ous in the organisation, and we need to test that it hits the required amount)
            OrganisationRegistryProperties properties = OrganisationRegistryProperties.GetInstance();
            string oldUuid = properties.MunicipalityOrganisationUUID[OrganisationRegistryProperties.GetCurrentMunicipality()];

            properties.MunicipalityOrganisationUUID[OrganisationRegistryProperties.GetCurrentMunicipality()] = Uuid();

            OrgUnitRegistration registration1 = OUReg();

            registration1.Name              = "magic";
            registration1.Email             = "*****@*****.**";
            registration1.ParentOrgUnitUuid = Uuid();
            orgUnitService.Update(registration1);

            orgUnitService.Read(registration1.Uuid);

            OrgUnitRegistration registration2 = OUReg();

            registration2.Name              = "magic";
            registration2.Email             = "*****@*****.**";
            registration2.ParentOrgUnitUuid = Uuid();
            orgUnitService.Update(registration2);

            registration2.Name = "different name";
            orgUnitService.Update(registration2);

            // TODO: a KMD bug prevents this test from working...
            OrgUnitRegistration registration3 = OUReg();

            registration3.Name              = "ou3";
            registration3.Email             = "*****@*****.**";
            registration3.ParentOrgUnitUuid = Uuid();
            orgUnitService.Update(registration3);
            orgUnitService.Delete(registration3.Uuid, DateTime.Now);

            List <string> ous = orgUnitService.List();

            if (ous.Count != 2)
            {
                throw new Exception("List() returned " + ous.Count + " ous, but 2 was expected");
            }

            foreach (var uuid in ous)
            {
                OrgUnitRegistration registration = orgUnitService.Read(uuid);

                if (uuid.Equals(registration1.Uuid))
                {
                    if (!registration1.Name.Equals(registration.Name))
                    {
                        throw new Exception("Name does not match");
                    }

                    if (!registration1.ParentOrgUnitUuid.Equals(registration.ParentOrgUnitUuid))
                    {
                        throw new Exception("ParentOU UUID does not match");
                    }

                    if (!registration1.Email.Equals(registration.Email))
                    {
                        throw new Exception("Email does not match");
                    }
                }
                else if (uuid.Equals(registration2.Uuid))
                {
                    if (!registration2.Name.Equals(registration.Name))
                    {
                        throw new Exception("Name does not match");
                    }

                    if (!registration2.ParentOrgUnitUuid.Equals(registration.ParentOrgUnitUuid))
                    {
                        throw new Exception("ParentOU UUID does not match");
                    }

                    if (!registration2.Email.Equals(registration.Email))
                    {
                        throw new Exception("Email does not match");
                    }
                }
                else
                {
                    throw new Exception("List returned the uuid of an unexpected ou");
                }
            }

            properties.MunicipalityOrganisationUUID[OrganisationRegistryProperties.GetCurrentMunicipality()] = oldUuid;
        }