Commit 7b20e092 authored by Marcel Nellesen's avatar Marcel Nellesen
Browse files

Extracted functionality (coscine/issues#1051)

parent 8616d313
......@@ -11,6 +11,6 @@ using System.Reflection;
[assembly: AssemblyProduct("Database.T4")]
[assembly: AssemblyVersion("1.25.0")]
[assembly: AssemblyFileVersion("1.25.0")]
[assembly: AssemblyInformationalVersion("1.25.0-topic-1051-basic0003")]
[assembly: AssemblyInformationalVersion("1.25.0-topic-1051-basic0005")]
[assembly: AssemblyCopyright("2020 IT Center, RWTH Aachen University")]
......@@ -11,6 +11,6 @@ using System.Reflection;
[assembly: AssemblyProduct("Database.Tests")]
[assembly: AssemblyVersion("1.25.0")]
[assembly: AssemblyFileVersion("1.25.0")]
[assembly: AssemblyInformationalVersion("1.25.0-topic-1051-basic0003")]
[assembly: AssemblyInformationalVersion("1.25.0-topic-1051-basic0005")]
[assembly: AssemblyCopyright("2020 IT Center, RWTH Aachen University")]
......@@ -93,6 +93,8 @@
<Compile Include="ReturnObjects\KpiObject.cs" />
<Compile Include="ReturnObjects\LanguageObject.cs" />
<Compile Include="ReturnObjects\LicenseObject.cs" />
<Compile Include="ReturnObjects\OrganizationResourceListObject.cs" />
<Compile Include="ReturnObjects\OrganizationCountObject.cs" />
<Compile Include="ReturnObjects\OrganizationObject.cs" />
<Compile Include="ReturnObjects\ProjectObject.cs" />
<Compile Include="ReturnObjects\ProjectQuotaObject.cs" />
......
......@@ -170,6 +170,20 @@ namespace Coscine.Database.Models
return project;
}
public List<OrganizationCountObject> GetProjectCountByOrganization()
{
return DatabaseConnection.ConnectToDatabase((db) =>
{
return (from p in db.Projects
join pi in db.ProjectInstitutes on p.Id equals pi.ProjectId into joinedPi
from jpi in joinedPi.DefaultIfEmpty()
where p.Deleted == false
group jpi by jpi.OrganizationUrl into g
select new OrganizationCountObject(g.Key, g.Count())).ToList();
});
}
private String GenerateSlug(ProjectObject projectObject)
{
// create slug for project
......
......@@ -72,6 +72,38 @@ namespace Coscine.Database.Models
return Delete(resource);
}
public List<OrganizationCountObject> GetRDSBucketCountByOrganization()
{
var resourceListByOrganization = GetRDSResourceListByOrganization();
var list = new List<OrganizationCountObject>();
foreach(OrganizationResourceListObject rlo in resourceListByOrganization)
{
list.Add(new OrganizationCountObject(rlo.Url, rlo.Resources.Count));
}
return list;
}
public List<OrganizationResourceListObject> GetRDSResourceListByOrganization()
{
return DatabaseConnection.ConnectToDatabase((db) =>
{
return (from r in db.Resources
join pr in db.ProjectResources on r.Id equals pr.ResourceId into joinedPr
from jpr in joinedPr.DefaultIfEmpty()
join p in db.Projects on jpr.ProjectId equals p.Id into joinedP
from jp in joinedP.DefaultIfEmpty()
join pi in db.ProjectInstitutes on jp.Id equals pi.ProjectId into joinedPi
from jpi in joinedPi.DefaultIfEmpty()
join rt in db.ResourceTypes on r.TypeId equals rt.Id into joinedRt
from jrt in joinedRt.DefaultIfEmpty()
where jp.Deleted == false &&
jrt.DisplayName == "rds"
group r by jpi.OrganizationUrl into g
select new OrganizationResourceListObject(g.Key, g.ToList())).ToList();
});
}
private void SetResourceTypeObject(Resource resource, JObject resourceTypeOption)
{
if (resource.Type.DisplayName == "rds")
......
using Coscine.Database.DataModel;
using Coscine.Database.ReturnObjects;
using Coscine.Database.Util;
using LinqToDB;
using System;
using System.Collections.Generic;
......@@ -89,6 +90,16 @@ namespace Coscine.Database.Models
return Update(user);
}
public List<Guid> GetActiveUserIds()
{
return DatabaseConnection.ConnectToDatabase((db) =>
{
return (from u in db.Users
join tos in db.TOSAccepteds on u.Id equals tos.UserId
select u.Id).Distinct().ToList();
});
}
private void SetDisciplines(User user, IEnumerable<DisciplineObject> disciplines)
{
UserDisciplineModel userDisciplineModel = new UserDisciplineModel();
......
......@@ -11,6 +11,6 @@ using System.Reflection;
[assembly: AssemblyProduct("Database")]
[assembly: AssemblyVersion("1.25.0")]
[assembly: AssemblyFileVersion("1.25.0")]
[assembly: AssemblyInformationalVersion("1.25.0-topic-1051-basic0003")]
[assembly: AssemblyInformationalVersion("1.25.0-topic-1051-basic0005")]
[assembly: AssemblyCopyright("2020 IT Center, RWTH Aachen University")]
using System;
namespace Coscine.Database.ReturnObjects
{
[Serializable]
public class OrganizationCountObject : IReturnObject
{
public string Url { get; set; }
public int Count { get; set; }
public OrganizationCountObject(string url, int count)
{
Url = url;
Count = count;
}
}
}
using Coscine.Database.DataModel;
using System;
using System.Collections.Generic;
namespace Coscine.Database.ReturnObjects
{
[Serializable]
public class OrganizationResourceListObject : IReturnObject
{
public string Url { get; set; }
public List<Resource> Resources { get; set; }
public OrganizationResourceListObject(string url, List<Resource> resources)
{
Url = url;
Resources = resources;
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment