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); } }
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); } }