public DataTable DataCollectionToDataTable(DataCollection dataCollection, string listSeparator = ListSeparator)
 {
     var dataTable = new DataTable();
     dataTable.AddDataCollectionColumns(dataCollection);
     var dataRow = dataTable.NewRow();
     dataRow.AddDataCollectionValues(dataCollection, listSeparator);
     dataTable.Rows.Add(dataRow);
     return dataTable;
 }
 public virtual bool UpdateHashCode(DataCollection collection)
 {
     var hashCode = collection.GetDataCollectionHash();
     if (this.HashCode != hashCode)
     {
         this.HashCode = hashCode;
         return true;
     }
     return false;
 }
 public static DataCollectionViewModelStep1 MapFrom(this DataCollectionViewModelStep1 vm, Project project, DataCollection collection = null)
 {
     if (vm == null || project == null)
     {
         return vm;
     }
     if (collection != null)
     {
         vm.InjectFrom(collection);
     }
     vm.ProjectTitle = project.Title;
     return vm;
 }
 public bool TrySave(DataCollection collection, out DataCollectionHashCode hashCode)
 {
     hashCode = GetByDataCollectionId(collection.Id);
     if (hashCode == null || hashCode.UpdateHashCode(collection))
     {
         if (hashCode == null)
         {
             hashCode = collection.NewDataCollectionHashCode();
         }
         Save(hashCode);
         return true;
     }
     return false;
 }
        public static DataCollectionViewModelStep2 MapFrom(this DataCollectionViewModelStep2 vm, DataCollection collection)
        {
            if (vm == null || collection == null)
                return vm;

            vm.InjectFrom(collection);

            MapForCodes(vm.FieldsOfResearch, collection.FieldsOfResearch);
            MapSeoCodes(vm.SocioEconomicObjectives, collection.SocioEconomicObjectives);
            vm.Manager = MapManager(collection.Parties);
            vm.UrdmsUsers = MapUrdmsUsers(collection.Parties);
            vm.NonUrdmsUsers = MapNonUrdmsUsers(collection.Parties);
            return vm;
        }
        public virtual DataCollection CreateInitialDataCollection()
        {
            var dataCollection = new DataCollection
                                            {
                                                Title = "Research data for " + this.Title,
                                                Keywords = this.Keywords,
                                                ProjectId = this.Id,
                                                IsFirstCollection = true,
                                                DataStoreLocationName = "Project Storage Space",
                                                DataStoreLocationUrl = SiteUrl
                                            };
            if (this.SourceProjectType == SourceProjectType.DEPOSIT && this.DataDeposit != null)
            {
                var deposit = this.DataDeposit;
                dataCollection.ResearchDataDescription = deposit.ResearchDataDescription;
                dataCollection.DataLicensingRights = deposit.LicensingArrangement;
                dataCollection.ShareAccess = deposit.ShareAccess;
                dataCollection.ShareAccessDescription = deposit.ShareAccessDescription;
                dataCollection.AvailabilityDate = deposit.AvailabilityDate;
                dataCollection.Availability = deposit.Availability;
            }
            else if (this.SourceProjectType != SourceProjectType.DEPOSIT && this.DataManagementPlan != null)
            {
                var dmp = this.DataManagementPlan;
                if (dmp.NewDataDetail != null)
                {
                    dataCollection.ResearchDataDescription = dmp.NewDataDetail.ResearchDataDescription;
                }
                if (dmp.DataSharing != null)
                {
                    dataCollection.DataLicensingRights = dmp.DataSharing.DataLicensingType;
                    dataCollection.ShareAccess = dmp.DataSharing.ShareAccess;
                    dataCollection.ShareAccessDescription = dmp.DataSharing.ShareAccessDescription;
                    dataCollection.AvailabilityDate = dmp.DataSharing.DataSharingAvailabilityDate;
                    dataCollection.Availability = dmp.DataSharing.DataSharingAvailability;
                }
            }
            var parties = this.GetDataCollectionParties(dataCollection);

            var socioEconomicObjectives = from o in (this.SocioEconomicObjectives ?? new List<ProjectSocioEconomicObjective>())
                                          select new DataCollectionSocioEconomicObjective { SocioEconomicObjective = o.SocioEconomicObjective };
            var fieldsOfResearch = from o in (this.FieldsOfResearch ?? new List<ProjectFieldOfResearch>())
                                   select new DataCollectionFieldOfResearch { FieldOfResearch = o.FieldOfResearch };

            dataCollection.Parties.AddRange(parties);
            dataCollection.SocioEconomicObjectives.AddRange(socioEconomicObjectives);
            dataCollection.FieldsOfResearch.AddRange(fieldsOfResearch);

            return dataCollection;
        }
        private void AddDataCollectionToFormCollection(DataCollection dataCollection)
        {

            foreach (var forCode in dataCollection.FieldsOfResearch)
            {
                var value = string.Format("{0}:{1}:{2}", forCode.Id, forCode.FieldOfResearch.Id, forCode.FieldOfResearch.Name);
                _form.Add("ForCodeRows", value);
            }

            foreach (var seoCode in dataCollection.SocioEconomicObjectives)
            {
                var value = string.Format("{0}:{1}:{2}", seoCode.Id, seoCode.SocioEconomicObjective.Id, seoCode.SocioEconomicObjective.Name);
                _form.Add("SeoCodeRows", value);
            }
        }
        private static IEnumerable<string> GetHashCodeParts(DataCollection collection)
        {
            yield return string.Format("Id:{0}", collection.Id);
            yield return string.Format("Title:{0}", collection.Title);
            yield return string.Format("ResearchDataDescription:{0}", collection.ResearchDataDescription);
            yield return string.Format("Type:{0}", (int)collection.Type);
            yield return string.Format("StartDate:{0}", collection.StartDate);
            yield return string.Format("EndDate:{0}", collection.EndDate);
            yield return string.Format("DataLicensingRights:{0}", (int)collection.DataLicensingRights);
            yield return string.Format("ShareAccess ShareAccess:{0}", (int)collection.ShareAccess);
            yield return string.Format("ShareAccessDescription:{0}", collection.ShareAccessDescription);
            yield return string.Format("Keywords:{0}", collection.Keywords);
            yield return string.Format("AwareOfEthics:{0}", collection.AwareOfEthics);
            yield return string.Format("Availability:{0}", (int)collection.Availability);
            yield return string.Format("AvailabilityDate:{0}", collection.AvailabilityDate);
            yield return string.Format("EthicsApprovalNumber:{0}", collection.EthicsApprovalNumber);
            yield return string.Format("DataStoreLocationName:{0}", collection.DataStoreLocationName);
            yield return string.Format("DataStoreLocationUrl:{0}", collection.DataStoreLocationUrl);
            yield return string.Format("DataStoreAdditionalDetails:{0}", collection.DataStoreAdditionalDetails);
            yield return string.Format("DataCollectionIdentifier:{0}", (int)collection.DataCollectionIdentifier);
            yield return string.Format("DataCollectionIdentifierValue:{0}", collection.DataCollectionIdentifierValue);
            foreach (var objectives in collection.SocioEconomicObjectives)
            {
                var code = objectives.Code;
                yield return string.Format("SeoCode:{0}", code.Id);
            }

            foreach (var fieldOfResearch in collection.FieldsOfResearch)
            {
                var code = fieldOfResearch.Code;
                yield return string.Format("ForCode:{0}", code.Id);
            }

            foreach (var dataCollectionParty in collection.Parties)
            {
                var party = dataCollectionParty.Party;
                yield return string.Format("Party[Id:{0}-Relationship:{1}-PartyId:{2}-UserId:{3}-FirstName:{4}-LastName:{5}-Email:{6}-Organisation:{7}-FullName:{8}]",
                                           dataCollectionParty.Id,
                                           (int)dataCollectionParty.Relationship,
                                           party.Id,
                                           party.UserId,
                                           party.FirstName,
                                           party.LastName,
                                           party.Email,
                                           party.Organisation,
                                           party.FullName);
            }
        }
        public void Map_DataCollectionViewModelStep2_with_seo_codes_to_DataCollection_with_existing_seo_codes()
        {
            var dataCollection = new DataCollection();
            var existingSocioEconomicObjectiveCodes = Builder<DataCollectionSocioEconomicObjective>
                .CreateListOfSize(3)
                .TheFirst(1).With(s => s.Id = 1).And(s => s.SocioEconomicObjective = new SocioEconomicObjective { Id = "SOP", Name = "SOP" })
                .TheNext(1).With(s => s.Id = 3).And(s => s.SocioEconomicObjective = new SocioEconomicObjective {Id = "ARM", Name = "Army"})
                .TheLast(1).With(s => s.Id = 4).And(s => s.SocioEconomicObjective = new SocioEconomicObjective {Id = "DEF", Name = "Defence"})
                .Build();
            dataCollection.SocioEconomicObjectives.AddRange(existingSocioEconomicObjectiveCodes);

            dataCollection.MapFrom(_dataCollectionViewModelStep2);

            Assert.That(dataCollection.ProjectId, Is.EqualTo(1), "Project Id incorrect");
            Assert.That(dataCollection.SocioEconomicObjectives.Count, Is.EqualTo(2), "Incorrect number of SEO codes");
            Assert.That(dataCollection.SocioEconomicObjectives[0].Id, Is.EqualTo(1), "First SEO Id does not match");
            Assert.That(dataCollection.SocioEconomicObjectives[0].SocioEconomicObjective.Name, Is.EqualTo("SOP"), "First SEO code Name does not match");
            Assert.That(dataCollection.SocioEconomicObjectives[1].Id, Is.EqualTo(0), "Second SEO Id does not match (needs to be zero as it is a new record)");
            Assert.That(dataCollection.SocioEconomicObjectives[1].SocioEconomicObjective.Name, Is.EqualTo("SOB"), "Second SEO code Name does not match");
        }
        public void Map_DataCollectionViewModelStep2_with_seo_codes_to_DataCollection()
        {
            var dataCollection = new DataCollection();
            dataCollection.MapFrom(_dataCollectionViewModelStep2);

            Assert.That(dataCollection.ProjectId == 1);
            Assert.That(dataCollection.SocioEconomicObjectives.Count == 2);
        }
        public void Map_DataCollectionViewModelStep2_with_for_codes_to_DataCollection_with_existing_for_codes()
        {
            var dataCollection = new DataCollection();
            var existingFieldsOfResearch = Builder<DataCollectionFieldOfResearch>
                .CreateListOfSize(3)
                .TheFirst(1).With(f => f.FieldOfResearch = new FieldOfResearch{ Id = "FOF", Name = "FOF" }).And(f => f.Id = 1)
                .TheNext(1).With(f => f.FieldOfResearch = new FieldOfResearch{ Id = "CAL", Name = "Calculus" }).And(f => f.Id = 3)
                .TheLast(1).With(f => f.FieldOfResearch = new FieldOfResearch{ Id = "SPA", Name = "Spatial Sciences"}).And(f => f.Id = 4)
                .Build();
            dataCollection.FieldsOfResearch.AddRange(existingFieldsOfResearch);

            dataCollection.MapFrom(_dataCollectionViewModelStep2);

            Assert.That(dataCollection.ProjectId, Is.EqualTo(1), "Project Id incorrect");
            Assert.That(dataCollection.FieldsOfResearch.Count, Is.EqualTo(2), "Incorrect number of FoR codes");
            Assert.That(dataCollection.FieldsOfResearch[0].Id, Is.EqualTo(1), "First FoR Id does not match");
            Assert.That(dataCollection.FieldsOfResearch[0].FieldOfResearch.Name, Is.EqualTo("FOF"), "First FoR code Name does not match");
            Assert.That(dataCollection.FieldsOfResearch[1].Id, Is.EqualTo(0), "Second FoR Id does not match (needs to be zero as it is a new record)");
            Assert.That(dataCollection.FieldsOfResearch[1].FieldOfResearch.Name, Is.EqualTo("POP"), "Second FoR code Name does not match");
        }
        public void Map_DataCollectionViewModelStep2_with_for_codes_to_DataCollection()
        {
            var dataCollection = new DataCollection();
            dataCollection.MapFrom(_dataCollectionViewModelStep2);

            Assert.That(dataCollection.ProjectId == 1);
            Assert.That(dataCollection.FieldsOfResearch.Count == 2);
        }
 public void SaveByDataCollection(DataCollection collection)
 {
     DataCollectionHashCode hashCode;
     TrySave(collection, out hashCode);
 }
        public void Map_DataCollectionViewModelStep2_with_parties_to_DataCollection()
        {
            var dataCollection = new DataCollection();
            dataCollection.MapFrom(_dataCollectionViewModelStep2);

            Assert.That(dataCollection.ProjectId == 1);
            Assert.That(dataCollection.Parties.Count == 4);
        }
        public static DataCollectionReadOnlyViewModel MapFrom(this DataCollectionReadOnlyViewModel vm, DataCollection collection, Project project)
        {
            if (vm == null || collection == null || project == null)
                return vm;

            vm.InjectFrom(collection);

            MapForCodes(vm.FieldsOfResearch, collection.FieldsOfResearch);
            MapSeoCodes(vm.SocioEconomicObjectives, collection.SocioEconomicObjectives);
            vm.Manager = MapManager(collection.Parties);
            vm.UrdmsUsers = MapUrdmsUsers(collection.Parties);
            vm.NonUrdmsUsers = MapNonUrdmsUsers(collection.Parties);
            vm.ProjectTitle = project.Title;

            return vm;
        }
 internal static void AddDataCollectionValues(this DataRow dataRow, DataCollection dataCollection, string listSeparator)
 {
     dataRow.AddValues(listSeparator, false, dataCollection);
 }
 internal static void AddDataCollectionColumns(this DataTable dataTable, DataCollection dataCollection)
 {
     dataTable.AddColumns(false, typeof(DataCollection));
     dataTable.Columns.Add(CreationDateColumn, typeof(DateTime));
 }
 public void Save(DataCollection dataCollection)
 {
    EnsureNonDuplicationOfParty(dataCollection.Parties);
    _session.SaveOrUpdate(dataCollection);
    _session.Flush();
 }
 public virtual IEnumerable<DataCollectionParty> GetDataCollectionParties(DataCollection collection)
 {
     return Parties
             .Where(p => p.Role != AccessRole.None 
                 && p.Id > 0 
                 && collection.Parties.All(cp => cp.Party.UserId != p.Party.UserId))
             .Select(n => new DataCollectionParty
                              {
                                  Party = n.Party,
                                  DataCollection = collection,
                                  Relationship = n.Relationship == ProjectRelationship.PrincipalInvestigator
                                     ? DataCollectionRelationshipType.Manager
                                     : DataCollectionRelationshipType.AssociatedResearcher
                              });
 }
        public void Map_DataCollectionViewModelStep2_with_keywords_to_DataCollection()
        {

            var dataCollection = new DataCollection();
            dataCollection.MapFrom(_dataCollectionViewModelStep2);

            Assert.That(dataCollection.ProjectId == 1);
            Assert.That(dataCollection.Keywords.Split(',').Length == 3);
        }
 public virtual bool IsDifferentHashCode(DataCollection collection)
 {
     var hashCode = collection.GetDataCollectionHash();
     return hashCode == null || this.HashCode != hashCode;
 }