Example #1
0
        public void Update(UserRegistration user)
        {
            log.Debug("Performing Update on User '" + user.Uuid + "'");

            ValidateAndEnforceCasing(user);

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

                    ServiceHelper.UpdatePosition(user);

                    string orgPersonUuid = null;
                    if (result.RelationListe.TilknyttedePersoner != null && result.RelationListe.TilknyttedePersoner.Length > 0)
                    {
                        // we read actual-state-only, so there is precisely ONE person object - but better safe than sorry
                        orgPersonUuid = result.RelationListe.TilknyttedePersoner[0].ReferenceID.Item;
                    }

                    string personUuid = null;
                    ServiceHelper.UpdatePerson(user, orgPersonUuid, out personUuid);

                    // Update the User object (attributes and all relationships)
                    brugerStub.Ret(MapRegistrationToUserDTO(user, addressRefs, personUuid));

                    log.Debug("Update successful on User '" + user.Uuid + "'");
                }
            }
            catch (Exception ex) when(ex is STSNotFoundException || ex is ServiceNotFoundException)
            {
                log.Warn("Update on UserService failed for '" + user.Uuid + "' due to unavailable KOMBIT services", ex);
                throw new TemporaryFailureException(ex.Message);
            }
        }
Example #2
0
        public List <string> Validate(string uuid)
        {
            List <String> errors = new List <string>();

            IntegrationLayer.Bruger.RegistreringType1 bruger = brugerStub.GetLatestRegistration(uuid);
            if (!string.IsNullOrEmpty(bruger.AttributListe.Egenskab?[0]?.BrugerTypeTekst))
            {
                errors.Add(BRUGERTYPE_TEKST_MSG);
            }

            if (bruger.RelationListe?.BrugerTyper != null)
            {
                errors.Add(BRUGERTYPER_MSG);
            }

            if (bruger.RelationListe?.Opgaver != null)
            {
                errors.Add(OPGAVER_MSG);
            }

            if (bruger.RelationListe.Tilhoerer == null)
            {
                errors.Add(TILHOERER_NULL_MSG);
            }
            else if (!bruger.RelationListe.Tilhoerer.ReferenceID.Item.Equals(organisationUuid))
            {
                errors.Add(string.Format(TILHOERER_BAD_RELATION_MSG, organisationUuid, bruger.RelationListe.Tilhoerer.ReferenceID.Item));
            }

            if (bruger.RelationListe.TilknyttedeEnheder != null)
            {
                errors.Add(string.Format(TILHOERER_TILKNYTTEDE_ENHEDER_MSG));
            }

            if (bruger.RelationListe.TilknyttedeFunktioner != null)
            {
                errors.Add(string.Format(TILHOERER_TILKNYTTEDE_FUNKTIONER));
            }

            if (bruger.RelationListe.TilknyttedeInteressefaellesskaber != null)
            {
                errors.Add(string.Format(TILKNYTTEDE_INTERESSE_FAELLESSKABER_MSG));
            }

            if (bruger.RelationListe.TilknyttedePersoner != null)
            {
                if (bruger.RelationListe.TilknyttedePersoner.Length != 1)
                {
                    errors.Add(string.Format(TILKNYTTEDE_PERSONER_MSG));
                }
            }


            if (bruger.RelationListe.TilknyttedeOrganisationer != null)
            {
                errors.Add(string.Format(TILKNYTTEDE_ORGANISATIONER_MSG));
            }

            if (bruger.RelationListe.TilknyttedeItSystemer != null)
            {
                errors.Add(string.Format(TILKNYTTEDE_ITSYSTEMER_MSG));
            }

            if (bruger.RelationListe.Adresser != null)
            {
                foreach (var address in bruger.RelationListe.Adresser ?? Enumerable.Empty <global::IntegrationLayer.Bruger.AdresseFlerRelationType>())
                {
                    string type = address.Type?.Item;
                    string role = address.Rolle?.Item;

                    if (!ValidateUserAddressType(type))
                    {
                        errors.Add(string.Format(TYPE_MSG, address.ReferenceID.Item, type));
                    }
                    if (!ValidateRole(role))
                    {
                        errors.Add(string.Format(ROLE_MSG, address.ReferenceID.Item, type));
                    }
                }
            }
            return(errors);
        }
Example #3
0
        public void Update(UserRegistration user)
        {
            log.Debug("Performing Update on User '" + user.Uuid + "'");

            ValidateAndEnforceCasing(user);

            try
            {
                var result = brugerStub.GetLatestRegistration(user.Uuid);
                if (result == null)
                {
                    log.Debug("Update on User '" + user.Uuid + "' changed to a Create because it does not exists as an active object within Organisation");
                    Create(user);
                }
                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;
                    if (result.RelationListe.Adresser != null)
                    {
                        foreach (var orgAddress in result.RelationListe.Adresser)
                        {
                            if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_USER_PHONE))
                            {
                                orgPhoneUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_USER_EMAIL))
                            {
                                orgEmailUuid = orgAddress.ReferenceID.Item;
                            }
                            else if (orgAddress.Rolle.Item.Equals(UUIDConstants.ADDRESS_ROLE_USER_LOCATION))
                            {
                                orgLocationUuid = orgAddress.ReferenceID.Item;
                            }
                        }
                    }

                    // run through all the input addresses, and deal with them one by one
                    ServiceHelper.UpdateAddress(user.Phone, orgPhoneUuid, user.Timestamp);
                    ServiceHelper.UpdateAddress(user.Email, orgEmailUuid, user.Timestamp);
                    ServiceHelper.UpdateAddress(user.Location, orgLocationUuid, user.Timestamp);
                    #endregion

                    #region Update Position if needed
                    ServiceHelper.UpdatePosition(user);
                    #endregion

                    #region Update Person reference if needed
                    string orgPersonUuid = null;
                    if (result.RelationListe.TilknyttedePersoner != null && result.RelationListe.TilknyttedePersoner.Length > 0)
                    {
                        // we read actual-state-only, so there is precisely ONE person object - but better safe than sorry
                        orgPersonUuid = result.RelationListe.TilknyttedePersoner[0].ReferenceID.Item;
                    }
                    ServiceHelper.UpdatePerson(user, orgPersonUuid);
                    #endregion

                    // Update the User object (attributes and all relationships)
                    brugerStub.Ret(MapRegistrationToUserDTO(user));

                    log.Debug("Update successful on User '" + user.Uuid + "'");
                }
            }
            catch (Exception ex) when(ex is STSNotFoundException || ex is ServiceNotFoundException)
            {
                log.Warn("Update on UserService failed for '" + user.Uuid + "' due to unavailable KOMBIT services", ex);
                throw new TemporaryFailureException(ex.Message);
            }
        }