Skip to content
Snippets Groups Projects
Commit b248de4e authored by Marcel Nellesen's avatar Marcel Nellesen
Browse files

Merge branch 'Product/510-niceProjectUrl' into 'Sprint/2020-10'

Product/510-niceProjectUrl

See merge request coscine/cs/database!78
parents bd37684e cc231cf9
Branches
Tags
2 merge requests!78Product/510-niceProjectUrl,!77Sprint/2020-10
......@@ -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")]
......@@ -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);
}
......
......@@ -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")]
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment