예제 #1
0
        private async Task CreateLinksForE2BStepAsync(ReportInstance reportInstanceFromRepo, ReportInstanceDetailDto mappedReportInstance)
        {
            if (reportInstanceFromRepo.CurrentActivity.CurrentStatus.Description == "NOTGENERATED" ||
                reportInstanceFromRepo.CurrentActivity.CurrentStatus.Description == "E2BSUBMITTED")
            {
                mappedReportInstance.Links.Add(new LinkDto(_linkGeneratorService.CreateResourceUriForReportInstance("CreateE2BInstance",
                                                                                                                    reportInstanceFromRepo.WorkFlow.WorkFlowGuid, reportInstanceFromRepo.Id), "createe2b", "PUT"));
            }

            if (reportInstanceFromRepo.CurrentActivity.CurrentStatus.Description == "E2BINITIATED")
            {
                mappedReportInstance.Links.Add(new LinkDto(_linkGeneratorService.CreateResourceUriForReportInstance("UpdateReportInstanceStatus",
                                                                                                                    reportInstanceFromRepo.WorkFlow.WorkFlowGuid, reportInstanceFromRepo.Id), "preparereporte2b", "PUT"));

                var evt = reportInstanceFromRepo.CurrentActivity.ExecutionEvents
                          .OrderByDescending(ee => ee.EventDateTime)
                          .First(ee => ee.ExecutionStatus.Id == reportInstanceFromRepo.CurrentActivity.CurrentStatus.Id);
                var tag = (reportInstanceFromRepo.WorkFlow.Description == "New Active Surveilliance Report") ? "Active" : "Spontaneous";

                var datasetInstance = await _datasetInstanceRepository.GetAsync(di => di.Tag == tag && di.ContextId == evt.Id);

                if (datasetInstance != null)
                {
                    mappedReportInstance.Links.Add(new LinkDto(_linkGeneratorService.CreateUpdateDatasetInstanceResourceUri(datasetInstance.Dataset.Id, datasetInstance.Id), "updatee2b", "PUT"));
                }
            }

            if (reportInstanceFromRepo.CurrentActivity.CurrentStatus.Description == "E2BGENERATED")
            {
                mappedReportInstance.Links.Add(new LinkDto(_linkGeneratorService.CreateResourceUriForReportInstance("UpdateReportInstanceStatus",
                                                                                                                    reportInstanceFromRepo.WorkFlow.WorkFlowGuid, reportInstanceFromRepo.Id), "confirmsubmissione2b", "PUT"));

                var executionEvent = reportInstanceFromRepo.CurrentActivity.ExecutionEvents
                                     .OrderByDescending(ee => ee.EventDateTime)
                                     .First(ee => ee.ExecutionStatus.Description == "E2BGENERATED");
                if (executionEvent != null)
                {
                    var e2bAttachment = executionEvent.Attachments.SingleOrDefault(att => att.Description == "E2b");
                    if (e2bAttachment != null)
                    {
                        mappedReportInstance.Links.Add(new LinkDto(_linkGeneratorService.CreateDownloadActivitySingleAttachmentResourceUri(
                                                                       reportInstanceFromRepo.WorkFlow.WorkFlowGuid, reportInstanceFromRepo.Id, executionEvent.Id, e2bAttachment.Id), "downloadxml", "GET"));
                    }
                }
            }
        }