Exemple #1
0
        public void Importer(OrgUnitData unit)
        {
            log.Debug("Attempting Importer on OrganisationEnhed with uuid " + unit.Uuid);

            // create ShortKey if not supplied
            EnsureKeys(unit);

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

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

            // add properties
            helper.AddProperties(unit.ShortKey, unit.Name, virkning, registration);

            // add relationships
            helper.AddAddressReferences(unit.Addresses, virkning, registration);
            helper.AddOrganisationRelation(StubUtil.GetMunicipalityOrganisationUUID(), virkning, registration);
            helper.AddOverordnetEnhed(unit.ParentOrgUnitUuid, virkning, registration);
            helper.AddTilknyttedeFunktioner(unit.OrgFunctionUuids, virkning, registration);

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

            // wire everything together
            OrganisationEnhedType organisationEnhedType = helper.GetOrganisationEnhedType(unit.Uuid, registration);
            ImportInputType       importInput           = new ImportInputType();

            importInput.OrganisationEnhed = organisationEnhedType;

            // 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
            OrganisationEnhedPortType channel = StubUtil.CreateChannel <OrganisationEnhedPortType>(OrganisationEnhedStubHelper.SERVICE, "Importer", helper.CreatePort());

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

                log.Debug("Importer successful on OrganisationEnhed with uuid " + unit.Uuid);
            }
            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 OrganisationEnhed", ex);
            }
        }
Exemple #2
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 #3
0
        public void Importer(AddressData address)
        {
            // create ShortKey and Uuid if not supplied
            EnsureKeys(address);

            log.Debug("Attempting Import on Address with uuid " + address.Uuid);

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

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

            // add properties
            helper.AddProperties(address.AddressText, address.ShortKey, virkning, registration);

            // wire everything together
            AdresseType     addresseType = helper.GetAdresseType(address.Uuid, registration);
            ImportInputType inportInput  = new ImportInputType();

            inportInput.Adresse = addresseType;

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

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

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

            try
            {
                importerResponse response = channel.importer(request);
                int statusCode            = Int32.Parse(response.ImporterResponse1.ImportOutput.StandardRetur.StatusKode);
                if (statusCode != 20)
                {
                    if (statusCode == 49) // object already exists is the most likely scenario here
                    {
                        // TODO: a better approach would be to try the read-then-update-if-exists-else-create approach we use elsewhere
                        log.Info("Skipping import on Address " + address.Uuid + " as Organisation returned status 49. The most likely cause is that the object already exists");
                        return;
                    }

                    string message = StubUtil.ConstructSoapErrorMessage(statusCode, "Import", AdresseStubHelper.SERVICE, response.ImporterResponse1.ImportOutput.StandardRetur.FejlbeskedTekst);
                    log.Error(message);
                    throw new SoapServiceException(message);
                }

                log.Debug("Import successful on Address with uuid " + address.Uuid);
            }
            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 Adresse", ex);
            }
        }
Exemple #4
0
        public void Importer(PersonData person)
        {
            // create ShortKey and Uuid if not supplied
            EnsureKeys(person);

            log.Debug("Attempting Import on Person with uuid " + person.Uuid);

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

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

            // add properties
            helper.AddProperties(person.Name, person.ShortKey, person.Cpr, virkning, registration);

            // wire everything together
            PersonType      personType  = helper.GetPersonType(person.Uuid, registration);
            ImportInputType importInput = new ImportInputType();

            importInput.Person = personType;

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

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

            // send request
            PersonPortType channel = StubUtil.CreateChannel <PersonPortType>(PersonStubHelper.SERVICE, "Import", 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", PersonStubHelper.SERVICE, response.ImporterResponse1.ImportOutput.StandardRetur.FejlbeskedTekst);
                    log.Error(message);
                    throw new SoapServiceException(message);
                }

                log.Debug("Import successful on Person with uuid " + person.Uuid);
            }
            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 Person", ex);
            }
        }
        public importerResponse Create(ImportInputType importInput)
        {
            // construct request
            importerRequest request = new importerRequest();

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

            // send request
            OrganisationFunktionPortType channel = StubUtil.CreateChannel <OrganisationFunktionPortType>(OrganisationFunktionStubHelper.SERVICE, "Import", helper.CreatePort());

            try
            {
                return(channel.importer(request));
            }
            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 OrganisationFunktion", ex);
            }
        }