public static XDocument ToXDocument(this DataManagementPlan entity) { if (entity == null) { return(null); } var doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XElement("dataManagementPlan")); Debug.Assert(doc.Root != null, "root is null"); doc.Root.Add( entity.GetPreExistingResearchData(), entity.GetNewResearchData(), entity.GetRelationshipBetweenNewAndPreExistingData(), entity.GetBackup(), entity.GetDocumentation(), entity.GetDataOrganisation(), entity.GetEthics(), entity.GetPrivacy(), entity.GetAccess(), entity.GetDataStorage(), entity.GetDataRetention(), entity.GetDataSharing()); return(doc); }
public void SetUp() { var files = Directory.GetFiles(Tempdir); Array.ForEach(files, File.Delete); _dmp = Builder <DataManagementPlan> .CreateNew() .With(o => o.BackupLocations = BackupLocations.MicrosoftSharePoint | BackupLocations.PersonalHardDrives | BackupLocations.InstitutionalBackup | BackupLocations.Other) .And(o => o.BackupPolicyResponsibilities = DataResponsibilities.Other | DataResponsibilities.PrincipalInvestigator) .And(o => o.IsSensitive = Pick <bool> .RandomItemFrom(new[] { false, true })) .And(o => o.CreationDate = DateTime.Now) .And(o => o.UrdmsUsers = Builder <UrdmsUser> .CreateListOfSize(5).Build()) .And(o => o.RelationshipBetweenExistingAndNewData = EnumValuesHelper.RandomItem(DataRelationship.None)) .And(o => o.DataRetentionLocations = DataRetentionLocations.External | DataRetentionLocations.Internal | DataRetentionLocations.Other) .And(o => o.DataRetentionPeriod = EnumValuesHelper.RandomItem(DataRetentionPeriod.Short)) .And(o => o.DataRetentionResponsibilities = DataResponsibilities.Other | DataResponsibilities.PrincipalInvestigator) .And(o => o.DepositToRepository = Pick <bool> .RandomItemFrom(new[] { false, true })) .And(o => o.DataSharingAvailability = DataSharingAvailability.AfterASpecifiedEmbargoPeriod) .And(o => o.DataSharingAvailabilityDate = DateTime.Today.AddYears(10)) .And(o => o.DataLicensingType = EnumValuesHelper.RandomItem <DataLicensingType>()) .And(o => o.ShareAccess = EnumValuesHelper.RandomItem(ShareAccess.None)) .And(o => o.InstitutionalStorageTypes = InstitutionalStorageTypes.ProjectStorageSpace | InstitutionalStorageTypes.PersonalNetworkDrive | InstitutionalStorageTypes.PersonalNetworkDrive | InstitutionalStorageTypes.Other) .And(o => o.ExternalStorageTypes = ExternalStorageTypes.DataFabric | ExternalStorageTypes.IvecPetabyte | ExternalStorageTypes.Other) .And(o => o.MaxDataSize = EnumValuesHelper.RandomItem(MaxDataSize.None)) .And(o => o.PersonalStorageTypes = PersonalStorageTypes.RemovableMedia | PersonalStorageTypes.InternalHardDrives | PersonalStorageTypes.Other) .And(o => o.VersionControl = EnumValuesHelper.RandomItem(VersionControl.None)) .And(o => o.EthicRequiresClearance = Pick <bool> .RandomItemFrom(new[] { false, true })) .And(o => o.ExistingDataAccessTypes = ExistingDataAccessTypes.DataIsFreelyAvailable | ExistingDataAccessTypes.ObtainApprovalFromOwner | ExistingDataAccessTypes.Other | ExistingDataAccessTypes.Purchase) .And(o => o.UseExistingData = Pick <bool> .RandomItemFrom(new[] { false, true })) .And(o => o.DataOwners = DataOwners.MyInstitution | DataOwners.Researcher | DataOwners.Other) .And(o => o.DataActionFrequency = EnumValuesHelper.RandomItem(DataActionFrequency.None)) .And(o => o.NonUrdmsUsers = Builder <User> .CreateListOfSize(4).Build()) .And(o => o.PricipalInvestigator = Pick <string> .RandomItemFrom(new[] { "John Doe", "Joe Bloggs", "Jane Doe", "John Smith" })) .And(o => o.ProjectTitle = Pick <string> .RandomItemFrom(new[] { "Feeding Habits of Polar Bears", "The Ecosystem in the Sahara Desert" })) .And(o => o.DateModified = DateTime.Now) .Build(); _dataManagementPlanRepository = Substitute.For <IDataManagementPlanRepository>(); _dataManagementPlanRepository.GetDataManagementPlanByProjectId(Arg.Is(ProjectId)).Returns(_dmp); _sharePointHelper = Substitute.For <ISharePointHelper>(); _pdfHelper = Substitute.For <IPdfHelper>(); _generatorHelper = Substitute.For <IGeneratorHelper>(); _xmlHelper = Substitute.For <IXmlHelper>(); _generator = new DmpGenerator(_sharePointHelper, _dataManagementPlanRepository, _pdfHelper, _generatorHelper, _xmlHelper); _projectRepository = Substitute.For <IProjectRepository>(); var projects = Builder <Project> .CreateListOfSize(2) .TheFirst(1) .With(o => o.SourceProjectType = EnumValuesHelper.RandomItem(SourceProjectType.None, SourceProjectType.DEPOSIT)) .TheNext(1) .With(o => o.SourceProjectType = SourceProjectType.DEPOSIT) .Build() .ToList(); _nonDepositProject = projects[0]; _depositProject = projects[1]; projects.ForEach(o => _projectRepository.Get(Arg.Is(o.Id)).Returns(o)); // Initialise PDF library // XSettings.InstallRedistributionLicense(ConfigurationManager.AppSettings["ABCPDFLicenseKey"]); }
private void PopulateUsersByProjectId(SqlConnection sqlConnection, DataManagementPlan dataManagementPlan, int projectId) { var urdmsUsers = new List <UrdmsUser>(); var nonUrdmsUsers = new List <User>(); if (sqlConnection.State == ConnectionState.Open) { var sqlCommand = new SqlCommand(string.Format(PartiesByProjectId, projectId, (int)AccessRole.Owners), _sqlConnection); var sqlReader = sqlCommand.ExecuteReader(); while (sqlReader.Read()) { int role; var userId = sqlReader["UserId"].ToString(); var fullName = sqlReader["FullName"].ToString(); int.TryParse(sqlReader["Role"].ToString(), out role); if (!string.IsNullOrWhiteSpace(userId)) { urdmsUsers.Add(new UrdmsUser { Id = userId, Name = fullName, Role = role }); } else { nonUrdmsUsers.Add(new User { Name = fullName, Role = role }); } } sqlReader.Close(); } dataManagementPlan.UrdmsUsers = urdmsUsers; dataManagementPlan.NonUrdmsUsers = nonUrdmsUsers; }
internal static void AddDmpValues(this DataRow dataRow, DataManagementPlan dmp, IList <ProjectParty> projectParties, string listSeparator) { dataRow.AddValues(listSeparator, false, dmp.DataStorage, dmp.NewDataDetail, dmp.ExistingDataDetail, dmp.DataDocumentation, dmp.Ethic, dmp.Confidentiality, dmp.BackupPolicy, dmp.DataRetention, dmp.DataSharing, dmp.DataRelationshipDetail); dataRow[CreationDateColumn] = dmp.CreationDate; dataRow[ProjectAccessRolesColumn] = ((IList)projectParties).ToStringValue(listSeparator); }
public void TearDown() { _dataManagementPlanRepository = null; _dmp = null; _sharePointHelper = null; _pdfHelper = null; _generatorHelper = null; _generator = null; }
internal static void AddDmpColumns(this DataTable dataTable, DataManagementPlan dmp) { dataTable.AddColumns(false, typeof(DataStorage), typeof(NewDataDetail), typeof(ExistingDataDetail), typeof(DataDocumentation), typeof(Ethic), typeof(Confidentiality), typeof(BackupPolicy), typeof(DataRetention), typeof(DataSharing), typeof(DataRelationshipDetail), typeof(DataOrganisation)); dataTable.Columns.Add(CreationDateColumn, typeof(DateTime)); dataTable.Columns.Add(ProjectAccessRolesColumn, typeof(string)); }
public void Generate_xml_and_handle_null_string_fields() { var dmp = new DataManagementPlan(); var xmlHelper = new XmlHelper(); var path = string.Format(@"{0}DmpDocument-{1}-{2:yyyyMMddhhmmss}.xml", Tempdir, dmp.Id, DateTime.Now); xmlHelper.Save(path, dmp); Assert.That(File.Exists(path), Is.True); File.Delete(path); }
public DataTable DataManagementPlanToDataTable(DataManagementPlan dmp, IList <ProjectParty> projectParties, string listSeparator = ListSeparator) { var dataTable = new DataTable(); dataTable.AddDmpColumns(dmp); var dataRow = dataTable.NewRow(); dataRow.AddDmpValues(dmp, projectParties, listSeparator); dataTable.Rows.Add(dataRow); return(dataTable); }
public static DataManagementPlan Clone(this DataManagementPlan srcDmp) { return(new DataManagementPlan { Id = 0, BackupPolicy = srcDmp.BackupPolicy, DataDocumentation = srcDmp.DataDocumentation, DataRelationshipDetail = srcDmp.DataRelationshipDetail, DataRetention = srcDmp.DataRetention, DataSharing = srcDmp.DataSharing, DataStorage = srcDmp.DataStorage, Ethic = srcDmp.Ethic, ExistingDataDetail = srcDmp.ExistingDataDetail, Confidentiality = srcDmp.Confidentiality, NewDataDetail = srcDmp.NewDataDetail }); }
public void Save(string filePath, DataManagementPlan entity) { var doc = entity.ToXDocument(); doc.Save(filePath); }
private void PopulatePrincipalInvestigatorByProjectId(SqlConnection sqlConnection, DataManagementPlan dataManagementPlan, int projectId) { if (sqlConnection.State == ConnectionState.Open) { var sqlCommand = new SqlCommand(string.Format(PrincipalinvestigatorByProjectId, projectId, (int)ProjectRelationship.PrincipalInvestigator), _sqlConnection); var sqlReader = sqlCommand.ExecuteReader(); while (sqlReader.Read()) { dataManagementPlan.PricipalInvestigator = (string)sqlReader["FullName"]; } sqlReader.Close(); } }
public DataManagementPlan GetDataManagementPlanByProjectId(int id) { var dataManagementPlan = new DataManagementPlan(); try { _sqlConnection.Open(); using (var sqlCommand = new SqlCommand(string.Format(DmpSqlString, id), _sqlConnection)) { using (var sqlReader = sqlCommand.ExecuteReader()) { while (sqlReader.Read()) { dataManagementPlan.Id = sqlReader.GetValue <int>("Id"); // Project details dataManagementPlan.ProjectTitle = sqlReader.GetStringValue("ProjectTitle"); dataManagementPlan.ProjectDescription = sqlReader.GetStringValue("ProjectDescription"); dataManagementPlan.CreationDate = sqlReader.GetValue <DateTime>("CreationDate"); // Backup dataManagementPlan.BackupLocations = sqlReader.GetEnumValue <BackupLocations>("BackupLocations"); dataManagementPlan.BackupPolicyLocationsDescription = sqlReader.GetStringValue("BackupPolicyLocationsDescription"); dataManagementPlan.BackupPolicyResponsibilities = sqlReader.GetEnumValue <DataResponsibilities>("BackupPolicyResponsibilities"); dataManagementPlan.BackupPolicyResponsibilitiesDescription = sqlReader.GetStringValue("BackupPolicyResponsibilitiesDescription"); // Data documentation dataManagementPlan.MetadataStandards = sqlReader.GetStringValue("MetadataStandards"); // Data organisation dataManagementPlan.DirectoryStructure = sqlReader.GetStringValue("DirectoryStructure"); // Relationship between new and pre-existing data dataManagementPlan.RelationshipBetweenExistingAndNewData = sqlReader.GetEnumValue <DataRelationship>("RelationshipBetweenExistingAndNewData"); // Data retention dataManagementPlan.DataRetentionPeriod = sqlReader.GetEnumValue <DataRetentionPeriod>("DataRetentionPeriod"); dataManagementPlan.DataRetentionResponsibilities = sqlReader.GetEnumValue <DataResponsibilities>("DataRetentionResponsibilities"); dataManagementPlan.DataRetentionResponsibilitiesDescription = sqlReader.GetStringValue("DataRetentionResponsibilitiesDescription"); dataManagementPlan.DataRetentionLocations = sqlReader.GetEnumValue <DataRetentionLocations>("DataRetentionLocations"); dataManagementPlan.DataRetentionLocationsDescription = sqlReader.GetStringValue("DataRetentionLocationsDescription"); dataManagementPlan.DepositToRepository = sqlReader.GetNullableValue <bool>("DepositToRepository"); // Data sharing dataManagementPlan.DataSharingAvailability = sqlReader.GetEnumValue <DataSharingAvailability>("DataSharingAvailability"); dataManagementPlan.ShareAccess = sqlReader.GetEnumValue <ShareAccess>("ShareAccess"); dataManagementPlan.ShareAccessDescription = sqlReader.GetStringValue("ShareAccessDescription"); dataManagementPlan.DataLicensingType = sqlReader.GetEnumValue <DataLicensingType>("DataLicensingType"); dataManagementPlan.ReuseByOrganisations = sqlReader.GetStringValue("ReuseByOrganisations"); dataManagementPlan.DataSharingAvailabilityDate = sqlReader.GetNullableValue <DateTime>("DataSharingAvailabilityDate"); // Ethical requirements dataManagementPlan.EthicRequiresClearance = sqlReader.GetNullableValue <bool>("EthicRequiresClearance"); dataManagementPlan.EthicComments = sqlReader.GetStringValue("EthicComments"); // Pre-existing research data dataManagementPlan.UseExistingData = sqlReader.GetNullableValue <bool>("UseExistingData"); dataManagementPlan.ExistingDataOwner = sqlReader.GetStringValue("ExistingDataOwner"); dataManagementPlan.ExistingDataAccessTypes = sqlReader.GetEnumValue <ExistingDataAccessTypes>("ExistingDataAccessTypes"); dataManagementPlan.AccessTypesDescription = sqlReader.GetStringValue("AccessTypesDescription"); // New research data dataManagementPlan.ResearchDataDescription = sqlReader.GetStringValue("ResearchDataDescription"); dataManagementPlan.DataOwners = sqlReader.GetEnumValue <DataOwners>("DataOwners"); dataManagementPlan.DataOwnersDescription = sqlReader.GetStringValue("DataOwnersDescription"); dataManagementPlan.DataActionFrequency = sqlReader.GetEnumValue <DataActionFrequency>("DataActionFrequency"); dataManagementPlan.IsVersioned = sqlReader.GetNullableValue <bool>("IsVersioned"); // Data storage dataManagementPlan.InstitutionalStorageTypes = sqlReader.GetEnumValue <InstitutionalStorageTypes>("InstitutionalStorageTypes"); dataManagementPlan.InstitutionalOtherTypeDescription = sqlReader.GetStringValue("InstitutionalOtherTypeDescription"); dataManagementPlan.ExternalStorageTypes = sqlReader.GetEnumValue <ExternalStorageTypes>("ExternalStorageTypes"); dataManagementPlan.ExternalOtherTypeDescription = sqlReader.GetStringValue("ExternalOtherTypeDescription"); dataManagementPlan.PersonalStorageTypes = sqlReader.GetEnumValue <PersonalStorageTypes>("PersonalStorageTypes"); dataManagementPlan.PersonalOtherTypeDescription = sqlReader.GetStringValue("PersonalOtherTypeDescription"); dataManagementPlan.MaxDataSize = sqlReader.GetEnumValue <MaxDataSize>("MaxDataSize"); dataManagementPlan.FileFormats = sqlReader.GetStringValue("FileFormats"); dataManagementPlan.VersionControl = sqlReader.GetEnumValue <VersionControl>("VersionControl"); dataManagementPlan.VersionControlDescription = sqlReader.GetStringValue("VersionControlDescription"); // Privacy and confidentiality requirements dataManagementPlan.IsSensitive = sqlReader.GetNullableValue <bool>("IsSensitive"); dataManagementPlan.ConfidentialityComments = sqlReader.GetStringValue("ConfidentialityComments"); } sqlReader.Close(); } } PopulatePrincipalInvestigatorByProjectId(_sqlConnection, dataManagementPlan, id); PopulateUsersByProjectId(_sqlConnection, dataManagementPlan, id); dataManagementPlan.DateModified = DateTime.Now; } finally { _sqlConnection.Close(); } return(dataManagementPlan); }