Ejemplo n.º 1
0
        public retResponse Update(RetInputType1 input)
        {
            // construct request
            retRequest request = new retRequest();

            request.RetRequest1                  = new RetRequestType();
            request.RetRequest1.RetInput         = input;
            request.RetRequest1.AuthorityContext = new AuthorityContextType();
            request.RetRequest1.AuthorityContext.MunicipalityCVR = OrganisationRegistryProperties.GetCurrentMunicipality();

            // send Ret request
            PersonPortType channel = StubUtil.CreateChannel <PersonPortType>(PersonStubHelper.SERVICE, "Ret", helper.CreatePort());

            try
            {
                return(channel.ret(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 Ret service on Person", ex);
            }
        }
Ejemplo n.º 2
0
        // this method only performs a call to Ret on Organisation if there are actual changes
        public void Ret(string uuid, string newName, string newCpr, DateTime timestamp)
        {
            log.Debug("Attempting Ret on Person with uuid " + uuid);

            // this should never fail - we always import the Person before the User, and we have a User with a reference to this object
            RegistreringType1 registration = GetLatestRegistration(uuid);

            if (registration == null)
            {
                log.Debug("Cannot call Ret on Person with uuid " + uuid + " because it does not exist in Organisation");
                return;
            }

            PersonPortType channel = StubUtil.CreateChannel <PersonPortType>(PersonStubHelper.SERVICE, "Ret", helper.CreatePort());

            try
            {
                RetInputType1 input = new RetInputType1();
                input.UUIDIdentifikator = uuid;
                input.AttributListe     = registration.AttributListe;
                input.TilstandListe     = registration.TilstandListe;
                input.RelationListe     = registration.RelationListe;

                // compare latest property to the local object
                EgenskabType latestProperty = StubUtil.GetLatestProperty(input.AttributListe);
                if (latestProperty == null || string.Compare(latestProperty.NavnTekst, newName) != 0 || string.Compare(latestProperty.CPRNummerTekst, newCpr) != 0)
                {
                    // create a new property
                    EgenskabType newProperty = new EgenskabType();
                    newProperty.Virkning = helper.GetVirkning(timestamp);
                    newProperty.BrugervendtNoegleTekst = ((latestProperty != null) ? latestProperty.BrugervendtNoegleTekst : IdUtil.GenerateShortKey());
                    newProperty.NavnTekst      = newName;
                    newProperty.CPRNummerTekst = newCpr;

                    // overwrite existing property set
                    input.AttributListe    = new EgenskabType[1];
                    input.AttributListe[0] = newProperty;
                }
                else
                {
                    log.Debug("No changes on Person, so returning without calling Organisation");

                    // if there are no changes to the attributes, we do not call the Organisation service
                    return;
                }

                // send Ret request
                retRequest request = new retRequest();
                request.RetRequest1                  = new RetRequestType();
                request.RetRequest1.RetInput         = input;
                request.RetRequest1.AuthorityContext = new AuthorityContextType();
                request.RetRequest1.AuthorityContext.MunicipalityCVR = OrganisationRegistryProperties.GetCurrentMunicipality();

                retResponse response = channel.ret(request);

                int statusCode = Int32.Parse(response.RetResponse1.RetOutput.StandardRetur.StatusKode);
                if (statusCode != 20)
                {
                    if (statusCode == 49)
                    {
                        log.Warn("Ret failed on Person " + uuid + " as Organisation returned status 49. The most likely cause is that the object has been Passiveret");
                        return;
                    }

                    string message = StubUtil.ConstructSoapErrorMessage(statusCode, "Ret", PersonStubHelper.SERVICE, response.RetResponse1.RetOutput.StandardRetur.FejlbeskedTekst);
                    log.Error(message);
                    throw new SoapServiceException(message);
                }

                log.Debug("Ret successful on Person with uuid " + 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 Ret service on Person", ex);
            }
        }