public static string GetChangeSummary(CatalogRecord record, CatalogRecordMethodsViewModel model)
        {
            var builder = new StringBuilder();

            ManagedFileChangeDetector.CheckProperty("Research Design", record.ResearchDesign, model.ResearchDesign, builder);
            ManagedFileChangeDetector.CheckProperty("Mode of Data Collection", record.ModeOfDataCollection, model.ModeOfDataCollection, builder);
            ManagedFileChangeDetector.CheckProperty("Field Dates", record.FieldDates, JsonConvert.SerializeObject(model.FieldDates), builder);
            ManagedFileChangeDetector.CheckProperty("Study Time Period", record.StudyTimePeriod, JsonConvert.SerializeObject(model.StudyTimePeriod), builder);
            ManagedFileChangeDetector.CheckProperty("Location", record.Location, model.Location, builder);
            ManagedFileChangeDetector.CheckProperty("Location Details", record.LocationDetails, model.LocationDetails, builder);
            ManagedFileChangeDetector.CheckProperty("Unit of Observation", record.UnitOfObservation, model.UnitOfObservation, builder);
            ManagedFileChangeDetector.CheckProperty("Sample Size", record.SampleSize, model.SampleSize, builder);
            ManagedFileChangeDetector.CheckProperty("Inclusion / Exclusion Criteria", record.InclusionExclusionCriteria, model.InclusionExclusionCriteria, builder);
            ManagedFileChangeDetector.CheckProperty("Randomization Procedure", record.RandomizationProcedure, model.RandomizationProcedure, builder);
            ManagedFileChangeDetector.CheckProperty("Unit of Randomization", record.UnitOfObservation, model.UnitOfObservation, builder);
            ManagedFileChangeDetector.CheckProperty("Treatment", record.Treatment, model.Treatment, builder);
            ManagedFileChangeDetector.CheckProperty("Treatment Administration", record.TreatmentAdministration, model.TreatmentAdministration, builder);
            ManagedFileChangeDetector.CheckProperty("Outcome Measures", record.OutcomeMeasures, model.OutcomeMeasures, builder);
            ManagedFileChangeDetector.CheckProperty("Data Type", record.DataType, model.CatalogRecordDataType, builder);
            ManagedFileChangeDetector.CheckProperty("Data Source", record.DataSource, model.CatalogRecordDataSource, builder);
            ManagedFileChangeDetector.CheckProperty("Data Source Information", record.DataSourceInformation, model.CatalogRecordDataSourceInformation, builder);

            return(builder.ToString());
        }
Esempio n. 2
0
        public ActionResult Records()
        {
            var logger = LogManager.GetLogger("Curation");

            logger.Debug("Entering Records()");

            logger.Debug("Creating XML root");
            var root = new XElement("publishedCatalogRecords");

            logger.Debug("Opening DB context");
            using (var db = ApplicationDbContext.Create())
            {
                var org = OrganizationHelper.GetOrganizationByHost(Request, db);
                if (org == null)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }

                // Get all published records.
                logger.Debug("Getting published records");
                var publishedRecords = db.CatalogRecords
                                       .Where(x => x.Organization.Id == org.Id)
                                       .Where(x => x.Status == CatalogRecordStatus.Published)
                                       .Include(x => x.Authors)
                                       .Include(x => x.Files);

                int i = 1;
                foreach (var record in publishedRecords)
                {
                    logger.Debug($"Writing record {i++}");

                    // Create an element for this record.
                    var recordElement = new XElement("Record");
                    root.Add(recordElement);

                    // Add all the properties to the XML.
                    recordElement.Add(new XElement("Guid", record.Id));
                    recordElement.Add(new XElement("Title", record.Title));
                    recordElement.Add(new XElement("Author", record.AuthorsText));

                    if (!string.IsNullOrWhiteSpace(record.Owner?.FullName))
                    {
                        recordElement.Add(new XElement("Owner", record.Owner.FullName));
                    }
                    else
                    {
                        recordElement.Add(new XElement("Owner", record.OwnerText));
                    }

                    recordElement.Add(new XElement("Description", record.Description));
                    recordElement.Add(new XElement("StudyID", record.Number));
                    recordElement.Add(new XElement("StudyIDLower", record.Number?.ToLower()));
                    recordElement.Add(new XElement("RelatedPublication", record.RelatedPublications));
                    recordElement.Add(new XElement("RelatedProject", record.RelatedProjects));
                    recordElement.Add(new XElement("RelatedDatabase", record.RelatedDatabase));
                    recordElement.Add(new XElement("keywords", record.Keywords));
                    recordElement.Add(new XElement("CreateDate", record.CreatedDate));
                    recordElement.Add(new XElement("ResearchDesign", record.ResearchDesign));

                    CatalogRecordMethodsViewModel.GetConcatenatedDataProperties(record, out string dataType, out string dataSource, out string dataSourceInformation);
                    recordElement.Add(new XElement("DataType", dataType));
                    recordElement.Add(new XElement("DataSource", dataSource));
                    recordElement.Add(new XElement("DataSourceInformation", dataSourceInformation));

                    // Show information from the catalog record independently.
                    recordElement.Add(new XElement("CatalogRecordDataType", record.DataType));
                    recordElement.Add(new XElement("CatalogRecordDataSource", record.DataSource));
                    recordElement.Add(new XElement("CatalogRecordDataSourceInformation", record.DataSourceInformation));

                    if (!string.IsNullOrWhiteSpace(record.PersistentId))
                    {
                        string pid = record.PersistentId;
                        if (!pid.StartsWith("http"))
                        {
                            pid = "http://hdl.handle.net/" + pid;
                        }

                        recordElement.Add(new XElement("PersistentId", pid));
                    }
                    else
                    {
                        recordElement.Add(new XElement("PersistentId", string.Empty));
                    }

                    bool hasFieldDates = false;
                    if (!string.IsNullOrWhiteSpace(record.FieldDates))
                    {
                        var fieldDatesModel = JsonConvert.DeserializeObject <DateModel>(record.FieldDates);
                        if (fieldDatesModel != null)
                        {
                            hasFieldDates = true;

                            if (fieldDatesModel.isRange)
                            {
                                recordElement.Add(new XElement("FieldDates", $"{fieldDatesModel.date} - {fieldDatesModel.endDate}"));
                            }
                            else
                            {
                                recordElement.Add(new XElement("FieldDates", fieldDatesModel.date));
                            }
                        }
                    }
                    if (!hasFieldDates)
                    {
                        recordElement.Add(new XElement("FieldDates", string.Empty));
                    }

                    recordElement.Add(new XElement("Location", record.Location));
                    recordElement.Add(new XElement("LocationDetails", record.LocationDetails));
                    recordElement.Add(new XElement("UnitOfObservation", record.UnitOfObservation));
                    recordElement.Add(new XElement("SampleSize", record.SampleSize));
                    recordElement.Add(new XElement("InclusionExclusionCriteria", record.InclusionExclusionCriteria));
                    recordElement.Add(new XElement("RandomizedProcedure", record.RandomizationProcedure));
                    recordElement.Add(new XElement("Treatment", record.Treatment));
                    recordElement.Add(new XElement("TreatmentAdministration", record.TreatmentAdministration));
                    recordElement.Add(new XElement("OutcomeMeasures", record.OutcomeMeasures));
                    recordElement.Add(new XElement("ArchiveDate", record.ArchiveDate));
                    var fileElement = new XElement("FileElement");

                    int f = 1;
                    foreach (var file in record.Files)
                    {
                        logger.Debug($"Writing file {f++}");

                        if (string.IsNullOrWhiteSpace(file.Number))
                        {
                            continue;
                        }

                        var fileinfo = new XElement("File");
                        fileinfo.Add(new XElement("id", file.Id));
                        fileinfo.Add(new XElement("FileSize", file.Size));

                        string fileUrl = file.PersistentLink;
                        if (!string.IsNullOrWhiteSpace(fileUrl))
                        {
                            if (!fileUrl.StartsWith("http"))
                            {
                                fileUrl = "http://hdl.handle.net/" + fileUrl;
                            }
                            fileinfo.Add(new XElement("FileUrl", fileUrl));
                        }
                        else
                        {
                            fileinfo.Add(new XElement("FileUrl", string.Empty));
                        }

                        fileinfo.Add(new XElement("FileNumber", file.Number));
                        fileinfo.Add(new XElement("FileDescription", file.Title));
                        fileinfo.Add(new XElement("FileFormat", file.FormatName));
                        fileinfo.Add(new XElement("PublicFile", file.IsPublicAccess ? "1" : "0"));
                        fileinfo.Add(new XElement("CatalogRecordId", record.Number));
                        fileElement.Add(fileinfo);
                    }

                    recordElement.Add(fileElement);
                }
            }

            // Write the XML to the web response.
            logger.Debug("Writing XML");

            XDocument document = new XDocument(root);
            string    xmlStr   = document.Root.ToString();

            return(Content(xmlStr, "text/xml"));

            logger.Debug("Leaving Records()");
        }