Project 'andrew.cornell/nfa-pruning-analysis' was moved to 'katherine.cornell/nfa-pruning-analysis'. Please update any links and bookmarks that may still have the old path.
Select Git revision
-
Andrew Cornell authoredAndrew Cornell authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
MetadataController.cs 8.77 KiB
using Coscine.Api.Project.Models;
using Coscine.ApiCommons;
using Coscine.ApiCommons.Exceptions;
using Coscine.ApiCommons.Factories;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using VDS.RDF.Writing;
using VDS.RDF.Parsing;
using VDS.RDF;
using Metadata;
using System.Web;
using System.IO;
namespace Coscine.Api.Project.Controllers
{
public class MetadataController : Controller
{
private readonly Authenticator _authenticator;
private readonly MetadataModel _metadataModel;
private readonly ResourceModel _resourceModel;
private readonly Util _util;
public MetadataController()
{
_authenticator = new Authenticator(this, Program.Configuration);
_metadataModel = new MetadataModel();
_resourceModel = new ResourceModel();
_util = new Util();
}
[Route("[controller]")]
public IActionResult Index()
{
return Ok(_authenticator.ValidateAndExecute((user) =>
{
return NoContent();
}));
}
// returns the basic application profile
[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 resource = _resourceModel.GetById(Guid.Parse(resourceId));
if (_metadataModel.IsProjectMember(user, resource) && applicationProfileId != null)