Skip to content
Snippets Groups Projects
Select Git revision
  • master
1 result

68.nfa

Blame
  • 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)