public FiltreretOejebliksbilledeType ReadPeriod(DateTime fromDate, DateTime toDate, PersonIdentifier pId, Func <string, Guid> cpr2UuidFunc) { using (var dataContext = new ExtractDataContext()) { var loadOptions = new System.Data.Linq.DataLoadOptions(); loadOptions.LoadWith <ExtractItem>(ei => ei.Extract); dataContext.LoadOptions = loadOptions; var individualResponses = Extract.GetPersonFromAllExtracts(pId.CprNumber, dataContext.ExtractItems, Constants.DataObjectMap); var fullResp = new IndividualHistoryResponseType(pId, individualResponses); var pnrs = fullResp.AllRelationPNRs; var uuids = CprBroker.Data.Part.PersonMapping.AssignGuids(pnrs); Func <string, Guid> uuidGetter = (pnr) => { Guid?uuid = null; var pnrIndex = Array.IndexOf <string>(pnrs, pnr); if (pnrIndex != -1) { uuid = uuids[pnrIndex]; } return(uuid.HasValue ? uuid.Value : cpr2UuidFunc(pnr)); }; return(fullResp .ToFiltreretOejebliksbilledeType(uuidGetter) .Filter(VirkningType.Create(fromDate, toDate))); } }
internal void AddAddressReferences(List <AddressRelation> references, VirkningType virkning, RegistreringType1 registration) { if (references == null || references.Count == 0) { return; } var adresses = new AdresseFlerRelationType[references.Count]; int referencesCount = references.Count; registration.RelationListe.Adresser = new AdresseFlerRelationType[referencesCount]; for (int i = 0; i < referencesCount; i++) { AddressRelation addressRelation = references[i]; switch (addressRelation.Type) { case AddressRelationType.URL: AdresseFlerRelationType urlAddress = CreateAddressReference(addressRelation.Uuid, (i + 1), UUIDConstants.ADDRESS_ROLE_ORGFUNCTION_URL, virkning); registration.RelationListe.Adresser[i] = urlAddress; break; default: throw new Exception("Cannot import OrganisationFunktion with addressRelationType = " + addressRelation.Type); } } }
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); } }
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); } }
internal void AddOrganisationRelation(string organisationUUID, VirkningType virkning, RegistreringType1 registration) { UnikIdType orgReference = StubUtil.GetReference <UnikIdType>(organisationUUID, ItemChoiceType.UUIDIdentifikator); OrganisationFlerRelationType organisationRelationType = new OrganisationFlerRelationType(); organisationRelationType.Virkning = virkning; organisationRelationType.ReferenceID = orgReference; int i = 0; OrganisationFlerRelationType[] newRelations = new OrganisationFlerRelationType[1]; if (registration.RelationListe.TilknyttedeOrganisationer != null && registration.RelationListe.TilknyttedeOrganisationer.Length > 0) { newRelations = new OrganisationFlerRelationType[registration.RelationListe.TilknyttedeOrganisationer.Length + 1]; foreach (OrganisationFlerRelationType oldRelation in registration.RelationListe.TilknyttedeOrganisationer) { newRelations[i++] = oldRelation; } } registration.RelationListe.TilknyttedeOrganisationer = newRelations; registration.RelationListe.TilknyttedeOrganisationer[i] = organisationRelationType; }
public void IsDoubleOpen_FromSpecified_ReturnsFalse( DateTime?fromDate) { var result = VirkningType.IsDoubleOpen(VirkningType.Create(fromDate, null)); Assert.False(result); }
public void ToRegisterOplysningType_Normal_OneOrMoreIntervals() { var person = GetPerson(); var registerOplysningIntervals = person.ToRegisterOplysningIntervalArray(); var registerOplysning = registerOplysningIntervals .Select( interval => interval.ToRegisterOplysningType() ) .ToArray(); Assert.GreaterOrEqual(registerOplysning.Length, 0); foreach (RegisterOplysningType interval in registerOplysning) { /* * We test if the address and end time attributes are set in any * of the intervals. */ /* * We have to cast the item object as the type CprBorgerType as * the type is not declared in the class. */ CprBorgerType item = (CprBorgerType)interval.Item; Assert.IsNotNull(item); //Assert.IsNotNull(item.AdresseNoteTekst); // <- is null //Assert.IsNotNull(item.FolkeregisterAdresse); // <- is null Console.WriteLine(item.FolkeregisterAdresse); // nothing is printed Console.WriteLine(item.AdresseNoteTekst); // prints out the object name VirkningType virkning = interval.Virkning; Assert.IsNotNull(virkning); Assert.IsNotNull(virkning.TilTidspunkt); } }
public void IsDoubleOpen_ToSpecified_ReturnsFalse( DateTime?toDate) { var result = VirkningType.IsDoubleOpen(VirkningType.Create(null, toDate)); Assert.False(result); }
public void Intersects_OneNulls_True() { var v1 = VirkningType.Create(DateTime.Today, DateTime.Today.AddDays(1)); var v2 = VirkningType.Create(null, null); Assert.True(v1.Intersects(v2)); Assert.True(v2.Intersects(v1)); }
public void Create_Valid_EqualFromDate( [ValueSource("PastDatesWithNull")] DateTime?fromDate, [ValueSource("FutureDatesWithNull")] DateTime?toDate) { var result = VirkningType.Create(fromDate, toDate); Assert.AreEqual(fromDate, result.FraTidspunkt.ToDateTime()); }
public void Create_Valid_NotNull( [ValueSource("PastDatesWithNull")] DateTime?fromDate, [ValueSource("FutureDatesWithNull")] DateTime?toDate) { var result = VirkningType.Create(fromDate, toDate); Assert.NotNull(result); }
public void Intersects_OneClosedOneHalfOpenBefore_False() { var v1 = VirkningType.Create(DateTime.Today, DateTime.Today.AddDays(2)); var v2 = VirkningType.Create(null, DateTime.Today.AddDays(-1)); Assert.False(v1.Intersects(v2)); Assert.False(v2.Intersects(v1)); }
public void Intersects_OneClosedOneHalfOpen_True() { var v1 = VirkningType.Create(DateTime.Today, DateTime.Today.AddDays(2)); var v2 = VirkningType.Create(DateTime.Today.AddDays(1), null); Assert.True(v1.Intersects(v2)); Assert.True(v2.Intersects(v1)); }
public void Intersects_TwoHalfOpenOneEndsBeforeOtherStart_False() { var v1 = VirkningType.Create(null, DateTime.Today.AddDays(-1)); var v2 = VirkningType.Create(DateTime.Today.AddDays(1), null); Assert.False(v1.Intersects(v2)); Assert.False(v2.Intersects(v1)); }
public void Intersects_TwoOpenEnd_True() { var v1 = VirkningType.Create(DateTime.Today, null); var v2 = VirkningType.Create(DateTime.Today.AddDays(-1), null); Assert.True(v1.Intersects(v2)); Assert.True(v2.Intersects(v1)); }
public void Intersects_AllNulls_True() { var v1 = VirkningType.Create(null, null); var v2 = VirkningType.Create(null, null); var ret = v1.Intersects(v2); Assert.True(ret); }
public void IsDoubleOpen_ClosedValues_ReturnsFalse( [ValueSource("PastDates")] DateTime?fromDate, [ValueSource("FutureDates")] DateTime?toDate) { var result = VirkningType.IsDoubleOpen(VirkningType.Create(fromDate, toDate)); Assert.False(result); }
public void Compose_ValidArray_CorrectTilTidspunkt( [ValueSource("PastDatesWithNull")] DateTime?fromDate) { var input = FutureDates.Select(pd => VirkningType.Create(fromDate, pd)).ToArray(); var result = VirkningType.Compose(input); Assert.AreEqual(FutureDates.Max(), result.TilTidspunkt.ToDateTime()); }
public void Compose_ValidArray_CorrectFraTidspunkt( [ValueSource("FutureDatesWithNull")] DateTime?toDate) { var input = PastDates.Select(pd => VirkningType.Create(pd, toDate)).ToArray(); var result = VirkningType.Compose(input); Assert.AreEqual(PastDates.Min(), result.FraTidspunkt.ToDateTime()); }
public void Intersects_OneNullsOneHalfOpen_True() { var v1 = VirkningType.Create(DateTime.Today, null); var v2 = VirkningType.Create(null, null); Assert.True(v1.Intersects(v2)); Assert.True(v2.Intersects(v1)); }
public void Intersects_TwoClosedNotIntersecting_True() { var v1 = VirkningType.Create(DateTime.Today.AddDays(0), DateTime.Today.AddDays(2)); var v2 = VirkningType.Create(DateTime.Today.AddDays(3), DateTime.Today.AddDays(4)); Assert.False(v1.Intersects(v2)); Assert.False(v2.Intersects(v1)); }
public void Create_Valid_CommentTextNull( [ValueSource("PastDatesWithNull")] DateTime?fromDate, [ValueSource("FutureDatesWithNull")] DateTime?toDate) { var result = VirkningType.Create(fromDate, toDate); Assert.IsNullOrEmpty(result.CommentText); }
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); } }
internal GyldighedType GetGyldighedType(GyldighedStatusKodeType type, VirkningType virkning) { GyldighedType gyldighed = new GyldighedType(); gyldighed.GyldighedStatusKode = type; gyldighed.Virkning = virkning; return(gyldighed); }
public void Compose_ValidSingle_TilTidspunktEqualsInput( [ValueSource("PastDatesWithNull")] DateTime?fromDate, [ValueSource("FutureDatesWithNull")] DateTime?toDate) { var virkning = VirkningType.Create(fromDate, toDate); var result = VirkningType.Compose(virkning); Assert.AreEqual(virkning.TilTidspunkt.ToDateTime(), result.TilTidspunkt.ToDateTime()); }
public void Compose_ValidSingle_EqualsInput( [ValueSource("PastDatesWithNull")] DateTime?fromDate, [ValueSource("FutureDatesWithNull")] DateTime?toDate) { var virkning = VirkningType.Create(fromDate, toDate); var result = VirkningType.Compose(virkning); Assert.NotNull(result); }
public override void ProcessPerson(string pnr) { /* Sample person in run "2013 05 27 14_12" * - First Egenskab has null start and end dates - shall the first start at birthdate? * - Married with unknown spouse PNR */ using (var dataContext = new ExtractDataContext()) { var extractItems = dataContext.ExtractItems.Where(ei => ei.PNR == pnr); var grouped = extractItems.GroupBy(ei => ei.Extract); var myOutDir = OutDir + pnr + "\\"; Directory.CreateDirectory(myOutDir); var registrations = new List <RegistreringType1>(); foreach (var extract in grouped.OrderBy(ex => ex.Key.ExtractDate)) { var resp = Extract.GetPersonFromLatestExtract(pnr, extract.AsQueryable(), CprBroker.Providers.CPRDirect.Constants.DataObjectMap); var reg = resp.ToRegistreringType1(GetUuid); registrations.Add(reg); File.WriteAllText( string.Format("{0}{1}.{2}.xml", myOutDir, pnr, reg.Tidspunkt.ToDateTime().Value.ToString("yyyyMMdd HHmm")), CprBroker.Utilities.Strings.SerializeObject(reg) ); } var merged1 = RegistreringType1.Merge(new CprBroker.Schemas.PersonIdentifier() { UUID = GetUuid(pnr), CprNumber = pnr }, VirkningType.Create(DateTime.MinValue, DateTime.MaxValue), registrations.ToArray()); File.WriteAllText( string.Format("{0}{1}.All.1.xml", myOutDir, pnr), CprBroker.Utilities.Strings.SerializeObject(merged1) ); var merged2 = new CPRDirectExtractDataProvider().ReadPeriod(DateTime.MinValue, DateTime.MaxValue, new CprBroker.Schemas.PersonIdentifier() { CprNumber = pnr, UUID = GetUuid(pnr) }, GetUuid); File.WriteAllText( string.Format("{0}{1}.All.2.xml", myOutDir, pnr), CprBroker.Utilities.Strings.SerializeObject(merged2) ); var effectDate = new DateTime(2013, 5, 1); var merged3 = new CPRDirectExtractDataProvider().ReadPeriod(effectDate, effectDate, new CprBroker.Schemas.PersonIdentifier() { CprNumber = pnr, UUID = GetUuid(pnr) }, GetUuid); File.WriteAllText( string.Format("{0}{1}.All.3.xml", myOutDir, pnr), CprBroker.Utilities.Strings.SerializeObject(merged3) ); } }
private GyldighedType GetGyldighedType(GyldighedStatusKodeType statusCode, VirkningType virkning) { GyldighedType gyldighed = new GyldighedType(); gyldighed.GyldighedStatusKode = statusCode; gyldighed.Virkning = virkning; return(gyldighed); }
public virtual VirkningType ToEgenskabTypeVirkning() { return(VirkningType.Create( Converters.GetMaxDate( this.ToBirthdate(), Converters.ToDateTime(this.AddressingNameDate, this.AddressingNameDateUncertainty) ), null )); }
internal void AddOrganisationRelation(string organisationUUID, VirkningType virkning, RegistreringType1 registration) { UnikIdType orgReference = StubUtil.GetReference <UnikIdType>(organisationUUID, ItemChoiceType.UUIDIdentifikator); OrganisationRelationType organisationRelationType = new OrganisationRelationType(); organisationRelationType.Virkning = virkning; organisationRelationType.ReferenceID = orgReference; registration.RelationListe.Tilhoerer = organisationRelationType; }