コード例 #1
0
        private Parliament.Model.Debate generateDebate(Debate sourceDebate, DateTime?scheduledDebateDate)
        {
            Parliament.Model.Debate debate = new Parliament.Model.Debate();
            debate.Id = GenerateNewId();
            debate.DebateProposedDate  = DeserializerHelper.GiveMeSingleDateValue(scheduledDebateDate);
            debate.DebateDate          = DeserializerHelper.GiveMeSingleDateValue(sourceDebate.debated_on);
            debate.DebateVideoUrl      = DeserializerHelper.GiveMeSingleTextValue(sourceDebate.video_url);
            debate.DebateTranscriptUrl = DeserializerHelper.GiveMeSingleTextValue(sourceDebate.transcript_url);
            debate.DebateOverview      = DeserializerHelper.GiveMeSingleTextValue(sourceDebate.overview);

            return(debate);
        }
コード例 #2
0
        public override BaseResource[] TransformSource(Rootobject sourceEPetition)
        {
            DateTime       petitionRetrievalTimestamp = DateTime.UtcNow;
            UkgapEPetition ukgapEPetition             = new UkgapEPetition();

            BaseResource[] moderations = null;
            if ((sourceEPetition != null) && (sourceEPetition.data != null) && (sourceEPetition.data.attributes != null))
            {
                ukgapEPetition.EPetitionUkgapId  = sourceEPetition.data.id.ToString();
                ukgapEPetition.CreatedAt         = DeserializerHelper.GiveMeSingleDateValue(sourceEPetition.data.attributes.created_at);
                ukgapEPetition.Background        = DeserializerHelper.GiveMeSingleTextValue(sourceEPetition.data.attributes.background);
                ukgapEPetition.AdditionalDetails = DeserializerHelper.GiveMeSingleTextValue(sourceEPetition.data.attributes.additional_details);
                ukgapEPetition.ClosedAt          = DeserializerHelper.GiveMeSingleDateValue(sourceEPetition.data.attributes.closed_at);
                ukgapEPetition.UpdatedAt         = DeserializerHelper.GiveMeSingleDateValue(sourceEPetition.data.attributes.updated_at);
                ukgapEPetition.Action            = DeserializerHelper.GiveMeSingleTextValue(sourceEPetition.data.attributes.action);
                if (sourceEPetition.data.attributes.government_response != null)
                {
                    GovernmentResponse governmentResponse = generateGovernmentResponse(sourceEPetition.data.attributes.government_response);
                    ukgapEPetition.EPetitionHasGovernmentResponse = new GovernmentResponse[] { governmentResponse };
                }
                if (sourceEPetition.data.attributes.debate != null)
                {
                    Parliament.Model.Debate debate = generateDebate(sourceEPetition.data.attributes.debate, sourceEPetition.data.attributes.scheduled_debate_date);
                    ukgapEPetition.EPetitionHasDebate = new Parliament.Model.Debate[] { debate };
                }
                moderations = generateModerations(sourceEPetition.data.attributes.open_at, sourceEPetition.data.attributes.rejected_at, sourceEPetition.data.attributes.rejection);
                ukgapEPetition.EPetitionHasThresholdAttainment = generateThresholdAttainments(sourceEPetition.data.attributes.moderation_threshold_reached_at, sourceEPetition.data.attributes.response_threshold_reached_at, sourceEPetition.data.attributes.debate_threshold_reached_at);
                List <LocatedSignatureCount> signatures = new List <LocatedSignatureCount>();
                if (sourceEPetition.data.attributes.signatures_by_country != null)
                {
                    signatures.AddRange(generateInternationalAreasSignatures(sourceEPetition.data.attributes.signatures_by_country, petitionRetrievalTimestamp));
                }
                if (sourceEPetition.data.attributes.signatures_by_constituency != null)
                {
                    signatures.AddRange(generateConstituencySignatures(sourceEPetition.data.attributes.signatures_by_constituency, petitionRetrievalTimestamp));
                }
                ukgapEPetition.EPetitionHasLocatedSignatureCount = signatures;
            }

            return(moderations.Concat(ukgapEPetition.AsEnumerable()).ToArray());
        }
コード例 #3
0
        public override BaseResource[] SynchronizeIds(BaseResource[] source, Uri subjectUri, BaseResource[] target)
        {
            UkgapEPetition ePetition = source.OfType <UkgapEPetition>().SingleOrDefault();

            ePetition.Id = subjectUri;

            GovernmentResponse governmentResponse = target.OfType <GovernmentResponse>().SingleOrDefault();

            if (governmentResponse != null)
            {
                ePetition.EPetitionHasGovernmentResponse.SingleOrDefault().Id = governmentResponse.Id;
            }
            Parliament.Model.Debate debate = target.OfType <Parliament.Model.Debate>().SingleOrDefault();
            if (debate != null)
            {
                ePetition.EPetitionHasDebate.SingleOrDefault().Id = debate.Id;
            }
            IEnumerable <Approval> approvals          = target.OfType <Approval>();
            List <Approval>        ePetitionApprovals = source.OfType <Approval>().ToList();

            foreach (Approval approval in approvals)
            {
                Approval foundModeration = ePetitionApprovals
                                           .SingleOrDefault(m => m.ApprovedAt == approval.ApprovedAt);
                if (foundModeration != null)
                {
                    foundModeration.Id = approval.Id;
                }
                else
                {
                    ePetitionApprovals.Add(approval);
                }
            }
            foreach (Approval approval in ePetitionApprovals)
            {
                approval.ApprovalHasApprovedEPetition = new ApprovedEPetition[]
                {
                    new ApprovedEPetition()
                    {
                        Id = subjectUri
                    }
                }
            }
            ;

            IEnumerable <Parliament.Model.Rejection> rejects             = target.OfType <Parliament.Model.Rejection>();
            List <Parliament.Model.Rejection>        ePetitionRejections = source.OfType <Parliament.Model.Rejection>().ToList();

            foreach (Parliament.Model.Rejection rejection in rejects)
            {
                Parliament.Model.Rejection foundModeration = ePetitionRejections
                                                             .SingleOrDefault(m => m.RejectedAt == rejection.RejectedAt);
                if (foundModeration != null)
                {
                    foundModeration.Id = rejection.Id;
                }
                else
                {
                    ePetitionRejections.Add(rejection);
                }
            }
            foreach (Parliament.Model.Rejection rejection in ePetitionRejections)
            {
                rejection.RejectionHasRejectedEPetition = new RejectedEPetition[]
                {
                    new RejectedEPetition()
                    {
                        Id = subjectUri
                    }
                }
            }
            ;

            IEnumerable <ThresholdAttainment> thresholdAttainments = target.OfType <ThresholdAttainment>();

            foreach (ThresholdAttainment thresholdAttainment in thresholdAttainments)
            {
                ThresholdAttainment foundThresholdAttainment = ePetition.EPetitionHasThresholdAttainment.SingleOrDefault(t => t.ThresholdAttainmentAt == thresholdAttainment.ThresholdAttainmentAt);
                if (foundThresholdAttainment != null)
                {
                    foundThresholdAttainment.Id = thresholdAttainment.Id;
                }
            }
            IEnumerable <LocatedSignatureCount> signatures = target.OfType <LocatedSignatureCount>();

            foreach (LocatedSignatureCount signature in signatures)
            {
                LocatedSignatureCount foundLocatedSignatureCount = ePetition.EPetitionHasLocatedSignatureCount
                                                                   .SingleOrDefault(s => s.LocatedSignatureCountHasPlace.Id == signature.LocatedSignatureCountHasPlace.Id);
                if (foundLocatedSignatureCount != null)
                {
                    foundLocatedSignatureCount.Id = signature.Id;
                    if (foundLocatedSignatureCount.SignatureCount.SingleOrDefault() == signature.SignatureCount.SingleOrDefault())
                    {
                        foundLocatedSignatureCount.SignatureCountRetrievedAt = signature.SignatureCountRetrievedAt;
                    }
                }
            }
            foreach (LocatedSignatureCount signature in ePetition.EPetitionHasLocatedSignatureCount.Where(s => s.Id == null))
            {
                signature.Id = GenerateNewId();
            }

            return(ePetitionApprovals.AsEnumerable <BaseResource>().Concat(ePetitionRejections).Concat(ePetition.AsEnumerable()).ToArray());
        }