context: // Copyright (c) The University of Dundee 2018-2019
  // This file is part of the Research Data Management Platform (RDMP).
  // RDMP is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  // RDMP is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  // You should have received a copy of the GNU General Public License along with RDMP. If not, see <https://www.gnu.org/licenses/>.
  
  using System;
  using System.Collections.Generic;
  using System.Data.Common;
  using System.IO;
  using System.Linq;
  using System.Text;
  using FAnsi;
  using FAnsi.Discovery;
  using FAnsi.Discovery.QuerySyntax;
  using MapsDirectlyToDatabaseTable;
  using MapsDirectlyToDatabaseTable.Attributes;
  using MapsDirectlyToDatabaseTable.Injection;
  using Rdmp.Core.CohortCreation.Execution;
  using Rdmp.Core.Curation.Data.Aggregation;
  using Rdmp.Core.Curation.Data.DataLoad;
  using Rdmp.Core.Curation.Data.Defaults;
  using Rdmp.Core.Curation.Data.ImportExport;
  using Rdmp.Core.Curation.Data.Serialization;
  using Rdmp.Core.Logging;
  using Rdmp.Core.QueryBuilding;
  using Rdmp.Core.Repositories;
  using Rdmp.Core.Ticketing;
  using ReusableLibraryCode;
  using ReusableLibraryCode.Annotations;
  using ReusableLibraryCode.Checks;
  using ReusableLibraryCode.DataAccess;
  
  namespace Rdmp.Core.Curation.Data
  {
      /// <inheritdoc cref="ICatalogue"/>
      public class Catalogue : DatabaseEntity, IComparable, ICatalogue, ICheckable, IInjectKnown<CatalogueItem[]>,IInjectKnown<CatalogueExtractabilityStatus>
      {
          #region Database Properties
          
          private string _acronym;
          private string _name;
          private CatalogueFolder _folder;
          private string _description;
          private Uri _detailPageUrl;
          private CatalogueType _type;
          private CataloguePeriodicity _periodicity;
          private CatalogueGranularity _granularity;
          private string _geographicalCoverage;
          private string _backgroundSummary;
          private string _searchKeywords;
          private string _updateFreq;
          private string _updateSched;
          private string _timeCoverage;
          private DateTime? _lastRevisionDate;
          private string _contactDetails;
          private string _resourceOwner;
          private string _attributionCitation;
          private string _accessOptions;
          private string _subjectNumbers;
          private Uri _apiAccessUrl;
          private Uri _browseUrl;
          private Uri _bulkDownloadUrl;
          private Uri _queryToolUrl;
          private Uri _sourceUrl;
          private string _countryOfOrigin;
  
  
          private string _dataStandards;
          private string _administrativeContactName;
          private string _administrativeContactEmail;
          private string _administrativeContactTelephone;
          private string _administrativeContactAddress;
          private bool? _explicitConsent;
          private string _ethicsApprover;
          private string _sourceOfDataCollection;
          private string _ticket;
          private DateTime? _datasetStartDate;
          private string _loggingDataTask;
          private string _validatorXml;
          private int? _timeCoverageExtractionInformationID;
          private int? _pivotCategoryExtractionInformationID;
          private bool _isDeprecated;
          private bool _isInternalDataset;
          private bool _isColdStorageDataset;
          private int? _liveLoggingServerID;
          
          private Lazy<CatalogueItem[]> _knownCatalogueItems;
          
          
          /// <inheritdoc/>
          [Unique]
          [DoNotImportDescriptions(AllowOverwriteIfBlank = true)]
          public string Acronym
          {
              get { return _acronym; }
              set { SetField(ref  _acronym, value); }
          }
  
          /// <summary>
          /// The full human readable name of the dataset.  This should usually match the name of the underlying <see cref="TableInfo"/> but might differ
          /// if there are multiple tables powering the Catalogue or they don't have user accessible names.
          /// </summary>
          [Unique]
          [NotNull]
          [DoNotImportDescriptions]
          public string Name
          {
              get { return _name; }
              set { SetField(ref  _name, value); }
          }
  
          /// <inheritdoc/>
          [DoNotImportDescriptions]
          [UsefulProperty]
          public CatalogueFolder Folder
          {
              get { return _folder; }
              set { SetField(ref  _folder, value); }
          }
           
          /// <inheritdoc/>
          public string Description
          {
              get { return _description; }
              set { SetField(ref  _description, value); }
          }
  
          /// <summary>
          /// User defined Uri for a website page which describes the dataset (probably null)
          /// </summary>
          public Uri Detail_Page_URL
          {
              get { return _detailPageUrl; }
              set { SetField(ref  _detailPageUrl, value); }
          }
  
          /// <summary>
          /// User defined classification of the Type of dataset the Catalogue is e.g. Cohort, ResearchStudy etc
          /// </summary>
          public CatalogueType Type
          {
              get { return _type; }
              set { SetField(ref  _type, value); }
          }
  
          /// <inheritdoc/>
          public CataloguePeriodicity Periodicity
          {
              get { return _periodicity; }
              set { SetField(ref  _periodicity, value); }
          }
  
          /// <summary>
          /// User specified field describing how the dataset is subdivided/bounded e.g. relates to a multiple 'HealthBoards' / 'Clinics' / 'Hosptials' etc.
          /// </summary>
          public CatalogueGranularity Granularity
          {
              get { return _granularity; }
              set { SetField(ref  _granularity, value); }
          }
  
          /// <summary>
          /// User specified free text field.  Not used for anything by RDMP.
          /// </summary>
          public string Geographical_coverage
          {
              get { return _geographicalCoverage; }
              set { SetField(ref  _geographicalCoverage, value); }
          }
  
          /// <summary>
          /// User specified free text field.  Not used for anything by RDMP.
          /// </summary>
          public string Background_summary
          {
              get { return _backgroundSummary; }
              set { SetField(ref  _backgroundSummary, value); }
          }
  
          /// <summary>
          /// User specified list of keywords that are intended to help in finding the Catalogue
          /// </summary>
          public string Search_keywords
          {
              get { return _searchKeywords; }
              set { SetField(ref  _searchKeywords, value); }
          }
  
          /// <summary>
          /// User specified free text field.  Not used for anything by RDMP.
          /// <seealso cref="Periodicity"/>
          /// </summary>
          public string Update_freq
          {
              get { return _updateFreq; }
              set { SetField(ref  _updateFreq, value); }
          }
  
          /// <summary>
          /// User specified free text field.  Not used for anything by RDMP.
          /// <seealso cref="Periodicity"/>
          /// </summary>
          public string Update_sched
          {
              get { return _updateSched; }
              set { SetField(ref  _updateSched, value); }
          }
  
  
          ///<inheritdoc/>
          public string Time_coverage
          {
              get { return _timeCoverage; }
              set { SetField(ref  _timeCoverage, value); }
          }
  
          /// <summary>
          /// User specified date that user alledgedly reviewed the contents of the Catalogue / Metadata
          /// </summary>
          public DateTime? Last_revision_date
          {
  
gt:             get { return _lastRevisionDate; }