Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • Hotfix/1316-nullCheck
  • Hotfix/1357-ymlFile
  • Hotfix/1370-swaggerDescription
  • Hotfix/1516-pidFix
  • Hotfix/2087-efNet6
  • Hotfix/82-updateDepsOfAPIs
  • Issue/1321-pidEnquiryOverhaul
  • Issue/1910-MigrationtoNET6.0
  • Issue/2259-updatePids
  • Issue/2309-docs
  • Product/1116-pidApiExtension
  • Product/1188-LoggingExtended
  • Product/1287-dotnet5Sharepoint
  • Product/789-userContactEmail
  • Sprint/2020-20
  • Sprint/2020-21
  • Sprint/2020-22
  • Sprint/2021-01
  • Sprint/2021-02
  • Sprint/2021-04
  • Sprint/2021-05
  • Sprint/2021-08
  • Sprint/2021-11
  • Sprint/2021-23
  • Sprint/2022-01
  • Topic/1202-pidApiExtension
  • Topic/1221-LogginExtendedNew
  • Topic/1221-LoggingExtended
  • Topic/1294-contactChangeFunctionality
  • Topic/1335-dotnet5Apis
  • dev
  • gitkeep
  • master
  • product/1182-testsForPidApi
  • topic/1203-testForPidApi
  • v1.1.0
  • v1.1.1
  • v1.1.2
  • v1.2.0
  • v1.2.1
  • v2.0.0
  • v2.0.1
  • v2.1.0
  • v2.2.0
  • v2.2.1
  • v2.2.2
  • v2.2.3
  • v2.2.4
  • v2.2.5
  • v2.2.6
  • v2.3.0
  • v2.3.1
  • v2.3.2
  • v2.4.0
  • v2.4.1
  • v2.4.2
56 results

Target

Select target project
  • coscine/backend/apis/pid
1 result
Select Git revision
  • Hotfix/1316-nullCheck
  • Hotfix/1357-ymlFile
  • Hotfix/1370-swaggerDescription
  • Hotfix/1516-pidFix
  • Hotfix/2087-efNet6
  • Hotfix/82-updateDepsOfAPIs
  • Issue/1321-pidEnquiryOverhaul
  • Issue/1910-MigrationtoNET6.0
  • Issue/2259-updatePids
  • Issue/2309-docs
  • Product/1116-pidApiExtension
  • Product/1188-LoggingExtended
  • Product/1287-dotnet5Sharepoint
  • Product/789-userContactEmail
  • Sprint/2020-20
  • Sprint/2020-21
  • Sprint/2020-22
  • Sprint/2021-01
  • Sprint/2021-02
  • Sprint/2021-04
  • Sprint/2021-05
  • Sprint/2021-08
  • Sprint/2021-11
  • Sprint/2021-23
  • Sprint/2022-01
  • Topic/1202-pidApiExtension
  • Topic/1221-LogginExtendedNew
  • Topic/1221-LoggingExtended
  • Topic/1294-contactChangeFunctionality
  • Topic/1335-dotnet5Apis
  • dev
  • gitkeep
  • master
  • product/1182-testsForPidApi
  • topic/1203-testForPidApi
  • v1.1.0
  • v1.1.1
  • v1.1.2
  • v1.2.0
  • v1.2.1
  • v2.0.0
  • v2.0.1
  • v2.1.0
  • v2.2.0
  • v2.2.1
  • v2.2.2
  • v2.2.3
  • v2.2.4
  • v2.2.5
  • v2.2.6
  • v2.3.0
  • v2.3.1
  • v2.3.2
  • v2.4.0
  • v2.4.1
  • v2.4.2
56 results
Show changes
Commits on Source (6)
using Coscine.Database.Models;
using Coscine.Database.ReturnObjects;
using Coscine.ApiCommons;
using Coscine.ApiCommons.Factories;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Linq;
using Coscine.Action;
using Coscine.Action.EventArgs;
using Coscine.Api.Pid.Models;
using Coscine.Configuration;
using Microsoft.AspNetCore.Authorization;
using Newtonsoft.Json.Linq;
using Coscine.Database.DataModel;
using Coscine.Database.Util;
using Coscine.Database.Models;
using Coscine.Database.ReturnObjects;
using Coscine.Logging;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Coscine.Api.Pid.Models;
using Coscine.Action;
using Coscine.Action.EventArgs;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace Coscine.Api.Pid.Controllers
{
......@@ -27,6 +26,11 @@ namespace Coscine.Api.Pid.Controllers
private readonly ProjectModel _projectModel;
private readonly IConfiguration _configuration;
private readonly Emitter _emitter;
private readonly CoscineLogger _coscineLogger;
private readonly ProjectRoleModel _projectRoleModel;
private readonly RoleModel _roleModel;
private readonly ProjectResourceModel _projectResourceModel;
private readonly VisibilityModel _visibilityModel;
/// <summary>
/// PidController constructor for contacting the pid owner.
......@@ -37,6 +41,11 @@ namespace Coscine.Api.Pid.Controllers
_emitter = new Emitter(_configuration);
_resourceModel = new ResourceModel();
_projectModel = new ProjectModel();
_coscineLogger = new CoscineLogger(logger);
_projectRoleModel = new ProjectRoleModel();
_roleModel = new RoleModel();
_projectResourceModel = new ProjectResourceModel();
_visibilityModel = new VisibilityModel();
}
/// <summary>
......@@ -69,23 +78,82 @@ namespace Coscine.Api.Pid.Controllers
Placeholder = placeholder
};
ResourceObject resourceObject = null;
ProjectObject projectObject = null;
IEnumerable<ProjectRole> projectOwners = null;
if (resource != null)
{
placeholder["resourceName"] = resource.DisplayName;
pidEventArgs.Resource = resource;
resourceObject = _resourceModel.CreateReturnObjectFromDatabaseObject(resource);
var projectId = _projectResourceModel.GetProjectForResource(resource.Id);
if (projectId.HasValue)
{
projectObject = _projectModel.CreateReturnObjectFromDatabaseObject(_projectModel.GetById(projectId.Value));
var ownerId = _roleModel.GetAllWhere((x) => (x.DisplayName == "owner")).First().Id;
projectOwners = _projectRoleModel.GetAllWhere((x) => x.RoleId == ownerId && x.ProjectId == project.Id);
}
}
else if (project != null)
{
placeholder["projectName"] = project.DisplayName;
pidEventArgs.Project = project;
projectObject = _projectModel.CreateReturnObjectFromDatabaseObject(project);
var ownerId = _roleModel.GetAllWhere((x) => (x.DisplayName == "owner")).First().Id;
projectOwners = _projectRoleModel.GetAllWhere((x) => x.RoleId == ownerId && x.ProjectId == project.Id);
}
else
{
// Log the error.
// ProjectId and ResourceId will be null and indicate an error in the logs.
LogAnalyticsPidEnquiry(null, null, null, null, null, null, null, null);
return BadRequest("No project/resource with this pid exists.");
}
if (CoscineLoggerConfiguration.IsLogLevelActivated(LogType.Analytics))
{
LogAnalyticsPidEnquiry(project, resource, resourceObject?.ApplicationProfile, resourceObject?.License?.DisplayName, projectObject?.Disciplines, projectObject?.Organizations, projectOwners, messageObject.Email);
}
_emitter.EmitPIDOwnerContact(pidEventArgs);
return Json(new JObject { ["status"] = "ok" });
}
private void LogAnalyticsPidEnquiry(Project project, Resource resource, string applicationsProfile, string license,
IEnumerable<DisciplineObject> disciplines, IEnumerable<OrganizationObject> organizations, IEnumerable<ProjectRole> owners, string email)
{
_coscineLogger.AnalyticsLog(
new AnalyticsLogObject
{
Type = "Action",
Operation = "PID Enquiry",
ProjectId = project?.Id.ToString(),
ResourceId = resource?.Id.ToString(),
ApplicationsProfile = applicationsProfile,
License = license,
Disciplines = disciplines?.Select(x => x.DisplayNameEn).ToList(),
Organizations = organizations?.Select(x => x.DisplayName).ToList(),
Visibility = project.VisibilityId.HasValue ? _visibilityModel.GetById(project.VisibilityId.Value)?.DisplayName : null,
UserList = owners?.Select(x => x.UserId.ToString()).ToList(),
ExternalInfo = email == null ? null : HashMail(email),
});
}
private static string HashMail(string email)
{
using var sha256Hash = SHA256.Create();
var data = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(email));
var stringBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
stringBuilder.Append(data[i].ToString("x2"));
}
return stringBuilder.ToString();
}
}
}
......@@ -3,8 +3,9 @@
<OutputType>Exe</OutputType>
<RootNamespace>Coscine.Api.Pid</RootNamespace>
<AssemblyName>Coscine.Api.Pid</AssemblyName>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFramework>net5.0</TargetFramework>
<Version>2.1.0</Version>
<Version>2.2.0</Version>
</PropertyGroup>
<PropertyGroup>
<Authors>RWTH Aachen University</Authors>
......@@ -18,5 +19,7 @@
<ItemGroup>
<PackageReference Include="Coscine.Action" Version="2.*-*" />
<PackageReference Include="Coscine.ApiCommons" Version="2.*-*" />
<PackageReference Include="Coscine.Database" Version="2.*-*" />
<PackageReference Include="Coscine.Logging" Version="2.*-*" />
</ItemGroup>
</Project>
\ No newline at end of file