diff --git a/src/Database.Tests/Properties/AssemblyInfo.cs b/src/Database.Tests/Properties/AssemblyInfo.cs index 6a5fce73ffaf7323bd9dc13a183be1c47ef56240..2f8ceba4374e10b55bc3ddf90bb907678c0b8703 100644 --- a/src/Database.Tests/Properties/AssemblyInfo.cs +++ b/src/Database.Tests/Properties/AssemblyInfo.cs @@ -9,8 +9,8 @@ using System.Reflection; [assembly: AssemblyDescription("Database.Tests is a part of the CoScInE group.")] [assembly: AssemblyCompany("IT Center, RWTH Aachen University")] [assembly: AssemblyProduct("Database.Tests")] -[assembly: AssemblyVersion("1.18.1")] -[assembly: AssemblyFileVersion("1.18.1")] -[assembly: AssemblyInformationalVersion("1.18.1-topic-712-organi0004")] +[assembly: AssemblyVersion("1.20.1")] +[assembly: AssemblyFileVersion("1.20.1")] +[assembly: AssemblyInformationalVersion("1.20.1-topic-804-nicepr0005")] [assembly: AssemblyCopyright("2020 IT Center, RWTH Aachen University")] diff --git a/src/Database/Models/ProjectModel.cs b/src/Database/Models/ProjectModel.cs index 1e7efeaea33ecfe85a21cce1189f8d361c294178..a641e36ead2f93fb7213a35a2321f78ae50300e7 100644 --- a/src/Database/Models/ProjectModel.cs +++ b/src/Database/Models/ProjectModel.cs @@ -7,6 +7,7 @@ using Coscine.Database.DataModel; using LinqToDB; using Coscine.Database.Util; using LinqKit; +using System.Text.RegularExpressions; namespace Coscine.Database.Models { @@ -37,6 +38,11 @@ namespace Coscine.Database.Models }); } + public Project GetBySlug(String slug) + { + return GetWhere((tableEntry) => tableEntry.Slug == slug); + } + public Project GetByIdIncludingDeleted(Guid id) { var expression = GetIdFromObject(); @@ -144,6 +150,7 @@ namespace Coscine.Database.Models ProjectName = projectObject.ProjectName, PrincipleInvestigators = projectObject.PrincipleInvestigators, GrantId = projectObject.GrantId, + Slug = GenerateSlug(projectObject), VisibilityId = projectObject.Visibility.Id, }; @@ -162,6 +169,41 @@ namespace Coscine.Database.Models return project; } + private String GenerateSlug(ProjectObject projectObject) + { + // create slug for project + var slug = projectObject.DisplayName; + slug = slug.ToLower(); + slug = Regex.Replace(slug, @"[\s-]+", "-"); + slug = Regex.Replace(slug, @"[^a-z0-9-]*|", ""); + slug = Regex.Replace(slug, @"^-|-$", ""); + + Random r = new Random(); + int rInt = r.Next(0, 9000000) + 1000000; + string fullSlug = "" + rInt; + + if (slug.Length >= 7) + { + rInt = r.Next(0, 9000) + 1000; + fullSlug = slug; + } + + if (GetBySlug(fullSlug) != null) + { + if (slug.Length >= 7) + { + fullSlug = slug + "-"; + } + while (GetBySlug(fullSlug + rInt) != null) + { + rInt++; + }; + fullSlug += rInt; + } + + return fullSlug; + } + private void SetDisciplines(Project project, IEnumerable<DisciplineObject> disciplines) { ProjectDisciplineModel projectDisciplineModel = new ProjectDisciplineModel(); @@ -332,6 +374,7 @@ namespace Coscine.Database.Models disciplines, organizations, project.Visibility == null ? null : new VisibilityObject(project.Visibility.Id, project.Visibility.DisplayName), + project.Slug, parentId); } diff --git a/src/Database/Properties/AssemblyInfo.cs b/src/Database/Properties/AssemblyInfo.cs index c9774aed82b7d178b7d0b4a7915b231c5fbb3003..3e18b175f143dc051f27e2bdfbd93569c8971168 100644 --- a/src/Database/Properties/AssemblyInfo.cs +++ b/src/Database/Properties/AssemblyInfo.cs @@ -9,8 +9,8 @@ using System.Reflection; [assembly: AssemblyDescription("Database is a part of the CoScInE group.")] [assembly: AssemblyCompany("IT Center, RWTH Aachen University")] [assembly: AssemblyProduct("Database")] -[assembly: AssemblyVersion("1.18.1")] -[assembly: AssemblyFileVersion("1.18.1")] -[assembly: AssemblyInformationalVersion("1.18.1-topic-712-organi0004")] +[assembly: AssemblyVersion("1.20.1")] +[assembly: AssemblyFileVersion("1.20.1")] +[assembly: AssemblyInformationalVersion("1.20.1-topic-804-nicepr0005")] [assembly: AssemblyCopyright("2020 IT Center, RWTH Aachen University")] diff --git a/src/Database/ReturnObjects/ProjectObject.cs b/src/Database/ReturnObjects/ProjectObject.cs index ce10c1b14290d2b622c27c08f86c22966c86e039..21df41588c64e1cef3cc15e054f46a3cab798488 100644 --- a/src/Database/ReturnObjects/ProjectObject.cs +++ b/src/Database/ReturnObjects/ProjectObject.cs @@ -18,6 +18,7 @@ namespace Coscine.Database.ReturnObjects public string ProjectName { get; set; } public string PrincipleInvestigators { get; set; } public string GrantId { get; set; } + public string Slug { get; set; } public IEnumerable<DisciplineObject> Disciplines { get; set; } public IEnumerable<OrganizationObject> Organizations { get; set; } @@ -25,7 +26,7 @@ namespace Coscine.Database.ReturnObjects public Guid ParentId { get; set; } - public ProjectObject(Guid id, string description, string displayName, DateTime startDate, DateTime endDate, string keywords, string projectName, string principleInvestigators, string grantId, IEnumerable<DisciplineObject> discipline, IEnumerable<OrganizationObject> organization, VisibilityObject visibility, Guid parentId = new Guid()) + public ProjectObject(Guid id, string description, string displayName, DateTime startDate, DateTime endDate, string keywords, string projectName, string principleInvestigators, string grantId, IEnumerable<DisciplineObject> discipline, IEnumerable<OrganizationObject> organization, VisibilityObject visibility, string slug, Guid parentId = new Guid()) { Id = id; Description = description; @@ -38,6 +39,7 @@ namespace Coscine.Database.ReturnObjects ProjectName = projectName; PrincipleInvestigators = principleInvestigators; GrantId = grantId; + Slug = slug; Disciplines = discipline; Organizations = organization;