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()); }
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()); }