Skip to content

Commit 2521db8

Browse files
committed
feat: Use defined ontologies to describe policies
1 parent e86168b commit 2521db8

5 files changed

Lines changed: 45 additions & 35 deletions

File tree

app/controllers/index.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,12 @@ export default class IndexController extends Controller {
267267
matches.prefixes = this.model.addIfNotIncluded(
268268
matches.prefixes,
269269
'pol',
270-
'https://www.example.org/ns/policy#',
270+
'https://w3id.org/DFDP/policy#',
271+
);
272+
matches.prefixes = this.model.addIfNotIncluded(
273+
matches.prefixes,
274+
'http',
275+
'http://www.w3.org/2011/http#',
271276
);
272277

273278
// Re-add the N3 rules to the resource.
@@ -325,7 +330,7 @@ export default class IndexController extends Controller {
325330
}
326331
valid &= !policy.urlError;
327332

328-
if (policy.executionTarget === 'http://example.org/httpRequest') {
333+
if (policy.executionTarget === 'http://www.w3.org/2011/http#Request') {
329334
if (
330335
!['GET', 'POST', 'PUT', 'DELETE', 'PATCH'].includes(policy.method)
331336
) {
@@ -565,15 +570,16 @@ export default class IndexController extends Controller {
565570
if (type && type.startsWith('policy-')) {
566571
let policy = { uuid: uuid(), url: '' };
567572
if (type === 'policy-redirect') {
568-
policy.executionTarget = 'http://example.org/redirect';
573+
policy.executionTarget = 'https://w3id.org/DFDP/policy#Redirect';
569574
} else if (type === 'policy-n3-patch') {
570-
policy.executionTarget = 'http://example.org/n3Patch';
575+
policy.executionTarget =
576+
'http://www.w3.org/ns/solid/terms#InsertDeletePatch';
571577
} else if (type === 'policy-http-request') {
572578
policy = {
573579
...policy,
574580
method: 'POST',
575581
contentType: '',
576-
executionTarget: 'http://example.org/httpRequest',
582+
executionTarget: 'http://www.w3.org/2011/http#Request',
577583
};
578584
}
579585
this.model.policies = [...this.model.policies, policy];
@@ -883,18 +889,20 @@ export default class IndexController extends Controller {
883889
// Add basic properties and N3 rule syntax equal for all policy types.
884890
let data = `
885891
{
886-
<${this.model.loadedFormUri}> ex:event ex:Submit.
892+
<${this.model.loadedFormUri}> pol:event pol:Submit.
887893
} => {
888894
ex:HttpPolicy pol:policy [
889895
a fno:Execution ;
890896
fno:executes <${policy.executionTarget}> ;
891-
ex:url <${policy.url}>`;
897+
http:requestURI <${policy.url}>`;
892898

893899
// If the policy is a HTTP request, add the method and content type.
894-
if (policy.executionTarget === 'http://example.org/httpRequest') {
900+
if (policy.executionTarget === 'http://www.w3.org/2011/http#Request') {
895901
data += ` ;
896-
ex:method "${policy.method}" ;
897-
ex:contentType "${policy.contentType}"`;
902+
http:methodName "${policy.method}" ;
903+
http:headers (
904+
[ http:fieldName "Content-Type" ; http:fieldValue "${policy.contentType}" ]
905+
)`;
898906
}
899907

900908
// Finish the policy syntax.

app/routes/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,25 @@ export default class IndexRoute extends Route {
9999
// Get policies from footprint tasks.
100100
const options = { outputType: 'string' };
101101
const reasonerResult = await n3reasoner(
102-
`<${formUri}> <http://example.org/event> <http://example.org/Submit> .`,
102+
`<${formUri}> <https://w3id.org/DFDP/policy#event> <https://w3id.org/DFDP/policy#Submit> .`,
103103
content,
104104
options,
105105
);
106106

107107
// Parse policies.
108108
const queryPolicy = `
109109
PREFIX ex: <http://example.org/>
110-
PREFIX pol: <https://www.example.org/ns/policy#>
110+
PREFIX pol: <https://w3id.org/DFDP/policy#>
111111
PREFIX fno: <https://w3id.org/function/ontology#>
112+
PREFIX http: <http://www.w3.org/2011/http#>
112113
113114
SELECT ?executionTarget ?method ?url ?contentType WHERE {
114115
?id pol:policy ?policy .
115116
?policy a fno:Execution .
116117
?policy fno:executes ?executionTarget .
117-
?policy ex:url ?url .
118-
OPTIONAL { ?policy ex:method ?method } .
119-
OPTIONAL { ?policy ex:contentType ?contentType } .
118+
?policy http:requestURI ?url .
119+
OPTIONAL { ?policy http:methodName ?method } .
120+
OPTIONAL { ?policy http:headers ( [ http:fieldName "Content-Type" ; http:fieldValue ?contentType ] ) } .
120121
}
121122
`;
122123
const bindings = await (
@@ -125,7 +126,7 @@ export default class IndexRoute extends Route {
125126
{
126127
type: 'stringSource',
127128
value: reasonerResult,
128-
mediaType: 'text/n3',
129+
mediaType: 'text/turtle',
129130
baseIRI: formUri.split('#')[0],
130131
},
131132
],

app/templates/index.hbs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,17 @@
183183
<div class="card">
184184
<div class="card-body">
185185
<div class="d-flex align-items-center field-title">
186-
{{#if (this.isEqual policy.executionTarget "http://example.org/httpRequest") }}
186+
{{#if (this.isEqual policy.executionTarget "http://www.w3.org/2011/http#Request") }}
187187
<h6 class="card-title">
188188
<FaIcon @icon="globe" />
189189
HTTP Request
190190
</h6>
191-
{{else if (this.isEqual policy.executionTarget "http://example.org/redirect") }}
191+
{{else if (this.isEqual policy.executionTarget "https://w3id.org/DFDP/policy#Redirect") }}
192192
<h6 class="card-title">
193193
<FaIcon @icon="external-link" />
194194
Redirect
195195
</h6>
196-
{{else if (this.isEqual policy.executionTarget "http://example.org/n3Patch") }}
196+
{{else if (this.isEqual policy.executionTarget "http://www.w3.org/ns/solid/terms#InsertDeletePatch") }}
197197
<h6 class="card-title">
198198
<FaIcon @icon="file-code" />
199199
N3 Patch
@@ -220,7 +220,7 @@
220220
</div>
221221
</div>
222222

223-
{{#if (this.isEqual policy.executionTarget "http://example.org/httpRequest") }}
223+
{{#if (this.isEqual policy.executionTarget "http://www.w3.org/2011/http#Request") }}
224224
<div class="mb-3 row">
225225
<label for="method-{{policy.uuid}}" id="label-method-{{policy.uuid}}"
226226
class="col-sm-3 col-form-label">HTTP Method</label>
@@ -387,7 +387,8 @@
387387
<div class="input-group mt-3">
388388
<Input @type="text" class="form-control" id="label-{{option.uuid}}" placeholder="Label"
389389
@value={{option.label}} aria-describedby="delete-{{option.uuid}}" />
390-
<Input @type="text" class="form-control" id="binding-{{option.uuid}}" placeholder="Binding"
390+
<Input @type="text" class="form-control" id="binding-{{option.uuid}}"
391+
placeholder="Binding"
391392
@value={{option.property}} aria-describedby="delete-{{option.uuid}}" {{ on
392393
"change" (fn this.updateBinding option) }} />
393394
<button class="btn btn-outline-danger" type="button" id="delete-{{option.uuid}}" {{ on

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@babel/core": "^7.23.6",
2929
"@babel/eslint-parser": "^7.22.15",
3030
"@babel/plugin-transform-class-properties": "^7.23.3",
31-
"@comunica/query-sparql": "^2.6.9",
31+
"@comunica/query-sparql": "^2.10.1",
3232
"@ember/optional-features": "^2.0.0",
3333
"@ember/string": "^3.1.1",
3434
"@ember/test-helpers": "^3.2.0",

0 commit comments

Comments
 (0)