Skip to content
Snippets Groups Projects
Select Git revision
  • 6e7e78ec53c71417bb5a08ee6cb8e2056afedddf
  • master default protected
  • gitkeep
  • dev protected
  • Issue/2449-GuidPidSlugToProjectSettings
  • Issue/2309-docs
  • Issue/2355-topLevelOrg
  • Issue/2328-noFailOnLog
  • Hotfix/2371-fixGitLabinRCV
  • Issue/2287-guestRole
  • Fix/xxxx-activateGitlab
  • Test/xxxx-enablingGitLab
  • Issue/2349-gitlabHttps
  • Issue/2259-updatePids
  • Issue/2101-gitLabResTypeUi
  • Hotfix/2202-fixNaNQuota
  • Issue/2246-quotaResoval
  • Issue/2221-projectDateCreated
  • Hotfix/2224-quotaSizeAnalytics
  • Fix/xxxx-resourceVisibility
  • Issue/2000-gitlabResourcesAPI
  • v4.4.3
  • v4.4.2
  • v4.4.1
  • v4.4.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
  • v4.3.0
  • v4.2.8
  • v4.2.7
  • v4.2.6
  • v4.2.5
  • v4.2.4
  • v4.2.3
  • v4.2.2
  • v4.2.1
  • v4.2.0
  • v4.1.1
  • v4.1.0
41 results

MetadataController.cs

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)