Commit e6b248f4 authored by Marcel Nellesen's avatar Marcel Nellesen
Browse files

New: Integrated the form generator (coscine/issues#522)

New: Add PID to Resource (coscine/issues#469)
New: Create PID for Resources (coscine/issues#468)
parent 14eb8272
...@@ -56,8 +56,8 @@ ...@@ -56,8 +56,8 @@
<Reference Include="Consul, Version=0.7.2.6, Culture=neutral, PublicKeyToken=20a6ad9a81df1d95, processorArchitecture=MSIL"> <Reference Include="Consul, Version=0.7.2.6, Culture=neutral, PublicKeyToken=20a6ad9a81df1d95, processorArchitecture=MSIL">
<HintPath>..\packages\Consul.0.7.2.6\lib\net45\Consul.dll</HintPath> <HintPath>..\packages\Consul.0.7.2.6\lib\net45\Consul.dll</HintPath>
</Reference> </Reference>
<Reference Include="Coscine.Action, Version=1.6.0.0, Culture=neutral, processorArchitecture=AMD64"> <Reference Include="Coscine.Action, Version=1.7.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\Coscine.Action.1.6.0\lib\net461\Coscine.Action.dll</HintPath> <HintPath>..\packages\Coscine.Action.1.7.0\lib\net461\Coscine.Action.dll</HintPath>
</Reference> </Reference>
<Reference Include="Coscine.ApiCommons, Version=1.2.2.0, Culture=neutral, PublicKeyToken=af4c1345df96546b, processorArchitecture=MSIL"> <Reference Include="Coscine.ApiCommons, Version=1.2.2.0, Culture=neutral, PublicKeyToken=af4c1345df96546b, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.ApiCommons.1.2.2\lib\net461\Coscine.ApiCommons.dll</HintPath> <HintPath>..\packages\Coscine.ApiCommons.1.2.2\lib\net461\Coscine.ApiCommons.dll</HintPath>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<package id="AutoMapper.Extensions.Microsoft.DependencyInjection" version="6.0.0" targetFramework="net472" /> <package id="AutoMapper.Extensions.Microsoft.DependencyInjection" version="6.0.0" targetFramework="net472" />
<package id="Castle.Core" version="4.4.0" targetFramework="net472" /> <package id="Castle.Core" version="4.4.0" targetFramework="net472" />
<package id="Consul" version="0.7.2.6" targetFramework="net472" /> <package id="Consul" version="0.7.2.6" targetFramework="net472" />
<package id="Coscine.Action" version="1.6.0" targetFramework="net472" /> <package id="Coscine.Action" version="1.7.0" targetFramework="net472" />
<package id="Coscine.ApiCommons" version="1.2.2" targetFramework="net472" /> <package id="Coscine.ApiCommons" version="1.2.2" targetFramework="net472" />
<package id="Coscine.Configuration" version="1.4.0" targetFramework="net472" /> <package id="Coscine.Configuration" version="1.4.0" targetFramework="net472" />
<package id="Coscine.Database" version="1.10.0" targetFramework="net472" /> <package id="Coscine.Database" version="1.10.0" targetFramework="net472" />
......
...@@ -39,13 +39,35 @@ namespace Coscine.Api.Project.Controllers ...@@ -39,13 +39,35 @@ namespace Coscine.Api.Project.Controllers
})); }));
} }
[HttpGet("[controller]/resource/{resourceId}/ap/{applicationProfileId}")] // returns the basic application profile
public IActionResult GetApplicationProfile(string resourceId, string applicationProfileId) [HttpGet("[controller]/resource/{projectId}/ap/{applicationProfileId}")]
public IActionResult GetApplicationProfile(Guid projectId, string applicationProfileId)
{
var user = _authenticator.GetUserFromToken();
if (_metadataModel.IsProjectMember(user, projectId))
{
var graph = _util.GetGraph(HttpUtility.UrlDecode(applicationProfileId));
var json = JToken.Parse(VDS.RDF.Writing.StringWriter.Write(graph, new RdfJsonWriter()));
return Ok(json);
}
else
{
throw new NotAuthorizedException("User is no project member!");
}
}
// returns the application profile with the fixed values
[HttpGet("[controller]/resource/{resourceId}/apc/{applicationProfileId}")]
public IActionResult GetApplicationProfileComplete(string resourceId, string applicationProfileId)
{ {
var user = _authenticator.GetUserFromToken(); var user = _authenticator.GetUserFromToken();
var resource = _resourceModel.GetById(Guid.Parse(resourceId)); var resource = _resourceModel.GetById(Guid.Parse(resourceId));
if (_metadataModel.IsProjectMember(user, resource)) if (_metadataModel.IsProjectMember(user, resource) && applicationProfileId != null)
{ {
var graph = _util.GetGraph(HttpUtility.UrlDecode(applicationProfileId)); var graph = _util.GetGraph(HttpUtility.UrlDecode(applicationProfileId));
var fixedValuesGraph = new Graph(); var fixedValuesGraph = new Graph();
...@@ -55,7 +77,7 @@ namespace Coscine.Api.Project.Controllers ...@@ -55,7 +77,7 @@ namespace Coscine.Api.Project.Controllers
graph.Merge(fixedValuesGraph); graph.Merge(fixedValuesGraph);
var json = JToken.Parse(VDS.RDF.Writing.StringWriter.Write(graph, new RdfJsonWriter())); var json = JToken.Parse(VDS.RDF.Writing.StringWriter.Write(graph, new RdfJsonWriter()));
return Ok(json); return Ok(json);
} }
else else
...@@ -65,13 +87,12 @@ namespace Coscine.Api.Project.Controllers ...@@ -65,13 +87,12 @@ namespace Coscine.Api.Project.Controllers
} }
[HttpGet("[controller]/resource/{resourceId}/aplist/")] [HttpGet("[controller]/project/{projectId}/aplist/")]
public IActionResult ListAllApplicationProfiles(string resourceId) public IActionResult ListAllApplicationProfiles(Guid projectId)
{ {
return Ok(_authenticator.ValidateAndExecute((user) => return Ok(_authenticator.ValidateAndExecute((user) =>
{ {
var resource = _resourceModel.GetById(Guid.Parse(resourceId)); if (_metadataModel.IsProjectMember(user, projectId))
if (_metadataModel.IsProjectMember(user, resource))
{ {
var graphUris = _util.ListGraphs(); var graphUris = _util.ListGraphs();
...@@ -169,13 +190,12 @@ namespace Coscine.Api.Project.Controllers ...@@ -169,13 +190,12 @@ namespace Coscine.Api.Project.Controllers
})); }));
} }
[HttpGet("[controller]/vocabulary/{resourceId}/{path}")] [HttpGet("[controller]/vocabulary/{projectId}/{path}")]
public IActionResult GetVocabulary(string resourceId, string path) public IActionResult GetVocabulary(Guid projectId, string path)
{ {
return Ok(_authenticator.ValidateAndExecute((user) => return Ok(_authenticator.ValidateAndExecute((user) =>
{ {
var resource = _resourceModel.GetById(Guid.Parse(resourceId)); if (_metadataModel.IsProjectMember(user, projectId))
if (_metadataModel.IsProjectMember(user, resource))
{ {
var graph = _util.GetGraph(HttpUtility.UrlDecode(path)); var graph = _util.GetGraph(HttpUtility.UrlDecode(path));
......
...@@ -21,6 +21,7 @@ namespace Coscine.Api.Project.Controllers ...@@ -21,6 +21,7 @@ namespace Coscine.Api.Project.Controllers
private readonly ProjectModel _projectModel; private readonly ProjectModel _projectModel;
private readonly IConfiguration _configuration; private readonly IConfiguration _configuration;
private readonly Emitter _emitter; private readonly Emitter _emitter;
public ProjectController() public ProjectController()
{ {
_authenticator = new Authenticator(this, Program.Configuration); _authenticator = new Authenticator(this, Program.Configuration);
......
...@@ -7,6 +7,9 @@ using Microsoft.AspNetCore.Mvc; ...@@ -7,6 +7,9 @@ using Microsoft.AspNetCore.Mvc;
using System; using System;
using System.Linq; using System.Linq;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Coscine.Action;
using Coscine.Configuration;
using Coscine.Action.EventArgs;
namespace Coscine.Api.Project.Controllers namespace Coscine.Api.Project.Controllers
{ {
...@@ -14,11 +17,15 @@ namespace Coscine.Api.Project.Controllers ...@@ -14,11 +17,15 @@ namespace Coscine.Api.Project.Controllers
{ {
private readonly Authenticator _authenticator; private readonly Authenticator _authenticator;
private readonly ResourceModel _resourceModel; private readonly ResourceModel _resourceModel;
private readonly IConfiguration _configuration;
private readonly Emitter _emitter;
public ResourceController() public ResourceController()
{ {
_authenticator = new Authenticator(this, Program.Configuration); _authenticator = new Authenticator(this, Program.Configuration);
_configuration = Program.Configuration;
_resourceModel = new ResourceModel(); _resourceModel = new ResourceModel();
_emitter = new Emitter(this._configuration);
} }
[Route("[controller]")] [Route("[controller]")]
...@@ -83,6 +90,10 @@ namespace Coscine.Api.Project.Controllers ...@@ -83,6 +90,10 @@ namespace Coscine.Api.Project.Controllers
if (_resourceModel.OwnsResource(user, resource)) if (_resourceModel.OwnsResource(user, resource))
{ {
var returnObject = _resourceModel.CreateReturnObjectFromDatabaseObject(resource); var returnObject = _resourceModel.CreateReturnObjectFromDatabaseObject(resource);
_emitter.EmitResourceDelete(new ResourceEventArgs(_configuration)
{
Resource = resource
});
_resourceModel.DeleteResource(resource); _resourceModel.DeleteResource(resource);
return returnObject; return returnObject;
} }
...@@ -108,6 +119,11 @@ namespace Coscine.Api.Project.Controllers ...@@ -108,6 +119,11 @@ namespace Coscine.Api.Project.Controllers
projectModel.AddResource(project, resource); projectModel.AddResource(project, resource);
_emitter.EmitResourceCreate(new ResourceEventArgs(_configuration)
{
Resource = resource
});
return _resourceModel.CreateReturnObjectFromDatabaseObject(resource); return _resourceModel.CreateReturnObjectFromDatabaseObject(resource);
} }
else else
......
...@@ -58,12 +58,24 @@ namespace Coscine.Api.Project.Models ...@@ -58,12 +58,24 @@ namespace Coscine.Api.Project.Models
return DatabaseConnection.ConnectToDatabase((db) => return DatabaseConnection.ConnectToDatabase((db) =>
{ {
return (from relation in db.ProjectRoles return (from relation in db.ProjectRoles
where relation.User == user where relation.UserId == user.Id
&& (relation.Role.DisplayName == "Owner" || relation.Role.DisplayName == "Member") && (relation.Role.DisplayName == "Owner" || relation.Role.DisplayName == "Member")
&& (relation.Project.ProjectResourceProjectIdIds != null && relation.Project.ProjectResourceProjectIdIds. && (relation.Project.ProjectResourceProjectIdIds != null && relation.Project.ProjectResourceProjectIdIds.
Any((projectResource) => projectResource.Resource == resource)) Any((projectResource) => projectResource.Resource == resource))
select relation).Any(); select relation).Any();
}); });
} }
public bool IsProjectMember(User user, Guid projectId)
{
return DatabaseConnection.ConnectToDatabase((db) =>
{
return (from relation in db.ProjectRoles
where relation.UserId == user.Id
&& (relation.Role.DisplayName == "Owner" || relation.Role.DisplayName == "Member")
&& (relation.ProjectId == projectId)
select relation).Any();
});
}
} }
} }
...@@ -192,9 +192,9 @@ namespace Coscine.Api.Project.Models ...@@ -192,9 +192,9 @@ namespace Coscine.Api.Project.Models
{ {
resource.LicenseId = resourceObject.License.Id; resource.LicenseId = resourceObject.License.Id;
} }
// the application profile can not be altered after creation
resource.ApplicationProfile = resourceObject.ApplicationProfile; // resource.ApplicationProfile = resourceObject.ApplicationProfile;
resource.FixedValues = resourceObject.FixedValues.ToString(); resource.FixedValues = resourceObject.FixedValues != null ? resourceObject.FixedValues.ToString() : "{}";
SetDisciplines(resource, resourceObject.Disciplines); SetDisciplines(resource, resourceObject.Disciplines);
SetResourceTypeObject(resource, resourceObject.ResourceTypeOption); SetResourceTypeObject(resource, resourceObject.ResourceTypeOption);
......
...@@ -45,8 +45,8 @@ ...@@ -45,8 +45,8 @@
<Reference Include="Consul, Version=0.7.2.6, Culture=neutral, PublicKeyToken=20a6ad9a81df1d95, processorArchitecture=MSIL"> <Reference Include="Consul, Version=0.7.2.6, Culture=neutral, PublicKeyToken=20a6ad9a81df1d95, processorArchitecture=MSIL">
<HintPath>..\packages\Consul.0.7.2.6\lib\net45\Consul.dll</HintPath> <HintPath>..\packages\Consul.0.7.2.6\lib\net45\Consul.dll</HintPath>
</Reference> </Reference>
<Reference Include="Coscine.Action, Version=1.6.0.0, Culture=neutral, processorArchitecture=AMD64"> <Reference Include="Coscine.Action, Version=1.7.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>..\packages\Coscine.Action.1.6.0\lib\net461\Coscine.Action.dll</HintPath> <HintPath>..\packages\Coscine.Action.1.7.0\lib\net461\Coscine.Action.dll</HintPath>
</Reference> </Reference>
<Reference Include="Coscine.ApiCommons, Version=1.2.2.0, Culture=neutral, PublicKeyToken=af4c1345df96546b, processorArchitecture=MSIL"> <Reference Include="Coscine.ApiCommons, Version=1.2.2.0, Culture=neutral, PublicKeyToken=af4c1345df96546b, processorArchitecture=MSIL">
<HintPath>..\packages\Coscine.ApiCommons.1.2.2\lib\net461\Coscine.ApiCommons.dll</HintPath> <HintPath>..\packages\Coscine.ApiCommons.1.2.2\lib\net461\Coscine.ApiCommons.dll</HintPath>
......
...@@ -9,6 +9,7 @@ namespace Coscine.Api.Project.ReturnObjects ...@@ -9,6 +9,7 @@ namespace Coscine.Api.Project.ReturnObjects
public class ResourceObject : IReturnObject public class ResourceObject : IReturnObject
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string PID { get { return Program.Configuration.GetStringAndWait("coscine/global/epic/prefix") + "/" + Id.ToString(); } }
public string DisplayName { get; set; } public string DisplayName { get; set; }
public string ResourceName { get; set; } public string ResourceName { get; set; }
public string Description { get; set; } public string Description { get; set; }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<package id="AutoMapper" version="8.0.0" targetFramework="net472" /> <package id="AutoMapper" version="8.0.0" targetFramework="net472" />
<package id="AutoMapper.Extensions.Microsoft.DependencyInjection" version="6.0.0" targetFramework="net472" /> <package id="AutoMapper.Extensions.Microsoft.DependencyInjection" version="6.0.0" targetFramework="net472" />
<package id="Consul" version="0.7.2.6" targetFramework="net472" /> <package id="Consul" version="0.7.2.6" targetFramework="net472" />
<package id="Coscine.Action" version="1.6.0" targetFramework="net472" /> <package id="Coscine.Action" version="1.7.0" targetFramework="net472" />
<package id="Coscine.ApiCommons" version="1.2.2" targetFramework="net472" /> <package id="Coscine.ApiCommons" version="1.2.2" targetFramework="net472" />
<package id="Coscine.Configuration" version="1.4.0" targetFramework="net472" /> <package id="Coscine.Configuration" version="1.4.0" targetFramework="net472" />
<package id="Coscine.Database" version="1.10.0" targetFramework="net472" /> <package id="Coscine.Database" version="1.10.0" targetFramework="net472" />
......
Markdown is supported
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