Ejemplo n.º 1
0
        public override BaseResource[] TransformSource(XDocument doc)
        {
            FormalBody formalBody        = new FormalBody();
            XElement   formalBodyElement = doc.Element(atom + "entry")
                                           .Element(atom + "content")
                                           .Element(m + "properties");

            formalBody.FormalBodyMnisId    = formalBodyElement.Element(d + "Committee_Id").GetText();
            formalBody.FormalBodyName      = formalBodyElement.Element(d + "Name").GetText();
            formalBody.FormalBodyStartDate = formalBodyElement.Element(d + "StartDate").GetDate();
            formalBody.FormalBodyHasHouse  = generateHouseMembership(formalBodyElement);
            string parentId = formalBodyElement.Element(d + "ParentCommittee_Id").GetText();

            if (string.IsNullOrWhiteSpace(parentId) == false)
            {
                Uri parentUri = IdRetrieval.GetSubject("formalBodyMnisId", parentId, false, logger);
                if (parentId != null)
                {
                    formalBody.FormalBodyHasParentFormalBody = new List <FormalBody>
                    {
                        new FormalBody()
                        {
                            Id = parentUri
                        }
                    }
                }
                ;
            }
            formalBody.FormalBodyEndDate = formalBodyElement.Element(d + "EndDate").GetDate();

            return(new BaseResource[] { formalBody });
        }
Ejemplo n.º 2
0
        private Person generatePerson(XElement contactPointElement)
        {
            Person person = null;
            string mnisId = contactPointElement.Element(d + "Member_Id").GetText();

            if (string.IsNullOrWhiteSpace(mnisId))
            {
                logger.Warning("No member info found");
                return(null);
            }
            Uri personUri = IdRetrieval.GetSubject("memberMnisId", mnisId, false, logger);

            if (personUri != null)
            {
                person = new Person()
                {
                    Id = personUri
                }
            }
            ;
            else
            {
                logger.Verbose("No person found");
            }

            return(person);
        }
Ejemplo n.º 3
0
 private void generateIncumbencyMemberAndCommittee(Incumbency mnisIncumbency, XElement elementMemberCommittee)
 {
     string memberId = elementMemberCommittee.Parent.Element(d + "Member_Id").GetText();
     if (string.IsNullOrWhiteSpace(memberId) == false)
     {
         Uri memberUri = IdRetrieval.GetSubject("memberMnisId", memberId, false, logger);
         mnisIncumbency.IncumbencyHasPerson = new Person()
         {
             Id = memberUri
         };
     }
     string committeeId = elementMemberCommittee.Parent.Element(d + "Committee_Id").GetText();
     if (string.IsNullOrWhiteSpace(committeeId) == false)
     {
         string positionCommand = @"
             construct {
                 ?position a parl:FormalBodyChair.
             }
             where {
                 ?position parl:formalBodyChairHasFormalBody ?committee.
                 ?committee parl:formalBodyMnisId @formalBodyMnisId.
             }";
         SparqlParameterizedString positionSparql = new SparqlParameterizedString(positionCommand);
         positionSparql.Namespaces.AddNamespace("parl", new Uri(schemaNamespace));
         positionSparql.SetLiteral("formalBodyMnisId", committeeId);
         Uri positionUri = IdRetrieval.GetSubject(positionSparql.ToString(), false, logger);
         if (positionUri != null)
             mnisIncumbency.IncumbencyHasPosition = new Position()
             {
                 Id = positionUri
             };
     }
 }
Ejemplo n.º 4
0
        private AnsweringBodyAllocation giveMeAnsweringBodyAllocation(Response data)
        {
            AnsweringBodyAllocation answeringBodyAllocation = null;

            if (data.AnsweringDeptSesId != null)
            {
                Uri answeringBodyId = IdRetrieval.GetSubject("sesId", data.AnsweringDeptSesId, false, logger);
                if (answeringBodyId != null)
                {
                    answeringBodyAllocation = new AnsweringBodyAllocation()
                    {
                        Id = GenerateNewId(),
                        AnsweringBodyAllocationHasAnsweringBody = new AnsweringBody()
                        {
                            Id = answeringBodyId
                        }
                    };
                    WrittenAnswer writtenAnswer = giveMeWrittenAnswer(data);
                    if (writtenAnswer != null)
                    {
                        answeringBodyAllocation
                        .AnsweringBodyAllocationHasAnsweringBody
                        .AnsweringBodyHasWrittenAnswer = new WrittenAnswer[] { writtenAnswer }
                    }
                    ;
                }
                else
                {
                    logger.Warning($"Answering body with Ses Id ({data.AnsweringDeptSesId}) not found");
                }
            }

            return(answeringBodyAllocation);
        }
Ejemplo n.º 5
0
        private FormalBody generateFormalBodyMembership(XElement formalBodyElement)
        {
            FormalBody formalBody  = null;
            string     committeeId = formalBodyElement.Element(d + "Committee_Id").GetText();

            if (string.IsNullOrWhiteSpace(committeeId) == false)
            {
                Uri formalBodyUri = IdRetrieval.GetSubject("formalBodyMnisId", committeeId, false, logger);
                if (formalBodyUri != null)
                {
                    formalBody = new FormalBody()
                    {
                        Id = formalBodyUri
                    }
                }
                ;
                else
                {
                    logger.Warning($"No committee found for id {committeeId}");
                }
            }
            else
            {
                logger.Warning("No committee data");
            }
            return(formalBody);
        }
Ejemplo n.º 6
0
        public override BaseResource[] TransformSource(JObject jsonResponse)
        {
            GovRegisterGovernmentOrganisation department = new GovRegisterGovernmentOrganisation();
            string id = ((JValue)jsonResponse.SelectToken("GovRegisterID")).GetText();

            department.GovernmentOrganisationGovRegisterId = id;
            int?mnisId = ((JValue)jsonResponse.SelectToken("mnisID")).GetNumber();

            if (mnisId.HasValue)
            {
                Uri departmentUri = IdRetrieval.GetSubject("mnisDepartmentId", mnisId.ToString(), false, logger);
                if (departmentUri == null)
                {
                    return(null);
                }
                else
                {
                    department.Id = departmentUri;
                }
            }
            else
            {
                return(null);
            }
            return(new BaseResource[] { department });
        }
Ejemplo n.º 7
0
        private LocatedSignatureCount[] generateConstituencySignatures(Signatures_By_Constituency[] signaturesByConstituency, DateTime petitionRetrievalTimestamp)
        {
            List <LocatedSignatureCount> signatures     = new List <LocatedSignatureCount>();
            Dictionary <string, string>  constituencies = IdRetrieval.GetSubjectsDictionary("constituencyGroupOnsCode", logger);

            foreach (Signatures_By_Constituency constituency in signaturesByConstituency)
            {
                LocatedSignatureCount locatedSignatureCount = new LocatedSignatureCount();
                locatedSignatureCount.SignatureCount            = DeserializerHelper.GiveMeSingleIntegerValue(constituency.signature_count);
                locatedSignatureCount.SignatureCountRetrievedAt = DeserializerHelper.GiveMeSingleDateValue(petitionRetrievalTimestamp);
                if (constituencies.ContainsKey(constituency.ons_code))
                {
                    locatedSignatureCount.LocatedSignatureCountHasPlace = new Place()
                    {
                        Id = new Uri(constituencies[constituency.ons_code])
                    };
                    signatures.Add(locatedSignatureCount);
                }
                else
                {
                    logger.Warning($"Found signature on petition without matching constituency code - {constituency.ons_code}");
                }
            }
            return(signatures.ToArray());
        }
Ejemplo n.º 8
0
        public override BaseResource[] TransformSource(XDocument doc)
        {
            Person   layPerson = new Person();
            XElement formalBodyLayPersonElement = doc.Element(atom + "entry")
                                                  .Element(atom + "content")
                                                  .Element(m + "properties");

            layPerson.FormalBodyLayPersonMnisId = formalBodyLayPersonElement.Element(d + "CommitteeLayMember_Id").GetText();
            layPerson.PersonGivenName           = formalBodyLayPersonElement.Element(d + "Forename").GetText();
            layPerson.PersonOtherNames          = formalBodyLayPersonElement.Element(d + "MiddleNames").GetText();
            layPerson.PersonFamilyName          = formalBodyLayPersonElement.Element(d + "Surname").GetText();

            string currentGenderText = formalBodyLayPersonElement.Element(d + "Gender").GetText();

            if (string.IsNullOrWhiteSpace(currentGenderText) == false)
            {
                Uri genderUri = IdRetrieval.GetSubject("genderMnisId", currentGenderText, false, logger);
                if (genderUri != null)
                {
                    layPerson.PersonHasGenderIdentity = new GenderIdentity[]
                    {
                        new GenderIdentity()
                        {
                            Id = GenerateNewId(),
                            GenderIdentityHasGender = new Gender()
                            {
                                Id = genderUri
                            }
                        }
                    }
                }
                ;
            }
            string committeeId = formalBodyLayPersonElement.Element(d + "Committee_Id").GetText();

            if (string.IsNullOrWhiteSpace(committeeId) == false)
            {
                Uri formalBodyUri = IdRetrieval.GetSubject("formalBodyMnisId", committeeId, false, logger);
                if (formalBodyUri != null)
                {
                    Uri formalBodymembershipId = GenerateNewId();
                    layPerson.PersonHasFormalBodyMembership = new FormalBodyMembership[]
                    {
                        new FormalBodyMembership()
                        {
                            Id = formalBodymembershipId,
                            FormalBodyMembershipHasFormalBody = new FormalBody()
                            {
                                Id = formalBodyUri
                            },
                            FormalBodyMembershipStartDate = formalBodyLayPersonElement.Element(d + "StartDate").GetDate(),
                            FormalBodyMembershipEndDate   = formalBodyLayPersonElement.Element(d + "EndDate").GetDate()
                        }
                    };
                }
            }

            return(new BaseResource[] { layPerson });
        }
Ejemplo n.º 9
0
        public override BaseResource[] TransformSource(JObject jsonResponse)
        {
            PersonWebLink personWebLink = new PersonWebLink();
            string        url           = ((JValue)jsonResponse.SelectToken("URL")).GetText();

            if (string.IsNullOrWhiteSpace(url))
            {
                logger.Warning("No url info found");
                return(null);
            }
            else
            {
                if (Uri.TryCreate(url, UriKind.Absolute, out Uri uri))
                {
                    personWebLink.Id = uri;
                }
                else
                {
                    logger.Warning($"Invalid url '{url}' found");
                    return(null);
                }
            }
            int?linkType = ((JValue)jsonResponse.SelectToken("x.Id")).GetInteger();

            if ((linkType != 6) && (linkType != 7) && (linkType != 8))
            {
                logger.Verbose("WebLink information marked as excluded");
                return(new BaseResource[] { personWebLink });
            }

            string mnisId = ((JValue)jsonResponse.SelectToken("Person_x003a_MnisId.Value")).GetText();

            if (string.IsNullOrWhiteSpace(mnisId))
            {
                logger.Warning("No member info found");
                return(null);
            }
            mnisId = Convert.ToInt32(Convert.ToDouble(mnisId)).ToString();
            Uri personUri = IdRetrieval.GetSubject("memberMnisId", mnisId, false, logger);

            if (personUri != null)
            {
                personWebLink.PersonWebLinkHasPerson = new List <Person>
                {
                    new Person()
                    {
                        Id = personUri
                    }
                }
            }
            ;
            else
            {
                logger.Warning("No person found");
            }


            return(new BaseResource[] { personWebLink });
        }
Ejemplo n.º 10
0
        public override BaseResource[] TransformSource(XDocument doc)
        {
            Member   member = new Member();
            XElement seatIncumbencyElement = doc.Element(atom + "entry")
                                             .Element(atom + "content")
                                             .Element(m + "properties");

            ParliamentaryIncumbency incumbency = new ParliamentaryIncumbency();

            incumbency.ParliamentaryIncumbencyStartDate = seatIncumbencyElement.Element(d + "StartDate").GetDate();
            incumbency.ParliamentaryIncumbencyEndDate   = seatIncumbencyElement.Element(d + "EndDate").GetDate();
            string memberId  = seatIncumbencyElement.Element(d + "Member_Id").GetText();
            Uri    memberUri = IdRetrieval.GetSubject("memberMnisId", memberId, false, logger);

            if (memberUri == null)
            {
                logger.Warning($"No member found for {memberId}");
                return(null);
            }
            incumbency.ParliamentaryIncumbencyHasMember = new Member()
            {
                Id = memberUri
            };
            incumbency.CommonsSeatIncumbencyMnisId = seatIncumbencyElement.Element(d + "MemberConstituency_Id").GetText();
            ParliamentPeriod parliamentPeriod = generateSeatIncumbencyParliamentPeriod(incumbency.ParliamentaryIncumbencyStartDate.Value, incumbency.ParliamentaryIncumbencyEndDate);

            if (parliamentPeriod != null)
            {
                incumbency.SeatIncumbencyHasParliamentPeriod = new ParliamentPeriod[] { parliamentPeriod }
            }
            ;

            string constituencyId   = seatIncumbencyElement.Element(d + "Constituency_Id").GetText();
            string houseSeatCommand = @"
        construct {
            ?id a parl:HouseSeat.
        }
        where {
            ?id parl:houseSeatHasConstituencyGroup ?houseSeatHasConstituencyGroup.
            ?houseSeatHasConstituencyGroup parl:constituencyGroupMnisId @constituencyGroupMnisId.
        }";
            SparqlParameterizedString seatSparql = new SparqlParameterizedString(houseSeatCommand);

            seatSparql.Namespaces.AddNamespace("parl", new Uri(schemaNamespace));
            seatSparql.SetLiteral("constituencyGroupMnisId", constituencyId);
            Uri houseSeatUri = IdRetrieval.GetSubject(seatSparql.ToString(), false, logger);

            if (houseSeatUri != null)
            {
                incumbency.SeatIncumbencyHasHouseSeat = new HouseSeat()
                {
                    Id = houseSeatUri
                }
            }
            ;

            return(new BaseResource[] { incumbency });
        }
Ejemplo n.º 11
0
        private GenderIdentity generateGenderIdentity(string currentGenderText)
        {
            GenderIdentity genderIdentity = new GenderIdentity();
            Gender         gender         = new Gender();

            genderIdentity.Id = GenerateNewId();
            gender.Id         = IdRetrieval.GetSubject("genderMnisId", currentGenderText, false, logger);
            genderIdentity.GenderIdentityHasGender = gender;
            return(genderIdentity);
        }
Ejemplo n.º 12
0
        public override BaseResource[] TransformSource(XDocument doc)
        {
            MnisAnsweringBody answeringBody = new MnisAnsweringBody();
            XElement          element       = doc.Descendants(m + "properties").SingleOrDefault();

            answeringBody.AnsweringBodyMnisId = element.Element(d + "AnsweringBody_Id").GetText();

            string GroupHasNameSparqlCommand = @"                
                construct {
                    ?answeringBody parl:groupName ?name.
                }
                where {
                    ?answeringBody 
                        parl:answeringBodyMnisId @id;
                        parl:groupName ?name;
                    .
                }";
            SparqlParameterizedString sparql = new SparqlParameterizedString(GroupHasNameSparqlCommand);

            sparql.SetLiteral("id", answeringBody.AnsweringBodyMnisId);
            sparql.Namespaces.AddNamespace("parl", new Uri(schemaNamespace));

            var  groupNameGraph = GraphRetrieval.GetGraph(sparql.ToString(), logger);
            bool groupHasNoName = groupNameGraph.IsEmpty;

            if (groupHasNoName == true)
            {
                answeringBody.GroupName = element.Element(d + "Name").GetText();
            }
            else
            {
                var currentName = groupNameGraph.GetTriplesWithPredicate(new Uri("https://id.parliament.uk/schema/groupName")).FirstOrDefault().Object.ToString();
                answeringBody.GroupName = currentName;
            }

            string departmentId = element.Element(d + "Department_Id").GetText();

            if (string.IsNullOrWhiteSpace(departmentId) == false)
            {
                Uri departmentUri = IdRetrieval.GetSubject("mnisDepartmentId", departmentId, false, logger);
                if (departmentUri != null)
                {
                    answeringBody.Id = departmentUri;
                }
                else
                {
                    logger.Warning($"Department ({departmentId}) not found for Answering Body ({answeringBody.AnsweringBodyMnisId})");
                    return(null);
                }
            }

            return(new BaseResource[] { answeringBody });
        }
Ejemplo n.º 13
0
        private ParliamentPeriod generateSeatIncumbencyParliamentPeriod(DateTimeOffset startDate, DateTimeOffset?endDate)
        {
            string sparqlCommand             = @"
        construct {
            ?parliamentPeriod a parl:ParliamentPeriod.
        }where { 
            ?parliamentPeriod parl:parliamentPeriodStartDate ?parliamentPeriodStartDate.
            optional {?parliamentPeriod parl:parliamentPeriodEndDate ?parliamentPeriodEndDate}
            bind(coalesce(?parliamentPeriodEndDate,@today) as ?endDate)
            filter ((?parliamentPeriodStartDate <= @startDate && ?endDate >= @startDate) ||
                    (?parliamentPeriodStartDate <= @endDate && ?endDate >= @endDate) ||
                    (?parliamentPeriodStartDate > @startDate && ?endDate < @endDate))
        }";
            SparqlParameterizedString sparql = new SparqlParameterizedString(sparqlCommand);

            sparql.Namespaces.AddNamespace("parl", new Uri(schemaNamespace));
            sparql.SetLiteral("startDate", startDate.ToString("yyyy-MM-dd+00:00"), new Uri("http://www.w3.org/2001/XMLSchema#date"));
            sparql.SetLiteral("endDate", endDate.HasValue ? endDate.Value.ToString("yyyy-MM-dd+00:00") : DateTime.UtcNow.ToString("yyyy-MM-dd+00:00"), new Uri("http://www.w3.org/2001/XMLSchema#date"));
            sparql.SetLiteral("today", DateTime.UtcNow.ToString("yyyy-MM-dd+00:00"), new Uri("http://www.w3.org/2001/XMLSchema#date"));
            Uri parliamentPeriodUri = null;

            try
            {
                parliamentPeriodUri = IdRetrieval.GetSubject(sparql.ToString(), false, logger);
            }
            catch (InvalidOperationException e)
            {
                if (e.Message == "Sequence contains more than one element")
                {
                    logger.Warning($"More than one parliamentary period found for incumbency {startDate}-{endDate}");
                }
                else
                {
                    logger.Exception(e);
                }
            }
            if (parliamentPeriodUri != null)
            {
                return(new ParliamentPeriod()
                {
                    Id = parliamentPeriodUri
                });
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 14
0
        private BaseResource[] generateModerations(DateTime?openedAt, DateTime?rejectedAt, Rejection sourceRejection)
        {
            List <BaseResource> moderations = new List <BaseResource>();

            if (openedAt.HasValue)
            {
                Approval approval = new Approval();
                approval.Id         = GenerateNewId();
                approval.ApprovedAt = openedAt;
                moderations.Add(approval);
            }
            if (rejectedAt.HasValue)
            {
                Parliament.Model.Rejection rejection = new Parliament.Model.Rejection();
                rejection.Id               = GenerateNewId();
                rejection.RejectedAt       = rejectedAt;
                rejection.RejectionDetails = DeserializerHelper.GiveMeSingleTextValue(sourceRejection.details);
                if (string.IsNullOrWhiteSpace(sourceRejection.code) == false)
                {
                    Uri rejectionCodeUri = IdRetrieval.GetSubject("rejectionCodeName", sourceRejection.code, false, logger);
                    if (rejectionCodeUri != null)
                    {
                        rejection.RejectionHasRejectionCode = new RejectionCode()
                        {
                            Id = rejectionCodeUri
                        }
                    }
                    ;
                    else
                    {
                        logger.Warning($"Found rejected petition with a rejection code not currently supported - {sourceRejection.code}");
                    }
                }
                else
                {
                    logger.Warning("Found rejected petition with no rejection code");
                }
                moderations.Add(rejection);
            }
            return(moderations.ToArray());
        }
Ejemplo n.º 15
0
        private ParliamentaryIncumbency generateIncumbency(XElement contactPointElement)
        {
            ParliamentaryIncumbency incumbency = null;
            string incumbencyCommand           = @"
        construct {
            ?id a parl:ParliamentaryIncumbency.
        }
        where {
            ?id parl:parliamentaryIncumbencyHasMember ?parliamentaryIncumbencyHasMember;
                parl:parliamentaryIncumbencyStartDate ?parliamentaryIncumbencyStartDate.
            ?parliamentaryIncumbencyHasMember parl:memberMnisId @memberMnisId.
        } order by desc(?parliamentaryIncumbencyStartDate) limit 1";
            Uri    incumbencyUri;

            string mnisId = contactPointElement.Element(d + "Member_Id").GetText();

            if (string.IsNullOrWhiteSpace(mnisId))
            {
                logger.Warning("No member info found");
                return(null);
            }
            SparqlParameterizedString incumbencySparql = new SparqlParameterizedString(incumbencyCommand);

            incumbencySparql.Namespaces.AddNamespace("parl", new Uri(schemaNamespace));
            incumbencySparql.SetLiteral("memberMnisId", mnisId);
            incumbencyUri = IdRetrieval.GetSubject(incumbencySparql.ToString(), false, logger);
            if (incumbencyUri != null)
            {
                incumbency = new ParliamentaryIncumbency()
                {
                    Id = incumbencyUri
                }
            }
            ;
            else
            {
                logger.Verbose("No contact found");
            }

            return(incumbency);
        }
Ejemplo n.º 16
0
        private LocatedSignatureCount[] generateInternationalAreasSignatures(Signatures_By_Country[] signaturesByCountry, DateTime petitionRetrievalTimestamp)
        {
            List <LocatedSignatureCount> signatures  = new List <LocatedSignatureCount>();
            Dictionary <string, string>  countries   = IdRetrieval.GetSubjectsDictionary("countryGovRegisterId", logger);
            Dictionary <string, string>  territories = IdRetrieval.GetSubjectsDictionary("territoryGovRegisterId", logger);

            foreach (Signatures_By_Country country in signaturesByCountry)
            {
                LocatedSignatureCount locatedSignatureCount = new LocatedSignatureCount();
                locatedSignatureCount.SignatureCount            = DeserializerHelper.GiveMeSingleIntegerValue(country.signature_count);
                locatedSignatureCount.SignatureCountRetrievedAt = DeserializerHelper.GiveMeSingleDateValue(petitionRetrievalTimestamp);
                Place place = null;
                if (territories.ContainsKey(country.code))
                {
                    place = new Place()
                    {
                        Id = new Uri(territories[country.code])
                    }
                }
                ;
                else
                if (countries.ContainsKey(country.code))
                {
                    place = new Place()
                    {
                        Id = new Uri(countries[country.code])
                    }
                }
                ;
                if (place != null)
                {
                    locatedSignatureCount.LocatedSignatureCountHasPlace = place;
                    signatures.Add(locatedSignatureCount);
                }
                else
                {
                    logger.Warning($"Found signature on petition without matching international area code - {country.code}");
                }
            }
            return(signatures.ToArray());
        }
Ejemplo n.º 17
0
        private AnsweringBodyAllocation giveMeCorrectingAnsweringBodyAllocation(Response data, Uri questionId)
        {
            AnsweringBodyAllocation answeringBodyAllocation = null;

            if (data.CorrectingAnsweringDeptSesId != null)
            {
                Uri answeringBodyId = IdRetrieval.GetSubject("sesId", data.CorrectingAnsweringDeptSesId, false, logger);
                if (answeringBodyId != null)
                {
                    string command = @"
                        construct{
                            ?question parl:questionHasAnsweringBodyAllocation ?questionHasAnsweringBodyAllocation.
                        }
                        where{
                            bind(@question as ?question)
                            ?question parl:questionHasAnsweringBodyAllocation ?questionHasAnsweringBodyAllocation.
                            ?questionHasAnsweringBodyAllocation parl:answeringBodyAllocationHasAnsweringBody @answeringBody.
                        }";
                    SparqlParameterizedString sparql = new SparqlParameterizedString(command);
                    sparql.Namespaces.AddNamespace("parl", new Uri(schemaNamespace));
                    sparql.SetUri("question", questionId);
                    sparql.SetUri("answeringBody", answeringBodyId);
                    IGraph graph = GraphRetrieval.GetGraph(sparql.ToString(), logger, "true");
                    answeringBodyAllocation = new AnsweringBodyAllocation()
                    {
                        Id = graph.IsEmpty ? GenerateNewId() : (graph.Triples.SingleOrDefault().Object as IUriNode).Uri,
                        AnsweringBodyAllocationHasAnsweringBody = new AnsweringBody()
                        {
                            Id = answeringBodyId
                        }
                    };
                }
                else
                {
                    logger.Warning($"Answering body with Ses Id ({data.CorrectingAnsweringDeptSesId}) not found");
                }
            }

            return(answeringBodyAllocation);
        }
Ejemplo n.º 18
0
        public override BaseResource[] TransformSource(XDocument doc)
        {
            XElement governmentIncumbencyElement = doc.Element(atom + "entry")
                                                   .Element(atom + "content")
                                                   .Element(m + "properties");

            Incumbency incumbency = new Incumbency();

            incumbency.GovernmentIncumbencyMnisId = governmentIncumbencyElement.Element(d + "MemberGovernmentPost_Id").GetText();
            incumbency.IncumbencyStartDate        = governmentIncumbencyElement.Element(d + "StartDate").GetDate();
            string governmentPostMnisId = governmentIncumbencyElement.Element(d + "GovernmentPost_Id").GetText();
            Uri    governmentPostUri    = IdRetrieval.GetSubject("governmentPositionMnisId", governmentPostMnisId, false, logger);

            if (governmentPostUri == null)
            {
                logger.Warning($"No government position found for {governmentPostMnisId}");
                return(null);
            }
            incumbency.GovernmentIncumbencyHasGovernmentPosition = new GovernmentPosition()
            {
                Id = governmentPostUri
            };
            string memberId  = governmentIncumbencyElement.Element(d + "Member_Id").GetText();
            Uri    memberUri = IdRetrieval.GetSubject("memberMnisId", memberId, false, logger);

            if (memberUri == null)
            {
                logger.Warning($"No member found for {memberId}");
                return(null);
            }
            incumbency.GovernmentIncumbencyHasGovernmentPerson = new GovernmentPerson()
            {
                Id = memberUri
            };
            incumbency.IncumbencyEndDate = governmentIncumbencyElement.Element(d + "EndDate").GetDate();

            return(new BaseResource[] { incumbency });
        }
Ejemplo n.º 19
0
        public override BaseResource[] TransformSource(XDocument doc)
        {
            MnisGovernmentPosition governmentPosition = new MnisGovernmentPosition();
            XElement element = doc.Descendants(d + "GovernmentPost_Id").SingleOrDefault();

            if ((element == null) || (element.Parent == null))
            {
                return(null);
            }

            XElement elementPosition = element.Parent;

            governmentPosition.GovernmentPositionMnisId = elementPosition.Element(d + "GovernmentPost_Id").GetText();
            governmentPosition.PositionName             = elementPosition.Element(d + "Name").GetText();
            List <Group> groups = new List <Group>();

            foreach (XElement elementLoop in doc.Descendants(d + "Department_Id"))
            {
                if ((elementLoop != null) && (elementLoop.Parent != null))
                {
                    XElement departmentElement = elementLoop.Parent;
                    string   departmentId      = departmentElement.Element(d + "Department_Id").GetText();
                    if (string.IsNullOrWhiteSpace(departmentId) == false)
                    {
                        Uri departmentUri = IdRetrieval.GetSubject("mnisDepartmentId", departmentId, false, logger);
                        if (departmentUri != null)
                        {
                            groups.Add(new Group()
                            {
                                Id = departmentUri
                            });
                        }
                    }
                }
            }
            governmentPosition.PositionHasGroup = groups;
            return(new BaseResource[] { governmentPosition });
        }
Ejemplo n.º 20
0
        public override BaseResource[] TransformSource(XDocument doc)
        {
            XElement oppositionIncumbencyElement = doc.Element(atom + "entry")
                                                   .Element(atom + "content")
                                                   .Element(m + "properties");

            Incumbency oppositionIncumbency = new Incumbency();

            oppositionIncumbency.OppositionIncumbencyMnisId = oppositionIncumbencyElement.Element(d + "MemberOppositionPost_Id").GetText();
            oppositionIncumbency.IncumbencyStartDate        = oppositionIncumbencyElement.Element(d + "StartDate").GetDate();
            string oppositionPositionMnisId = oppositionIncumbencyElement.Element(d + "OppositionPost_Id").GetText();
            Uri    oppositionPostUri        = IdRetrieval.GetSubject("oppositionPositionMnisId", oppositionPositionMnisId, false, logger);

            if (oppositionPostUri == null)
            {
                logger.Warning($"No opposition position found for {oppositionPositionMnisId}");
                return(null);
            }
            oppositionIncumbency.OppositionIncumbencyHasOppositionPosition = new OppositionPosition()
            {
                Id = oppositionPostUri
            };
            string memberId  = oppositionIncumbencyElement.Element(d + "Member_Id").GetText();
            Uri    memberUri = IdRetrieval.GetSubject("memberMnisId", memberId, false, logger);

            if (memberUri == null)
            {
                logger.Warning($"No member found for {memberId}");
                return(null);
            }
            oppositionIncumbency.OppositionIncumbencyHasOppositionPerson = new OppositionPerson()
            {
                Id = memberUri
            };
            oppositionIncumbency.IncumbencyEndDate = oppositionIncumbencyElement.Element(d + "EndDate").GetDate();

            return(new BaseResource[] { oppositionIncumbency, });
        }
Ejemplo n.º 21
0
        public override BaseResource[] TransformSource(XDocument doc)
        {
            PartyMembership partyMembership = new PartyMembership();
            XElement        partyElement    = doc.Element(atom + "entry")
                                              .Element(atom + "content")
                                              .Element(m + "properties");

            string partyId  = partyElement.Element(d + "Party_Id").GetText();
            Uri    partyUri = IdRetrieval.GetSubject("partyMnisId", partyId, false, logger);

            if (partyUri == null)
            {
                logger.Warning($"No party found for {partyId}");
                return(null);
            }
            partyMembership.PartyMembershipHasParty = new Party()
            {
                Id = partyUri
            };
            string memberId  = partyElement.Element(d + "Member_Id").GetText();
            Uri    memberUri = IdRetrieval.GetSubject("memberMnisId", memberId, false, logger);

            if (memberUri == null)
            {
                logger.Warning($"No member found for {memberId}");
                return(null);
            }
            partyMembership.PartyMembershipHasPartyMember = new PartyMember()
            {
                Id = memberUri
            };
            partyMembership.PartyMembershipStartDate = partyElement.Element(d + "StartDate").GetDate();
            partyMembership.PartyMembershipEndDate   = partyElement.Element(d + "EndDate").GetDate();
            partyMembership.PartyMembershipMnisId    = partyElement.Element(d + "MemberParty_Id").GetText();

            return(new BaseResource[] { partyMembership });
        }
Ejemplo n.º 22
0
        private void generateMembershipMember(FormalBodyMembership formalBodyMembership,
                                              XElement formalBodyElement)
        {
            string memberMnisId = formalBodyElement.Element(d + "Member_Id").GetText();

            if (string.IsNullOrWhiteSpace(memberMnisId) == false)
            {
                Uri personUri = IdRetrieval.GetSubject("memberMnisId", memberMnisId, false, logger);
                if (personUri != null)
                {
                    if (formalBodyElement.Element(d + "ExOfficio").GetBoolean() == true)
                    {
                        formalBodyMembership.ExOfficioMembershipHasMember = new Member()
                        {
                            Id = personUri
                        }
                    }
                    ;
                    else
                    {
                        formalBodyMembership.FormalBodyMembershipHasPerson = new Person()
                        {
                            Id = personUri
                        }
                    };
                }
                else
                {
                    logger.Warning($"No member found for id {memberMnisId}");
                }
            }
            else
            {
                logger.Warning("No member data");
            }
        }
Ejemplo n.º 23
0
        private ThresholdAttainment[] generateThresholdAttainments(DateTime?moderatedAt, DateTime?respondedAt, DateTime?debatedAt)
        {
            List <ThresholdAttainment>  thresholdAttainments = new List <ThresholdAttainment>();
            Dictionary <string, string> thresholds           = IdRetrieval.GetSubjectsDictionary("thresholdName", logger);

            foreach (KeyValuePair <string, string> threshold in thresholds)
            {
                DateTime?timestamp = null;
                switch (threshold.Key.ToLower())
                {
                case "moderation":
                    timestamp = moderatedAt;
                    break;

                case "response":
                    timestamp = respondedAt;
                    break;

                case "debate":
                    timestamp = debatedAt;
                    break;
                }
                if (timestamp.HasValue)
                {
                    ThresholdAttainment thresholdAttainment = new ThresholdAttainment();
                    thresholdAttainment.Id = GenerateNewId();
                    thresholdAttainment.ThresholdAttainmentAt           = timestamp;
                    thresholdAttainment.ThresholdAttainmentHasThreshold = new Threshold()
                    {
                        Id = new Uri(threshold.Value)
                    };
                    thresholdAttainments.Add(thresholdAttainment);
                }
            }
            return(thresholdAttainments.ToArray());
        }
Ejemplo n.º 24
0
        public override BaseResource[] TransformSource(XDocument doc)
        {
            var questionElements = doc?.Element("response")?.Element("result")?.Element("doc")?.Elements("arr")?.ToList();

            if (questionElements == null)
            {
                return(null);
            }
            Response data = new Response();

            data.QuestionUri = FindXElementByAttributeName(questionElements, "correctedItem_uri", "str").GetText();
            if (data.QuestionUri == null)
            {
                data.QuestionUri = FindXElementByAttributeName(questionElements, "correctedItem_t", "str").GetText();
            }
            questionUriText = data.QuestionUri;
            data.CorrectingAnsweringDeptSesId   = FindXElementByAttributeName(questionElements, "answeringDept_ses", "int").GetText();
            data.CorrectingAnsweringMemberSesId = FindXElementByAttributeName(questionElements, "correctingMember_ses", "int").GetText();
            data.CorrectingAnswerText           = FindXElementByAttributeName(questionElements, "content_t", "str").GetText();

            var dateElements = doc.Element("response").Element("result").Element("doc").Elements("date").ToList();

            data.CorrectingDateOfAnswer = dateElements.Where(x => x.Attribute("name").Value == "date_dt").FirstOrDefault().GetDate();

            CorrectingAnswer correctingAnswer = new CorrectingAnswer();

            correctingAnswer.Id              = GenerateNewId();
            correctingAnswer.AnswerText      = new string[] { data.CorrectingAnswerText };
            correctingAnswer.AnswerGivenDate = data.CorrectingDateOfAnswer;
            if (string.IsNullOrWhiteSpace(data.CorrectingAnsweringMemberSesId))
            {
                logger.Warning("No information about correcting minister");
            }
            else
            {
                Uri ministerId = GetMemberId(data.CorrectingAnsweringMemberSesId, data.CorrectingDateOfAnswer, logger);

                if (ministerId != null)
                {
                    correctingAnswer.AnswerHasAnsweringPerson = new Person[]
                    {
                        new Person()
                        {
                            Id = ministerId
                        }
                    }
                }
                ;
                else
                {
                    logger.Warning($"Minister with Ses Id ({data.CorrectingAnsweringMemberSesId}) not found");
                }
            }
            Uri questionId = IdRetrieval.GetSubject("indexingAndSearchUri", data.QuestionUri, false, logger);

            Question question = null;

            if (questionId != null)
            {
                question = new Question()
                {
                    Id = questionId
                };
                correctingAnswer.CorrectingAnswerHasQuestion = new Question[] { question };
            }
            else
            {
                logger.Warning($"Question with Uri ({data.QuestionUri}) not found");
                return(null);
            }

            Answer originalAnswer = giveMeOriginalAnswer(questionId);

            if (originalAnswer != null)
            {
                correctingAnswer.AnswerReplacesAnswer = originalAnswer;
            }
            else
            {
                logger.Warning($"No answer found to replace for question with Uri ({data.QuestionUri})");
                return(null);
            }

            AnsweringBodyAllocation correctingAnsweringBodyAllocation = giveMeCorrectingAnsweringBodyAllocation(data, questionId);

            if (correctingAnsweringBodyAllocation != null)
            {
                question.QuestionHasAnsweringBodyAllocation = new AnsweringBodyAllocation[] { correctingAnsweringBodyAllocation };
                correctingAnsweringBodyAllocation.AnsweringBodyAllocationHasAnsweringBody.AnsweringBodyHasWrittenAnswer
                    = new WrittenAnswer[] { new WrittenAnswer()
                                            {
                                                Id = correctingAnswer.Id
                                            } };
            }
            else
            {
                return(null);
            }

            IndexingAndSearchThing iast = new IndexingAndSearchThing();
            var uriElements             = doc.Element("response").Element("result").Element("doc").Elements("str").ToList();

            iast.IndexingAndSearchUri = new String[] { uriElements.Where(x => x.Attribute("name").Value == "uri").FirstOrDefault().GetText() };

            return(new BaseResource[] { correctingAnswer, iast });
        }
Ejemplo n.º 25
0
        public override BaseResource[] TransformSource(JObject jsonResponse)
        {
            MemberImage memberImage      = new MemberImage();
            string      imageResourceUri = ((JValue)jsonResponse.SelectToken("ImageResourceUri")).GetText();

            if (string.IsNullOrWhiteSpace(imageResourceUri))
            {
                logger.Warning("No image resource uri info found");
                return(null);
            }
            memberImage.Id = new Uri($"{idNamespace}{imageResourceUri}");

            bool?photoTakenDown = ((JValue)jsonResponse.SelectToken("Photo_x0020_Taken_x0020_Down")).GetBoolean();

            if (photoTakenDown == true)
            {
                logger.Verbose("Image information marked as removed");
                return(new BaseResource[] { memberImage });
            }

            var mnisId = ((JValue)jsonResponse.SelectToken("Person_x0020_MnisId"))?.Value;

            if (mnisId == null)
            {
                logger.Warning("No member info found");
                return(null);
            }

            string mnisIdStr = Convert.ToInt32(Convert.ToDouble(mnisId)).ToString();

            Uri personUri = IdRetrieval.GetSubject("memberMnisId", mnisIdStr, false, logger);

            if (personUri != null)
            {
                memberImage.MemberImageHasMember = new List <Member>
                {
                    new Member()
                    {
                        Id = personUri
                    }
                };
            }
            else
            {
                logger.Warning("No person found");
            }

            var midX = ((JValue)jsonResponse.SelectToken("MidX"))?.Value;
            var midY = ((JValue)jsonResponse.SelectToken("MidY"))?.Value;

            if (midX == null || midY == null)
            {
                logger.Warning("No MidX or MidY info found");
                return(null);
            }
            string midXStr = Convert.ToInt32(Convert.ToDouble(midX)).ToString();
            string midYStr = Convert.ToInt32(Convert.ToDouble(midY)).ToString();

            memberImage.PersonImageFaceCentrePoint = new List <string>
            {
                string.Format("POINT({0} {1})", midXStr, midYStr)
            };

            return(new BaseResource[] { memberImage });
        }