File: SWD.sql

package info (click to toggle)
virtuoso-opensource 7.2.5.1%2Bdfsg1-0.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 285,240 kB
  • sloc: ansic: 641,220; sql: 490,413; xml: 269,570; java: 83,893; javascript: 79,900; cpp: 36,927; sh: 31,653; cs: 25,702; php: 12,690; yacc: 10,227; lex: 7,601; makefile: 7,129; jsp: 4,523; awk: 1,697; perl: 1,013; ruby: 1,003; python: 326
file content (76 lines) | stat: -rw-r--r-- 2,173 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use ODS;

create procedure swd_get_app_type (in svc varchar)
{
  declare app, arr varchar;
  arr := sprintf_inverse (svc, 'urn:openlinksw.com:ods:%s', 0);
  app := arr[0];
  return db.dba.wa_app_to_type (app);
}
;

create procedure "simple-web-discovery" (in principal varchar, in service varchar) __SOAP_HTTP 'application/json'
{
  declare host, mail, uname varchar;
  declare arr, tmp, graph, app any;
  declare f int;

  host := http_host ();
  arr := WS.WS.PARSE_URI (principal);
  graph := sioc..get_graph ();

  if (arr [0] = 'http')
    {
      tmp := (sparql define input:storage "" 
        prefix foaf: <http://xmlns.com/foaf/0.1/> 
      	select ?mbox where 
	 { graph `iri(?:graph)` { `iri(?:principal)` foaf:mbox ?mbox }});
      if (tmp is not null)
        {
	  arr := WS.WS.PARSE_URI (tmp);
	}	  
    } 
  mail := arr[2];
  uname := (select top 1 U_NAME from DB.DBA.SYS_USERS where U_E_MAIL = mail order by U_ID);
  if (uname is null)
    {
      uname := (sparql define input:storage "" 
      	prefix owl: <http://www.w3.org/2002/07/owl#> 
        prefix foaf: <http://xmlns.com/foaf/0.1/> 
      	select ?nick 
         where { graph `iri(?:graph)` { ?s owl:sameAs `iri(?:principal)` ; foaf:nick ?nick . }});
    }
  if (uname is null)
    signal ('22023', sprintf ('The user account "%s" does not exist', principal));
  app := swd_get_app_type (service);
  http ('{\n');
  http (' "locations":[\n');
  for select WAM_HOME_PAGE, WAM_INST, WAM_APP_TYPE 
    from DB.DBA.SYS_USERS, DB.DBA.WA_MEMBER where WAM_USER = U_ID and U_NAME = uname and WAM_MEMBER_TYPE = 1 and WAM_APP_TYPE = app do
    {
      declare url varchar; 
      url := sioc..forum_iri (WAM_APP_TYPE, WAM_INST, uname);
      if (not f)
	f := 1;
      else
	http (',');
      http (sprintf ('   "%s"\n', url));
    }
  http ('   ] \n');
  http ('}\n');
  return '';
}
;

create procedure SWD_INIT ()
{
  DB.DBA.VHOST_REMOVE (lpath=>'/.well-known/simple-web-discovery');
  DB.DBA.VHOST_DEFINE (lpath=>'/.well-known/simple-web-discovery', ppath=>'/SOAP/Http/simple-web-discovery', soap_user=>'ODS_API');
}
;

SWD_INIT ();

grant execute on ODS.DBA."simple-web-discovery" to ODS_API;

use DB;