Beispiel #1
0
        private static void testWriteReadOUThroughDB()
        {
            OrgUnitDao dao = new OrgUnitDao();

            OrgUnitRegistration registration = new OrgUnitRegistration();

            registration.Name = "Navn";
            registration.Uuid = GetFreshUuid();
            registration.ContactPlaces.Add(new BusinessLayer.DTO.V1_1.ContactPlace()
            {
                OrgUnitUuid = GetFreshUuid(),
                Tasks       = new List <string>()
                {
                    GetFreshUuid(), GetFreshUuid(), GetFreshUuid()
                }
            });
            registration.ContactPlaces.Add(new BusinessLayer.DTO.V1_1.ContactPlace()
            {
                OrgUnitUuid = GetFreshUuid(),
                Tasks       = new List <string>()
                {
                    GetFreshUuid(), GetFreshUuid()
                }
            });

            // save OU with 2 ContactPlaces with 2 and 3 Tasks associated
            dao.Save(registration, OperationType.UPDATE);

            // read and see that we get the expected back
            OrgUnitRegistrationExtended fromDaoRegistration = dao.GetOldestEntry();
        }
Beispiel #2
0
        public IActionResult Update([FromBody] OrgUnitRegistration ou, [FromHeader] string cvr, [FromHeader] string apiKey)
        {
            if ((cvr = AuthorizeAndFetchCvr(cvr, apiKey)) == null)
            {
                return(Unauthorized());
            }

            // setting it will revert to default if no value is supplied, so we can read a valid value afterwards
            OrganisationRegistryProperties.SetCurrentMunicipality(cvr);
            cvr = OrganisationRegistryProperties.GetCurrentMunicipality();

            string error;

            if ((error = ValidateOU(ou)) == null)
            {
                try
                {
                    orgUnitDao.Save(ou, OperationType.UPDATE, cvr);
                }
                catch (Exception ex)
                {
                    log.Error("Failed to save OrgUnit", ex);

                    return(BadRequest(ex.Message));
                }
            }
            else
            {
                return(BadRequest(error));
            }

            return(Ok(ou));
        }
Beispiel #3
0
        private OrgUnitData MapRegistrationToOrgUnitDTO(OrgUnitRegistration registration, List <AddressRelation> addressRefs)
        {
            OrgUnitData organisationEnhed = new OrgUnitData();

            organisationEnhed.ShortKey          = registration.ShortKey;
            organisationEnhed.Name              = registration.Name;
            organisationEnhed.Addresses         = addressRefs;
            organisationEnhed.Timestamp         = registration.Timestamp;
            organisationEnhed.Uuid              = registration.Uuid;
            organisationEnhed.ParentOrgUnitUuid = registration.ParentOrgUnitUuid;
            organisationEnhed.Tasks             = registration.Tasks;

            switch (registration.Type)
            {
            case OrgUnitType.DEPARTMENT:
                organisationEnhed.OrgUnitType = UUIDConstants.ORGUNIT_TYPE_DEPARTMENT;
                break;

            case OrgUnitType.TEAM:
                organisationEnhed.OrgUnitType = UUIDConstants.ORGUNIT_TYPE_TEAM;
                break;

            default:
                throw new Exception("Unknown type: " + registration.Type);
            }

            return(organisationEnhed);
        }
Beispiel #4
0
        public IActionResult Read(string uuid, [FromHeader] string cvr, [FromHeader] string apiKey)
        {
            if (AuthorizeAndFetchCvr(cvr, apiKey) == null)
            {
                return(Unauthorized());
            }

            if (string.IsNullOrEmpty(uuid))
            {
                return(BadRequest("uuid is null"));
            }

            try
            {
                OrgUnitRegistration registration = orgUnitService.Read(uuid);
                if (registration != null)
                {
                    return(Ok(registration));
                }
            }
            catch (RegistrationNotFoundException)
            {
                return(NotFound());
            }
            catch (Exception ex)
            {
                log.Error("Failed to read OrgUnit", ex);

                return(BadRequest(ex.Message));
            }

            return(NotFound());
        }
Beispiel #5
0
        private bool ValidateOU(OrgUnitRegistration ou)
        {
            if (String.IsNullOrEmpty(ou.Name) || String.IsNullOrEmpty(ou.Uuid))
            {
                return(false);
            }

            return(true);
        }
Beispiel #6
0
        private static OrgUnitRegistration OUReg()
        {
            OrgUnitRegistration registration = new OrgUnitRegistration();

            registration.Uuid = Uuid();
            registration.Name = "Default OU Name";

            return(registration);
        }
Beispiel #7
0
        private static void TestCreateAndUpdateFullUser()
        {
            // create parent OUs
            OrgUnitRegistration parentReg = OUReg();

            orgUnitService.Update(parentReg);

            OrgUnitRegistration parentReg2 = OUReg();

            orgUnitService.Update(parentReg2);

            OrgUnitRegistration parentReg3 = OUReg();

            orgUnitService.Update(parentReg3);

            UserRegistration registration = UserReg();

            registration.Email       = "EmailValue";
            registration.Location    = "LocationValue";
            registration.Person.Cpr  = "0000000000";
            registration.Person.Name = "PersonNameValue";
            registration.PhoneNumber = "PhoneValue";
            Position position = new Position();

            registration.Positions.Add(position);
            position.Name        = "PositionNameValue";
            position.OrgUnitUuid = parentReg.Uuid;

            Position position2 = new Position();

            registration.Positions.Add(position2);
            position2.Name        = "PositionNameValue3";
            position2.OrgUnitUuid = parentReg3.Uuid;

            registration.UserId = "UserIdValue";
            userService.Update(registration);

            var user = inspectorService.ReadUserObject(registration.Uuid);

            ValidateUser(user, registration);

            registration.Email       = "EmailValue2";
            registration.Location    = "LocationValue2";
            registration.Person.Cpr  = "0000000001";
            registration.Person.Name = "PersonNameValue2";
            registration.PhoneNumber = "PhoneValue2";
            position = new Position();
            registration.Positions.Clear();
            registration.Positions.Add(position);
            position.Name        = "PositionNameValue2";
            position.OrgUnitUuid = parentReg2.Uuid;
            registration.UserId  = "UserIdValue2";
            userService.Update(registration);

            user = inspectorService.ReadUserObject(registration.Uuid);
            ValidateUser(user, registration);
        }
Beispiel #8
0
        /// <summary>
        /// This method will check whether the OrgUnit already exists inside Organisation, read it if it does, and perform
        /// the correct update (registering the delta-changes between the local object and the org-object). If the object
        /// does not already exist, it will pass the registration to the Create method.
        /// </summary>
        public void Update(OrgUnitRegistration registration)
        {
            log.Debug("Performing Update on OrgUnit '" + registration.Uuid + "'");

            ValidateAndEnforceCasing(registration);

            try
            {
                var result = organisationEnhedStub.GetLatestRegistration(registration.Uuid);
                if (result == null)
                {
                    log.Debug("Update on OrgUnit '" + registration.Uuid + "' changed to a Create because it does not exists as an active object within Organisation");
                    Create(registration);
                }
                else
                {
                    var addressRefs = UpdateAddresses(registration, result);

                    // this must happen after addresses have been imported, as it might result in UUID's being created
                    OrgUnitData orgUnitData = MapRegistrationToOrgUnitDTO(registration, addressRefs);

                    #region Update payout units
                    // if this unit handles payouts on behalf of a payout unit, create a reference to that payout unit
                    if (!string.IsNullOrEmpty(registration.PayoutUnitUuid))
                    {
                        string payoutUnitFunctionUuid = ServiceHelper.EnsurePayoutUnitFunctionExists(registration.PayoutUnitUuid, registration.Timestamp);

                        orgUnitData.OrgFunctionUuids.Add(payoutUnitFunctionUuid);
                    }
                    #endregion

                    ServiceHelper.UpdateManager(registration);

                    organisationEnhedStub.Ret(orgUnitData);

                    // ensure "henvendelsessted" tasks are updated
                    if (!OrganisationRegistryProperties.GetInstance().DisableHenvendelsessteder)
                    {
                        ServiceHelper.UpdateContactForTasks(registration.Uuid, registration.ContactForTasks, registration.Timestamp);
                    }

                    UpdateOrganisationObject(orgUnitData);

                    log.Debug("Update successful on OrgUnit '" + registration.Uuid + "'");
                }
            }
            catch (Exception ex) when(ex is STSNotFoundException || ex is ServiceNotFoundException)
            {
                log.Warn("Update on OrgUnitService failed for '" + registration.Uuid + "' due to unavailable KOMBIT services", ex);
                throw new TemporaryFailureException(ex.Message);
            }
        }
Beispiel #9
0
        private static void TestCreateAndUpdateFullOU()
        {
            // create parent OUs
            OrgUnitRegistration parentReg = OUReg();

            orgUnitService.Update(parentReg);

            OrgUnitRegistration parentReg2 = OUReg();

            orgUnitService.Update(parentReg2);

            OrgUnitRegistration registration = OUReg();

            registration.Name = "Some Random OU Name";
            registration.ParentOrgUnitUuid = parentReg.Uuid;
            registration.ContactOpenHours  = "ContactOpenHoursValue";
            registration.Ean            = "EanValue";
            registration.Email          = "EmailValue";
            registration.EmailRemarks   = "EmailRemark";
            registration.Contact        = "Contact";
            registration.PostReturn     = "PostReturn";
            registration.Location       = "LocationValue";
            registration.LOSShortName   = "LOSShortNameValue";
            registration.PayoutUnitUuid = parentReg.Uuid;
            registration.PhoneNumber    = "PhoneValue";
            registration.PhoneOpenHours = "PhoneOpenHoursValue";
            registration.Post           = "PostValue";
            orgUnitService.Update(registration);

            var ou = inspectorService.ReadOUObject(registration.Uuid);

            ValidateOU(ou, registration);

            registration.Name = "Some Random OU Name 2";
            registration.ParentOrgUnitUuid = parentReg2.Uuid;
            registration.ContactOpenHours  = "ContactOpenHoursValue2";
            registration.Ean            = "EanValue2";
            registration.Email          = "EmailValue2";
            registration.EmailRemarks   = "EmailOpenHoursValue2";
            registration.Contact        = "ContactValue2";
            registration.PostReturn     = "PostReturnValue2";
            registration.Location       = "LocationValue2";
            registration.LOSShortName   = "LOSShortNameValue2";
            registration.PayoutUnitUuid = parentReg2.Uuid;
            registration.PhoneNumber    = "PhoneValue2";
            registration.PhoneOpenHours = "PhoneOpenHoursValue2";
            registration.Post           = "PostValue2";
            orgUnitService.Update(registration);

            ou = inspectorService.ReadOUObject(registration.Uuid);
            ValidateOU(ou, registration);
        }
Beispiel #10
0
        private string ValidateOU(OrgUnitRegistration ou)
        {
            if (string.IsNullOrEmpty(ou.Name))
            {
                return("name is null");
            }
            else if (string.IsNullOrEmpty(ou.Uuid))
            {
                return("uuid is null");
            }

            return(null);
        }
Beispiel #11
0
        private static void TestCreateDeleteUpdateOU()
        {
            OrgUnitRegistration registration = OUReg();

            registration.Timestamp = DateTime.Now.AddMinutes(-5);
            orgUnitService.Update(registration);

            orgUnitService.Delete(registration.Uuid, DateTime.Now.AddMinutes(-3));

            registration.Timestamp = DateTime.Now.AddMinutes(-1);
            orgUnitService.Update(registration);

            var ou = inspectorService.ReadOUObject(registration.Uuid);

            ValidateOU(ou, registration);
        }
Beispiel #12
0
        private static void TestUpdateWithoutChanges()
        {
            OrgUnitRegistration orgUnitRegistration = OUReg();

            orgUnitService.Update(orgUnitRegistration);
            orgUnitService.Update(orgUnitRegistration);

            UserRegistration userRegistration = UserReg();
            Position         position         = new Position();

            userRegistration.Positions.Add(position);
            position.Name        = "PositionNameValue";
            position.OrgUnitUuid = orgUnitRegistration.Uuid;

            userService.Update(userRegistration);
            userService.Update(userRegistration);
        }
Beispiel #13
0
        /// <summary>
        /// This method will create the object in Organisation - note that if the object already exists, this method
        /// will fail. If unsure whether the object exists, use Update() instead, as that will fallback to Create
        /// if the object does not exist.
        /// </summary>
        public void Create(OrgUnitRegistration registration)
        {
            log.Debug("Performing Create on OrgUnit '" + registration.Uuid + "'");

            ValidateAndEnforceCasing(registration);

            try
            {
                var addressRefs = ImportAddresses(registration);

                // mapping the unit must come after the addresses, as importing the address might set a UUID on the addresses if not supplied by the caller
                OrgUnitData orgUnitData = MapRegistrationToOrgUnitDTO(registration, addressRefs);

                // create manager relationship
                if (!string.IsNullOrEmpty(registration.ManagerUuid))
                {
                    ServiceHelper.UpdateManager(registration);
                }

                // if this unit is a working unit, that does payouts in behalf of a payout unit, create a reference to that payout unit
                if (!string.IsNullOrEmpty(registration.PayoutUnitUuid))
                {
                    string payoutUnitFunctionUuid = ServiceHelper.EnsurePayoutUnitFunctionExists(registration.PayoutUnitUuid, registration.Timestamp);

                    orgUnitData.OrgFunctionUuids.Add(payoutUnitFunctionUuid);
                }

                organisationEnhedStub.Importer(orgUnitData);

                UpdateOrganisationObject(orgUnitData);

                // ensure "henvendelsessted" tasks are created
                if (!OrganisationRegistryProperties.GetInstance().DisableHenvendelsessteder)
                {
                    ServiceHelper.UpdateContactForTasks(registration.Uuid, registration.ContactForTasks, registration.Timestamp);
                }

                log.Debug("Create successful on OrgUnit '" + registration.Uuid + "'");
            }
            catch (Exception ex) when(ex is STSNotFoundException || ex is ServiceNotFoundException)
            {
                log.Warn("Create on OrgUnitService failed for '" + registration.Uuid + "' due to unavailable KOMBIT services", ex);
                throw new TemporaryFailureException(ex.Message);
            }
        }
Beispiel #14
0
        public IHttpActionResult Update(OrgUnitRegistration ou)
        {
            bool isValid = ValidateOU(ou);

            if (isValid)
            {
                try
                {
                    orgUnitDao.Save(ou, OperationType.UPDATE);
                    return(Ok(ou));
                }
                catch (Exception ex)
                {
                    log.Error(messages.GetOuMessage(messages.UPDATE_FAILED), ex);
                }
            }

            return(BadRequest());
        }
Beispiel #15
0
        internal static string CreateContactPlace(OrgUnitRegistration orgUnit, DTO.V1_1.ContactPlace contactPlace)
        {
            string uuid = IdUtil.GenerateUuid();

            organisationFunktionStub.Importer(new OrgFunctionData()
            {
                Uuid             = uuid,
                Name             = "Henvendelsessted",
                FunctionTypeUuid = UUIDConstants.ORGFUN_CONTACT_UNIT,
                OrgUnits         = new List <string>()
                {
                    contactPlace.OrgUnitUuid
                },
                Tasks     = contactPlace.Tasks,
                Timestamp = orgUnit.Timestamp
            });

            return(uuid);
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            InitEnvironment();

            OrgUnitRegistration registration = OUReg();

            registration.Name = "Testenhed til Opgaver";
            registration.ParentOrgUnitUuid = Uuid();
            registration.Tasks             = new List <string>();
            registration.Tasks.Add("407a84c9-5347-4871-9842-fa7a5f8fe607");
            registration.Tasks.Add("dbb1b318-3c85-11e3-9b13-0050c2490048");
            registration.Tasks.Add("1b72daba-5e77-4512-a92e-5e4ca9950a35");
            orgUnitService.Update(registration);

            var ou = inspectorService.ReadOUObject(registration.Uuid);

            registration.Name = "Navneændring";
            orgUnitService.Update(registration);

            ou = inspectorService.ReadOUObject(registration.Uuid);

            /* ordinary tests
             * TestListAndReadOUs();
             * TestListAndReadUsers();
             * TestCreateAndUpdateFullUser();
             * TestCreateDeleteUpdateUser();
             * TestCreateDeleteUpdateOU();
             * TestCreateAndUpdateFullOU();
             * TestUpdateWithoutChanges();
             * TestPayoutUnits();
             * TestPositions();
             * //            TestContactPlaces();
             * TestUpdateAndSearch();
             * TestMultipleAddresses();
             */

            System.Environment.Exit(0);
        }
        public ProcessingResult InvokeOperation(ADEvent adEvent)
        {
            if (ObjectType.User.Equals(adEvent.AffectedObjectType))
            {
                UserRegistration user = EventMapper.MapUser(adEvent);

                UserDao.Save(user, EventMapper.Map(adEvent.OperationType), AppConfiguration.Cvr);
                log.Debug("User (" + user.Person.Name + ", " + user.Uuid + ") " + adEvent.OperationType);

                return((adEvent.OperationType == OperationType.Remove) ? ProcessingResult.USER_DELETE : ProcessingResult.USER_UPDATE);
            }
            else if (ObjectType.OU.Equals(adEvent.AffectedObjectType))
            {
                OrgUnitRegistration orgUnit = EventMapper.MapOU(adEvent);

                OrgUnitDao.Save(orgUnit, EventMapper.Map(adEvent.OperationType), AppConfiguration.Cvr);
                log.Debug("OrgUnit (" + orgUnit.Name + ", " + orgUnit.Uuid + ") " + adEvent.OperationType + ". Parent = '" + orgUnit.ParentOrgUnitUuid + "'");

                return((adEvent.OperationType == OperationType.Remove) ? ProcessingResult.OU_DELETE : ProcessingResult.OU_UPDATE);
            }

            return(ProcessingResult.FAILURE);
        }
Beispiel #18
0
        private static void TestCreateDeleteUpdateUser()
        {
            OrgUnitRegistration parentRegistration = OUReg();

            orgUnitService.Update(parentRegistration);

            UserRegistration registration = UserReg();
            Position         position     = new Position();

            registration.Positions.Add(position);
            position.Name        = "PositionNameValue";
            position.OrgUnitUuid = parentRegistration.Uuid;

            userService.Update(registration);
            userService.Delete(registration.Uuid, DateTime.Now.AddMinutes(-3));

            registration.Timestamp = DateTime.Now.AddMinutes(-1);
            userService.Update(registration);

            var user = inspectorService.ReadUserObject(registration.Uuid);

            ValidateUser(user, registration);
        }
Beispiel #19
0
        public IHttpActionResult Read(string uuid)
        {
            if (string.IsNullOrEmpty(uuid))
            {
                return(BadRequest());
            }

            try
            {
                OrgUnitRegistration registration = orgUnitService.Read(uuid);
                if (registration == null)
                {
                    return(NotFound());
                }

                return(Ok(registration));
            }
            catch (Exception ex)
            {
                log.Error(messages.GetOuMessage(messages.READ_FAILED), ex);

                return(InternalServerError());
            }
        }
Beispiel #20
0
        private void ValidateAndEnforceCasing(OrgUnitRegistration registration)
        {
            List <string> errors = new List <string>();

            if (string.IsNullOrEmpty(registration.Name))
            {
                errors.Add("name");
            }

            if (string.IsNullOrEmpty(registration.Uuid))
            {
                errors.Add("uuid");
            }

            if (registration.Timestamp == null)
            {
                errors.Add("timestamp");
            }

            if (errors.Count > 0)
            {
                throw new InvalidFieldsException("Invalid registration object - the following fields are invalid: " + string.Join(",", errors));
            }

            if (OrganisationRegistryProperties.GetInstance().DisableHenvendelsessteder)
            {
                registration.ContactForTasks = new List <string>();
            }

            if (OrganisationRegistryProperties.GetInstance().DisableUdbetalingsenheder)
            {
                registration.PayoutUnitUuid = null;
            }

            registration.Uuid = registration.Uuid.ToLower();
        }
Beispiel #21
0
        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");
            }
        }
Beispiel #22
0
        public OrgUnitRegistration Read(string uuid)
        {
            log.Debug("Performing Read on OrgUnit " + uuid);

            OrgUnitRegistration registration = null;

            var ou = inspectorService.ReadOUObject(uuid, ReadTasks.YES, ReadManager.YES, ReadAddresses.YES, ReadPayoutUnit.YES, ReadPositions.NO, ReadContactForTasks.YES);

            if (ou != null)
            {
                registration = new OrgUnitRegistration();

                registration.Name = ou.Name;
                registration.ParentOrgUnitUuid = ou.ParentOU?.Uuid;
                registration.PayoutUnitUuid    = ou.PayoutOU?.Uuid;
                registration.ShortKey          = ou.ShortKey;
                registration.Type            = ou.Type;
                registration.Uuid            = uuid;
                registration.ManagerUuid     = ou.Manager.Uuid;
                registration.Tasks           = ou.Tasks;
                registration.ContactForTasks = ou.ContactForTasks;

                foreach (var address in ou.Addresses)
                {
                    if (address is DTO.Read.Email)
                    {
                        registration.Email = address.Value;
                    }
                    else if (address is DTO.Read.Location)
                    {
                        registration.Location = address.Value;
                    }
                    else if (address is DTO.Read.Phone)
                    {
                        registration.PhoneNumber = address.Value;
                    }
                    else if (address is DTO.Read.LOSShortName)
                    {
                        registration.LOSShortName = address.Value;
                    }
                    else if (address is DTO.Read.LOSID)
                    {
                        registration.LOSId = address.Value;
                    }
                    else if (address is DTO.Read.PostReturn)
                    {
                        registration.PostReturn = address.Value;
                    }
                    else if (address is DTO.Read.Contact)
                    {
                        registration.Contact = address.Value;
                    }
                    else if (address is DTO.Read.EmailRemarks)
                    {
                        registration.EmailRemarks = address.Value;
                    }
                    else if (address is DTO.Read.PhoneHours)
                    {
                        registration.PhoneOpenHours = address.Value;
                    }
                    else if (address is DTO.Read.ContactHours)
                    {
                        registration.ContactOpenHours = address.Value;
                    }
                    else if (address is DTO.Read.DtrId)
                    {
                        registration.DtrId = address.Value;
                    }
                    else if (address is DTO.Read.Url)
                    {
                        registration.Url = address.Value;
                    }
                    else if (address is DTO.Read.Landline)
                    {
                        registration.Landline = address.Value;
                    }
                    else if (address is DTO.Read.Ean)
                    {
                        registration.Ean = address.Value;
                    }
                    else if (address is DTO.Read.Post)
                    {
                        registration.Post = address.Value;
                    }
                    else
                    {
                        log.Warn("Trying to Read OrgUnit " + uuid + " with unknown address type " + address.GetType().ToString());
                    }
                }

                registration.Timestamp = ou.Timestamp;

                log.Debug("Found OrgUnit " + uuid + " when reading");
            }
            else
            {
                log.Debug("Did not find OrgUnit " + uuid + " when reading");
            }

            return(registration);
        }
Beispiel #23
0
        /// <summary>
        /// This method will check whether the OrgUnit already exists inside Organisation, read it if it does, and perform
        /// the correct update (registering the delta-changes between the local object and the org-object). If the object
        /// does not already exist, it will pass the registration to the Create method.
        /// </summary>
        public void Update(OrgUnitRegistration registration)
        {
            log.Debug("Performing Update on OrgUnit '" + registration.Uuid + "'");

            ValidateAndEnforceCasing(registration);

            try
            {
                var result = organisationEnhedStub.GetLatestRegistration(registration.Uuid);
                if (result == null)
                {
                    log.Debug("Update on OrgUnit '" + registration.Uuid + "' changed to a Create because it does not exists as an active object within Organisation");
                    Create(registration);
                }
                else
                {
                    #region Update Addresses in Organisation if needed
                    // check what already exists in Organisation - and store the UUIDs of the existing addresses, we will need those later
                    string orgPhoneUuid = null, orgEmailUuid = null, orgLocationUuid = null, orgLOSShortNameUuid = null, orgEanUuid = null, orgContactHoursUuid = null, orgPhoneHoursUuid = null, orgPostUuid = null, orgPostReturnUuid = null, orgContactUuid = null, orgEmailRemarksUuid = null;
                    if (result.RelationListe.Adresser != null)
                    {
                        foreach (var orgAddress in result.RelationListe.Adresser)
                        {
                            if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_PHONE))
                            {
                                orgPhoneUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_EMAIL))
                            {
                                orgEmailUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_LOCATION))
                            {
                                orgLocationUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_LOSSHORTNAME))
                            {
                                orgLOSShortNameUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_EAN))
                            {
                                orgEanUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_PHONE_OPEN_HOURS))
                            {
                                orgPhoneHoursUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_POST))
                            {
                                orgPostUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_CONTACT_ADDRESS_OPEN_HOURS))
                            {
                                orgContactHoursUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_POST_RETURN))
                            {
                                orgPostReturnUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_CONTACT_ADDRESS))
                            {
                                orgContactUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_EMAIL_REMARKS))
                            {
                                orgEmailRemarksUuid = orgAddress.ReferenceID.Item;
                            }
                        }
                    }

                    // run through all the input addresses, and deal with them one by one
                    ServiceHelper.UpdateAddress(registration.Phone, orgPhoneUuid, registration.Timestamp);
                    ServiceHelper.UpdateAddress(registration.Email, orgEmailUuid, registration.Timestamp);
                    ServiceHelper.UpdateAddress(registration.Location, orgLocationUuid, registration.Timestamp);
                    ServiceHelper.UpdateAddress(registration.LOSShortName, orgLOSShortNameUuid, registration.Timestamp);
                    ServiceHelper.UpdateAddress(registration.Ean, orgEanUuid, registration.Timestamp);
                    ServiceHelper.UpdateAddress(registration.ContactOpenHours, orgContactHoursUuid, registration.Timestamp);
                    ServiceHelper.UpdateAddress(registration.EmailRemarks, orgEmailRemarksUuid, registration.Timestamp);
                    ServiceHelper.UpdateAddress(registration.PostReturn, orgPostReturnUuid, registration.Timestamp);
                    ServiceHelper.UpdateAddress(registration.Contact, orgContactUuid, registration.Timestamp);
                    ServiceHelper.UpdateAddress(registration.PhoneOpenHours, orgPhoneHoursUuid, registration.Timestamp);
                    ServiceHelper.UpdateAddress(registration.Post, orgPostUuid, registration.Timestamp);
                    #endregion

                    // this must happen after addresses have been imported, as it might result in UUID's being created
                    OrgUnitData orgUnitData = MapRegistrationToOrgUnitDTO(registration);

                    #region Update it-usage
                    List <string> itSystemsInOrg = ServiceHelper.FindItSystemsForOrgUnit(registration.Uuid);

                    // TODO, it is not stopping the old ones, but it is adding the new ones (hurray) - this is a bug in KMD read method, which needs to be fixed before this will work correctly
                    foreach (string itSystemUuid in ServiceHelper.GetItSystemsNoLongerInUse(itSystemsInOrg, registration.ItSystemUuids))
                    {
                        ServiceHelper.OrgUnitStopUsingItSystem(registration.Uuid, itSystemUuid, registration.Timestamp);
                    }

                    foreach (string itSystemUuid in ServiceHelper.GetItSystemsNewInUse(itSystemsInOrg, registration.ItSystemUuids))
                    {
                        ServiceHelper.OrgUnitStartUsingItSystem(registration.Uuid, itSystemUuid, registration.Timestamp);
                    }
                    #endregion

                    #region Update payout units
                    // if this unit handles payouts on behalf of a payout unit, create a reference to that payout unit
                    if (!string.IsNullOrEmpty(registration.PayoutUnitUuid))
                    {
                        string payoutUnitFunctionUuid = ServiceHelper.EnsurePayoutUnitFunctionExists(registration.PayoutUnitUuid, registration.Timestamp);

                        orgUnitData.OrgFunctionUuids.Add(payoutUnitFunctionUuid);
                    }
                    #endregion

                    #region Update ContactPlaces

                    /*
                     * 1. iterate over all existing functions
                     *    1a) read the function
                     *    1b) compare to local list of OU's
                     *        1ba) if match, compare KLE and update if needed (history, sigh) - save UUID of function for later use
                     *        1bb) if not match, do nothing for now (but add TODO, as we might want to delete it in a later update of the code)
                     *    1c) any local contact place not already existing is created, and UUID of function is stored for later use
                     *    1d) all UUIDs of functinos (created, skipped or updated (but not deleted)) are added to the update
                     *  2. the ret() method already performs the correct update
                     */
                    List <string> foundContactPlaces = new List <string>(); // use this for keeping track of already existing ContactPlaces

                    // compare all existing functions, to see which to update (and to grab the UUID of the functions)
                    if (result.RelationListe?.Opgaver != null)
                    {
                        foreach (var opgave in result.RelationListe.Opgaver)
                        {
                            string functionUuid = opgave.ReferenceID.Item;
                            string orgUnitUuid  = null;

                            // see if we can read the existing function
                            var orgContactPlace = organisationFunktionStub.GetLatestRegistration(functionUuid);
                            if (orgContactPlace == null)
                            {
                                log.Warn("OrgUnit " + registration.Uuid + " has a relation to a ContactPlaces function " + functionUuid + " that does not exist");
                                continue;
                            }

                            // figure out which OrgUnit this function points to
                            var tilknyttedeEnheder = orgContactPlace.RelationListe?.TilknyttedeEnheder;
                            if (tilknyttedeEnheder != null && tilknyttedeEnheder.Length == 1)
                            {
                                orgUnitUuid = tilknyttedeEnheder[0].ReferenceID?.Item;
                            }
                            if (orgUnitUuid == null)
                            {
                                log.Warn("OrgUnit " + registration.Uuid + " has a relation to a ContactPlaces function " + functionUuid + " that does not have a single OrgUnit reference");
                                continue;
                            }

                            // let us see if this is one of the locally supplied ContactPlaces (we might need to update the one stored in Org, and we need the UUID if it already exists)
                            if (registration.ContactPlaces != null)
                            {
                                foreach (DTO.V1_1.ContactPlace localContactPlace in registration.ContactPlaces)
                                {
                                    if (localContactPlace.OrgUnitUuid.Equals(orgUnitUuid))
                                    {
                                        ServiceHelper.UpdateContactPlace(functionUuid, localContactPlace.Tasks, registration.Timestamp);

                                        // store a reference, so this function is not deleted
                                        orgUnitData.OrgFunctionUuids.Add(functionUuid);

                                        // and flag it as found, so we do not create a new one
                                        foundContactPlaces.Add(localContactPlace.OrgUnitUuid);
                                    }
                                }
                            }
                        }
                    }

                    // create all *new* ContactPlaces
                    if (registration.ContactPlaces != null)
                    {
                        foreach (DTO.V1_1.ContactPlace contactPlace in registration.ContactPlaces)
                        {
                            if (!foundContactPlaces.Contains(contactPlace.OrgUnitUuid))
                            {
                                string contactPlaceUuid = ServiceHelper.CreateContactPlace(registration, contactPlace);

                                orgUnitData.OrgFunctionUuids.Add(contactPlaceUuid);
                            }
                        }
                    }
                    #endregion

                    organisationEnhedStub.Ret(orgUnitData);

                    UpdateOrganisationObject(orgUnitData);

                    log.Debug("Update successful on OrgUnit '" + registration.Uuid + "'");
                }
            }
            catch (Exception ex) when(ex is STSNotFoundException || ex is ServiceNotFoundException)
            {
                log.Warn("Update on OrgUnitService failed for '" + registration.Uuid + "' due to unavailable KOMBIT services", ex);
                throw new TemporaryFailureException(ex.Message);
            }
        }
Beispiel #24
0
        /// <summary>
        /// This method will create the object in Organisation - note that if the object already exists, this method
        /// will fail. If unsure whether the object exists, use Update() instead, as that will fallback to Create
        /// if the object does not exist.
        /// </summary>
        public void Create(OrgUnitRegistration registration)
        {
            log.Debug("Performing Create on OrgUnit '" + registration.Uuid + "'");

            ValidateAndEnforceCasing(registration);

            try
            {
                string uuid = null;

                // Import addresses
                ServiceHelper.ImportAddress(registration.Phone, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    registration.Phone.Uuid = uuid;
                }

                ServiceHelper.ImportAddress(registration.Email, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    registration.Email.Uuid = uuid;
                }

                ServiceHelper.ImportAddress(registration.Location, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    registration.Location.Uuid = uuid;
                }

                ServiceHelper.ImportAddress(registration.LOSShortName, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    registration.LOSShortName.Uuid = uuid;
                }

                ServiceHelper.ImportAddress(registration.EmailRemarks, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    registration.EmailRemarks.Uuid = uuid;
                }

                ServiceHelper.ImportAddress(registration.PostReturn, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    registration.PostReturn.Uuid = uuid;
                }

                ServiceHelper.ImportAddress(registration.Contact, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    registration.Contact.Uuid = uuid;
                }

                ServiceHelper.ImportAddress(registration.PhoneOpenHours, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    registration.PhoneOpenHours.Uuid = uuid;
                }

                ServiceHelper.ImportAddress(registration.ContactOpenHours, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    registration.ContactOpenHours.Uuid = uuid;
                }

                ServiceHelper.ImportAddress(registration.Ean, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    registration.Ean.Uuid = uuid;
                }

                ServiceHelper.ImportAddress(registration.Post, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    registration.Post.Uuid = uuid;
                }

                // mapping the unit must come after the addresses, as importing the address might set a UUID on the addresses if not supplied by the caller
                OrgUnitData orgUnitData = MapRegistrationToOrgUnitDTO(registration);

                // flag all it-systems that we use within this OU
                if (registration.ItSystemUuids != null)
                {
                    foreach (string itSystemUuid in registration.ItSystemUuids)
                    {
                        ServiceHelper.OrgUnitStartUsingItSystem(registration.Uuid, itSystemUuid, registration.Timestamp);
                    }
                }

                // create relations to all ContactPlaces
                if (registration.ContactPlaces != null)
                {
                    foreach (DTO.V1_1.ContactPlace contactPlace in registration.ContactPlaces)
                    {
                        string contactPlaceUuid = ServiceHelper.CreateContactPlace(registration, contactPlace);

                        orgUnitData.OrgFunctionUuids.Add(contactPlaceUuid);
                    }
                }

                // if this unit is a working unit, that does payouts in behalf of a payout unit, create a reference to that payout unit
                if (!string.IsNullOrEmpty(registration.PayoutUnitUuid))
                {
                    string payoutUnitFunctionUuid = ServiceHelper.EnsurePayoutUnitFunctionExists(registration.PayoutUnitUuid, registration.Timestamp);

                    orgUnitData.OrgFunctionUuids.Add(payoutUnitFunctionUuid);
                }

                organisationEnhedStub.Importer(orgUnitData);

                UpdateOrganisationObject(orgUnitData);

                log.Debug("Create successful on OrgUnit '" + registration.Uuid + "'");
            }
            catch (Exception ex) when(ex is STSNotFoundException || ex is ServiceNotFoundException)
            {
                log.Warn("Create on OrgUnitService failed for '" + registration.Uuid + "' due to unavailable KOMBIT services", ex);
                throw new TemporaryFailureException(ex.Message);
            }
        }
Beispiel #25
0
        private List <AddressRelation> ImportAddresses(OrgUnitRegistration registration)
        {
            var    addressRefs = new List <AddressRelation>();
            string uuid;

            if (!string.IsNullOrEmpty(registration.PhoneNumber))
            {
                ServiceHelper.ImportAddress(registration.PhoneNumber, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.PHONE
                    });
                }
            }


            if (!string.IsNullOrEmpty(registration.Email))
            {
                ServiceHelper.ImportAddress(registration.Email, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.EMAIL
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.Location))
            {
                ServiceHelper.ImportAddress(registration.Location, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.LOCATION
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.LOSShortName))
            {
                ServiceHelper.ImportAddress(registration.LOSShortName, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.LOSSHORTNAME
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.LOSId))
            {
                ServiceHelper.ImportAddress(registration.LOSId, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.LOSID
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.EmailRemarks))
            {
                ServiceHelper.ImportAddress(registration.EmailRemarks, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.EMAIL_REMARKS
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.PostReturn))
            {
                ServiceHelper.ImportAddress(registration.PostReturn, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.POST_RETURN
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.Contact))
            {
                ServiceHelper.ImportAddress(registration.Contact, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.CONTACT_ADDRESS
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.PhoneOpenHours))
            {
                ServiceHelper.ImportAddress(registration.PhoneOpenHours, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.PHONE_OPEN_HOURS
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.ContactOpenHours))
            {
                ServiceHelper.ImportAddress(registration.ContactOpenHours, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.CONTACT_ADDRESS_OPEN_HOURS
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.DtrId))
            {
                ServiceHelper.ImportAddress(registration.DtrId, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.DTR_ID
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.Ean))
            {
                ServiceHelper.ImportAddress(registration.Ean, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.EAN
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.Url))
            {
                ServiceHelper.ImportAddress(registration.Url, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.URL
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.Landline))
            {
                ServiceHelper.ImportAddress(registration.Landline, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.LANDLINE
                    });
                }
            }

            if (!string.IsNullOrEmpty(registration.Post))
            {
                ServiceHelper.ImportAddress(registration.Post, registration.Timestamp, out uuid);
                if (uuid != null)
                {
                    addressRefs.Add(new AddressRelation()
                    {
                        Uuid = uuid,
                        Type = AddressRelationType.POST
                    });
                }
            }

            return(addressRefs);
        }
Beispiel #26
0
        private List <AddressRelation> UpdateAddresses(OrgUnitRegistration registration, global::IntegrationLayer.OrganisationEnhed.RegistreringType1 result)
        {
            // check what already exists in Organisation - and store the UUIDs of the existing addresses, we will need those later
            string orgPhoneUuid = null, orgEmailUuid = null, orgLocationUuid = null, orgDtrIdUuid = null, orgLOSShortNameUuid = null, orgEanUuid = null, orgContactHoursUuid = null, orgPhoneHoursUuid = null, orgPostUuid = null, orgPostReturnUuid = null, orgContactUuid = null, orgEmailRemarksUuid = null, orgLandlineUuid = null, orgUrlUuid = null, orgLosIdUuid = null;

            if (result.RelationListe.Adresser != null)
            {
                foreach (var orgAddress in result.RelationListe.Adresser)
                {
                    if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_PHONE))
                    {
                        orgPhoneUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_EMAIL))
                    {
                        orgEmailUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_LOCATION))
                    {
                        orgLocationUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_LOSSHORTNAME))
                    {
                        orgLOSShortNameUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_LOSID))
                    {
                        orgLosIdUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_URL))
                    {
                        orgUrlUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_LANDLINE))
                    {
                        orgLandlineUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_EAN))
                    {
                        orgEanUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_PHONE_OPEN_HOURS))
                    {
                        orgPhoneHoursUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_POST))
                    {
                        orgPostUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_CONTACT_ADDRESS_OPEN_HOURS))
                    {
                        orgContactHoursUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_DTR_ID))
                    {
                        orgDtrIdUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_POST_RETURN))
                    {
                        orgPostReturnUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_CONTACT_ADDRESS))
                    {
                        orgContactUuid = orgAddress.ReferenceID.Item;
                    }
                    else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_ORGUNIT_EMAIL_REMARKS))
                    {
                        orgEmailRemarksUuid = orgAddress.ReferenceID.Item;
                    }
                }
            }

            // run through all the input addresses, and deal with them one by one
            List <AddressRelation> addressRefs = new List <AddressRelation>();
            string uuid;

            ServiceHelper.UpdateAddress(registration.PhoneNumber, orgPhoneUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.PHONE
                });
            }

            ServiceHelper.UpdateAddress(registration.Email, orgEmailUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.EMAIL
                });
            }

            ServiceHelper.UpdateAddress(registration.Location, orgLocationUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.LOCATION
                });
            }

            ServiceHelper.UpdateAddress(registration.DtrId, orgDtrIdUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.DTR_ID
                });
            }

            ServiceHelper.UpdateAddress(registration.LOSShortName, orgLOSShortNameUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.LOSSHORTNAME
                });
            }

            ServiceHelper.UpdateAddress(registration.Ean, orgEanUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.EAN
                });
            }

            ServiceHelper.UpdateAddress(registration.LOSId, orgLosIdUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.LOSID
                });
            }

            ServiceHelper.UpdateAddress(registration.Url, orgUrlUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.URL
                });
            }

            ServiceHelper.UpdateAddress(registration.Landline, orgLandlineUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.LANDLINE
                });
            }

            ServiceHelper.UpdateAddress(registration.ContactOpenHours, orgContactHoursUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.CONTACT_ADDRESS_OPEN_HOURS
                });
            }

            ServiceHelper.UpdateAddress(registration.EmailRemarks, orgEmailRemarksUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.EMAIL_REMARKS
                });
            }

            ServiceHelper.UpdateAddress(registration.PostReturn, orgPostReturnUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.POST_RETURN
                });
            }

            ServiceHelper.UpdateAddress(registration.Contact, orgContactUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.CONTACT_ADDRESS
                });
            }

            ServiceHelper.UpdateAddress(registration.PhoneOpenHours, orgPhoneHoursUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.PHONE_OPEN_HOURS
                });
            }

            ServiceHelper.UpdateAddress(registration.Post, orgPostUuid, registration.Timestamp, out uuid);
            if (uuid != null)
            {
                addressRefs.Add(new AddressRelation()
                {
                    Uuid = uuid,
                    Type = AddressRelationType.POST
                });
            }

            return(addressRefs);
        }
Beispiel #27
0
        public OrgUnitRegistration Read(string uuid)
        {
            log.Debug("Performing Read on OrgUnit " + uuid);

            OrgUnitRegistration registration = null;

            OU ou = inspectorService.ReadOUObject(uuid, ReadAddresses.YES, ReadPayoutUnit.YES, ReadPositions.NO, ReadItSystems.YES, ReadContactPlaces.YES);

            if (ou != null)
            {
                registration = new OrgUnitRegistration();

                registration.Name = ou.Name;
                registration.ParentOrgUnitUuid = ou.ParentOU?.Uuid;
                registration.PayoutUnitUuid    = ou.PayoutOU?.Uuid;
                registration.ShortKey          = ou.ShortKey;
                registration.Uuid = uuid;

                if (ou.ContactPlaces != null)
                {
                    foreach (var cp in ou.ContactPlaces)
                    {
                        registration.ContactPlaces.Add(new DTO.V1_1.ContactPlace()
                        {
                            OrgUnitUuid = cp.OrgUnit.Uuid,
                            Tasks       = cp.Tasks
                        });
                    }
                }
                foreach (var itSystem in ou.ItSystems)
                {
                    registration.ItSystemUuids.Add(itSystem);
                }

                foreach (var address in ou.Addresses)
                {
                    if (address is Email)
                    {
                        registration.Email.Uuid     = address.Uuid;
                        registration.Email.Value    = address.Value;
                        registration.Email.ShortKey = address.ShortKey;
                    }
                    else if (address is Location)
                    {
                        registration.Location.Uuid     = address.Uuid;
                        registration.Location.Value    = address.Value;
                        registration.Location.ShortKey = address.ShortKey;
                    }
                    else if (address is Phone)
                    {
                        registration.Phone.Uuid     = address.Uuid;
                        registration.Phone.Value    = address.Value;
                        registration.Phone.ShortKey = address.ShortKey;
                    }
                    else if (address is LOSShortName)
                    {
                        registration.LOSShortName.Uuid     = address.Uuid;
                        registration.LOSShortName.Value    = address.Value;
                        registration.LOSShortName.ShortKey = address.ShortKey;
                    }
                    else if (address is PostReturn)
                    {
                        registration.PostReturn.Uuid     = address.Uuid;
                        registration.PostReturn.Value    = address.Value;
                        registration.PostReturn.ShortKey = address.ShortKey;
                    }
                    else if (address is Contact)
                    {
                        registration.Contact.Uuid     = address.Uuid;
                        registration.Contact.Value    = address.Value;
                        registration.Contact.ShortKey = address.ShortKey;
                    }
                    else if (address is EmailRemarks)
                    {
                        registration.EmailRemarks.Uuid     = address.Uuid;
                        registration.EmailRemarks.Value    = address.Value;
                        registration.EmailRemarks.ShortKey = address.ShortKey;
                    }
                    else if (address is PhoneHours)
                    {
                        registration.PhoneOpenHours.Uuid     = address.Uuid;
                        registration.PhoneOpenHours.Value    = address.Value;
                        registration.PhoneOpenHours.ShortKey = address.ShortKey;
                    }
                    else if (address is ContactHours)
                    {
                        registration.ContactOpenHours.Uuid     = address.Uuid;
                        registration.ContactOpenHours.Value    = address.Value;
                        registration.ContactOpenHours.ShortKey = address.ShortKey;
                    }
                    else if (address is Ean)
                    {
                        registration.Ean.Uuid     = address.Uuid;
                        registration.Ean.Value    = address.Value;
                        registration.Ean.ShortKey = address.ShortKey;
                    }
                    else if (address is Post)
                    {
                        registration.Post.Uuid     = address.Uuid;
                        registration.Post.Value    = address.Value;
                        registration.Post.ShortKey = address.ShortKey;
                    }
                    else
                    {
                        log.Warn("Trying to Read OrgUnit " + uuid + " with unknown address type " + address.GetType().ToString());
                    }
                }

                registration.Timestamp = ou.Timestamp;

                log.Debug("Found OrgUnit " + uuid + " when reading");
            }
            else
            {
                log.Debug("Did not find OrgUnit " + uuid + " when reading");
            }

            return(registration);
        }
Beispiel #28
0
        public void Save(OrgUnitRegistration ou, OperationType operation)
        {
            long orgunit_id = 0;

            if (useSqlLite)
            {
                using (SQLiteConnection connection = new SQLiteConnection(connectionString))
                {
                    connection.Open();

                    using (SQLiteTransaction transaction = connection.BeginTransaction())
                    {
                        try
                        {
                            using (SQLiteCommand command = new SQLiteCommand(OrgUnitStatements.INSERT_SQLITE, connection))
                            {
                                command.Transaction = transaction;

                                command.Parameters.Add(new SQLiteParameter("@uuid", ou.Uuid));
                                command.Parameters.Add(new SQLiteParameter("@shortkey", ou.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@name", ou.Name ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@parent_ou_uuid", ou.ParentOrgUnitUuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@payout_ou_uuid", ou.PayoutUnitUuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@operation", operation.ToString()));

                                command.Parameters.Add(new SQLiteParameter("@los_shortname_uuid", ou.LOSShortName?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@los_shortname_shortkey", ou.LOSShortName?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@los_shortname_value", ou.LOSShortName?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SQLiteParameter("@phone_uuid", ou.Phone?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@phone_shortkey", ou.Phone?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@phone_value", ou.Phone?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SQLiteParameter("@email_uuid", ou.Email?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@email_shortkey", ou.Email?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@email_value", ou.Email?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SQLiteParameter("@location_uuid", ou.Location?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@location_shortkey", ou.Location?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@location_value", ou.Location?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SQLiteParameter("@ean_uuid", ou.Ean?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@ean_shortkey", ou.Ean?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@ean_value", ou.Ean?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SQLiteParameter("@contact_open_hours_uuid", ou.ContactOpenHours?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@contact_open_hours_shortkey", ou.ContactOpenHours?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@contact_open_hours_value", ou.ContactOpenHours?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SQLiteParameter("@email_remarks_uuid", ou.EmailRemarks?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@email_remarks_shortkey", ou.EmailRemarks?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@email_remarks_value", ou.EmailRemarks?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SQLiteParameter("@contact_uuid", ou.Contact?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@contact_shortkey", ou.Contact?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@contact_value", ou.Contact?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SQLiteParameter("@post_return_uuid", ou.PostReturn?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@post_return_shortkey", ou.PostReturn?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@post_return_value", ou.PostReturn?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SQLiteParameter("@phone_open_hours_uuid", ou.PhoneOpenHours?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@phone_open_hours_shortkey", ou.PhoneOpenHours?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@phone_open_hours_value", ou.PhoneOpenHours?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SQLiteParameter("@post_uuid", ou.Post?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@post_shortkey", ou.Post?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SQLiteParameter("@post_value", ou.Post?.Value ?? (object)DBNull.Value));

                                command.ExecuteNonQuery();

                                orgunit_id = connection.LastInsertRowId;
                            }

                            // insert itsystems
                            foreach (string itSystemUuid in ou.ItSystemUuids ?? Enumerable.Empty <string>())
                            {
                                using (SQLiteCommand command = new SQLiteCommand(OrgUnitStatements.INSERT_ITSYSTEMS, connection))
                                {
                                    command.Transaction = transaction;

                                    command.Parameters.Add(new SQLiteParameter("@orgunit_id", orgunit_id));
                                    command.Parameters.Add(new SQLiteParameter("@itsystem_uuid", itSystemUuid));

                                    command.ExecuteNonQuery();
                                }
                            }

                            // insert contact places
                            foreach (ContactPlace contactPlace in ou.ContactPlaces ?? Enumerable.Empty <ContactPlace>())
                            {
                                foreach (string task in contactPlace.Tasks ?? Enumerable.Empty <string>())
                                {
                                    using (SQLiteCommand command = new SQLiteCommand(OrgUnitStatements.INSERT_CONTACT_PLACES, connection))
                                    {
                                        command.Transaction = transaction;

                                        command.Parameters.Add(new SQLiteParameter("@orgunit_id", orgunit_id));
                                        command.Parameters.Add(new SQLiteParameter("@contact_place_uuid", contactPlace.OrgUnitUuid));
                                        command.Parameters.Add(new SQLiteParameter("@task", task));

                                        command.ExecuteNonQuery();
                                    }
                                }
                            }

                            transaction.Commit();
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();

                            throw;
                        }
                    }
                }
            }
            else
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    connection.Open();

                    using (SqlTransaction transaction = connection.BeginTransaction())
                    {
                        try
                        {
                            using (SqlCommand command = new SqlCommand(OrgUnitStatements.INSERT_MSSQL, connection))
                            {
                                command.Transaction = transaction;

                                command.Parameters.Add(new SqlParameter("@uuid", ou.Uuid));
                                command.Parameters.Add(new SqlParameter("@shortkey", ou.ShortKey)); // ?? (object) DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@name", ou.Name ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@parent_ou_uuid", ou.ParentOrgUnitUuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@payout_ou_uuid", ou.PayoutUnitUuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@operation", operation.ToString()));

                                command.Parameters.Add(new SqlParameter("@los_shortname_uuid", ou.LOSShortName?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@los_shortname_shortkey", ou.LOSShortName?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@los_shortname_value", ou.LOSShortName?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SqlParameter("@phone_uuid", ou.Phone?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@phone_shortkey", ou.Phone?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@phone_value", ou.Phone?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SqlParameter("@email_uuid", ou.Email?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@email_shortkey", ou.Email?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@email_value", ou.Email?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SqlParameter("@location_uuid", ou.Location?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@location_shortkey", ou.Location?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@location_value", ou.Location?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SqlParameter("@ean_uuid", ou.Ean?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@ean_shortkey", ou.Ean?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@ean_value", ou.Ean?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SqlParameter("@contact_open_hours_uuid", ou.ContactOpenHours?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@contact_open_hours_shortkey", ou.ContactOpenHours?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@contact_open_hours_value", ou.ContactOpenHours?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SqlParameter("@email_remarks_uuid", ou.EmailRemarks?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@email_remarks_shortkey", ou.EmailRemarks?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@email_remarks_value", ou.EmailRemarks?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SqlParameter("@contact_uuid", ou.Contact?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@contact_shortkey", ou.Contact?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@contact_value", ou.Contact?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SqlParameter("@post_return_uuid", ou.PostReturn?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@post_return_shortkey", ou.PostReturn?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@post_return_value", ou.PostReturn?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SqlParameter("@phone_open_hours_uuid", ou.PhoneOpenHours?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@phone_open_hours_shortkey", ou.PhoneOpenHours?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@phone_open_hours_value", ou.PhoneOpenHours?.Value ?? (object)DBNull.Value));

                                command.Parameters.Add(new SqlParameter("@post_uuid", ou.Post?.Uuid ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@post_shortkey", ou.Post?.ShortKey ?? (object)DBNull.Value));
                                command.Parameters.Add(new SqlParameter("@post_value", ou.Post?.Value ?? (object)DBNull.Value));

                                orgunit_id = (long)command.ExecuteScalar();
                            }

                            // insert itsystems
                            foreach (string itSystemUuid in ou.ItSystemUuids ?? Enumerable.Empty <string>())
                            {
                                using (SqlCommand command = new SqlCommand(OrgUnitStatements.INSERT_ITSYSTEMS, connection))
                                {
                                    command.Transaction = transaction;

                                    command.Parameters.Add(new SqlParameter("@orgunit_id", orgunit_id));
                                    command.Parameters.Add(new SqlParameter("@itsystem_uuid", itSystemUuid));

                                    command.ExecuteNonQuery();
                                }
                            }

                            // insert contact places
                            foreach (ContactPlace contactPlace in ou.ContactPlaces ?? Enumerable.Empty <ContactPlace>())
                            {
                                foreach (string task in contactPlace.Tasks ?? Enumerable.Empty <string>())
                                {
                                    using (SqlCommand command = new SqlCommand(OrgUnitStatements.INSERT_CONTACT_PLACES, connection))
                                    {
                                        command.Transaction = transaction;

                                        command.Parameters.Add(new SqlParameter("@orgunit_id", orgunit_id));
                                        command.Parameters.Add(new SqlParameter("@contact_place_uuid", contactPlace.OrgUnitUuid));
                                        command.Parameters.Add(new SqlParameter("@task", task));

                                        command.ExecuteNonQuery();
                                    }
                                }
                            }

                            transaction.Commit();
                        }
                        catch (Exception)
                        {
                            transaction.Rollback();

                            throw;
                        }
                    }
                }
            }
        }
Beispiel #29
0
        private OrgUnitData MapRegistrationToOrgUnitDTO(OrgUnitRegistration registration)
        {
            // loop through all address information in the input, and build the corresponding relations for OrgUnit object
            List <AddressRelation> addressRelations = new List <AddressRelation>();

            if (registration.Phone != null)
            {
                AddressRelation address = new AddressRelation();
                address.Type = AddressRelationType.PHONE;
                address.Uuid = registration.Phone.Uuid;
                addressRelations.Add(address);
            }

            if (registration.Email != null)
            {
                AddressRelation address = new AddressRelation();
                address.Type = AddressRelationType.EMAIL;
                address.Uuid = registration.Email.Uuid;
                addressRelations.Add(address);
            }

            if (registration.Location != null)
            {
                AddressRelation address = new AddressRelation();
                address.Type = AddressRelationType.LOCATION;
                address.Uuid = registration.Location.Uuid;
                addressRelations.Add(address);
            }

            if (registration.LOSShortName != null)
            {
                AddressRelation address = new AddressRelation();
                address.Type = AddressRelationType.LOSSHORTNAME;
                address.Uuid = registration.LOSShortName.Uuid;
                addressRelations.Add(address);
            }

            if (registration.Ean != null)
            {
                AddressRelation address = new AddressRelation();
                address.Type = AddressRelationType.EAN;
                address.Uuid = registration.Ean.Uuid;
                addressRelations.Add(address);
            }

            if (registration.Post != null)
            {
                AddressRelation address = new AddressRelation();
                address.Type = AddressRelationType.POST;
                address.Uuid = registration.Post.Uuid;
                addressRelations.Add(address);
            }

            if (registration.ContactOpenHours != null)
            {
                AddressRelation address = new AddressRelation();
                address.Type = AddressRelationType.CONTACT_ADDRESS_OPEN_HOURS;
                address.Uuid = registration.ContactOpenHours.Uuid;
                addressRelations.Add(address);
            }

            if (registration.EmailRemarks != null)
            {
                AddressRelation address = new AddressRelation();
                address.Type = AddressRelationType.EMAIL_REMARKS;
                address.Uuid = registration.EmailRemarks.Uuid;
                addressRelations.Add(address);
            }

            if (registration.PostReturn != null)
            {
                AddressRelation address = new AddressRelation();
                address.Type = AddressRelationType.POST_RETURN;
                address.Uuid = registration.PostReturn.Uuid;
                addressRelations.Add(address);
            }

            if (registration.Contact != null)
            {
                AddressRelation address = new AddressRelation();
                address.Type = AddressRelationType.CONTACT_ADDRESS;
                address.Uuid = registration.Contact.Uuid;
                addressRelations.Add(address);
            }

            if (registration.PhoneOpenHours != null)
            {
                AddressRelation address = new AddressRelation();
                address.Type = AddressRelationType.PHONE_OPEN_HOURS;
                address.Uuid = registration.PhoneOpenHours.Uuid;
                addressRelations.Add(address);
            }

            OrgUnitData organisationEnhed = new OrgUnitData();

            organisationEnhed.ShortKey          = registration.ShortKey;
            organisationEnhed.Name              = registration.Name;
            organisationEnhed.Addresses         = addressRelations;
            organisationEnhed.Timestamp         = registration.Timestamp;
            organisationEnhed.Uuid              = registration.Uuid;
            organisationEnhed.ParentOrgUnitUuid = registration.ParentOrgUnitUuid;

            return(organisationEnhed);
        }
Beispiel #30
0
        private void ValidateAndEnforceCasing(OrgUnitRegistration registration)
        {
            List <string> errors = new List <string>();

            if (string.IsNullOrEmpty(registration.Name))
            {
                errors.Add("name");
            }

            if (string.IsNullOrEmpty(registration.Uuid))
            {
                errors.Add("uuid");
            }

            if (registration.Timestamp == null)
            {
                errors.Add("timestamp");
            }

            if (registration.ContactPlaces != null)
            {
                foreach (var contactPlace in registration.ContactPlaces)
                {
                    if (string.IsNullOrEmpty(contactPlace.OrgUnitUuid) || contactPlace.Tasks == null || contactPlace.Tasks.Count == 0)
                    {
                        errors.Add("contactPlace");
                    }
                }
            }

            if (errors.Count > 0)
            {
                throw new InvalidFieldsException("Invalid registration object - the following fields are invalid: " + string.Join(",", errors));
            }

            if (registration.Phone != null && string.IsNullOrEmpty(registration.Phone.Value))
            {
                registration.Phone = null;
            }

            if (registration.Email != null && string.IsNullOrEmpty(registration.Email.Value))
            {
                registration.Email = null;
            }

            if (registration.Location != null && string.IsNullOrEmpty(registration.Location.Value))
            {
                registration.Location = null;
            }

            if (registration.Post != null && string.IsNullOrEmpty(registration.Post.Value))
            {
                registration.Post = null;
            }

            if (registration.LOSShortName != null && string.IsNullOrEmpty(registration.LOSShortName.Value))
            {
                registration.LOSShortName = null;
            }

            if (registration.PhoneOpenHours != null && string.IsNullOrEmpty(registration.PhoneOpenHours.Value))
            {
                registration.PhoneOpenHours = null;
            }

            if (registration.ContactOpenHours != null && string.IsNullOrEmpty(registration.ContactOpenHours.Value))
            {
                registration.ContactOpenHours = null;
            }

            if (registration.EmailRemarks != null && string.IsNullOrEmpty(registration.EmailRemarks.Value))
            {
                registration.EmailRemarks = null;
            }

            if (registration.PostReturn != null && string.IsNullOrEmpty(registration.PostReturn.Value))
            {
                registration.PostReturn = null;
            }

            if (registration.Contact != null && string.IsNullOrEmpty(registration.Contact.Value))
            {
                registration.Contact = null;
            }

            if (registration.Ean != null && string.IsNullOrEmpty(registration.Ean.Value))
            {
                registration.Ean = null;
            }

            if (registration.Email?.Uuid != null)
            {
                registration.Email.Uuid = registration.Email.Uuid.ToLower();
            }

            if (registration.Location?.Uuid != null)
            {
                registration.Location.Uuid = registration.Location.Uuid.ToLower();
            }

            if (registration.LOSShortName?.Uuid != null)
            {
                registration.LOSShortName.Uuid = registration.LOSShortName.Uuid.ToLower();
            }

            if (registration.Post?.Uuid != null)
            {
                registration.Post.Uuid = registration.Post.Uuid.ToLower();
            }

            if (registration.Phone?.Uuid != null)
            {
                registration.Phone.Uuid = registration.Phone.Uuid.ToLower();
            }

            if (registration.PayoutUnitUuid != null)
            {
                registration.PayoutUnitUuid = registration.PayoutUnitUuid.ToLower();
            }

            if (registration.ParentOrgUnitUuid != null)
            {
                registration.ParentOrgUnitUuid = registration.ParentOrgUnitUuid.ToLower();
            }

            if (registration.ItSystemUuids != null)
            {
                List <string> lowerCaseValues = new List <string>();

                foreach (string uuid in registration.ItSystemUuids)
                {
                    lowerCaseValues.Add(uuid.ToLower());
                }

                registration.ItSystemUuids = lowerCaseValues;
            }

            if (registration.ContactPlaces != null)
            {
                foreach (var contactPlace in registration.ContactPlaces)
                {
                    contactPlace.OrgUnitUuid = contactPlace.OrgUnitUuid.ToLower();
                }
            }

            registration.Uuid = registration.Uuid.ToLower();
        }