Exemple #1
0
        public void Importer(UserData user)
        {
            // create ShortKey if not supplied
            EnsureKeys(user);

            log.Debug("Attempting Import on Bruger with uuid " + user.Uuid);

            // create timestamp object to be used on all registrations, properties and relations
            VirkningType virkning = helper.GetVirkning(user.Timestamp);

            // setup registration
            RegistreringType1 registration = helper.CreateRegistration(user.Timestamp, LivscyklusKodeType.Importeret);

            // add properties
            helper.AddProperties(user.ShortKey, user.UserId, virkning, registration);

            // setup relations
            helper.AddAddressReferences(user.Addresses, virkning, registration);
            helper.AddPersonRelationship(user.PersonUuid, virkning, registration);
            helper.AddOrganisationRelation(StubUtil.GetMunicipalityOrganisationUUID(), virkning, registration);

            // set Tilstand to Active
            helper.SetTilstandToActive(virkning, registration, user.Timestamp);

            // wire everything together
            BrugerType      brugerType  = helper.GetBrugerType(user.Uuid, registration);
            ImportInputType importInput = new ImportInputType();

            importInput.Bruger = brugerType;

            // construct request
            importerRequest request = new importerRequest();

            request.ImporterRequest1                  = new ImporterRequestType();
            request.ImporterRequest1.ImportInput      = importInput;
            request.ImporterRequest1.AuthorityContext = new AuthorityContextType();
            request.ImporterRequest1.AuthorityContext.MunicipalityCVR = OrganisationRegistryProperties.GetMunicipality();

            // send request
            BrugerPortType channel = StubUtil.CreateChannel <BrugerPortType>(BrugerStubHelper.SERVICE, "Importer", helper.CreatePort());

            try
            {
                importerResponse response = channel.importer(request);
                int statusCode            = Int32.Parse(response.ImporterResponse1.ImportOutput.StandardRetur.StatusKode);
                if (statusCode != 20)
                {
                    string message = StubUtil.ConstructSoapErrorMessage(statusCode, "Import", BrugerStubHelper.SERVICE, response.ImporterResponse1.ImportOutput.StandardRetur.FejlbeskedTekst);
                    log.Error(message);

                    throw new SoapServiceException(message);
                }

                log.Debug("Import on Bruger with uuid " + user.Uuid + " succeeded");
            }
            catch (Exception ex) when(ex is CommunicationException || ex is IOException || ex is TimeoutException || ex is WebException)
            {
                throw new ServiceNotFoundException("Failed to establish connection to the Importer service on Bruger", ex);
            }
        }
Exemple #2
0
        internal BrugerType GetBrugerType(string uuid, RegistreringType1 registration)
        {
            BrugerType organisationType = new BrugerType();

            organisationType.UUIDIdentifikator = uuid;

            RegistreringType1[] registreringTypes = new RegistreringType1[1];
            registreringTypes[0]          = registration;
            organisationType.Registrering = registreringTypes;

            return(organisationType);
        }