MetadataModel.cs 2.01 KB
Newer Older
1
2
3
4
5
6
7
using Coscine.Api.Project.ReturnObjects;
using Coscine.ApiCommons.Models;
using Coscine.Database.Model;
using LinqToDB;
using System;
using System.Linq;
using System.Linq.Expressions;
8
using System.Web;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

namespace Coscine.Api.Project.Models
{
    public class MetadataModel : DatabaseModel<Resource>
    {

        public MetadataModel() : base(Program.Configuration)
        {
        }

        public override Expression<Func<Resource, Guid>> GetIdFromObject()
        {
            throw new NotImplementedException();
        }

        public override void SetObjectId(Resource databaseObject, Guid id)
        {
            throw new NotImplementedException();
        }

        public override ITable<Resource> GetITableFromDatabase(CoscineDB db)
        {
            throw new NotImplementedException();
        }

        public Resource StoreFromObject(ResourceObject resourceObject)
        {
            Resource resource = new Resource()
            {
                DisplayName = resourceObject.DisplayName,
                ResourceName = resourceObject.ResourceName,
                Keywords = resourceObject.Keywords,
                UsageRights = resourceObject.UsageRights,
                TypeId = resourceObject.Type.Id,
                Type = new ResourceTypeModel().GetById(resourceObject.Type.Id),
                VisibilityId = resourceObject.Visibility.Id,
                LicenseId = resourceObject.License.Id
            };


            return resource;
        }

        public string GenerateId(string resourceId, string filename, string version)
        {
54
55
56
57
58
59
60
61
62
            // Double UrlEncode since converting it to Uri executes one UrlDecode and Virtuoso
            // graph names don't support special characters
            var encodedFileName = HttpUtility.UrlEncode(HttpUtility.UrlEncode(filename));
            return $"https://purl.org/coscine/md/{resourceId}/{encodedFileName}/{version}/";
        }

        public Uri CreateUri(string graphName)
        {
            return new Uri(graphName);
63
64
65
        }
    }
}