Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get ontologies by project iri #204

Merged
merged 22 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
00ad4f2
test: New generated test data
kilchenmann Jun 18, 2020
7952def
feat(ontology): Get project specific ontologies
kilchenmann Jun 18, 2020
d40ce7a
fix(test): Reverse previous commit
kilchenmann Jun 18, 2020
29aead7
test(ontology): Update test framework and e2e test
kilchenmann Jun 19, 2020
0321445
test(e2e): Get project ontologies
kilchenmann Jun 23, 2020
ae11141
Merge branch 'master' into wip/dsp-71-getOntologiesByProjectIri
kilchenmann Jun 23, 2020
0a2ba40
feat(onto): ReadOntologySequence
kilchenmann Jun 23, 2020
ac6d6f3
chore(gh): Ignore yalc.lock
kilchenmann Jun 23, 2020
3ee6734
test: Get project ontologies for e2e test
kilchenmann Jun 23, 2020
598e127
feat(onto): Get project ontologies
kilchenmann Jun 23, 2020
81c8d7c
Merge branch 'master' into wip/dsp-71-getOntologiesByProjectIri
kilchenmann Jun 23, 2020
f17473e
chore: Ignore build in test-framework
kilchenmann Jun 23, 2020
1b8607c
fix: Fix comma issue
kilchenmann Jun 23, 2020
dded53b
test: Rename variable
kilchenmann Jun 23, 2020
1b26545
Delete yalc.lock
kilchenmann Jun 23, 2020
6e30bad
refactor(onto): Clean up
kilchenmann Jun 23, 2020
cf3870a
refactor(onto): Return OntologiesMetadata
kilchenmann Jun 25, 2020
f67fefb
test(onto): Additional project example
kilchenmann Jun 25, 2020
4151e1e
test(app): Rename section id
kilchenmann Jun 25, 2020
b4ed75e
test(data): Update test data
kilchenmann Jun 25, 2020
da44f14
refactor(onto): Update jsdocs and simplified
kilchenmann Jun 26, 2020
c7da096
fix(onto): Add missing semicolon
kilchenmann Jun 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
/docs
.DS_Store

# Do not add package-lock.json of the test app to git because it could lead to problems when some dependency version change in the lib and is not adapted here.
test-framework/package-lock.json

############################
# PhpStorm/WebStorm ignore #
############################
Expand Down Expand Up @@ -37,7 +34,10 @@ test-framework/package-lock.json
.idea/**/dbnavigator.xml
############################

/test-framework/node_modules
/test-framework/.yalc
/test-framework/dist
# Do not add package-lock.json of the test app to git because it could lead to problems when some dependency version change in the lib and is not adapted here.
test-framework/package-lock.json
test-framework/yalc.lock
test-framework/dist
test-framework/node_modules
test-framework/.yalc
/.tmp
8 changes: 8 additions & 0 deletions scripts/v2-test-data-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
"source": "/v2/ontologies/incunabula-ontology.json",
"destination": "./test/data/api/v2/ontologies/incunabula-ontology.json"
},
{
"source": "/v2/ontologies/get-ontologies-project-anything-response.json",
"destination": "./test/data/api/v2/ontologies/get-ontologies-project-anything-response.json"
},
{
"source": "/v2/ontologies/get-ontologies-project-incunabula-response.json",
"destination": "./test/data/api/v2/ontologies/get-ontologies-project-incunabula-response.json"
},
{
"source": "/v2/resources/testding.json",
"destination": "./test/data/api/v2/resources/testding.json"
Expand Down
27 changes: 25 additions & 2 deletions src/api/v2/ontology/ontologies-endpoint-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Observable } from "rxjs";
import { AjaxResponse } from "rxjs/ajax";
import { catchError, map, mergeMap } from "rxjs/operators";
import { ApiResponseError } from "../../../models/api-response-error";
import { OntologiesMetadata } from "../../../models/v2/ontologies/ontology-metadata";
import { OntologiesMetadata, OntologyMetadata } from "../../../models/v2/ontologies/ontology-metadata";
import { OntologyConversionUtil } from "../../../models/v2/ontologies/OntologyConversionUtil";
import { ReadOntology } from "../../../models/v2/ontologies/read-ontology";
import { Endpoint } from "../../endpoint";
Expand All @@ -27,7 +27,7 @@ export class OntologiesEndpointV2 extends Endpoint {
// TODO: adapt getOntologyIriFromEntityIri
return jsonld.compact(ajaxResponse.response, {});
}), map((jsonldobj: object) => {
return this.jsonConvert.deserializeObject(jsonldobj, OntologiesMetadata);
return OntologyConversionUtil.convertOntologiesList(jsonldobj, this.jsonConvert);
}),
catchError(error => {
return this.handleError(error);
Expand Down Expand Up @@ -58,4 +58,27 @@ export class OntologiesEndpointV2 extends Endpoint {
);
}

/**
* Requests metadata about all ontologies from a specific project
*
* @param projectIri the IRI of the project
* @return OntologiesMetadata or an error
*/
getOntologiesByProjectIri(projectIri: string): Observable<OntologiesMetadata | ApiResponseError> {

return this.httpGet("/metadata/" + encodeURIComponent(projectIri)).pipe(
mergeMap((ajaxResponse: AjaxResponse) => {
// TODO: @rosenth Adapt context object
// TODO: adapt getOntologyIriFromEntityIri
return jsonld.compact(ajaxResponse.response, {});
}), map((jsonldobj: object) => {
return OntologyConversionUtil.convertOntologiesList(jsonldobj, this.jsonConvert);
}),
catchError(error => {
return this.handleError(error);
})
);

}

}
53 changes: 52 additions & 1 deletion src/api/v2/ontology/ontologies-endpoint.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MockAjaxCall } from "../../../../test/mockajaxcall";
import { KnoraApiConfig } from "../../../knora-api-config";
import { KnoraApiConnection } from "../../../knora-api-connection";
import { OntologiesMetadata } from "../../../models/v2/ontologies/ontology-metadata";
import { OntologiesMetadata, OntologyMetadata } from "../../../models/v2/ontologies/ontology-metadata";
import { ReadOntology } from "../../../models/v2/ontologies/read-ontology";
import { ResourceClassDefinition } from "../../../models/v2/ontologies/resource-class-definition";
import { ResourcePropertyDefinition } from "../../../models/v2/ontologies/resource-property-definition";
Expand Down Expand Up @@ -168,4 +168,55 @@ describe("OntologiesEndpoint", () => {

});

describe("Method getOntologiesByProjectIri", () => {

it("should return all ontologies from 'anything' project", done => {

knoraApiConnection.v2.onto.getOntologiesByProjectIri("http://rdfh.ch/projects/0001").subscribe(
(response: OntologiesMetadata) => {
expect(response.ontologies.length).toEqual(3);
expect(response.ontologies[0].id).toEqual("http://0.0.0.0:3333/ontology/0001/anything/v2");
expect(response.ontologies[1].id).toEqual("http://0.0.0.0:3333/ontology/0001/minimal/v2");
expect(response.ontologies[2].id).toEqual("http://0.0.0.0:3333/ontology/0001/something/v2");
done();
}
);

const request = jasmine.Ajax.requests.mostRecent();

const ontoMetadata = require("../../../../test/data/api/v2/ontologies/get-ontologies-project-anything-response.json");
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved

request.respondWith(MockAjaxCall.mockResponse(JSON.stringify(ontoMetadata)));

expect(request.url).toBe("http://0.0.0.0:3333/v2/ontologies/metadata/http%3A%2F%2Frdfh.ch%2Fprojects%2F0001");

expect(request.method).toEqual("GET");

});

it("should return all ontologies from 'incunabula' project", done => {

knoraApiConnection.v2.onto.getOntologiesByProjectIri("http://rdfh.ch/projects/0803").subscribe(
(response: OntologiesMetadata) => {
expect(response.ontologies.length).toEqual(1);
expect(response.ontologies[0].id).toEqual("http://0.0.0.0:3333/ontology/0803/incunabula/v2");
done();
}
);

const request = jasmine.Ajax.requests.mostRecent();

const ontoMetadata = require("../../../../test/data/api/v2/ontologies/get-ontologies-project-incunabula-response.json");

request.respondWith(MockAjaxCall.mockResponse(JSON.stringify(ontoMetadata)));

expect(request.url).toBe("http://0.0.0.0:3333/v2/ontologies/metadata/http%3A%2F%2Frdfh.ch%2Fprojects%2F0803");

expect(request.method).toEqual("GET");

});

});


});
19 changes: 19 additions & 0 deletions src/models/v2/ontologies/OntologyConversionUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ResourceClassDefinition } from "./resource-class-definition";
import { ResourcePropertyDefinition } from "./resource-property-definition";
import { StandoffClassDefinition } from "./standoff-class-definition";
import { SystemPropertyDefinition } from "./system-property-definition";
import { OntologiesMetadata, OntologyMetadata } from "./ontology-metadata";

export namespace OntologyConversionUtil {

Expand Down Expand Up @@ -219,4 +220,22 @@ export namespace OntologyConversionUtil {

};

/**
* Converts a list of ontolgies or a single ontology serialized as JSON-LD to an instance of `OntologiesMetadata`
*
* @param ontologiesJsonld
* @param jsonConvert
*/
export const convertOntologiesList = (ontologiesJsonld: object, jsonConvert: JsonConvert): OntologiesMetadata => {
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved


if (ontologiesJsonld.hasOwnProperty("@graph")) {
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved
return jsonConvert.deserializeObject(ontologiesJsonld, OntologiesMetadata);
} else {
const ontologies: OntologiesMetadata = new OntologiesMetadata();
ontologies.ontologies = [jsonConvert.deserializeObject(ontologiesJsonld, OntologyMetadata)];
return ontologies;
}
};

}
29 changes: 29 additions & 0 deletions test-framework/e2e/src/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,35 @@ describe('workspace-project App', () => {

});


it('request the anything project ontologies', () => {

page.navigateTo();

const button = page.getEle('div section#ontologymetadata button.anything');

button.click();

const result = page.getEle('div section#ontologymetadata span.anything');

expect(result.getText()).toEqual('3 ontologies');

});

it('request the dokubib project ontologies', () => {

page.navigateTo();

const button = page.getEle('div section#ontologymetadata button.dokubib');

button.click();

const result = page.getEle('div section#ontologymetadata span.dokubib');

expect(result.getText()).toEqual('1 ontology');

});

it('request a resource', () => {

page.navigateTo();
Expand Down
12 changes: 12 additions & 0 deletions test-framework/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ <h3>Ontology Cache</h3>
</div>
</section>

<section id="ontologymetadata">
<h3>Project specific ontologies</h3>
<button class="anything" (click)="getAnythingOntologies()">Get anything project ontologies</button>
<div>
Anything project has<br><span class="anything">{{anythingOntologies?.ontologies.length | i18nPlural: itemPluralMapping['ontology']}}</span>
</div>
<button class="dokubib" (click)="getDokubibOntologies()">Get dokubib project ontologies</button>
<div>
Dokubib project has<br><span class="dokubib">{{dokubibOntologies?.ontologies.length | i18nPlural: itemPluralMapping['ontology']}}</span>
</div>
</section>

<section id="resource">
<h3>Resource</h3>
<button class="read" (click)="getResource('http://rdfh.ch/0001/H6gBWUuJSuuO-CilHV8kQw')">Get testding</button> <br /><br />
Expand Down
38 changes: 37 additions & 1 deletion test-framework/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit } from "@angular/core";
import {
ApiResponseData,
ApiResponseError,
Constants,
CountQueryResponse,
CreateBooleanValue,
Expand All @@ -14,6 +15,7 @@ import {
KnoraApiConnection,
ListNodeV2,
LoginResponse,
OntologiesMetadata,
ReadOntology,
ReadResource,
ReadResourceSequence,
Expand All @@ -27,9 +29,10 @@ import {
UsersResponse,
WriteValueResponse,
DeleteResourceResponse,
OntologyMetadata,
MockOntology,
MockProjects,
MockUsers
MockUsers,
} from "@dasch-swiss/dsp-js";

import { map } from "rxjs/operators";
Expand All @@ -46,6 +49,8 @@ export class AppComponent implements OnInit {
userCache: UserCache;

ontologies: Map<string, ReadOntology>;
anythingOntologies: OntologiesMetadata;
dokubibOntologies: OntologiesMetadata;

resource: ReadResource;

Expand All @@ -60,6 +65,13 @@ export class AppComponent implements OnInit {

resourceStatus = '';

itemPluralMapping = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this used for?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it for use with i18nPlural?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's an example how we can use plural and singular notation and I can test in e2e if it's 3 ontologies or 1 ontology. I know, the js-lib is not the best place to use it, but I thought I want to test it in the test-framework.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, got it. Thanks for the explanation.

ontology: {
'=1': '1 ontology',
other: '# ontologies'
}
};

ngOnInit() {
const config = new KnoraApiConfig('http', '0.0.0.0', 3333, undefined, undefined, true);
this.knoraApiConnection = new KnoraApiConnection(config);
Expand Down Expand Up @@ -119,6 +131,30 @@ export class AppComponent implements OnInit {
);
}

getAnythingOntologies() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this one method taking the ontology Iri as a parameter?

You could even make the parameter optional so it would query all ontologies metadata if the param is not provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can write a helper method getProjectOntologies. The thing is I have to handle the response twice. One response is for anything project ontologies, the other one for dokubib project ontology. I need two separate variables here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

this.knoraApiConnection.v2.onto.getOntologiesByProjectIri('http://rdfh.ch/projects/0001').subscribe(
(response: OntologiesMetadata) => {
console.log('anythingOntologies ', response);
this.anythingOntologies = response;
},
(error: ApiResponseError) => {
console.error('project ontologies error', error);
}
)
}
getDokubibOntologies() {
this.knoraApiConnection.v2.onto.getOntologiesByProjectIri('http://rdfh.ch/projects/0804').subscribe(
(response: OntologiesMetadata) => {
console.log('dokubibOntologies ', response);
this.dokubibOntologies = response;
},
(error: ApiResponseError) => {
console.error('project ontologies error', error);
}
)
}


getResourceClass(iri: string) {

this.knoraApiConnection.v2.ontologyCache.getResourceClassDefinition(iri).subscribe(
Expand Down
9 changes: 0 additions & 9 deletions test-framework/yalc.lock

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"@graph":[{"@id":"http://0.0.0.0:3333/ontology/0001/anything/v2","@type":"http://www.w3.org/2002/07/owl#Ontology","http://api.knora.org/ontology/knora-api/v2#attachedToProject":{"@id":"http://rdfh.ch/projects/0001"},"http://api.knora.org/ontology/knora-api/v2#lastModificationDate":{"@type":"http://www.w3.org/2001/XMLSchema#dateTimeStamp","@value":"2017-12-19T15:23:42.166Z"},"http://www.w3.org/2000/01/rdf-schema#label":"The anything ontology"},{"@id":"http://0.0.0.0:3333/ontology/0001/minimal/v2","@type":"http://www.w3.org/2002/07/owl#Ontology","http://api.knora.org/ontology/knora-api/v2#attachedToProject":{"@id":"http://rdfh.ch/projects/0001"},"http://api.knora.org/ontology/knora-api/v2#lastModificationDate":{"@type":"http://www.w3.org/2001/XMLSchema#dateTimeStamp","@value":"2019-09-10T08:57:46.633162Z"},"http://www.w3.org/2000/01/rdf-schema#label":"A minimal ontology"},{"@id":"http://0.0.0.0:3333/ontology/0001/something/v2","@type":"http://www.w3.org/2002/07/owl#Ontology","http://api.knora.org/ontology/knora-api/v2#attachedToProject":{"@id":"http://rdfh.ch/projects/0001"},"http://www.w3.org/2000/01/rdf-schema#label":"The something ontology"}]}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"@graph" : [ {
"@id" : "http://0.0.0.0:3333/ontology/0001/anything/v2",
"@type" : "owl:Ontology",
"knora-api:attachedToProject" : {
"@id" : "http://rdfh.ch/projects/0001"
},
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "2017-12-19T15:23:42.166Z"
},
"rdfs:label" : "The anything ontology"
}, {
"@id" : "http://0.0.0.0:3333/ontology/0001/minimal/v2",
"@type" : "owl:Ontology",
"knora-api:attachedToProject" : {
"@id" : "http://rdfh.ch/projects/0001"
},
"knora-api:lastModificationDate" : {
"@type" : "xsd:dateTimeStamp",
"@value" : "2019-09-10T08:57:46.633162Z"
},
"rdfs:label" : "A minimal ontology"
}, {
"@id" : "http://0.0.0.0:3333/ontology/0001/something/v2",
"@type" : "owl:Ontology",
"knora-api:attachedToProject" : {
"@id" : "http://rdfh.ch/projects/0001"
},
"rdfs:label" : "The something ontology"
} ],
"@context" : {
"knora-api" : "http://api.knora.org/ontology/knora-api/v2#",
"xsd" : "http://www.w3.org/2001/XMLSchema#",
"rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
"owl" : "http://www.w3.org/2002/07/owl#"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"@id":"http://0.0.0.0:3333/ontology/0803/incunabula/v2","@type":"http://www.w3.org/2002/07/owl#Ontology","http://api.knora.org/ontology/knora-api/v2#attachedToProject":{"@id":"http://rdfh.ch/projects/0803"},"http://www.w3.org/2000/01/rdf-schema#label":"The incunabula ontology"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"@id" : "http://0.0.0.0:3333/ontology/0803/incunabula/v2",
"@type" : "owl:Ontology",
"knora-api:attachedToProject" : {
"@id" : "http://rdfh.ch/projects/0803"
},
"rdfs:label" : "The incunabula ontology",
"@context" : {
"knora-api" : "http://api.knora.org/ontology/knora-api/v2#",
"xsd" : "http://www.w3.org/2001/XMLSchema#",
"rdfs" : "http://www.w3.org/2000/01/rdf-schema#",
"owl" : "http://www.w3.org/2002/07/owl#"
}
}