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 16 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
4 changes: 4 additions & 0 deletions scripts/v2-test-data-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
"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/resources/testding.json",
"destination": "./test/data/api/v2/resources/testding.json"
Expand Down
28 changes: 27 additions & 1 deletion 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 Down Expand Up @@ -58,4 +58,30 @@ export class OntologiesEndpointV2 extends Endpoint {
);
}

/**
* Requests metadata about all ontologies from specific project
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved
*
* @param projectIri the IRI of the project
*/
getOntologiesByProjectIri(projectIri: string): Observable<OntologyMetadata[] | ApiResponseError> {
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved

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) => {
if (jsonldobj.hasOwnProperty("@graph")) {
return (this.jsonConvert.deserializeObject(jsonldobj, OntologiesMetadata).ontologies as OntologyMetadata[]);
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved
} else {
return ([this.jsonConvert.deserializeObject(jsonldobj, OntologyMetadata)] as OntologyMetadata[]);
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved
}
}),
catchError(error => {
return this.handleError(error);
})
);

}

}
31 changes: 30 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,33 @@ 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: OntologyMetadata[]) => {
expect(response.length).toEqual(3);
expect(response[0].id).toEqual("http://0.0.0.0:3333/ontology/0001/anything/v2");
expect(response[1].id).toEqual("http://0.0.0.0:3333/ontology/0001/minimal/v2");
expect(response[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");

});

});


});
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#ontologyendpoint button.anything');

button.click();

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

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

});

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

page.navigateTo();

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

button.click();

const result = page.getEle('div section#ontologyendpoint 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="ontologyendpoint">
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved
<h3>OntologyEndpoint</h3>
<button class="anything" (click)="getAnythingOntologies()">Get anything project ontologies</button>
<div>
Anything project has<br><span class="anything">{{anythingOntologies?.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?.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
35 changes: 35 additions & 0 deletions test-framework/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
UsersResponse,
WriteValueResponse,
DeleteResourceResponse,
ApiResponseError,
OntologyMetadata,
MockOntology,
MockProjects,
MockUsers
Expand All @@ -46,6 +48,8 @@ export class AppComponent implements OnInit {
userCache: UserCache;

ontologies: Map<string, ReadOntology>;
anythingOntologies: OntologyMetadata[];
dokubibOntologies: OntologyMetadata[];

resource: ReadResource;

Expand All @@ -60,6 +64,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 +130,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: OntologyMetadata[]) => {
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: OntologyMetadata[]) => {
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#"
}
}